ROS/ROS2Foxy

ros2 launch

leohycho 2022. 5. 4. 15:34

ros2 launch <my_package> <my.launch.py>

 

ros2 launch ~/src/my_package/launch/my.launch.py

 

my.launch.py : 

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'),
            ]
        )
    ])

 

setup.py : 

import os
from glob import glob
from setuptools import setup

package_name = 'my_package'

setup(
    # Other parameters ...
    data_files=[
        # ... Other data files
        # Include all launch files. This is the most important line here!
        (os.path.join('share', package_name), glob('launch/*.launch.py'))
    ]
)

CMakeLists.txt :

# Install launch files.
install(DIRECTORY
  launch
  DESTINATION share/${PROJECT_NAME}/
)

 

package.xml :

<exec_depend>ros2launch</exec_depend>

 

 

[ Reference ]

[1] https://docs.ros.org/en/foxy/Tutorials/Launch/Launch-system.html

 

Launching/monitoring multiple nodes with Launch — ROS 2 Documentation: Foxy documentation

ROS 2 launch system The launch system in ROS 2 is responsible for helping the user describe the configuration of their system and then execute it as described. The configuration of the system includes what programs to run, where to run them, what arguments

docs.ros.org