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

How to use <param> in launch files to change variable values in node scripts?

asked 2016-03-28 20:32:05 -0600

pgigioli gravatar image

updated 2016-03-28 20:52:13 -0600

I'm trying to use in launch files to change variable values in node scripts but it doesn't seem to work.

Here is my launch file:

<launch>

  <include file="$(find turtlebot_bringup)/launch/minimal.launch" />

  <include file="$(find turtlebot_navigation)/launch/gmapping_demo.launch" />

  <include file="$(find frontier_exploration)/launch/global_map.launch" />

  <node name="send_exploration_goal" pkg="turtlebot_demos" type="send_exploration_goal"/>
     <param name="set_linear_vel" value="0.1" />
     <param name="set_angular_vel" value="0.1" />
  </node>

</launch>

And here is a skeleton of the node script:

#include ...

void function()
{ 
   ....
}

int main(int arcg, char** argv)
{
  ....
   float set_linear_vel = 0.25;
   float set_angular_vel = 0.50;
  ....
 }
  1. My first question is, am I doing this right?
  2. Second, does it matter where I define the variables in the node script? Should they be defined as global variables, defined inside int main(), or inside void function()?

Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2016-03-28 20:53:00 -0600

ahendrix gravatar image

updated 2016-03-28 20:56:03 -0600

If you want to use ROS parameters in your C++ code, you need to explicitly read those parameters into a variable.

I'd suggest you go through the ROS C++ parameters tutorial

When you declare a parameter with a <param> tag in a launch file, you're creating a private parameter within that node's namespace, so you should also read through the tutorial on private namespaces: Accessing Private Names from a NodeHandle (roscpp)

edit flag offensive delete link more

Comments

Thanks! I didnt realize there was documentation for this. I'll check it out.

pgigioli gravatar image pgigioli  ( 2016-03-28 22:11:43 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-03-28 20:32:05 -0600

Seen: 3,309 times

Last updated: Mar 28 '16