with-RL
로봇 / ROS2024년 1월 26일

ROS2 Minimal Tutorial - Basic

이 포스트는 ROS2에 대한 기본적인 내용에 대한 간단한 설명입니다.

이 과정은 다음 환경에서 구성했습니다.

Windows에 간단하게 시험을 하기 위해서는 과정을 완료한 후에 참고하시길 바랍니다.

1. ROS vs ROS2

2. Node

(img src) https://docs.ros.org/en/foxy/Tutorials/Beginner-CLI-Tools/Understanding-ROS2-Nodes/Understanding-ROS2-Nodes.html
$ ros2 run turtlesim turtlesim_node
$ ros2 run turtlesim turtle_teleop_key
$ ros2 node list
ros2 node info /turtlesim
$ rqt_graph

3. Package

$ ros2 pkg create --build-type ament_cmake <PackageName>
$ ros2 pkg create --build-type ament_python <PackageName>
$ mkdir -p ~/Workspace/ros_ws
$ cd ~/Workspace/ros_ws
$ mkdir src
$ cd src
$ ros2 pkg create --build-type ament_python ros_tutorial

4. Launch

import os
from glob import glob
from setuptools import setup

package_name = 'ros_tutorial'

setup(
    name=package_name,
    version='0.0.0',
    packages=[package_name],
    data_files=[
        ('share/ament_index/resource_index/packages',
            ['resource/' + package_name]),
        ('share/' + package_name, ['package.xml']),
        (os.path.join('share', package_name, 'launch'), glob('launch/*.launch.py')),
    ],
    install_requires=['setuptools'],
    zip_safe=True,
    maintainer='cchyun',
    maintainer_email='cchyun@todo.todo',
    description='TODO: Package description',
    license='TODO: License declaration',
    tests_require=['pytest'],
    entry_points={
        'console_scripts': [
        ],
    },
)
#!/usr/bin/env python3

from launch import LaunchDescription
from launch.actions import ExecuteProcess
from launch_ros.actions import Node


def generate_launch_description():
    return LaunchDescription(
        [
            Node(
                package='turtlesim',
                executable='turtlesim_node',
                parameters=[],
                arguments=[],
                output='screen'
            ),
            ExecuteProcess(
                cmd=["ros2", "run", "rqt_graph", "rqt_graph"],
                output="screen",
            )
        ]
    )
$ cd ~/Workspace/ros_ws
$ colcon build --symlink-install
$ source install/setup.bash
$ ros2 launch ros_tutorial turtlesim.launch.py

5. Parameter

$ ros2 run turtlesim turtlesim_node
$ ros2 run turtlesim turtle_teleop_key
$ ros2 param list
$ ros2 param get <node_name> <parameter_name>
$ ros2 param get /turtlesim background_r
$ ros2 param set /turtlesim background_r 150
$ ros2 param dump /turtlesim > turtlesim.yaml
$ ros2 param load /turtlesim turtlesim.yaml
$ ros2 run turtlesim turtlesim_node --ros-args --params-file turtlesim.yaml
ROS2 Minimal Tutorial - Basic | with-RL