Skip to content

Commit 3c5bb9b

Browse files
committed
feat: allows message clearing behaviour to be customised by the implementer
1 parent d4da1cf commit 3c5bb9b

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

behaviortree_ros2/include/behaviortree_ros2/bt_topic_sub_node.hpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,16 @@ class RosTopicSubNode : public BT::ConditionNode
173173
*/
174174
virtual NodeStatus onTick(const std::shared_ptr<TopicT>& last_msg) = 0;
175175

176+
/** Clear the message that has been processed. If returns true and no new message is
177+
* received, before next call there will be no message to process. If returns false,
178+
* the next call will process the same message again, if no new message received.
179+
*
180+
* This can be equated with latched vs non-latched topics in ros 1.
181+
*
182+
* @return true will clear the message after ticking/processing.
183+
*/
184+
virtual bool clear_processed_message() { return true; }
185+
176186
private:
177187

178188
bool createSubscriber(const std::string& topic_name);
@@ -294,8 +304,10 @@ template<class T> inline
294304
};
295305
sub_instance_->callback_group_executor.spin_some();
296306
auto status = CheckStatus (onTick(last_msg_));
297-
last_msg_ = nullptr;
298-
307+
if (clear_processed_message())
308+
{
309+
last_msg_ = nullptr;
310+
}
299311
return status;
300312
}
301313

0 commit comments

Comments
 (0)