Interesting practice of robot programming 12 - launch tool

Posted by KoshNaranek on Wed, 02 Feb 2022 00:23:51 +0100

In most previous cases, a new window needs to be opened every time an instruction is entered. How to start a big project

  • launch

target

Create startup files to run complex ROS 2 systems. Simple launch, powerful function, detailed knowledge points will be introduced later.

Basic knowledge

In the tutorial so far, it has been necessary to open a new terminal for each new node running. As more complex systems with more and more nodes running simultaneously are created, opening terminals and re entering configuration details become tedious.

The startup file allows you to start and configure multiple executables containing ROS 2 nodes at the same time.

Running a single boot file using the ros2 launch command will immediately start the entire system -- all nodes and their configurations.

Key points of function package

  1. rqt_graph
  2. turtlesim
  3. source

practice

1 configuration

New turnlesim_ mimic_ launch. Py, you can use the terminal or graphics.

Copy the following code into it and save it.

from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    return LaunchDescription([
        Node(
            package='turtlesim',
            namespace='turtlesim1',
            executable='turtlesim_node',
            name='sim'
        ),
        Node(
            package='turtlesim',
            namespace='turtlesim2',
            executable='turtlesim_node',
            name='sim'
        ),
        Node(
            package='turtlesim',
            executable='mimic',
            name='mimic',
            remappings=[
                ('/input/pose', '/turtlesim1/turtle1/pose'),
                ('/output/cmd_vel', '/turtlesim2/turtle1/cmd_vel'),
            ]
        )
    ])

As shown in the figure below:

Annotation code 2

These import statements introduce some Python startup modules. Header file function similar to C + +.

from launch import LaunchDescription
from launch_ros.actions import Node

Next, the launch description officially begins:

def generate_launch_description():
   return LaunchDescription([

   ])

LaunchDescription is a system composed of three nodes, all from the turnlesim package. The goal of the system is to start two robot windows and let one robot imitate the motion of the other robot.

Start the first two operations in the description and start the two turnlesim windows:

Node(
    package='turtlesim',
    namespace='turtlesim1',
    executable='turtlesim_node',
    name='sim'
),
Node(
    package='turtlesim',
    namespace='turtlesim2',
    executable='turtlesim_node',
    name='sim'
),

Note that the only difference between the two nodes is their namespace value. A unique namespace allows the system to start two simulators without node or topic name conflicts.

Two robots in the system receive commands about the same topic and publish their poses on the same topic. Without a unique namespace, messages for one robot or another cannot be distinguished.

The last node is also from the turnlesim package, but there is a different executable: mimic.

Node(
    package='turtlesim',
    executable='mimic',
    name='mimic',
    remappings=[
      ('/input/pose', '/turtlesim1/turtle1/pose'),
      ('/output/cmd_vel', '/turtlesim2/turtle1/cmd_vel'),
    ]
)

This node adds configuration details in the form of remapping. The simulated / input/pose topic is remapped to / turnlesim1 / turnle1 / pose, and its / output / CMD_ The vel theme is remapped to / turnlesim2 / turnle1 / CMD_ vel. This means that mimic will subscribe to the pose theme of / turnlesim1 / SIM and republish it for the speed command theme of / turnlesim2 / SIM. In other words, turnlesim2 will mimic the actions of turnlesim1.

3 launch

If this file is not added to the function pack, you need to start it manually in the corresponding folder:

  1. cd launch
  2. ros2 launch turtlesim_mimic_launch.py

The details will be explained later.

You can start the startup file directly (as you did above) or provided by the package. When it is provided by package, the syntax is: ros2 launch < package_ name> <launch_ file_ name>

Learn more about creating packages in later tutorials.

Two turnlesim windows will open and you will see the following [INFO] message telling the startup file which node has been started:

Use the speed command to see the effect as follows:

  • ros2 topic pub -r 1 /turtlesim1/turtle1/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 1.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: -1.8}}"

The speed can be modified.

4. View system node information

Using rqt_graph.

summary

Startup files simplify running complex systems with many nodes and specific configuration details. You can create startup files using Python and run them using the ros2 launch command.

-Fin-