Ask Your Question

How to read rosparam in a launch file

asked 2019-12-04 17:06:56 -0600

chaoshydra gravatar image

I am aiming to write a bag recording launch script for two same robots with different storage configuration, hence the stored location for the robots will be different.
The robots name are in rosparam. How do I read the publishing /robot_name in a launch script and then do a if statement to change my current recording node .

 <group if="$(eval arg('robot_name') == robot_name_rosparam)">
      <node pkg="rosbag" type="record" args="record -o /directory /topics">
edit retag flag offensive close merge delete


#q213145 is dealing with something similar, take a look and see if that's what you are trying to do.

Choco93 gravatar imageChoco93 ( 2019-12-05 07:39:13 -0600 )edit

@Choco93, I did check that answer when I was searching. It is for loading yaml file to set rosparameter. In my case, the rosparam is already set, I wish to read its value.

chaoshydra gravatar imagechaoshydra ( 2019-12-05 09:41:32 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-12-06 02:28:22 -0600

Choco93 gravatar image

Here is one way that can be done.

<arg name="foo"/>
<arg name="bar"/>
<arg name ="dir1" value="directory1"/>

<node pkg="rosbag" type="record" name="recorder" args="-o $(arg dir1)/($arg foo)"/>

and you launch this file like roslaunch my_pkg my_launch.launch foo:=$(rosparam get foo).

edit flag offensive delete link more


Pedantic, but this is using args, which are not the same as ROS parameters.

gvdhoorn gravatar imagegvdhoorn ( 2019-12-06 03:06:39 -0600 )edit

Yeah, have to get that param into launchfile somehow. Might be possible to do it directly in launchfile but couldn't find a way for that.

Choco93 gravatar imageChoco93 ( 2019-12-06 03:26:14 -0600 )edit

I don't believe it's actually supported.

gvdhoorn gravatar imagegvdhoorn ( 2019-12-06 04:15:10 -0600 )edit

What my answer suggests works, don't know about doing same within launchfile.

Choco93 gravatar imageChoco93 ( 2019-12-06 05:08:33 -0600 )edit

Yes, it works, but it doesn't actually use ROS parameters.

But perhaps this is already what the OP was asking for. Let's wait and see.

gvdhoorn gravatar imagegvdhoorn ( 2019-12-06 05:10:26 -0600 )edit

Yes, I have done something like that by passing a variable in the launch file.

chaoshydra gravatar imagechaoshydra ( 2019-12-09 15:36:44 -0600 )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

1 follower


Asked: 2019-12-04 17:06:56 -0600

Seen: 38 times

Last updated: Dec 06 '19