splintered-reality / py_trees

Python implementation of behaviour trees.
Other
415 stars 139 forks source link

Blocking behaviours question #420

Closed DarkJoker9817 closed 10 months ago

DarkJoker9817 commented 1 year ago

Hello, thanks for your work on this library, I have a doubt about the execution of the tree. What if a custom Behaviour is blocking, for example when in the update method there is a call to a ROS service that takes longer to execute than the tree tick period? What is the 'behaviour' of the tree in this case?

stonier commented 1 year ago

If you're the curator of a tree, you have to keep an eye on problems like these. The tree manager drops some statistics on tree tick time for diagnosing exactly these problems. Options:

  1. Use blocking service calls. Might be ok if you've only a couple and those calls are local. No guarantees, not recommended.
  2. Put a timeout on the blocking service call request. Still touch and go - you risk slowing the tree down with too many of these and/or not providing enough time for the response.
  3. Use a non-blocking (async) service call. Pick up the future response in a subsequent tick of the tree. Ros2 has these I believe, Ros1 doesn't.
  4. Use an action client (similar to a non-blocking service call)
  5. Use a pub-sub pair, pick up the response on the sub in a future tick
DarkJoker9817 commented 1 year ago

OK thank you very much, I'm already using action clients and pub-sub, mine was just a curiosity about how the behavior of the tree might evolve in that case. In which class I can find tree manager?

stonier commented 10 months ago

Very late reply sorry, but you'd be looking for the ROS tree manager, look at py_trees_ros.trees.BehaviourTree.