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

Revision history [back]

The best way to do this using the ROS system is to use the parameter system. This allows the setting to be controlled when you start the node by itself using rosrun or as part of a larger launch file. You would run your node using the following command:

rosrun <package_name> <node_name> _topic:=<topic_name>

You can then access this parameter in your node using the following code:

ros::NodeHandle n("~");
std::string topicName;
n.param<std::string>("topic", topicName, "default_topic");
printf("topic is [%s]\n", topicName.c_str() );

Hope this helps.