0
$\begingroup$

Rosanswers logo

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!!


Originally posted by emchenk on ROS Answers with karma: 43 on 2016-07-15

Post score: 4


Original comments

Comment by emielke on 2016-07-21:
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.

Comment by emchenk on 2016-07-21:
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.

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

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)"/>

Originally posted by Rufus with karma: 1083 on 2019-12-19

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by Orhan on 2021-02-18:
This is the most up-to-date way so I marked this as the correct answer.

$\endgroup$
0
$\begingroup$

Rosanswers logo

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.


Originally posted by Chrissi with karma: 1642 on 2016-07-15

This answer was NOT ACCEPTED on the original site

Post score: 4


Original comments

Comment by emchenk on 2016-07-21:
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. :-)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.