ROS2

[ROS2] Tutorial Intermediate - Integrating launch files into ROS 2 packages

씨주 2024. 11. 27. 18:45

Integrating launch files into ROS 2 packages

Tasks

Create a package

mkdir -p launch_ws/src
cd launch_ws/src
ros2 pkg create --build-type ament_python --license Apache-2.0 py_launch_example

 

Creating the structure to hold launch files

모든 launch file은 launch directory안에 저장된다.

launch file을 사용하기 위헤 setup.py의 data_file에 launch 파일을 추가해야 한다.

import os
from glob import glob
# Other imports ...

package_name = 'py_launch_example'

setup(
    # Other parameters ...
    data_files=[
        # ... Other data files
        # Include all launch files.
        (os.path.join('share', package_name, 'launch'), glob(os.path.join('launch', '*launch.[pxy][yma]*')))
    ]
)

 

Writing the launch file

이제 my_script_launch.py 를 만들어 보자. ros2 launch 명령어를 실행하기 위해 파일명은 launch.py로 끝나야 한다.

# launch_ws/src/py_launnch_example/launch

import launch
import launch_ros.actions

def generate_launch_description():
    return launch.LaunchDescription([
        launch_ros.actions.Node(
            package='demo_nodes_cpp',
            executable='talker',
            name='talker'),
  ])

 

Building and running the launch file

# launch_ws
colcon build
source ~/launch_ws/install/setup.bash
ros2 launch py_launch_example my_script_launch.py

 

 

 

ROS2_Humble Documentation : https://docs.ros.org/en/humble/Tutorials/Intermediate.html