Ask Your Question
1

How to execute command inside launch file?

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

Cerin gravatar image

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']
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
5

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

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.

edit flag offensive delete link more

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

Stats

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

Seen: 1,052 times

Last updated: Mar 26 '17