-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add initial ui_script prototype #10
Conversation
approach_door = py_trees.behaviours.Success(name="approach_door") | ||
|
||
#go_through_door | ||
go_through_door = py_trees.behaviours.Dummy(name="go_through_door") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is approaching the door is "success" but not going through? We won't be changing this behavior, right? We are just adding another one in between? Is the "dummy" there because they will shift down in the three?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey thanks for taking a look at the code, that is actually my fault. approach_door
should actually be a Dummy like go_through_door
. I just forgot to change it.
To give a little more context, we are just trying to demonstrate what it would look like communicating a change to the behavior tree by choosing a new behavior and adding it somewhere inside the behavior tree. If you look at the rest of the code, you will notice I don't actually call the "tick()" function which is what runs the behavior tree, so we're not even running the behavior tree yet in this script. I think we just wanted to show an example of what it would be like for the user to go through the process of making an update to the tree. Correct me if i'm wrong @hollandjg
|
||
# Get user input to decide which behavior to add | ||
print("1. Knock on door") | ||
print("2. Sound siren") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the user chooses 2 or 3, will we accept it or claim that it is not appropriate for the situation (or some type of other error message)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We haven't gotten that far yet, but that could definitely be something we add next. I think at this point we could go in multiple directions, such as working on the error checking like you said, or simulating "what comes next" after you make a change to the tree. I think we could have a great discussion about this on Monday, after showing Bertram this basic but important first part of the prototype
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanations, @jashlu!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey Josh, thanks for putting this together! I've got some suggestions for simplifications and a couple of UI bugs I found.
import py_trees | ||
|
||
|
||
def main(tick_time: float = 1): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we're using this variable, so should we remove it?
def main(tick_time: float = 1): | |
def main(): |
|
||
root = py_trees.composites.Sequence(name="Sequence", memory=False) | ||
|
||
#approach_door |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment is redundant – the following line says the same thing.
#approach_door | ||
approach_door = py_trees.behaviours.Dummy(name="approach_door") | ||
|
||
#go_through_door |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same with this one
# Get user input to decide which behavior to add | ||
print("1. Knock on door") | ||
print("2. Sound siren") | ||
print("3. Turn around") | ||
behavior_choice = input("Enter the number of which behavior to add to the tree: ") | ||
|
||
if behavior_choice == "1": | ||
new_behavior = py_trees.behaviours.Dummy(name="knock_on_door") | ||
elif behavior_choice == "2": | ||
new_behavior = py_trees.behaviours.Dummy(name="sound_siren") | ||
elif behavior_choice == "3": | ||
new_behavior = py_trees.behaviours.Dummy(name="turn_around") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels to me like a lot of duplication of the names like "knock on door" / "knock_on_door". Is there a way we could abstract it?
# Get user to decide where to place new behavior in the tree | ||
index_choice = input("Enter the number of which behavior to place the new behavior in front of: ") | ||
|
||
if index_choice: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you say something about this line? What's the check you're doing here? What happens if the user doesn't give an index?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be good to run the black
or ruff format
on all our python files, so we have consistent new-lines and comment formatting – will reduce some of the noise in the PRs.
new_behavior = py_trees.behaviours.Dummy(name="sound_siren") | ||
elif behavior_choice == "3": | ||
new_behavior = py_trees.behaviours.Dummy(name="turn_around") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I input something like e
, it causes an error because new_behavior isn't defined. Any ideas how to fix that?
index = 1 | ||
for x in root.children: | ||
print(f"{index}. {x.name}") | ||
index += 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use the enumerate
builtin here to make this a bit simpler.
index = 1 | |
for x in root.children: | |
print(f"{index}. {x.name}") | |
index += 1 | |
for index, x in enumerate(root.children): | |
print(f"{index + 1}. {x.name}") |
print(f"{index}. {x.name}") | ||
index += 1 | ||
# Get user to decide where to place new behavior in the tree | ||
index_choice = input("Enter the number of which behavior to place the new behavior in front of: ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if I want to put it at the end?
new_behavior = py_trees.behaviours.Dummy(name="sound_siren") | ||
elif behavior_choice == "3": | ||
new_behavior = py_trees.behaviours.Dummy(name="turn_around") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if I input "4"? I think it'll crash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more minor change, and then the README is good to merge!
4. (Temporary) You may need to install the py trees library | ||
``` | ||
pip install py_trees | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be necessary – it's in the dependencies.
4. (Temporary) You may need to install the py trees library | |
``` | |
pip install py_trees | |
``` |
[rst]: http://docutils.sourceforge.net/rst.html | ||
[md]: https://tools.ietf.org/html/rfc7764#section-3.5 "CommonMark variant" | ||
[md use]: https://packaging.python.org/specifications/core-metadata/#description-content-type-optional | ||
5. Now you can navigate to the file you want to run, and press the triangle play button to run the py_tree file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5. Now you can navigate to the file you want to run, and press the triangle play button to run the py_tree file. | |
4. Now you can navigate to the file you want to run, and press the triangle play button to run the py_tree file. |
Closing initial PRs – merged everything to main and starting over from there. |
This is an example of a basic interaction where the user chooses 1 of 3 different behaviors to add to the behavior tree.
The user also chooses where (in front of which existing behavior) to add the new behavior.
Lastly, the updated behavior tree is displayed to the user