1 분 소요

Launch file 이란?

ROS2에서 ‘launch’ 파일은 여러 노드 및 다양한 ROS2 컴포넌트들을 동시에 관리하는 데 사용되는 파일이다. ‘launch’ 파일은 Python 스크립트로 작성되며, 시스템 전반적인 설정 및 구성을 정의한다.

launch 파일 실행과 관련한 명령어는 다음과 같다.

ros2 launch <패키지 이름> <launch 파일 이름>

ROS2 launch 파일에서 사용되는 액션 유형에는 ‘ExecuteProcess’‘Node’ 가 있다.

ExecuteProcess

‘ExecuteProcess’는 노드가 아닌 외부 프로세스실행 파일을 시작하는 데 사용된다. 일반적으로 시스템에 속하지 않는 ROS2 노드나 외부 실행 파일을 실행하려는 경우에 선택된다.

from launch import LaunchDescription
from launch.actions import ExecuteProcess

def generate_launch_description():
    return LaunchDescription([
        ExecuteProcess(
            cmd=['/path/to/external_process'],
            output='screen',
        ),
    ])

Node

‘Node’는 ROS2의 실행 가능한 애플리케이션을 나타내는 노드를 실행하거나, ROS2의 노드를 구성하고 실행할 때 주로 사용된다.

from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    return LaunchDescription([
        Node(
            package='my_robot_pkg',
            executable='robot_node',
            name='robot_node',
            output='screen',
            parameters=[{'param_name': 'param_value'}]
        ),
    ])

주요 차이점에 대해서 간단하게 정리하면 다음과 같다.

  ExecuteProcess Node
대상 유형 외부 프로세스나 실행 파일을 대상 ROS2의 실행 가능한 노드를 대상
ROS2 컴포넌트 실행 외부 프로세스 실행 및 ROS2 노드 외 실행 파일 관리에 사용 ROS2 노드를 실행하고 관리하는 데 사용
ROS2 관련 기능 외부 프로세스 실행으로 ROS2 통신과 관련 없음 ROR2의 노드를 실행하여 ROS2 통신과 상호 작용 가능

Examples

Example1 (ExecuteProcess)

    # create and return launch description object
    return LaunchDescription(
        [
            # robot state publisher allows robot model spawn in RVIZ
            robot_state_publisher_node,
            # start gazebo, notice we are using libgazebo_ros_factory.so instead of libgazebo_ros_init.so
            # That is because only libgazebo_ros_factory.so contains the service call to /spawn_entity
            ExecuteProcess(
                cmd=["gazebo", "--verbose", world, "-s", "libgazebo_ros_factory.so"],
                output="screen",
            ),
            # tell gazebo to spwan your robot in the world by calling service
            ExecuteProcess(
                cmd=[ "ros2", "service", "call", "/spawn_entity", "gazebo_msgs/SpawnEntity", spwan_args ],
                output="screen",
            ),
            ExecuteProcess(
                cmd=["ros2", "run", "rviz2", "rviz2", "-d", rviz], 
								output="screen"
            ),
        ]
    )

아래의 명령어를 실행시켜보면 크게 세 가지 작업이 동작하는 것을 확인할 수 있다.

ros2 launch gcamp_gazebo gcamp_world.launch.py
  • Gazebo 실행
  • robot을 등장시키기
  • rviz를 실행

image

Example2 (Node)

#!/usr/bin/env python3

import os

from launch import LaunchDescription
from launch.actions import ExecuteProcess, IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration

from launch_ros.actions import Node

# this is the function launch  system will look for
def generate_launch_description():

    turtlesim_node = Node(
        package='turtlesim',
        executable='turtlesim_node',
        parameters=[],
        arguments=[],
        output="screen",
    )

    turtlesim_teleop_node = Node(
        package='turtlesim',
        executable='draw_square',
        parameters=[],
        arguments=[],
        output="screen",
    )

    # create and return launch description object
    return LaunchDescription(
        [
            turtlesim_node,
            turtlesim_teleop_node,
        ]
    )

태그: ,

카테고리:

업데이트: