Ask Your Question
1

can I change arg value in roslaunch?

asked 2016-07-15 14:36:01 -0500

emchenk gravatar image

updated 2016-07-21 06:45:27 -0500

Hi! Is it possible in roslaunch to change the value of an arg? I would like to write a launch file for rosbag record with arguments about which topics to record. Like this:

roslaunch record record.launch record_scan:=true record_image:=true

where the launch file might look like this:

<launch>

    <arg name="record_scan" default="false" />
    <arg name="record_image" default="false" />

    <arg name="scan_topic" default="" />
    <arg name="image_topic" value="" />

    <group if="$(arg record_scan)">
        <arg name="scan_topic" value="/scan />
    </group>

    <group if="$(arg record_image)">
        <arg name="image_topic" value="/image />
    </group>

    <node pkg="rosbag" type="record" name="rosbag" output="screen" args="/tf /odom $(arg image_topic) $(arg scan_topic)"/>

<launch>

If I try it like this, ros complains:

Invalid <arg> tag: arg 'scan_topic has already been declared.

Is there some way to do this? I also tried nested group statements and putting an unless statement instead of declaring the arg before, but both didn't work. Thank you for your help!!

edit retag flag offensive close merge delete

Comments

Why don't you simply input the scan topic and image topic as args rather than the boolean args? Is it necessary for you to be able to turn one off and leave the other on? I guess this is more curiosity since it seems you found a solution.

emielke gravatar imageemielke ( 2016-07-21 08:34:14 -0500 )edit

I posted a simplified version of what I want to do. When I specify "image", I want rosbag to record multiple image related topics and so on. Furthermore, the topic names are harder to remember than the args I wanted to specify.

emchenk gravatar imageemchenk ( 2016-07-21 10:04:18 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
3

answered 2016-07-15 15:55:00 -0500

Chrissi gravatar image

Sadly, this is not possible. You can only define an arg once and a change value function does not exist AFAIK. You would have to create groups where the <node> command is in the same group as the definition of the arg:

<launch>
<arg name="record_scan" default="false" />
<group if="$(arg record_scan)">

    <arg name="scan_topic" default="/scan />
    <node pkg="rosbag" type="record" name="rosbag" output="screen" args="/tf /odom $(arg scan_topic)"/>

</group>
</launch>

Because, if you try to define an arg in a group and use it outside that group, it will not know it anymore as it was defined in a different scope. You see this is a lot of copy and paste that one does not want.

edit flag offensive delete link more

Comments

Thank you for your answer! I solved it in a different way now, by passing command line arguments to rosrun, processing them in c++ and them making a system call to rosbag from c++. A little hacky, but it works. :-)

emchenk gravatar imageemchenk ( 2016-07-21 04:56:43 -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

Stats

Asked: 2016-07-15 14:36:01 -0500

Seen: 2,329 times

Last updated: Jul 21 '16