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

Revision history [back]

click to hide/show revision 1
initial version

But how would I implement the launching of a series of nodes, setting of parameters and so on and so forth, in python? Is there an api that I could use.

yes, there is the API that roslaunch itself uses, which is a Python API.

I would actually not recommend you use it though. It's a tad finicky, and leads to a lot of manual work which roslaunch takes care of for you.

I just read that ROS2 has an alternative to .launch files, where instead of .xml the logic is defined in a python script. [..] I assume that this won't work with ROS1 per-se

No, launch and launch_ros can't work with ROS 1, although launch is pretty much ROS-agnostic, so you could theoretically perhaps implement a ROS 1 wrapper similar to launch_ros but for ROS 1.

Whether that would make sense, I don't know.

There is however already someone who wrote a Python-based roslaunch wrapper: CodeFinder2/roslaunch2.

From its readme:

roslaunch2 is a (pure Python based) ROS package that facilitates writing versatile, flexible and dynamic launch configurations for the Robot Operating System (ROS 1) using Python, both for simulation and real hardware setups, as contrasted with the existing XML based launch file system of ROS, namely roslaunch. Note that roslaunch2 is not (yet) designed and developed for ROS 2 but for ROS 1 only although it may also inspire the development (of the launch system) of ROS 2. It is compatible with all ROS versions providing roslaunch which is used as its backend. roslaunch2 has been tested and heavily used on ROS Indigo, Jade, Kinetic, and Lunar; it also supports a “dry-mode” to generate launch files without ROS being installed at all. The key features of roslaunch2 are

  • versatile control structures (conditionals, loops),
  • extended support for launching and querying information remotely,
  • an easy-to-use API for also launching from Python based ROS nodes dynamically, as well as
  • basic load balancing capabilities for simulation setups.

If you really like using Python instead of roslaunch XML, perhaps you could take a look at that.

But how would I implement the launching of a series of nodes, setting of parameters and so on and so forth, in python? Is there an api that I could use.

yes, there is the API that roslaunch itself uses, which is a Python API.API. See wiki/roslaunch/API Usage for some example scripts.

I would actually not recommend you use it though. It's a tad finicky, and leads to a lot of manual work which roslaunch takes care of for you.

I just read that ROS2 has an alternative to .launch files, where instead of .xml the logic is defined in a python script. [..] I assume that this won't work with ROS1 per-se

No, launch and launch_ros can't work with ROS 1, although launch is pretty much ROS-agnostic, so you could theoretically perhaps implement a ROS 1 wrapper similar to launch_ros but for ROS 1.

Whether that would make sense, I don't know.

There is however already someone who wrote a Python-based roslaunch wrapper: CodeFinder2/roslaunch2.

From its readme:

roslaunch2 is a (pure Python based) ROS package that facilitates writing versatile, flexible and dynamic launch configurations for the Robot Operating System (ROS 1) using Python, both for simulation and real hardware setups, as contrasted with the existing XML based launch file system of ROS, namely roslaunch. Note that roslaunch2 is not (yet) designed and developed for ROS 2 but for ROS 1 only although it may also inspire the development (of the launch system) of ROS 2. It is compatible with all ROS versions providing roslaunch which is used as its backend. roslaunch2 has been tested and heavily used on ROS Indigo, Jade, Kinetic, and Lunar; it also supports a “dry-mode” to generate launch files without ROS being installed at all. The key features of roslaunch2 are

  • versatile control structures (conditionals, loops),
  • extended support for launching and querying information remotely,
  • an easy-to-use API for also launching from Python based ROS nodes dynamically, as well as
  • basic load balancing capabilities for simulation setups.

If you really like using Python instead of roslaunch XML, perhaps you could take a look at that.