🔄 1. Topic (토픽)
비동기적 메시지 스트리밍 방식
Publisher → 토픽 → Subscriber
✅ 구조
[Publisher Node] --(msg)--> [Topic] --(msg)--> [Subscriber Node]
✅ 특징
- 실시간 연속 데이터 전송에 적합
- 예: 센서 데이터, 로봇 상태, 영상 스트림 등
✅ 예시
# 메시지 타입: geometry_msgs/msg/Twist
# 토픽 이름: /cmd_vel
📮 2. Service (서비스)
요청-응답 구조의 통신 방식
Client → Request → Server → Response
✅ 구조
[Client Node] --(Request)--> [Service] --(Response)--> [Client Node]
✅ 특징
- 하나의 요청 → 하나의 응답
- 블로킹 방식 (응답 올 때까지 대기)
- 예: 특정 위치로 점프하기, 모드 변경 등
✅ 예시
# 서비스 타입: example_interfaces/srv/AddTwoInts
# 서비스 이름: /add_two_ints
🌀 3. Action (액션)
장기 실행 작업을 위한 통신 방식
Goal + Feedback + Result 지원
✅ 구조
[Action Client]
|
Goal
|
[Action Server] ← Feedback ← Client
|
Result
✅ 특징
- 수 초 ~ 수 분 걸리는 작업에 적합
- Goal 전송 후 중간 상태(feedback)도 받을 수 있음
- 예: 경로 따라가기, 로봇 회전, 이미지 캡처
✅ 예시
# 액션 타입: example_interfaces/action/Fibonacci
# 액션 이름: /fibonacci
📦 4. Message (메시지)
ROS에서 노드 간 데이터를 주고받는 단위 구조
✅ 구조
- .msg: Topic이나 Action에서 사용되는 기본 데이터 구조
geometry_msgs/msg/Twist.msg
std_msgs/msg/String.msg
- .srv: Service용 메시지 → 요청/응답 구조
example_interfaces/srv/AddTwoInts.srv
# 구조:
int64 a
int64 b
---
int64 sum
- .action: Action 전용 메시지 → Goal / Feedback / Result 세 가지 구조
example_interfaces/action/Fibonacci.action
# 구조:
int32 order
---
int32[] sequence ← feedback
---
int32[] sequence ← result
🕸️ ROS 2 전체 통신 구조 시각화
+----------------+
| Sensor Node |
+----------------+
|
| (Topic Msg)
v
+----------------+
| Control Node |<----------------+
+----------------+ |
| |
| (Action Goal/Feedback) |
v |
+---------------------+ |
| Action Server (Nav)| |
+---------------------+ |
|
+------------------+ |
| Service Node |<-------------+
+------------------+
^
| (Service Request)
|
+------------------+
| User Interface |
+------------------+
🛠️ 명령어 요약
기능 / 명령어
| 토픽 목록 | ros2 topic list |
| 토픽 메시지 확인 | ros2 topic echo /topic_name |
| 서비스 목록 | ros2 service list |
| 서비스 요청 | ros2 service call /service_name srv_type "{...}" |
| 액션 목록 | ros2 action list |
| 액션 피드백 확인 | ros2 action send_goal /action_name action_type "{goal}" |
✅ 실제 예시 통합
구조 / 예시
| Topic | /cmd_vel (Twist 메시지로 로봇 제어) |
| Service | /turtle1/teleport_absolute (거북이 위치 점프) |
| Action | /turtle1/rotate_absolute (회전 명령, 피드백 포함) |
| Message | geometry_msgs/msg/Twist, example_interfaces/srv/AddTwoInts, example_interfaces/action/Fibonacci 등 |
📌 핵심 요약
항목 / 목적 / 사용 예
| Topic | 실시간 데이터 스트리밍 | 센서, 모터 제어 |
| Service | 요청-응답 구조 | 위치 설정, 초기화 요청 |
| Action | 장시간 작업 + 피드백 | 경로 이동, 회전 등 |
| Message | 데이터 구조 정의 | Pose, Twist, Image 등 |
'ROS' 카테고리의 다른 글
| ROS 2 Python 서비스/클라이언트 실습 요약 (py_srvcli) (0) | 2025.04.23 |
|---|