Skip to content

Commit f56c578

Browse files
Merge upstream into humble
2 parents cc31ea7 + acb016b commit f56c578

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

behaviortree_ros2/include/behaviortree_ros2/bt_topic_sub_node.hpp

+15-10
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class RosTopicSubNode : public BT::ConditionNode
5151
protected:
5252
struct SubscriberInstance
5353
{
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);
5555

5656
std::shared_ptr<Subscriber> subscriber;
5757
rclcpp::CallbackGroup::SharedPtr callback_group;
@@ -82,6 +82,7 @@ class RosTopicSubNode : public BT::ConditionNode
8282
std::string topic_name_;
8383
boost::signals2::connection signal_connection_;
8484
std::string subscriber_key_;
85+
rclcpp::QoS qos_profile_;
8586

8687
rclcpp::Logger logger()
8788
{
@@ -156,7 +157,8 @@ class RosTopicSubNode : public BT::ConditionNode
156157
}
157158

158159
private:
159-
bool createSubscriber(const std::string& topic_name);
160+
161+
bool createSubscriber(const std::string& topic_name, const rclcpp::QoS& qos_profile);
160162
};
161163

162164
//----------------------------------------------------------------
@@ -180,14 +182,14 @@ inline RosTopicSubNode<T>::SubscriberInstance::SubscriberInstance(
180182
last_msg = msg;
181183
broadcaster(msg);
182184
};
183-
subscriber = node->create_subscription<T>(topic_name, 1, callback, option);
185+
subscriber = node->create_subscription<T>(topic_name, qos_profile, callback, option);
184186
}
185187

186188
template <class T>
187189
inline RosTopicSubNode<T>::RosTopicSubNode(const std::string& instance_name,
188190
const NodeConfig& conf,
189191
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)
191193
{
192194
// check port remapping
193195
auto portIt = config().input_ports.find("topic_name");
@@ -204,15 +206,15 @@ inline RosTopicSubNode<T>::RosTopicSubNode(const std::string& instance_name,
204206
}
205207
else
206208
{
207-
createSubscriber(params.default_port_value);
209+
createSubscriber(params.default_port_value, params.qos_profile);
208210
}
209211
}
210212
else if(!isBlackboardPointer(bb_topic_name))
211213
{
212214
// If the content of the port "topic_name" is not
213215
// a pointer to the blackboard, but a static string, we can
214216
// create the client in the constructor.
215-
createSubscriber(bb_topic_name);
217+
createSubscriber(bb_topic_name, params.qos_profile);
216218
}
217219
else
218220
{
@@ -229,13 +231,13 @@ inline RosTopicSubNode<T>::RosTopicSubNode(const std::string& instance_name,
229231
}
230232
else
231233
{
232-
createSubscriber(params.default_port_value);
234+
createSubscriber(params.default_port_value, params.qos_profile);
233235
}
234236
}
235237
}
236238

237239
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)
239241
{
240242
if(topic_name.empty())
241243
{
@@ -261,7 +263,7 @@ inline bool RosTopicSubNode<T>::createSubscriber(const std::string& topic_name)
261263
auto it = registry.find(subscriber_key_);
262264
if(it == registry.end() || it->second.expired())
263265
{
264-
sub_instance_ = std::make_shared<SubscriberInstance>(node, topic_name);
266+
sub_instance_ = std::make_shared<SubscriberInstance>(node, topic_name, qos_profile);
265267
registry.insert({ subscriber_key_, sub_instance_ });
266268

267269
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)
283285
[this](const std::shared_ptr<T> msg) { last_msg_ = msg; });
284286

285287
topic_name_ = topic_name;
288+
286289
return true;
287290
}
288291

@@ -303,7 +306,9 @@ inline NodeStatus RosTopicSubNode<T>::tick()
303306

304307
if(!sub_instance_)
305308
{
306-
createSubscriber(topic_name);
309+
std::string topic_name;
310+
getInput("topic_name", topic_name);
311+
createSubscriber(topic_name, qos_profile_);
307312
}
308313

309314
auto CheckStatus = [](NodeStatus status) {

behaviortree_ros2/include/behaviortree_ros2/ros_node_params.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ struct RosNodeParams
4747
RosNodeParams(std::shared_ptr<rclcpp::Node> node, const std::string& port_name)
4848
: nh(node), default_port_value(port_name)
4949
{}
50+
51+
// parameter only used by the subscriber
52+
rclcpp::QoS qos_profile=1;
5053
};
5154

5255
} // namespace BT

0 commit comments

Comments
 (0)