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

Negative values in launch file arguments

asked 2016-04-27 05:37:09 -0500

Orhan gravatar image

updated 2016-04-27 05:45:07 -0500

Hello everyone,

roslaunch can't read negative argument.

I'm launching my node via this launch file:

<launch>
    <arg name="inc" default="-0.02"/>
    <node pkg="parameter_analyzer" type="kld_err" name="parameter_analyzer" output="screen">
        <param name="increment" value="$(arg inc)"/>
    </node>
</launch>

Output:

[ INFO] [1461752716.797017994, 13371.605000000]:  INCREMENT VALUE: 0

If parameter is set to positive, output:

[ INFO] [1461752338.872513841, 13012.430000000]: INCREMENT VALUE: 0.02

Any suggestions? Thanks.

edit retag flag offensive close merge delete

Comments

1

It works for me in both hydro and indigo. Could you check your code that you are not doing something wrong while retrieving the parameter?

mgruhler gravatar image mgruhler  ( 2016-04-27 05:57:37 -0500 )edit
1

kindly also post the line from your source file where you are loading this param.

naveedhd gravatar image naveedhd  ( 2016-04-27 06:00:57 -0500 )edit

My roslaunch's version is 1.11.19 in indigo. And there is only 3 lines: double INC; and ros::param::get("parameter_analyzer/increment", INC); and ROS_INFO("INCREMENT VALUE: %lf", INC);

Orhan gravatar image Orhan  ( 2016-04-27 06:05:58 -0500 )edit
1

By using ros::param::get() I am also recieving 0 (very small value in exponent). Using:

ros::NodeHandle n("~"); double increment; n.param<double>("increment", increment, 5.0);

you can receive negative values.

naveedhd gravatar image naveedhd  ( 2016-04-27 06:20:52 -0500 )edit

Thanks! I'm trying, Please write as answer to let me marking correct answer.

Orhan gravatar image Orhan  ( 2016-04-27 06:25:02 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
3

answered 2016-04-27 09:18:20 -0500

mgruhler gravatar image

Alright, so the problem is most probably in this line of your code.

You use dynamic_reconfigure for your parameters, and you limit the increment param to the range [0.0, 500]. Thus, setting to positive should work, but not to negative. However, I'm not quite sure how dynamic_reconfigure reacts to parameters being not properly set from the outside...

edit flag offensive delete link more
1

answered 2016-04-27 06:32:02 -0500

naveedhd gravatar image

updated 2016-04-27 06:33:05 -0500

In your launch file:

<launch>
<arg name="inc" default="-0.02"/>
<node pkg="parameter_analyzer" type="kld_err" name="parameter_analyzer" output="screen">
    <param name="increment" type="double" value="$(arg inc)"/>
</node>

</launch>

In your source file, use:

 ros::NodeHandle nodehandle("~");
 double INC = 0.0;
 nodehandle.param<double>("parameter_analyzer/increment", INC, INC);

make sure to pass default value as 3rd argument to param() (I'm not sure for what reason If I don't pass this a double/float value here, it gives me 0)

edit flag offensive delete link more

Comments

I've just tried. Sorry, but I think the problem isn't caused by getting parameter. Because I'm setting manually via rosparam set /parameter_analyzer -0.07 but the value in parameter server changes to 0.0 when I launching the node via roslaunch.

Orhan gravatar image Orhan  ( 2016-04-27 06:45:22 -0500 )edit
1

your parameter should be /parameter_analyzer/increment

naveedhd gravatar image naveedhd  ( 2016-04-27 07:00:02 -0500 )edit
1

This is due to the fact that when you roslaunch the launch file, the argument specified therein is still set as the parameter. You need to commount the param line in the launch file to take the parameter which is already on the parameter server.

mgruhler gravatar image mgruhler  ( 2016-04-27 07:01:53 -0500 )edit

Thanks for an answers. I've tried /parameter_analyzer/increment before too. And commenting increment values in launch file isn't helped. I've setted manually to -0.7 and started commented-launch-file, it gave 0.0 too.

Orhan gravatar image Orhan  ( 2016-04-27 07:20:29 -0500 )edit

It's getting positive values succesfully. Why? :) I'm really confused.

Orhan gravatar image Orhan  ( 2016-04-27 07:25:33 -0500 )edit
1

There must be something wrong with your code then. Please post the full code in question, otherwise it is almost impossible to debug.

Check out https://github.com/ipa-mig/ros_sandbo... there is an example python and cpp package where this works...

mgruhler gravatar image mgruhler  ( 2016-04-27 07:51:06 -0500 )edit

Thank you very much for your code. I've just executed rosrun cpp_test cpp_test_node (tried roslaunch before). It doesn't output's anything. I also looked to code, It must be write something. Now I'm trying on different computer.

Orhan gravatar image Orhan  ( 2016-04-27 08:09:10 -0500 )edit

I accidentally clonned master branch before, It runs succesfully and gets parameter. And I've just uploaded code to repo. I'm running node via roslaunch parameter_analyzer laser_lambda_short.launch.

Orhan gravatar image Orhan  ( 2016-04-27 08:48:33 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2016-04-27 05:37:09 -0500

Seen: 926 times

Last updated: Apr 27 '16