Ask Your Question

Correct way to use arguments

asked 2021-04-07 20:36:10 -0500

Kansai gravatar image

updated 2021-04-08 01:17:54 -0500

mgruhler gravatar image

I have a launch file that plays rosbag files among other things. Right now it is something like this

   <node name="rosbag" type="play" pkg="rosbag" args="--pause $(find my_ros_package)/bags/this_bag01.bag" >

So, when launched it plays the rosbag file this_bag01.bag

I want to make it more flexible so that I can call it with any rosbag file. What is the most appropriate way to do this?

The way I am thinking is
1. Create a shell script file that I can call with an argument
2. In this shell I can put

  export LAUNCH_FILE= (and here the argument)
  roslaunch my_ros_package  thelauch_file.launch
  1. Inside the launch file put $(env LAUNCH_FILE)

       <node name="rosbag" type="play" pkg="rosbag" args="--pause $(find my_ros_package)/bags/($ env LAUNCH_FILE)" ></node>
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-04-08 01:30:00 -0500

mgruhler gravatar image

Well, only for changing the file to play, this seems pretty overkill to me. And still limits you to have the file located at my_ros_package/bags/, which again isn't very generic...

A few points to consider:

  1. wrapping the whole thing in a shell script, when all you do is export the environment variable and then call the launch file is not required. You could simply export the variable manually. I see no benefit in adding the additional step there.
  2. You could also use a launch arg, instead of the environment variable substitution. Basically change the launch file to

         <arg name="file" default="this_bag01.bag"/>
         <node name="rosbag" type="play" pkg="rosbag" args="--pause $(find my_ros_package)/bags/($arg file)"/> 

    and call it with roslaunch my_ros_package thelaunch_file.launch file:=otherfile.bag.

Check out the docs about the various posibilities.

Personally, I'd definitely go for option two (actually, I'll manually launch the rosbag executable, but then again, you might need the filename somewhere else). Option one seems to me to try to accomplish the same thing, at the expense of adding another file that you'd have to change every time (which is not good for any VCS)...

edit flag offensive delete link more



Why even consider using anything but roslaunchargs for this?

The advantage of the shell script approach is unclear to me and it seems like this is a textbook example of a situation where args are meant to be used.

gvdhoorn gravatar image gvdhoorn  ( 2021-04-08 01:59:14 -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



Asked: 2021-04-07 20:36:10 -0500

Seen: 20 times

Last updated: Apr 08