[ROS 1 NOTE] Basis of ROS
ROS는 Robot Operating System의 줄임말로 오늘날 로보틱스 분야에서 대중적으로 사용되는 시스템이다.
ROS의 특징으로는...
1. Peer to peer : 정의된 API를 통해 각 프로그램 간 통신 가능
2. Distributed : 네트워크를 통해 다중 컴퓨터 간 통신 가능
3. Multi-lingual : C++, Python, MATLAB 등 다양한 언어로 사용
4. Light-weight : Stand-alone Libraries를 통해 가벼움
5. Free and open-source : 대부분의 ROS 소프트웨어는 무료로 사용 가능
ROS Master
roscore
- 노드(프로세스) 간의 커뮤니케이션 관리 지원
- ROS Master 실행을 통해 모든 노드 등록
ROS Nodes
- 개별적으로 컴파일, 실행, 관리
- packages 내에 구성
## node 실행
rosrun package_name node_name
## See active nodes with
rosnode list
## Retrieve information about a node with
rosnode info node_name
ROS Topics
- 메세지 stream의 이름
- Topic을 통해 노드 간 통신(노드는 topic을 publish/subscribe 함)
- 1 publisher <-> n subscribers
## 실행 중인 topic들
rostopic list
## topic 내용 출력
rostopic echo /topic
## topic 정보 보기
rostopic info /topic
ROS Messages
- topic 타입을 정의하는 Data structure
- integers, floats, booleans, strings 등으로 구성
- *.msg file 형태
## topic 타입 확인
rostopic type /topic
## topic으로 message publish
rostopic pub /topic type data
ROS Workspace Environment
- 현재 workspace 내용 확인
## 기본 workspace load
source /opt/ros/noetic/setup.bash
## Overlay catkin workspace
cd ~/catkin_ws
source devel/setup.bash
## Check workspace
echo $ROS_PACKAGE_PATH
## See setup with
gedit ~/.bashrc
Catkin Build System
- catkin : executables, libraries, interfaces 를 생성하는 ROS build system
* git clone 시 src 에 위치하도록 한다
## catkin workspace로 이동
cd ~/catkin_ws
## Build a package with
catkin build package_name
** 새로운 패키지 만들 때마다, 환경 업데이트 **
source devel/setup.bash
## build & devel space를 지울 때
catkin clean
## catkin workspace setup can be checked with
catkin config
ROS Launch
- launch : a tool for launching multiple nodes
- XML 파일 형태로 작성(*.launch)
- roscore가 시작되지 않은 경우, launch시 자동으로 roscore 시작
## Start a launch file with
roslaunch file_name.launch
## Start a launch file from a package with
roslaunch package_name file_name.launch
- launch : Root element of the launch file
- node : Each <node> tag specifies a node to be launched
- name : Name of the node (free to choose)
- pkg : Package containing the node
- type : Type of the node, there must be a corresponding executable with the same name
- output : Specifies where to output log messages(screen:console, log:log file)
Arguments
## Create re-usable launch files with <arg> tag (파라미터 같은 역할)
<arg name="arg_name" default="default_value"/>
## Use arguments in launch file with
$(arg arg_name)
## When launching, arguments can be set with
roslaunch launch_file.launch arg_nmae:=value
## Include other launch files with <include> tag
<include file="package_name"/>
## Find the system path to other packages with
$(find package_name)
## Pass arguments to the included file
<arg name="arg_name" value="value"/>