Ask Your Question
0

reading parameter in c

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

hemant T gravatar image

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

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 -0500

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 -0500

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

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

Seen: 62 times

Last updated: Nov 05 '15