Ask Your Question
3

Reading rosrun command line arguments inside your node?

asked 2016-11-29 18:35:31 -0600

2ROS0 gravatar image

updated 2016-11-30 13:16:37 -0600

rosrun my_package my_node _param_int:=1 _param_string:="test"

How do I read this inside of the node? I couldn't find something in the tutorials.

Thanks

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
7

answered 2016-11-29 18:45:25 -0600

ahendrix gravatar image

The call to ros::init() will parse argc and argv looking for the := operator and seting private parameters and remappings. It then modifies argc and argvto leave any unrecognized command-line parameters for your code to parse. This behavior is documented in roscpp Initialization and Shutdown

Per the documentation on remapping arguments, any remapping arguments that start with _ are interpreted as setting a private parameter, and other arguments that do not start with _ are interpreted as topic remappings.

As described in roscpp Parameters, you can retrieve private parameters by creating a private NodeHandle and calling getParam() on it:

ros::NodeHandle nh("~");
std::string param;
nh.getParam("private_name", param);

It's also possible to retrieve remappings from a NodeHandle object, but unless you're explicitly trying to use this for more complex topic or service remappings within your node, it's not recommended.

edit flag offensive delete link more

Comments

Ah, what ros::init() does was the missing piece for me - that's sorted now. Thanks.

2ROS0 gravatar image2ROS0 ( 2016-11-30 15:18:34 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2016-11-29 18:35:31 -0600

Seen: 9,496 times

Last updated: Nov 30 '16