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

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

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

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)

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

1 Answer

Sort by ยป oldest newest most voted
1

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

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

    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

Comments

1

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

Question Tools

2 followers

Stats

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

Seen: 206 times

Last updated: Apr 08 '21