BehaviorTree / BehaviorTree.ROS2

BehaviorTree.CPP utilities to work with ROS2
Apache License 2.0
144 stars 59 forks source link

Add get_clock() method #77

Open EGAlberts opened 2 months ago

EGAlberts commented 2 months ago

When using ROS2 logging it is desirable to throttle logged messages to keep output manageable ([https://docs.ros.org/en/humble/Tutorials/Demos/Logging-and-logger-configuration.html#logging-throttled]).

To do so, you need access to the node's clock. Since with new changes there is no more direct access to the node object within a subclass of bt_action_node and bt_service_node it is not possible to get the clock and therefore not possible to log with throttling. This PR adds a get_clock() method to the parent classes which can be used to for throttled logging which I exemplify with an Feedback callback in the existing sleep action sample.

N.B. The samples are still broken in the latest commit. To use any sample (including my edit to exemplify the PR), you need to use BT.CPP with pull 804 https://github.com/BehaviorTree/BehaviorTree.CPP/pull/804 because this actually exports the plugins to be used by the sample behavior trees. I would suggest that you please merge that PR before this one.