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

How to pass an argument to roslaunch file from shell script?

asked 2015-06-11 04:39:52 -0500

lapadets gravatar image

I have a shell script that takes some input from the user in the form of arguments and executes a launch file with some nodes. One of these nodes is a rosbag record. Currently, I have hardcoded the output directory for the recorded bag, but I'd like to parametrize this and let the user decide where to store the folder from the shell script.

I start the node like this at the moment:

<node pkg="rosbag" type="record" name="record" output="screen" args="-o /home/output/output_name -e /myTopic"/>

I cannot figure out how to to pass this args from a shell script. Any ideas? it should be possible...

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-06-11 05:46:11 -0500

130s gravatar image

updated 2015-06-11 10:14:17 -0500

Use arg element in launch syntax.

An example can look like:


  <arg name="hoge" default="fuga" />
  <node pkg="rosbag" type="record" name="record" output="screen" args="-o $(arg hoge) -e /myTopic"/>


  <arg name="hoge" default="fuga" />
  <include file="rosbag_record.launch">
    <arg name="hoge" value="$(arg hoge)" />

And you can run

roslaunch top_level.launch hoge:=my_value
edit flag offensive delete link more


But do you need to have the <arg> in both launch files? So runstop_level.launch, which contains rosbag_record.launch. Or the <arg> tag is in the top_level, while the <node> tag is in the other launcher? or?

lapadets gravatar image lapadets  ( 2015-06-11 07:08:47 -0500 )edit

@lapadets sorry, my sample was completely wrong. Now it's corrected with the file structures you provided in addition.

130s gravatar image 130s  ( 2015-06-11 10:13:33 -0500 )edit

Thanks! that's way more clear now!

lapadets gravatar image lapadets  ( 2015-06-11 11:08:58 -0500 )edit

Question Tools

1 follower


Asked: 2015-06-11 04:39:52 -0500

Seen: 3,068 times

Last updated: Jun 11 '15