1
$\begingroup$

Rosanswers logo

How do you run a command inside a launch file to set a param value?

I have launch file like:

<launch>
    <group ns="motor_arduino">
        <node pkg="rosserial_python" type="serial_node.py" name="serial_node" output="screen">
            <param name="~port" value="/dev/ttyACM0" />
            <param name="~baud" value="115200" />
        </node>
    </group>
</launch>

which allows communication with one of several Arduino Unos connected to the host computer. However, I've found that the mount path /dev/ttyACM0 is variable, and based on how the Arduino's initialize, this may be /dev/ttyACM0 or /dev/ttyACM1.

To fix this problem, I've written a script that reads the output of udevadm info --query=all --name=/dev/ttyACM* and determines the correct device path to use. However, how do I call this script from inside the launch file to set the port param dynamically?

The docs show that roslaunch does support some simply substitution commands, but I don't see a way to run an arbitrary script, e.g.

<param name="~port" value="$(identify_port.py device1)" />

gives me the error:

Unknown substitution command [identify_port.py device1]. Valid commands are ['find', 'env', 'optenv', 'anon', 'arg']

Originally posted by Cerin on ROS Answers with karma: 940 on 2017-03-26

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

You need to use the command attribute, like so: <param name="port" command="identify_port.py device1" />. This will set the output of your script as the value of port.

Don't forget that the script should be in your PATH and have execute permission.


Originally posted by nlamprian with karma: 366 on 2017-03-26

This answer was ACCEPTED on the original site

Post score: 7


Original comments

Comment by askkvn on 2020-05-28:
It works. I tried with <param name="any_name" command="rosrun <pkg_name> <executable_file>" />

$\endgroup$
2
  • $\begingroup$ Is the same possible with launch file arg? $\endgroup$ Commented Sep 15, 2023 at 18:19
  • $\begingroup$ No, it's not. Arguments have either default or user-specified values. You can see the available attributes here wiki.ros.org/roslaunch/XML/arg $\endgroup$ Commented Sep 22, 2023 at 16:20

Your Answer

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