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

Set node parameter in launch file

asked 2014-07-24 09:05:55 -0600

Glen gravatar image

updated 2014-07-24 10:10:57 -0600

Hi

I was trying to run a node through launch file and set its node parameter. The correspond launch file code:

<node pkg="hector_quadrotor_demo" type="uav1_pathplan" name="uav1_pathplan" args="-d $(find hector_quadrotor_demo)/src/uav1_pathplan.cpp">
<param name="ref.x" type="double" value="7.0" />
<param name="ref.y" type="double" value="-8.0"/>
<param name="ref.z" type="double" value="4.0" />

When I start the launch file, the node just didn't receive parameter values.

In my node files,

ros::init(argc, argv, "uav1_pathplan");
ros::NodeHandle n;
destination[1]=ref.x;
destination[2]=ref.y;
destination[3]=ref.z;

I just want the node can read "ref" to "destination[]". Then I can do further calculation. I'm not sure what's wrong.

Any advice appreciated. Glen

edit retag flag offensive close merge delete

Comments

1

Do "rosparam list" - can you see the parameters? The NodeHandle might just be looking in the wrong namespace.

sterlingm gravatar image sterlingm  ( 2014-07-24 09:10:14 -0600 )edit

yes, I can read the parameter values through "rosparam list". Then, should I modify anything in my .cpp file?

Glen gravatar image Glen  ( 2014-07-24 09:42:35 -0600 )edit

Whenever you load them in with your NodeHandle you need to include their namespace. If in "rosparam list" it says "uav1_pathplan/ref.x" you need to do loadParam("uav1_pathplan/ref.x").

sterlingm gravatar image sterlingm  ( 2014-07-24 09:53:38 -0600 )edit

No you should use a private node handle instead.

demmeln gravatar image demmeln  ( 2014-07-24 10:15:07 -0600 )edit

Do you mean use: loadParam("uav1_pathplan/ref.x") in .cpp file? But function loadParam() is not declared yet.

Glen gravatar image Glen  ( 2014-07-24 10:16:07 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2014-07-24 10:18:04 -0600

demmeln gravatar image

updated 2014-07-24 10:18:58 -0600

How do you retrieve the ref object in your code. I don't see you accessing the parameters at all. The launch file is fine; in you code do something like:

ros::NodeHandle nh("~");
double ref_x;
nh.getParam("ref.x", ref_x);
destination[1] = ref_x;

Edit: Best read up on retrieving parameters in the wiki.

edit flag offensive delete link more

Comments

I retrieve the object as you said. When roslaunch the launch file, error shows "process has died[pid 21550, exit code...]". It is close to run successfully and I'm still trying to figure it out. Thanks!

Glen gravatar image Glen  ( 2014-07-24 11:23:49 -0600 )edit

It finally works. I just redefine all the variables "destination and ref_" and it worked! Thanks

Glen gravatar image Glen  ( 2014-07-24 19:06:37 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2014-07-24 09:05:55 -0600

Seen: 6,471 times

Last updated: Jul 24 '14