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

Can't make "getParams" work in C++

asked 2013-03-05 04:54:33 -0500

uuilly gravatar image

updated 2013-03-05 04:56:30 -0500

I'm able to set params but when I get them, it returns success with the wrong value.

double myDouble = 7.7;

_node.setParam("/my_double", myDouble);

double myDoubleFromRos;

std::cout << "get success = " << _node.getParam("/my_double", myDoubleFromRos) << " get value = " << myDoubleFromRos << " value should be = " << myDouble << std::endl;

The output of this is:

get success = 1 get value = 6.95333e-310 value should be = 7.7

On the command line I type:

rosparam get "/my_double"

7.7

So I'm successfully setting the parameter but I'm not able to get it. I'm fairly new to ROS so there must be some assumption I'm missing.

Any advice would be greatly appreciated.

Using fuerte-desktop-full latest.

edit retag flag offensive close merge delete

Comments

Next time please format your code correctly.

Claudio gravatar image Claudio  ( 2013-03-05 23:57:43 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
6

answered 2013-03-05 05:06:59 -0500

I think your problem here is not with getParam, but with the way you've structured your output.

The evaluation order of "<<" is undefined, so the compiler is free to evaluate the statements on the output line in whatever order it chooses. If it chooses a right-to-left order, then it will try and string-ify the value of "myDoubleFromRos" before the call to _node.getParam(), so the value is uninitialized.

Try the following:

double myDouble = 7.7, myDoubleFromRos;
_node.setParam("/my_double", myDouble);

std::cout << "get success = " << _node.getParam("/my_double", myDoubleFromRos);
std::cout << "get value = " << myDoubleFromRos << " value should be = " << myDouble;

For more explanation, see the discussion here.

edit flag offensive delete link more
0

answered 2013-03-05 12:01:51 -0500

uuilly gravatar image

Wow. I had no idea about that evaluation order. Thank you so much. That worked.

edit flag offensive delete link more

Comments

Don't comment with an answer please, this is not supposed to work as a forum (been bashed about it myself).

Claudio gravatar image Claudio  ( 2013-03-05 23:57:01 -0500 )edit

Question Tools

Stats

Asked: 2013-03-05 04:54:33 -0500

Seen: 269 times

Last updated: Mar 05 '13