ROS 2

ROS 2 Tutorials : Launching nodes

정지홍 2025. 1. 12. 10:13

https://docs.ros.org/en/jazzy/Tutorials/Beginner-CLI-Tools/Launching-Multiple-Nodes/Launching-Multiple-Nodes.html

 

Launching nodes — ROS 2 Documentation: Jazzy documentation

For now, don’t worry about the contents of this launch file. You can find more information on ROS 2 launch in the ROS 2 launch tutorials.

docs.ros.org

 

Goal

  • command line을 이용하여 multiple nodes를 한번에 실행하는 방법

 

Background

  • 지금까지의 튜토리얼에서는 각 노드마다 새로운 terminal을 열면서 작업을 수행하였다.
    하지만 더 복잡한 시스템을 만들고 더 많은 노드를 실행하게 된다면, terminal을 다시열고 설정 세부 사항을 다시 입력하는 것은 매우 번거로운 일이다.
    • Launch 파일을 사용한다면, ROS 2 nodes가 포함된 여러 실행 파일을 동시에 시작하고 구성하는 것이 가능하다.
    • 하나의 ROS 2 Launch 명령으로 단일 런치 파일을 실행하면, system의 모든 nodes와 설정을 한번에 시작하는 것이 가능하다.

 

Tasks

  • 1. terminal을 열고 다음의 명령어를 입력하자.
    • 그러면 거북이가 2개가 뜰것임. ( turtlesim )
ros2 launch turtlesim multisim.launch.py
  • 2. 위에서 실행시킨 multisim.launch.py의 코드는 다음과 같다.
    • 지금은 ROS 2의 Launch에 대해서 이해못해도 된다. 나중에 Intermediate튜토리얼에서 자세히 다룰것이다.
# turtlesim/launch/multisim.launch.py

from launch import LaunchDescription
import launch_ros.actions

def generate_launch_description():
    return LaunchDescription([
        launch_ros.actions.Node(
            namespace= "turtlesim1", package='turtlesim', executable='turtlesim_node', output='screen'),
        launch_ros.actions.Node(
            namespace= "turtlesim2", package='turtlesim', executable='turtlesim_node', output='screen'),
    ])
  • 3. 당연히 cmd에서 turtle을 움직이게 하는 명령어를 입력할수있다.
ros2 topic pub  /turtlesim1/turtle1/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.8}}"

ros2 topic pub  /turtlesim2/turtle1/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: -1.8}}"

 

Summary

  • 지금까지 수행한 작업의 중요한 점은 단 한번의 명령어로 두개의 turtlesim node를 실행했다는 것이다.
  • Launch 파일을 작성하는 방법을 배운다면, ros2 launch명령어를 사용해서 여러 nodes를 실행하고 이들의 설정을 동일한 방식으로 구성하는 것이 가능하다.
    • 이에 대한 내용은 위에서도 말했듯이 중급 튜토리얼에서 다룰것이다.