From 3c5bb9b485930773911b834943eed6e722c42eed Mon Sep 17 00:00:00 2001 From: Tony Paulussen Date: Wed, 31 Jan 2024 11:06:39 +0100 Subject: [PATCH 1/2] feat: allows message clearing behaviour to be customised by the implementer --- .../behaviortree_ros2/bt_topic_sub_node.hpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/behaviortree_ros2/include/behaviortree_ros2/bt_topic_sub_node.hpp b/behaviortree_ros2/include/behaviortree_ros2/bt_topic_sub_node.hpp index 311594b..7ea9fc6 100644 --- a/behaviortree_ros2/include/behaviortree_ros2/bt_topic_sub_node.hpp +++ b/behaviortree_ros2/include/behaviortree_ros2/bt_topic_sub_node.hpp @@ -173,6 +173,16 @@ class RosTopicSubNode : public BT::ConditionNode */ virtual NodeStatus onTick(const std::shared_ptr& last_msg) = 0; + /** Clear the message that has been processed. If returns true and no new message is + * received, before next call there will be no message to process. If returns false, + * the next call will process the same message again, if no new message received. + * + * This can be equated with latched vs non-latched topics in ros 1. + * + * @return true will clear the message after ticking/processing. + */ + virtual bool clear_processed_message() { return true; } + private: bool createSubscriber(const std::string& topic_name); @@ -294,8 +304,10 @@ template inline }; sub_instance_->callback_group_executor.spin_some(); auto status = CheckStatus (onTick(last_msg_)); - last_msg_ = nullptr; - + if (clear_processed_message()) + { + last_msg_ = nullptr; + } return status; } From ac2e0ac6938ad97e23973541b6d32c0396fc571c Mon Sep 17 00:00:00 2001 From: Tony Paulussen Date: Fri, 2 Feb 2024 13:53:23 +0100 Subject: [PATCH 2/2] style: match camel case function name --- .../include/behaviortree_ros2/bt_topic_sub_node.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/behaviortree_ros2/include/behaviortree_ros2/bt_topic_sub_node.hpp b/behaviortree_ros2/include/behaviortree_ros2/bt_topic_sub_node.hpp index 7ea9fc6..a2ed0d4 100644 --- a/behaviortree_ros2/include/behaviortree_ros2/bt_topic_sub_node.hpp +++ b/behaviortree_ros2/include/behaviortree_ros2/bt_topic_sub_node.hpp @@ -181,7 +181,7 @@ class RosTopicSubNode : public BT::ConditionNode * * @return true will clear the message after ticking/processing. */ - virtual bool clear_processed_message() { return true; } + virtual bool clearProcessedMessage() { return true; } private: @@ -304,7 +304,7 @@ template inline }; sub_instance_->callback_group_executor.spin_some(); auto status = CheckStatus (onTick(last_msg_)); - if (clear_processed_message()) + if (clearProcessedMessage()) { last_msg_ = nullptr; }