Ask Your Question
0

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

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

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 reopen merge delete

Closed for the following reason question is not relevant or outdated by pnn16004
close date 2022-01-24 14:55:40.278701

1 Answer

Sort by ยป oldest newest most voted
0

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

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

Stats

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

Seen: 119 times

Last updated: Jan 24