https://www.robotstory.co.kr/king/?board_page=4&vid=874 참고하여 요약함
1. 설치 (humble 기준)
ROS2 Ardent == Ubuntu 16.04
ROS2 Dashing == Ubuntu 16.04, 18.04
ROS2 Foxy == Ubuntu 20.04
ROS2 Rolling / Humble / Iron / == Ubuntu 22.04
아래 따라하기
https://docs.ros.org/en/foxy/Installation/Ubuntu-Install-Debians.html
https://docs.ros.org/en/humble/Installation.html
2. 활용 (humble 기준)
2.1 환경 설정 (새로운 terminal 열면 해야 함)
# source the setup files
source /opt/ros/humble/setup.bash
# check env. var. (ROS_DISTRO, ROS_DOMAIN_ID, ROS_VERSION 확인가능)
printenv | grep -i ROS
# set ROS_DOMAIN_ID (default 0)
같은 DOMAIN상의 노드들끼리만 잘 보이고, 메시지 전송이 가능함
export ROS_DOMAIN_ID=<your_domain_id>
# limit to localhost only (cannot communicate w/ other coms)
export ROS_LOCALHOST_ONLY=1
(option. 다음 설정을 하면 매번 안해도 됨)
# All setups in bash
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc
echo "export ROS_DOMAIN_ID=<your_domain_id>" >> ~/.bashrc
echo "export ROS_LOCALHOST_ONLY=1" >> ~/.bashrc
2.2 이해 (node, topic, service, action)
# node: 단일 기능 객체 (ex: 바퀴제어, 이미지센서수집), 다른 노드와 데이터를 topics, services, action, param 형태로 주고 받을 수 있음
ros2 node list
ros2 node info
# topic: publisher-subscriber 형태 (Youtube/뉴스처럼 한명이 올리고, 다수가 받아보는 형태)의 메시지 전달 방법
ros2 topic list
ros2 topic list -t (w/ type)
ros2 interface show <msg> (see msg type)
ros2 topic echo <topic_name> (see topic contents)
ros2 topic pub <topic_name> <msg_type> '<args>' (실제 topic을 cmd로 뿌리기)
# call-and-respose 형태의 메시지 전달 방법 (client의 요청이 있을 때만 답함)
ros2 service list -t (w/ type)
ros2 service type <service_name>
ros2 service find <type_name>
ros2 interface show <type_name>.srv
ros2 service call <service_name> <service_type> <arguments>
# params: node setting argument
ros2 param list
ros2 param get <node_name> <parameter_name>
ros2 param set <node_name> <parameter_name> <value>
ros2 param dump <node_name> (params to file <node_name>.yaml)
ros2 param load <node_name> <parameter_file>
# action은 긴 시간동안 동작하도록 설계된 communication type
# goal, feedback, result로 구성됨
# goal 설정, 결과는 service형태로, feedback은 topic형태로 구성
# 기본적으로 동작은 client-server형태
ros2 action list
ros2 action info /turtle1/rotate_absolute
ros2 interface show turtlesim/action/RotateAbsolute
ros2 action send_goal <action_name> <action_type> <values>
# messages: topic의 실질적 정의된 형태 (A topic은 A msg현태로, B topic은 B msg 형태로)
# to view logs
rqt_console
# install turtlebot and rqt
sudo apt update
sudo apt install ros-foxy-turtlesim
ros2 run turtlesim turtlesim_node
ros2 run turtlesim turtle_teleop_key
sudo apt install ~nros-foxy-rqt*
rqt
rqt_graph
# topic을 선택해서 기록할 수 있음
ros2 bag record <topic_name> <topic_name2> ...
ros2 bag play subset
######################################################
2.3 colcon: package 구현 툴
sudo apt install python3-colcon-common-extensions
underlay: ROS2설치 및 셋업에서 설정됨
overlay: 내가 목적을 가지고 짜는 프로그램
source /opt/ros/humble/setup.bash
colcon build --symlink-install
# if meet error
conda install -c conda-forge catkin_pkg empy lark
# if meet error again
delete cpp src in src code
echo "source /usr/share/colcon_cd/function/colcon_cd.sh" >> ~/.bashrc
echo "export _colcon_cd_root=/opt/ros/humble/" >> ~/.bashrc
colcon_cd (pkg간 폴더이동)
tab으로 완성하기
echo "source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash" >> ~/.bashrc
#######################################
2.4 workspace 만들기 (프로젝트 같은)
source /opt/ros/humble/setup.bash
ros2_ws가 workspace이름임.
mkdir -p ~/ros2_ws/src
cd ~/ros2_ws/src
# copy from github for sample code
git clone https://github.com/ros/ros_tutorials.git -b humble
# cd if you're still in the ``src`` directory with the ``ros_tutorials`` clone
cd ..
rosdep install -i --from-path src --rosdistro humble -y
colcon build
open new terminal
# <underlay>
source /opt/ros/humble/setup.bash
# <overlay>
cd ~/ros2_<ws_name>
source install/local_setup.bash
#############################
2.5 package 만들기 (모듈 같은)
구성
package.xml (패키지 메타 정보)
resource/<pkg_name>
setup.cfg (실행파일일 경우 필요, ros2 run <>)
setup.py (설치파일)
<pkg_name> (ros2용 검색 폴더)
cd ~/ros2_ws/src
ros2 pkg create --build-type ament_python <package_name>
ros2 pkg create --build-type ament_python --node-name my_node my_package
cd ~/ros2_ws
colcon build
colcon build --packages-select my_package
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release # Relese모드로 빌드
source install/local_setup.bash
ros2 run my_package my_node
# fill the TODO information in package.xml and setup.py
######################################################
2.6 node for publisher and subscriber
2.6.1 create package
cd ~/ros2_ws/src
ros2 pkg create --build-type ament_python py_pubsub
2.6.2 make node by getting toy python code
cd ros2_ws/src/py_pubsub/py_pubsub
wget https://raw.githubusercontent.com/ros2/examples/humble/rclpy/topics/minimal_publisher/examples_rclpy_minimal_publisher/publisher_member_function.py
2.6.3 add dependency at package.xml
<exec_depend>rclpy</exec_depend>
<exec_depend>std_msgs</exec_depend>
2.6.4 add entry point at setup.py
entry_points={
'console_scripts': [
'talker = py_pubsub.publisher_member_function:main',
],
},
2.6.5 install related dependency
rosdep install -i --from-path src --rosdistro humble -y
# build
colcon build --packages-select py_pubsub
2.6.7 run
source /opt/ros/humble/setup.bash # source underlay (bash에 있음 안해도 됨)
source install/setup.bash # source overlay
ros2 run py_pubsub talker
ros2 run py_pubsub listener
####################################################
2.7 cv_bridge 설치 (opencv - ros image 컨버터)
sudo apt-get install ros-(ROS version name)-cv-bridge
sudo apt-get install ros-(ROS version name)-vision-opencv
해보고 안되면 아래도 설치
sudo apt install python3-numpy
sudo apt install libboost-python-dev
cd <YOUR_ROS2_WORKSPACE>/src
git clone https://github.com/ros-perception/vision_opencv.git -b humble
cd ..
colcon build --symlink-install
sudo apt install python3-opencv
source <YOUR_ROS2_WORKSPACE>/install/local_setup.bash
colcon test