ros2_control
ros2_control은 수 많은 컨트롤 알고리즘과 컨트롤 시스템을 쉽게 사용할 수 있게 도와주는 패키지입니다.
센서나 모터의 컨트롤에 익숙치 않아 어려움을 겪는 개발자들 혹은 그런 로우 레벨 엔지니어링 개발 시간을 줄여주기 위해 ros2_control은 하드웨어와 컨트롤러를 이어주는 역할을 해줍니다.
기존 ros1의 ros_control은 PR2라는 로봇을 제어하는 패키지를 변형하여 사용했지만, ros2_control은 스크래치부터 새로 작성하여 기존보다 더 안정적으로 제작되고 있습니다.
이 글에서는 간략한 ROS2_control에 대한 내용과 ros2_control_demo에 포함된 RRBOT예제를 돌려봅니다.
Welcome to the ros2_control documentation! — ROS2_Control: Rolling Aug 2022 documentation
© Copyright 2022, ros2_control Maintainers.
control.ros.org
ros2_control 설치
sudo apt install ros-galactic-ros2-control ros-galactic-ros2-controllers -y
ros2_control은 프레임워크의 메인 인터페이스와 컴포넌트를 설치하는 것입니다.
ros2_controllers는 joint trajectory controller, differential drive controller와 같이 많이 쓰이는 컨트롤러를 담고 있습니다.
아키텍처
위 다이어그램은 ros2_control의 아키텍처입니다.
아키텍처에 대한 설명은 아래 글에서 진행됩니다.
[ros2_control] 아키텍처 분석
본 글에서는 ros2_control의 아키텍처 시스템을 분석해보려고 합니다. ros2_control_architecture Getting Started — ROS2_Control: Rolling Aug 2022 documentation The ros2_control framework’s source can b..
huroint.tistory.com
다음 예제를 위의 아키텍처에 결부시켜 이해해보면 좋을듯 합니다.
ros2_control_demos 데모 설치하기
https://github.com/ros-controls/ros2_control_demos/tree/master
GitHub - ros-controls/ros2_control_demos: This repository aims at providing examples to illustrate ros2_control and ros2_control
This repository aims at providing examples to illustrate ros2_control and ros2_controllers - GitHub - ros-controls/ros2_control_demos: This repository aims at providing examples to illustrate ros2...
github.com
ros2_control_demos를 이용하여 ros2_control를 활용해봅시다.
우선 본인의 ros2 워크스페이스로 이동하고, 자신의 ROS 버전에 맞는 레포지터리를 클론합니다.
cd ~/robot_ws/src
git clone -b galactic https://github.com/ros-controls/ros2_control_demos.git
저는 ROS2버전이 galatic이므로 위와 같이 클론했습니다.
그 후 필요한 패키지를 추가로 설치해줍니다.
vcs import --input ros2_control_demos/ros2_control_demos.galactic.repos
본인의 ROS2버전에 맞는 "ros2_control_demos.<ROS2_version>.repos" 를 넣어 실행하면 됩니다.
다음 rosdep을 이용해 남은 디펜던시 패키지를 설치하고 colcon을 이용하여 빌드합니다.
cd ~/robot_ws
rosdep install --from-paths src --ignore-src -r -y
colcon build --symlink-install
RRBOT 예제 실행
빌드가 완료되면 RRBOT 디스크립션 예제를 실행합니다.
RRBOT은 3개의 링크와 2개의 Revolute joint를 가진 간단한 형태의 매니퓰레이터입니다.
# 본인의 워크스페이스의 local_setup.bash를 실행합니다.
soruce ~/robot_ws/install/local_setup.bash
ros2 launch rrbot_description view_robot.launch.py
각 조인트를 컨트롤할 수 있습니다.
이전의 런치파일을 종료한 뒤, 다음 명령어로 다시 RRBOT을 준비합니다.
ros2 launch ros2_control_demo_bringup rrbot.launch.py
그러면 RRBOT Rviz가 다시 켜지고 하드웨어 상태 정보를 계속 나타냅니다.
Reading 아래는 RRBOT 조인트의 현재 값을 표현합니다.
Writing 아래는 RRBOT 조인트의 명령 값을 표현합니다.
ros2_control은 ros2 control 명령어를 활용합니다.
자세한 사용법은 다음 CLI문서를 참조하세요.
https://control.ros.org/master/doc/ros2_control/ros2controlcli/doc/userdoc.html
Command Line Interface — ROS2_Control: Rolling Aug 2022 documentation
© Copyright 2022, ros2_control Maintainers.
control.ros.org
계속해서 다음 명령어를 통해 사용 중인 하드웨어 인터페이스 리스트를 확인할 수 있습니다.
ros2 control list_hardware_interfaces
hardware_interfaces는 바퀴 조인트나 관절 조인트와 같은 모터 등 하드웨어의 인터페이스를 의미합니다.
RRBOT의 경우는 각 조인트의 position을 인터페이스로 잡았습니다.
여기서 [claimed]이라는 표식은 ros2_conrol의 컨트롤러가 해당 조인트를 제어하기 위해 접근했다는 의미입니다.
추가로 다른 예제인 디퍼런셜 타입의 모바일로봇 예제인 DiffBot의 hardware_interfaces는
이 같이 제어할 수 있는 인터페이스로 velocity로 나옵니다. 모바일로봇의 바퀴 경우 포지션 제어를 할 일이 거의 없으니 안 넣은 거고요.
다음 명령어를 통해 컨트롤러 리스트를 볼 수 있습니다.
ros2 control list_controllers
컨트롤러는 하드웨어를 제어하기 위한 기법들입니다.
현재 동작하고 있는 컨트롤러로는 joint_state_broadcaster와 forward_position_controller가 있군요.
joint_state_broadcaster는 모든 스테이트 인터페이스의 조인트의 값을 읽고 그것을 /joint_states와 /dynamic_joint_states로 리포트해주는 기능을 합니다.
forward_command_controller는 effort joint command입니다. 즉, 토크 기반의 제어기로 토크->속도->위치로 제어를 시도합니다.
https://github.com/ros-controls/ros2_controllers/blob/master/joint_state_broadcaster/doc/userdoc.rst
GitHub - ros-controls/ros2_controllers: Generic robotic controllers to accompany ros2_control
Generic robotic controllers to accompany ros2_control - GitHub - ros-controls/ros2_controllers: Generic robotic controllers to accompany ros2_control
github.com
GitHub - ros-controls/ros2_controllers: Generic robotic controllers to accompany ros2_control
Generic robotic controllers to accompany ros2_control - GitHub - ros-controls/ros2_controllers: Generic robotic controllers to accompany ros2_control
github.com
마찬가지로 diffbot을 살펴보면
디퍼런셜 모바일로봇 제어기인 diffbot_base_controller가 대신 실행되고 있는 것을 볼 수 있습니다.
다시 돌아가 RRBOT의 topic list를 호출해봅니다.
위와 같이 /joint_states와 /dynamic_joint_states가 존재합니다.
여기서 조인트를 제어명령을 하기 위해서는 /position_commands에 명령을 주어야합니다.
해당 토픽의 정보를 살펴보면 forawrd_position_controller 노드와 관련된 것을 알 수 있습니다.
마지막으로 RRBOT의 조인트 이동을 명령하기 위해 다음의 토픽을 보내봅니다.
ros2 topic pub /position_commands std_msgs/msg/Float64MultiArray "data:
- 1
- 1"
그러면 영상과 같이 움직이는 것을 볼 수 있습니다.
'Robot > ROS' 카테고리의 다른 글
[DDS] DDS와 RTPS (0) | 2022.10.02 |
---|---|
[ros2_control] 아키텍처 분석 (0) | 2022.08.21 |
[ROS2] 치트시트 (0) | 2022.08.14 |
[MicroROS] 참고할만한 자료들 (0) | 2022.08.06 |
[MicroROS] Publisher와 Subscriber 생성하기 (2) | 2022.08.06 |
댓글