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

Revision history [back]

click to hide/show revision 1
initial version

roslaunch guarantees that all of the parameters set in the launch file will be set before your node starts.

So roslaunch sets the parameter to 1 before starting your node.

Once your node starts, it immediately sets the parameter to 0.

Then your node reads the parameter, and gets the value 0.

It sounds like you want your node to have a default value for the parameter, and you want to override that from the launch file. the common way to do this is by explicitly specifying a default value when you get parameter.

This is documented on the roscpp parameters page, and the syntax for it looks like:

int b;
nh.param<int>("param_str", b, 0);

This will fetch the value of the param_str parameter into b, and use the value 0 if the parameter is not set. You can then set param_str in your launch file (as you have already done) to override the default value of 0.