sea-bass / turtlebot3_behavior_demos

Example repository for autonomous behaviors using TurtleBot3, as well as Docker workflows in ROS based projects.
MIT License
270 stars 53 forks source link

OneShot behavior and queue #50

Closed SyZbidi closed 1 month ago

SyZbidi commented 1 month ago

Hello

I came across your article about behavior_trees, and the GetFromQueue inspired me to find a work around the repeat decorator (I'm using py_trees).

I was looking for a way to make num_success of repeat configurable because my robot needs to move along a surface a number of times that depends on the length of this surface, sometimes 2 sometimes 4 or 5, but I think that doesn't work if I set num_success from a blackboard for example. So I thought if I use your approach to write those counts on a blackboard then have a retry and check if that number has been reached -> return success maybe that will work.

My question to you is if the queue is empty and it returns failure, wouldn't the tree fail and abort? how do you work around that? I also saw that in your blog the CPP version of BT has a behavior called retry until successful is there something similar in py_trees?

My last question, I don't get the OneShot concept, (I would've asked in py_trees repo but they're anot answering for awhile) does it only return success after all the children are successful or returns success fo a specific child?

Thanks!

sea-bass commented 1 month ago

I was looking for a way to make num_success of repeat configurable because my robot needs to move along a surface a number of times that depends on the length of this surface, sometimes 2 sometimes 4 or 5, but I think that doesn't work if I set num_success from a blackboard for example. So I thought if I use your approach to write those counts on a blackboard then have a retry and check if that number has been reached -> return success maybe that will work.

It could if you modify the Repeat decorator source code (that is, make a copy and name it something else), and then change the num_success value from a constructor argument to a proper blackboard variable that gets read in initialise().

My question to you is if the queue is empty and it returns failure, wouldn't the tree fail and abort? how do you work around that? I also saw that in your blog the CPP version of BT has a behavior called retry until successful is there something similar in py_trees?

There is a Retry decorator in py_trees as well, though the number of attempts is int meaning it has a finite limit. Similarly to the above question, I'm sure one can make quick modifications to be able to support infinite retries (if you need it), but otherwise should work.

My last question, I don't get the OneShot concept, (I would've asked in py_trees repo but they're anot answering for awhile) does it only return success after all the children are successful or returns success fo a specific child?

I may be sounding like a broken record, but check out the OneShot decorator source code. Nominally, these behavior tree nodes will keep ticking, meaning a terminated node ticked again will re-initialize and keep looping forever... unless you use a "OneShot" pattern to tell it to stop updating if it's hit some particular event. As you can see, the options are either

So technically you could also implement the "retry until success" from your previous question with this decorator.

But as always, testing for yourself is the best way to see what works!

SyZbidi commented 1 month ago

Nominally, these behavior tree nodes will keep ticking, meaning a terminated node ticked again will re-initialize and keep looping forever... unless you use a "OneShot" pattern to tell it to stop updating if it's hit some particular event.

I didn't get this from the documentation, thank you

and thank you for the rest of the suggestions, changing the Repeat is a good idea, will try things out and test