Robotics StackExchange | Archived questions

Don´t understand ROS::nodehandler

I have the following code.

double globalResizingFactor; ros::init(argc, argv, "image_listener"); ros::NodeHandle nh; ...

if (!nh.getParam("resizingfactor", globalResizingFactor)) { ROSERROR (" .... "); ros::shutdown(); }

This code compiles with no problems, but it is a transition from a old ROS distribution to a more recente one, this is, Fuerte to Hydro, both are very diferent, a made a huge problem to be solved, the fact is that I was able to change e few things and compile.

When Runing It stops here, at this if, since the globalResizingFactor isn´t got, it fails. Please some help understanding what´s hapening in this code.

Rodrigo

Asked by Rodrigo Lourenço on 2016-08-15 10:00:34 UTC

Comments

Answers

nh.getParam("variable", variable in class) will get the values from your launch file or you have to pass the value when you launch your node something like rosrun [package_name] [node_name] variable="resizing_factor"

In your case, probably the values are not getting passed while launching the node so it falls in ROS_ERROR. Please try the above method or use a launch file.

For launch file, follow this link: http://wiki.ros.org/roslaunch/XML Refer 5.1 and 5.3 I hope this will help to solve your problem.

Asked by ghkraju on 2016-08-15 15:32:37 UTC

Comments

You´re right, that was the problem. Thanks.

Asked by Rodrigo Lourenço on 2016-08-18 17:46:51 UTC

Nice to hear that..... You can mark it as answered in that case.

Asked by ghkraju on 2016-08-19 04:03:20 UTC

How do I mark answered?

Asked by Rodrigo Lourenço on 2016-08-19 04:50:58 UTC

I am new too here.... I think you can click the tick mark on the left side of the comment(answer provided).

Asked by ghkraju on 2016-08-19 06:05:28 UTC