Ask Your Question

How to execute command inside launch file?

asked 2017-03-26 14:02:02 -0600

Cerin gravatar image

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

I have launch file like:

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

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="$( device1)" />

gives me the error:

Unknown substitution command [ device1]. Valid commands are ['find', 'env', 'optenv', 'anon', 'arg']
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-03-26 17:15:28 -0600

You need to use the command attribute, like so: <param name="port" command=" 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.

edit flag offensive delete link more


It works. I tried with <param name="any_name" command="rosrun <pkg_name> <executable_file>" />

askkvn gravatar image askkvn  ( 2020-05-28 02:19:05 -0600 )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

1 follower


Asked: 2017-03-26 14:02:02 -0600

Seen: 1,538 times

Last updated: Mar 26 '17