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

What's the difference to name a topic with or without "/"

asked 2023-08-07 20:12:24 -0600

felixf4xu gravatar image

Hi,

In ros2 programming, sometimes I see code like this:

nh->create_publisher<sensor_msgs::msg::PointCloud2>("/ndt_map", 1000);

the topic name has a prefix of "/";

sometimes I see code like this:

nh->create_subscription<sensor_msgs::msg::PointCloud2>("points_raw",

the topic name has no "/".

What's the difference?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-08-08 02:14:42 -0600

updated 2023-08-08 02:15:22 -0600

The difference appear when using namespaces. If I am using a node with namespace "robot1" and subscribe to the topic "/my_topic" it will subscribe to this topic. But if I subscribe to the topic "my_topic" the node will subscribe to the topic "/robot1/my_topic".

You can add namespaces when launch a node from a launch file by using the group tag for example

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2023-08-07 20:12:24 -0600

Seen: 182 times

Last updated: Aug 08 '23