Welcome to Jetson AGX Thor repository
19.ROS2 Launch startup file configuration
19. ROS2 Launch startup file configuration
1. Introduction to Launch
Until now, every time we launched a ROS node, we had to open a new terminal and run a command. With so many nodes in a robotic system, doing this every time is cumbersome. Is there a way to launch all nodes at once? The answer is, of course, a launch file, a script that launches and configures multiple nodes in the ROS system.
In ROS2, launch is used to launch multiple nodes and configure program parameters. ROS2 launch files are available in XML, YAML, and Python formats. This lesson uses a Python launch file as an example. Compared to the other two formats, the Python format is more flexible:
- Python has numerous function libraries that can be used in launch files;
- ROS2 general and specific launch features are written in Python, allowing access to launch features that may not be exposed in XML and YAML;
The key to writing ROS2 launch files in Python is to abstract each node, file, script, etc. into an action, launching them using a unified interface.
References:
- Launch System Design Document: ROS 2 Launch System
- Official Launch API Documentation: Architecture of launch — launch 0.4.0 documentation
- Preparation: Create a package to store program files
xxxxxxxxxxros2 pkg create learn_launch --build-type ament_python2. Writing a Single Node Launch Program
2.1. Creating a Launch File
Create a launch folder under the package, then create a file called [single_node_launch.py] within the launch folder. Copy the following content into the file:
xxxxxxxxxxfrom launch import LaunchDescriptionfrom launch_ros.actions import Nodedef generate_launch_description(): node = Node( package='pkg_helloworld_py', executable='helloworld', output='screen' ) return LaunchDescription([node])
2.2 Configuring the setup.py File
The launch file is often named "LaunchName_launch.py." LaunchName is customizable, while _launch.py is considered fixed. You need to modify the setup.py file in the package to add the files in the launch path and compile to generate the executable .py file.