Ask Your Question
0

ROS2 add parameter to c++ and launch file

asked 2020-03-26 04:59:34 -0500

Joe28965 gravatar image

So I'm a novice when it comes to ROS2, but have some experience with ROS1. I've been trying to convert an existing project from ROS kinetic to ROS eloquent. In this project I've made a node in c++ that I would like to add a parameter to. In ROS1 this could be done using:

ros::param::param<bool>("/use_simulation_mode", simulation_mode_, false);

And then simply adding it to the launch file like so:

<param name="/use_simulation_mode" type="bool" value="true"/>

(and yes, it's a global parameter. I have learned this is no longer possible in ROS2, so I'll have to find another way there)

This no longer works with ROS2. As I've said, I'm quite the novice when it comes to ROS2 and am struggling to find information out there on how I can accomplish this. If anybody knows how to accomplish this and could show me, or point me in the direction of a tutorial or something the like, that would be much appreciated.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-03-28 21:13:12 -0500

The steps that I have taken generally are:

Steps:

  1. Create yaml file with params and place in appropriate directory.
  2. Load yaml file in the launch file, and pass params to parameters argument in ComposableNode constructor.
  3. Declare the parameters in the class constructor of your node object.
  4. Get the parameters before using in your program.

You can use a ROS 2 (eloquent) package, ros2_ipcamera, I created as a specific working example:

The numbering below is associated with the steps above.

  1. see /config/ipcamera.yaml
  2. see /launch/ipcamera.launch.py
  3. and 4. see /src/ipcamera_component.cpp

Reading through the discussion associated with issue #715 was informational as well.

edit flag offensive delete link more

Comments

1

Thanks, I got it working with the help of your example!

Joe28965 gravatar image Joe28965  ( 2020-03-31 01:45:53 -0500 )edit

Great to hear!

surfertas gravatar image surfertas  ( 2020-03-31 09:25:50 -0500 )edit

Your Answer

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

Add Answer

Question Tools

2 followers

Stats

Asked: 2020-03-26 04:59:34 -0500

Seen: 35 times

Last updated: Mar 28