1. ROS(Robot Operating System) 간단하게 알아보고 동작 확인해보기
강의 동영상(유튜브): Autoware Course Lecture 2: ROS2 101
ROS의 탄생 배경, 개요, 특징에 관하여 설명을 한다.
ROS에 관한 자세한 설명과 기본 튜토리얼은 네이버 오로카 카페에서 참고하면 이해가 잘된다.
1.1. 강의에 필요한 튜토리얼 설치
sip2@sip2-NG-N-i5750:~/adehome$ cd AutowareAuto/
sip2@sip2-NG-N-i5750:~/adehome/AutowareAuto$ ade start
Starting ade with the following images:
ade | 18425565a9fd | master | registry.gitlab.com/autowarefoundation/autoware.auto/autowareauto/ade:master
ade-atom | v1.39.1 | latest | registry.gitlab.com/apexai/ade-atom:latest
autowareauto | c9dbc109642c | master | registry.gitlab.com/autowarefoundation/autoware.auto/autowareauto:master
ade_registry.gitlab.com_apexai_ade-atom_latest
ade_registry.gitlab.com_autowarefoundation_autoware.auto_autowareauto_master
non-network local connections being added to access control list
Current default time zone: 'Asia/Tokyo'
Local time is now: Mon May 18 20:53:18 JST 2020.
Universal Time is now: Mon May 18 11:53:18 UTC 2020.
Adding user sip2 to group video
Adding user sip2 to group dialout
Initializing /opt/atom
Initializing /opt/atom done
ADE startup completed.
ADE has been started, enter or run commands using: ade enter
sip2@sip2-NG-N-i5750:~/adehome/AutowareAuto$ ade enter
Entering ade with following images:
ade | 18425565a9fd | master | registry.gitlab.com/autowarefoundation/autoware.auto/autowareauto/ade:master
ade-atom | v1.39.1 | latest | registry.gitlab.com/apexai/ade-atom:latest
autowareauto | c9dbc109642c | master | registry.gitlab.com/autowarefoundation/autoware.auto/autowareauto:master
sip2@ade:~$ source /opt/ros/dashing/setup.bash
sip2@ade:~$ sudo apt update
sip2@ade:~$ sudo apt install ros-dashing-turtlesim
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
python3-rosdistro-modules python3-rospkg-modules
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
ros-dashing-turtlesim
0 upgraded, 1 newly installed, 0 to remove and 26 not upgraded.
Need to get 1,509 kB of archives.
After this operation, 20.5 MB of additional disk space will be used.
Get:1 http://packages.ros.org/ros2/ubuntu bionic/main amd64 ros-dashing-turtlesim amd64 1.0.1-1bionic.20200318.041354 [1,509 kB]
Fetched 1,509 kB in 10s (158 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package ros-dashing-turtlesim.
(Reading database ... 120477 files and directories currently installed.)
Preparing to unpack .../ros-dashing-turtlesim_1.0.1-1bionic.20200318.041354_amd64.deb ...
Unpacking ros-dashing-turtlesim (1.0.1-1bionic.20200318.041354) ...
Setting up ros-dashing-turtlesim (1.0.1-1bionic.20200318.041354) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
sip2@ade:~$ sudo apt install ros-dashing-rqt-*
sip2@ade:~$ sudo apt install byobu
1.2. 예제 실행해 보기
sip2@ade:~$ byobu
sip2@ade:~$ source /opt/ros/dashing/setup.bash
sip2@ade:~$ mkdir -p ~/ros2_example_ws/src
sip2@ade:~$ cd ~/ros2_example_ws/
sip2@ade:~/ros2_example_ws$ git clone https://github.com/ros2/examples src/examples
Cloning into 'src/examples'...
remote: Enumerating objects: 213, done.
remote: Counting objects: 100% (213/213), done.
remote: Compressing objects: 100% (135/135), done.
remote: Total 4124 (delta 122), reused 131 (delta 67), pack-reused 3911
Receiving objects: 100% (4124/4124), 627.80 KiB | 941.00 KiB/s, done.
Resolving deltas: 100% (2715/2715), done.
sip2@ade:~/ros2_example_ws$ cd ~/ros2_example_ws/src/examples/
sip2@ade:~/ros2_example_ws/src/examples (master u=)$ git checkout dashing
Branch 'dashing' set up to track remote branch 'dashing' from 'origin' by rebasing.
Switched to a new branch 'dashing'
sip2@ade:~/ros2_example_ws/src/examples (dashing u=)$ cd ~/ros2_example_ws
sip2@ade:~/ros2_example_ws$ colcon build --symlink-install
Starting >>> examples_rclcpp_minimal_action_client
Starting >>> examples_rclcpp_minimal_action_server
Starting >>> examples_rclcpp_minimal_client
Starting >>> examples_rclcpp_minimal_composition
Starting >>> examples_rclcpp_minimal_publisher
Starting >>> examples_rclcpp_minimal_service
Starting >>> examples_rclcpp_minimal_subscriber
Starting >>> examples_rclcpp_minimal_timer
Starting >>> examples_rclpy_executors
Starting >>> examples_rclpy_minimal_action_client
Starting >>> examples_rclpy_minimal_action_server
Starting >>> examples_rclpy_minimal_client
Finished <<< examples_rclpy_executors [2.85s]
Starting >>> examples_rclpy_minimal_publisher
Finished <<< examples_rclpy_minimal_action_client [2.96s]
Finished <<< examples_rclpy_minimal_action_server [3.01s]
Finished <<< examples_rclpy_minimal_client [3.06s]
Starting >>> examples_rclpy_minimal_service
Starting >>> examples_rclpy_minimal_subscriber
Finished <<< examples_rclpy_minimal_subscriber [3.99s]
Finished <<< examples_rclpy_minimal_publisher [4.52s]
Finished <<< examples_rclpy_minimal_service [4.38s]
Finished <<< examples_rclcpp_minimal_service [9.76s]
Finished <<< examples_rclcpp_minimal_client [9.98s]
Finished <<< examples_rclcpp_minimal_timer [10.1s]
Finished <<< examples_rclcpp_minimal_publisher [10.6s]
Finished <<< examples_rclcpp_minimal_action_server [10.7s]
Finished <<< examples_rclcpp_minimal_subscriber [10.7s]
Finished <<< examples_rclcpp_minimal_action_client [11.4s]
Finished <<< examples_rclcpp_minimal_composition [12.1s]
Summary: 15 packages finished [12.8s]
sip2@ade:~/ros2_example_ws$ source ./install/setup.bash
Pub/Sub 예제 실행해보기
sip2@ade:~/ros2_example_ws$ ros2 run examples_rclcpp_minimal_publisher publisher_lambda
[INFO] [minimal_publisher]: Publishing: 'Hello, world! 0'
[INFO] [minimal_publisher]: Publishing: 'Hello, world! 1'
[INFO] [minimal_publisher]: Publishing: 'Hello, world! 2'
[INFO] [minimal_publisher]: Publishing: 'Hello, world! 3'
[INFO] [minimal_publisher]: Publishing: 'Hello, world! 4'
[INFO] [minimal_publisher]: Publishing: 'Hello, world! 5'
[INFO] [minimal_publisher]: Publishing: 'Hello, world! 6'
[INFO] [minimal_publisher]: Publishing: 'Hello, world! 7'
[INFO] [minimal_publisher]: Publishing: 'Hello, world! 8'
[INFO] [minimal_publisher]: Publishing: 'Hello, world! 9'
새로운 창 생성(byobu에서는 F2을 누르면 새로운 창이 생성되고, F3,F4로 창간 이동을 수행)
sip2@ade:~$ source /opt/ros/dashing/setup.bash
sip2@ade:~$ cd ros2_example_ws/
sip2@ade:~/ros2_example_ws$ source ./install/setup.bash
sip2@ade:~/ros2_example_ws$ ros2 topic list
/parameter_events
/rosout
/topic
sip2@ade:~/ros2_example_ws$ ros2 topic echo /topic
data: Hello, world! 97
---
data: Hello, world! 98
---
data: Hello, world! 99
---
data: Hello, world! 100
---
^C
sip2@ade:~/ros2_example_ws$ ros2 topic hz /topic
average rate: 2.000
min: 0.500s max: 0.500s std dev: 0.00009s window: 4
average rate: 2.000
min: 0.500s max: 0.500s std dev: 0.00008s window: 7
average rate: 2.000
min: 0.500s max: 0.500s std dev: 0.00007s window: 10
sip2@ade:~/ros2_example_ws$ cd src/examples/rclcpp/minimal_publisher/
sip2@ade:~/ros2_example_ws/src/examples/rclcpp/minimal_publisher (dashing u=)$ ls
CHANGELOG.rst lambda.cpp not_composable.cpp README.md
CMakeLists.txt member_function.cpp package.xml
sip2@ade:~/ros2_example_ws/src/examples/rclcpp/minimal_publisher (dashing u=)$ less member_function.cpp
pub 소스코드 살펴보기
sip2@ade:~/ros2_example_ws/src/examples/rclcpp/minimal_publisher (dashing u=)$ emacs member_function.cpp
내용 대충 수정하고 다시 colon build
sip2@ade:~/ros2_example_ws$ colcon build --symlink-install
Starting >>> examples_rclcpp_minimal_action_client
Starting >>> examples_rclcpp_minimal_action_server
Starting >>> examples_rclcpp_minimal_client
Starting >>> examples_rclcpp_minimal_composition
Starting >>> examples_rclcpp_minimal_publisher
Starting >>> examples_rclcpp_minimal_service
Starting >>> examples_rclcpp_minimal_subscriber
Starting >>> examples_rclcpp_minimal_timer
Starting >>> examples_rclpy_executors
Starting >>> examples_rclpy_minimal_action_client
Starting >>> examples_rclpy_minimal_action_server
Starting >>> examples_rclpy_minimal_client
Finished <<< examples_rclcpp_minimal_client [1.85s]
Starting >>> examples_rclpy_minimal_publisher
Finished <<< examples_rclcpp_minimal_action_client [2.02s]
Finished <<< examples_rclcpp_minimal_action_server [2.02s]
Finished <<< examples_rclcpp_minimal_subscriber [1.92s]
Finished <<< examples_rclcpp_minimal_service [1.99s]
Finished <<< examples_rclcpp_minimal_timer [1.97s]
Starting >>> examples_rclpy_minimal_service
Starting >>> examples_rclpy_minimal_subscriber
Finished <<< examples_rclcpp_minimal_composition [2.20s]
Finished <<< examples_rclpy_executors [2.40s]
Finished <<< examples_rclpy_minimal_action_client [2.42s]
Finished <<< examples_rclpy_minimal_action_server [2.43s]
Finished <<< examples_rclpy_minimal_client [2.44s]
Finished <<< examples_rclcpp_minimal_publisher [3.35s]
Finished <<< examples_rclpy_minimal_publisher [1.92s]
Finished <<< examples_rclpy_minimal_service [1.74s]
Finished <<< examples_rclpy_minimal_subscriber [1.74s]
sip2@ade:~/ros2_example_ws$ ros2 run examples_rclcpp_minimal_publisher publisher_member_function
[INFO] [revenge_of_minimal_publisher]: Publishing: 'Hello, open road! 0'
[INFO] [revenge_of_minimal_publisher]: Publishing: 'Hello, open road! 1'
[INFO] [revenge_of_minimal_publisher]: Publishing: 'Hello, open road! 2'
[INFO] [revenge_of_minimal_publisher]: Publishing: 'Hello, open road! 3'
[INFO] [revenge_of_minimal_publisher]: Publishing: 'Hello, open road! 4'
[INFO] [revenge_of_minimal_publisher]: Publishing: 'Hello, open road! 5'
[INFO] [revenge_of_minimal_publisher]: Publishing: 'Hello, open road! 6'
[INFO] [revenge_of_minimal_publisher]: Publishing: 'Hello, open road! 7'
[INFO] [revenge_of_minimal_publisher]: Publishing: 'Hello, open road! 8'
[INFO] [revenge_of_minimal_publisher]: Publishing: 'Hello, open road! 9'
[INFO] [revenge_of_minimal_publisher]: Publishing: 'Hello, open road! 10'
[INFO] [revenge_of_minimal_publisher]: Publishing: 'Hello, open road! 11'
[INFO] [revenge_of_minimal_publisher]: Publishing: 'Hello, open road! 12'
[INFO] [revenge_of_minimal_publisher]: Publishing: 'Hello, open road! 13'
[INFO] [revenge_of_minimal_publisher]: Publishing: 'Hello, open road! 14'
[INFO] [revenge_of_minimal_publisher]: Publishing: 'Hello, open road! 15'
ROS1이랑 똑같다.. 헤더랑 문법만 약간 다를뿐..
새로운 창 실행
ROS의 Pub/Sub은 토픽 이름과 타입을 잘 맞춰주는 것이 포인트이다.
ROS1와 ROS2는 많이 비슷해서 강의 2에서 예제는 넘어가도 될 것 같다.
참고문헌
2) byobu 기본 사용법
コメント
コメントを投稿