ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
I like to create parameters in my node that are used to set the topic names for all the publishers, and then set those parameters using a private node handle. The result is that your topics will have a prefix of the node name, including namespaces. For example, if you were to have a node acting as a driver for an IMU then you could simply have your topic names default to
ros::NodeHandle pnh("~");
std::string raw_pub_topic_name;
std::string cal_pub_topic_name;
pnh.param("raw_pub_topic_name", raw_pub_topic_name, std::string("raw"));
pnh.param("cal_pub_topic_name", cal_pub_topic_name, std::string("calibrated"));
In your launch file, if you simply start the node and give it the name imu_node
then your topics will be
/imu_node/raw
/imu_node/calibrated
However, if your launch file started 2 of your IMU nodes (both with the name imu_node
) with one pushed down into the left_arm
namespace and the other pushed down into the torso
namespace then you would end up with your topics being published on
/left_arm/imu_node/raw
/left_arm/imu_node/calibrated
/torso/imu_node/raw
/torso/imu_node/calibrated
The benefit of this is that if you have another node written that is supposed to listen for these topics then you can do the same thing for your subscribers. Just create parameters for the subscription topics using a private node handle, have them default to imu_node/raw
and imu_node/calibrated
, and then push them into appropriate namespaces so that they will get left_arm
or torso
.