@@ -66,6 +66,7 @@ class RosTopicSubNode : public BT::ConditionNode
66
66
// The callback will broadcast to all the instances of RosTopicSubNode<T>
67
67
auto callback = [this ](const std::shared_ptr<TopicT> msg)
68
68
{
69
+ last_msg = msg;
69
70
broadcaster (msg);
70
71
};
71
72
subscriber = node->create_subscription <TopicT>(topic_name, 1 , callback, option);
@@ -75,6 +76,7 @@ class RosTopicSubNode : public BT::ConditionNode
75
76
rclcpp::CallbackGroup::SharedPtr callback_group;
76
77
rclcpp::executors::SingleThreadedExecutor callback_group_executor;
77
78
boost::signals2::signal<void (const std::shared_ptr<TopicT>)> broadcaster;
79
+ std::shared_ptr<TopicT> last_msg = nullptr ;
78
80
79
81
80
82
};
@@ -270,6 +272,11 @@ template<class T> inline
270
272
sub_instance_ = it->second ;
271
273
}
272
274
275
+ // Check if there was a message received before the creation of this subscriber action
276
+ if (sub_instance_.last_msg )
277
+ {
278
+ last_msg_ = sub_instance_.last_msg ;
279
+ }
273
280
274
281
// add "this" as received of the broadcaster
275
282
signal_connection_ = sub_instance_->broadcaster .connect (
@@ -286,12 +293,18 @@ template<class T> inline
286
293
// First, check if the subscriber_ is valid and that the name of the
287
294
// topic_name in the port didn't change.
288
295
// otherwise, create a new subscriber
296
+ std::string topic_name;
297
+ getInput (" topic_name" , topic_name);
298
+
289
299
if (!sub_instance_)
290
300
{
291
- std::string topic_name;
292
- getInput (" topic_name" , topic_name);
293
301
createSubscriber (topic_name);
294
302
}
303
+ else if (topic_name_ != topic_name)
304
+ {
305
+ sub_instance_.reset ();
306
+ createSubscriber (topic_name_);
307
+ }
295
308
296
309
auto CheckStatus = [](NodeStatus status)
297
310
{
0 commit comments