@@ -51,7 +51,7 @@ class RosTopicSubNode : public BT::ConditionNode
51
51
protected:
52
52
struct SubscriberInstance
53
53
{
54
- SubscriberInstance (std::shared_ptr<rclcpp::Node> node, const std::string& topic_name);
54
+ SubscriberInstance (std::shared_ptr<rclcpp::Node> node, const std::string& topic_name, const rclcpp::QoS& qos_profile );
55
55
56
56
std::shared_ptr<Subscriber> subscriber;
57
57
rclcpp::CallbackGroup::SharedPtr callback_group;
@@ -82,6 +82,7 @@ class RosTopicSubNode : public BT::ConditionNode
82
82
std::string topic_name_;
83
83
boost::signals2::connection signal_connection_;
84
84
std::string subscriber_key_;
85
+ rclcpp::QoS qos_profile_;
85
86
86
87
rclcpp::Logger logger ()
87
88
{
@@ -156,7 +157,8 @@ class RosTopicSubNode : public BT::ConditionNode
156
157
}
157
158
158
159
private:
159
- bool createSubscriber (const std::string& topic_name);
160
+
161
+ bool createSubscriber (const std::string& topic_name, const rclcpp::QoS& qos_profile);
160
162
};
161
163
162
164
// ----------------------------------------------------------------
@@ -180,14 +182,14 @@ inline RosTopicSubNode<T>::SubscriberInstance::SubscriberInstance(
180
182
last_msg = msg;
181
183
broadcaster (msg);
182
184
};
183
- subscriber = node->create_subscription <T>(topic_name, 1 , callback, option);
185
+ subscriber = node->create_subscription <T>(topic_name, qos_profile , callback, option);
184
186
}
185
187
186
188
template <class T >
187
189
inline RosTopicSubNode<T>::RosTopicSubNode(const std::string& instance_name,
188
190
const NodeConfig& conf,
189
191
const RosNodeParams& params)
190
- : BT::ConditionNode(instance_name, conf), node_(params.nh)
192
+ : BT::ConditionNode(instance_name, conf), node_(params.nh), qos_profile_(params.qos_profile)
191
193
{
192
194
// check port remapping
193
195
auto portIt = config ().input_ports .find (" topic_name" );
@@ -204,15 +206,15 @@ inline RosTopicSubNode<T>::RosTopicSubNode(const std::string& instance_name,
204
206
}
205
207
else
206
208
{
207
- createSubscriber (params.default_port_value );
209
+ createSubscriber (params.default_port_value , params. qos_profile );
208
210
}
209
211
}
210
212
else if (!isBlackboardPointer (bb_topic_name))
211
213
{
212
214
// If the content of the port "topic_name" is not
213
215
// a pointer to the blackboard, but a static string, we can
214
216
// create the client in the constructor.
215
- createSubscriber (bb_topic_name);
217
+ createSubscriber (bb_topic_name, params. qos_profile );
216
218
}
217
219
else
218
220
{
@@ -229,13 +231,13 @@ inline RosTopicSubNode<T>::RosTopicSubNode(const std::string& instance_name,
229
231
}
230
232
else
231
233
{
232
- createSubscriber (params.default_port_value );
234
+ createSubscriber (params.default_port_value , params. qos_profile );
233
235
}
234
236
}
235
237
}
236
238
237
239
template <class T >
238
- inline bool RosTopicSubNode<T>::createSubscriber(const std::string& topic_name)
240
+ inline bool RosTopicSubNode<T>::createSubscriber(const std::string& topic_name, const rclcpp::QoS& qos_profile )
239
241
{
240
242
if (topic_name.empty ())
241
243
{
@@ -261,7 +263,7 @@ inline bool RosTopicSubNode<T>::createSubscriber(const std::string& topic_name)
261
263
auto it = registry.find (subscriber_key_);
262
264
if (it == registry.end () || it->second .expired ())
263
265
{
264
- sub_instance_ = std::make_shared<SubscriberInstance>(node, topic_name);
266
+ sub_instance_ = std::make_shared<SubscriberInstance>(node, topic_name, qos_profile );
265
267
registry.insert ({ subscriber_key_, sub_instance_ });
266
268
267
269
RCLCPP_INFO (logger (), " Node [%s] created Subscriber to topic [%s]" , name ().c_str (),
@@ -283,6 +285,7 @@ inline bool RosTopicSubNode<T>::createSubscriber(const std::string& topic_name)
283
285
[this ](const std::shared_ptr<T> msg) { last_msg_ = msg; });
284
286
285
287
topic_name_ = topic_name;
288
+
286
289
return true ;
287
290
}
288
291
@@ -303,7 +306,9 @@ inline NodeStatus RosTopicSubNode<T>::tick()
303
306
304
307
if (!sub_instance_)
305
308
{
306
- createSubscriber (topic_name);
309
+ std::string topic_name;
310
+ getInput (" topic_name" , topic_name);
311
+ createSubscriber (topic_name, qos_profile_);
307
312
}
308
313
309
314
auto CheckStatus = [](NodeStatus status) {
0 commit comments