노드 실행

평범한컴공생·2022년 8월 4일
0

[ROS2]

목록 보기
11/19
post-thumbnail

배경

지금까지 새 노드를 매번 실행할 때마다 새 터미널을 열어야 해서 적지 아니하게 번거로웠다.

이때, 실행 파일을 사용하면 여러 개의 노드들을 동시에 시작하고 구성할 수 있다.

실행 파일을 실행하기 위해서는 ros2 launch를 사용한다.

작업

실행 파일 실행

터미널을 열자.

ros2 launch turtlesim multisim.launch.py
# 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'),
    ])

위와 같은 실행 파일이 실행될 것이다.

실행 파일은 Python뿐만 아니라 XML, YAML을 통해서도 만들 수 있다.

turtlesim 노드 제어

2개의 터미널을 새로 열어 ros2 topic pub 명령어를 통해 노드를 제어해보자.

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}}"

참고

ROS 2 Documentation: Foxy

profile
학부 연구생(220627~)

0개의 댓글