ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

[ROS2] How to set QoS policy for topic in cpp script

asked 2022-01-17 23:37:46 -0600

pnn16004 gravatar image

How do I set QoS policy when initializing a publisher or subscriber in rclcpp?

In micro-ROS I only need to do, e.g rclc_publisher_init_best_effort() to set the best effort policy for a publisher.

I'm currently able to set the queue depth like this:

sub_ = this->create_subscription<std_msgs::msg::string>( "topic", rclcpp::QoS(QUEUE_DEPTH), std::bind(&Node::callback, this, std::placeholders::_1));

But what do I write to set the QoS policy? Is it possible to only change the policy like this without needing to create a whole QoS profile?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2022-01-24 14:55:17 -0600

pnn16004 gravatar image

I guess it isn't possible. For now I'm solving it by using the sensor data profile as following:

rmw_qos_profile_t qos_profile = rmw_qos_profile_sensor_data;
auto qos = rclcpp::QoS(rclcpp::QoSInitialization(qos_profile.history, QUEUE_DEPTH), qos_profile);

sub_ = this->create_subscription<std_msgs::msg::Header>(
SUB_TOPIC_NAME, qos, std::bind(&Node::callback, this, std::placeholders::_1));
edit flag offensive delete link more

Question Tools

1 follower


Asked: 2022-01-17 23:37:46 -0600

Seen: 2,172 times

Last updated: Jan 24 '22