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

set parameter using launch file

asked 2015-03-23 10:50:32 -0500

Carollour gravatar image

I have three different but related questions

1st: Is it possible to set the value of a variable using the launch file? I read about it online but I couldn't understand how to use it.

2nd: I couldn't find anything on how to use the launch file to set the value of a variable in a message. for instance if I have:


mymessage myvector[2]


int32 value
string ID

Is there a way to set the myvector[0].ID="ID1" and myvector[1].ID="ID2" and always publish that without having to define it everytime I sent the message to a topic?

3rd: If I don't know how many variables I have and I want to publish each variable in a different topic like /commontopic/var1 ; /commontopic/var2 ; /commontopic/varN , is there a way to achieve this using the terminal? Thank you in advance

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-03-23 13:34:05 -0500

Tabjones gravatar image

1st) Take a look here: roslaunch/xml/param.

For example you can set the parameter test to be a double of value 2.0:

<param name="test" type="double" value="2.0" />

Now the parameter 'test' is loaded into ROS parameter server and you can access it from your node like this:

double testvar;
node_handle.getParam("/test", testvar);
std::cout<<testvar; //prints 2

Look also here for more examples.

2nd) You can do this using the method described above, simply load ID1 and ID2 as default values of parameters and load them inside your node where you can publish them.

3rd) I don't think there's a way to do this from command line only, AFAIK, and i would not endorse that, what if there are 1000 variables? creating a tousand topics would probaly clog your system.

I think the best way would be to create a custom message with an array, if the variables are double the message would look like this:

double[] myvars

Then the subscriber can parse the message and determine how many variables are there.

edit flag offensive delete link more


Thank you, that helped!

Carollour gravatar image Carollour  ( 2015-03-24 05:34:30 -0500 )edit

Question Tools



Asked: 2015-03-23 10:50:32 -0500

Seen: 6,952 times

Last updated: Mar 23 '15