BehaviorTree.ROS2
BehaviorTree.ROS2 copied to clipboard
Make RosTopicSubNode a StatefulActionNode and handle different reliability QoS configurations
There were two things I wanted to improve about the RosTopicSubNode:
- The requirement that
onTick
must strictly either returnSUCCESS
orFAILURE
doesn't match up well with the process of waiting for a message to be received. Practically there are actually three states: the message has not yet been received and we should continueRUNNING
while we wait for it, or the message has been received and the user's code determines if the contents of the message meanSUCCESS
orFAILURE
. - As currently implemented it can't subscribe to publishers that use the BestEffort reliability QoS config, which is often used when publishing sensor data.
Here's what I did to achieve these goals:
- Make RosTopicSubNode a StatefulActionNode. The user's implementation of
onTick
can now returnRUNNING
, which allows explicitly waiting for a new message to be received. This allows the behavior tree to be simpler if the goal is to get a new message before continuing. - Always create the subscriber during the first tick. This solves two problems:
- We can get information about the publishers on the specified topic and dynamically determine the correct QoS settings to use for the subscriber. This lets us handle both Reliable and BestEffort publishers without adding more fields to
RosNodeParams
and requiring the user to set the QoS themselves. This is a partial fix for #14. - Getting the topic name only at runtime requires less handling for special situations than allowing both getting it in the constructor and later getting it at runtime.
- We can get information about the publishers on the specified topic and dynamically determine the correct QoS settings to use for the subscriber. This lets us handle both Reliable and BestEffort publishers without adding more fields to
- Add some tests to exercise these different situations.
I've kept this as a draft for now because I have a few design questions (see comments below).