Skip to content
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

Closed
wants to merge 7 commits into from
Closed

add initial ui_script prototype #10

wants to merge 7 commits into from

Conversation

jashlu
Copy link
Collaborator

@jashlu jashlu commented Aug 7, 2024

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

@jashlu
Copy link
Collaborator Author

jashlu commented Aug 7, 2024

Screenshot 2024-08-07 at 3 45 33 PM

@jashlu jashlu requested review from hollandjg and zzaydin August 7, 2024 19:50
approach_door = py_trees.behaviours.Success(name="approach_door")

#go_through_door
go_through_door = py_trees.behaviours.Dummy(name="go_through_door")
Copy link
Collaborator

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?

Copy link
Collaborator Author

@jashlu jashlu Aug 8, 2024

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")
Copy link
Collaborator

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)?

Copy link
Collaborator Author

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

Copy link
Collaborator

@zzaydin zzaydin left a 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!

Copy link
Member

@hollandjg hollandjg left a 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):
Copy link
Member

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?

Suggested change
def main(tick_time: float = 1):
def main():


root = py_trees.composites.Sequence(name="Sequence", memory=False)

#approach_door
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with this one

Comment on lines +34 to +45
# 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")
Copy link
Member

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:
Copy link
Member

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?

Copy link
Member

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")

Copy link
Member

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?

Comment on lines +49 to +52
index = 1
for x in root.children:
print(f"{index}. {x.name}")
index += 1
Copy link
Member

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.

Suggested change
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: ")
Copy link
Member

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")

Copy link
Member

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.

Copy link
Member

@hollandjg hollandjg left a 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!

Comment on lines +22 to +25
4. (Temporary) You may need to install the py trees library
```
pip install py_trees
```
Copy link
Member

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.

Suggested change
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

@hollandjg
Copy link
Member

Closing initial PRs – merged everything to main and starting over from there.

@hollandjg hollandjg closed this Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants