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

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 image emielke  ( 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 image emchenk  ( 2016-07-21 10:04:18 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2019-12-19 19:10:35 -0500

Rufus gravatar image

updated 2019-12-19 19:13:55 -0500

Another way is to use the if or unless tags within the arg

Ugly but works.. I do hope your syntax becomes viable along the line

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

<arg name="image_topic" value="" unless="$(arg record_image)"/>
<arg name="image_topic" value="/image" if="$(arg record_image)"/>
edit flag offensive delete link more

Comments

This is the most up-to-date way so I marked this as the correct answer.

Orhan gravatar image Orhan  ( 2021-02-18 20:08:05 -0500 )edit
4

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 image emchenk  ( 2016-07-21 04:56:43 -0500 )edit

Question Tools

1 follower

Stats

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

Seen: 6,565 times

Last updated: Dec 19 '19