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

Is it possible to launch non ros applications with roslaunch?

asked 2017-10-04 03:48:17 -0500

l4ncelot gravatar image

updated 2017-10-04 03:48:50 -0500


I would like to know whether it's possible to launch non ros applications with roslaunch? And if so, how can it achieved?

Thanks for the answer.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2017-10-04 04:32:08 -0500

gvdhoorn gravatar image

updated 2017-10-05 05:54:58 -0500

Yes, that is possible, but you will have to take care of some details.

roslaunch (and rosrun is the same) will add a nr of extra arguments to the command line it generates when starting ROS nodes, and those will also be passed to 'non ros applications'. Examples of those extra command line arguments (CLAs) are the node name (as __name:=..) and the location of the log file the node is expected to use (as __log:=..).

Ordinary programs typically do not use such arguments and their CLA parsers will get confused.

Three approaches I've seen:

  1. write a bash script that wraps the 'non-ros binary': this script takes in all CLAs, strips out the ROS-specific ones and then invokes the target binary with the remaining arguments. Advantage: simple to create. Disadvantage: it is not really convenient to manipulate strings (ie: command lines) with bash, and these scripts often assume a fixed order of CLAs, which is not guaranteed, leading to brittle implementations.

  2. write a small Python wrapper that can use rospy.myargv(..) to remove ROS-specific CLAs and then use subprocess to start the target binary (while passing on the remaining CLAs).

  3. same as the previous, but in C++ and using ros::removeROSArgs(..).

I'm not aware of publicly available implementations of any of the above options, but they could already exist. Writing them yourself should not be too hard though.

Note: to use either the rospy or roscpp CLA parsing functions the wrappers do not have to be ROS nodes themselves.

Edit: as roslaunch can only start binaries that are located in packages, the wrappers would have to live in a ROS package themselves. But that is hardly a constraint.

Edit2: and obviously, if your target binary does not expect any arguments at all, then all of the above is unnecessary, as the args that roslaunch adds will not be processed anyway (but you would still need some way to start your target binary 'from' a ROS package).

Edit3: (very) minimal Python2 example:

#!/usr/bin/env python
import sys, subprocess, rospy 

when used with a launch file that contains something like:

<node name=".." type=".." pkg=".." args="nc localhost 12345" />

will make nc try to connect to localhost:12345 with roslaunch waiting for it to exit (as it would with 'regular' ROS binaries).

edit flag offensive delete link more


Related (prior) questions and answers: #q9161 and #q51474.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-04 04:33:36 -0500 )edit

Cool, thanks a lot.

l4ncelot gravatar image l4ncelot  ( 2017-10-04 05:33:18 -0500 )edit

answered 2018-10-24 17:47:13 -0500

aschaefer gravatar image

You could use the aliencontrol ROS package. This package contains a node that starts an external application.

For example, if you wanted to start, say, top in a roslaunch script, you would include the following node:

<node pkg="aliencontrol" type="aliencontrol" name="aliencontrol_top">
    <param name="cmd" value="top"/>

There are some benefits of using this package over creating a ROS package and putting bash scripts inside it:

  1. Not only does the aliencontrol node launch your external script or application, but it also takes care of shutting down cleanly. This means that if you shut down ROS, the external application is automatically shut down.
  2. You do not need to undergo the process of creating a bash script and fiddling with the input arguments.
  3. You can start and stop the external application from ROS GUIs like node_manager_fkie.
edit flag offensive delete link more


Nice contribution.

This basically does what I wrote in my answer.

re: shuts down cleanly: can you clarify how that is special to your script? Even with the simple bash or Python script approach that automatically works.

gvdhoorn gravatar image gvdhoorn  ( 2018-10-25 01:08:11 -0500 )edit

Thanks! There are two ways of shutting down a node that controls (not only launches) a subprocess: 1. Terminate subprocess. 2. Exit ROS node. In case 1, the subprocess returns and the node shuts down. In case 2, you need to terminate the subprocess in your script before shutting down the node.

aschaefer gravatar image aschaefer  ( 2018-10-25 12:51:59 -0500 )edit

Question Tools



Asked: 2017-10-04 03:48:17 -0500

Seen: 2,252 times

Last updated: Oct 24 '18