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

ROS2 Resolve topic names rclcpp

asked 2021-02-12 09:44:17 -0500

vinny gravatar image

updated 2021-02-17 11:31:28 -0500

In ros1 cpp I was able to resolve a string containing the topic name to the actual topic name that accounts for remappings using the following block:

  // Determine topic name (including remapping)
  std::string mag_topic_name = "/imu/mag";
  mag_topic_name = ros::names::resolve(mag_topic_name);

Is there a similar way I can do this in rclcpp ROS2? I tried digging through the documentations, but could not find something.

Thanks in advance!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-11-21 21:12:27 -0500

KenYN gravatar image

I've been looking for this today, and there is a function in Galactic Rolling:

RCLCPP_PUBLIC std::string resolve_topic_name(const std::string & name, bool only_expand = false) const override;

See this pull request. I've copied the code over to my own node.

The only_expand parameter, if true, just adds on the namespace. If false, it also applies remapping, which is probably the option you want.

edit flag offensive delete link more

Question Tools



Asked: 2021-02-12 09:44:17 -0500

Seen: 738 times

Last updated: Nov 21 '21