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

reading parameter in c

asked 2015-11-04 01:42:31 -0600

hemant T gravatar image

updated 2015-11-04 02:09:46 -0600

Akif gravatar image

Hello, I am trying to read parameters in my program based on this example http://wiki.ros.org/Parameter%20Server

Here is code snippet

std::string my_number;
nh_.getParam("my_number",my_number);

ROS_INFO("\n My Number %s",my_number.c_str());

And I am calling like this rosrun mypkg my_node my_number:=5

This value is not getting read.

Please help, how can I read in my C program.

Thanks, Hemant

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2015-11-04 05:26:01 -0600

dornhege gravatar image

my_number:=5 does NOT set a parameter. It remaps the topic my_number to 5.

Either set the parameter on the param server, e.g., via rosparam set or use _my_number:=5 to set a private parameter. In that case you'll also need a private NodeHandle("~") before retrieving the parameter.

edit flag offensive delete link more
0

answered 2015-11-05 17:54:02 -0600

hemant T gravatar image

Based on suggestion above following code works. and I also set parameter at command line _my_number:=5

ros::NodeHandle nh_param("~");
int my_number;
nh_param.param("my_number", my_number ,int(0));

Thanks, Hemant

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-11-04 01:42:31 -0600

Seen: 539 times

Last updated: Nov 05 '15