[2023-2] Mobility Service 강좌 정리본
1. Turtlesim 패키지 설치
sudo apt update
sudo apt install ros-foxy-turtlesim
2. ROS 동작 개념
- 기본적으로 노드라는 개념에서 출발
- 노드 + 노드 실행 정보 = 패키지, 그룹 패키지 = 메타패키지
- 노드간 입출력 데이터 송수신 가능하게 설계가 필요함.
- 통신 미들 웨어 차이 사진
3. Turtlesim 패키지와 노드
ros2 pkg list
ros2 pkg executables turtlesim
4. Turtlesim 패키지의 노드 실행
# 파란창 거북이 한마리
ros2 run turtlesim turtlesim_node
# 거북이 움직이기 시작
ros2 run turtlesim turtle_teleop_key
5. 노드, 토픽, 서비스, 액션의 조회
ros2 node list
/turtlesim
/teleop_turtle
ros2 topic list
/parameter_events
/rosout
/turtle1/cmd_vel
/turtle1/color_sensor
/turtle1/pose
ros2 service list
/clear
/kill
/reset
/spawn
/teleop_turtle/describe_parameters
/teleop_turtle/get_parameter_types
/teleop_turtle/get_parameters
/teleop_turtle/list_parameters
/teleop_turtle/set_parameters
/teleop_turtle/set_parameters_atomically
/turtle1/set_pen
/turtle1/teleport_absolute
/turtle1/teleport_relative
/turtlesim/describe_parameters
/turtlesim/get_parameter_types
/turtlesim/get_parameters
/turtlesim/list_parameters
/turtlesim/set_parameters
/turtlesim/set_parameters_atomically
ros2 action list
/turtle1/rotate_absolute
6. rqt_graph 로 보는 노드와 토픽의 그래프 뷰
rqt_graph
- 노드를 실행시키고 위의 코드를 입력하면 밑의 사진처럼 볼 수 있다.
- 설정을 바꾸면 밑의 사진처럼도 할 수 있다 !
7. 노드 목록
ros2 node list
/rqt_gui_py_node_28168
/teleop_turtle
/turtlesim
# 다른 노드명으로 동일 노드 복수 개 실행
ros2 run turtlesim turtlesim_node __node:=new_turtle
# 다시 목록 확인하면 추가된 것 볼 수 있음
ros2 node list
/rqt_gui_py_node_29017
/teleop_turtle
/new_turtle
/turtlesim
# 그래프도 확인
rqt_graph
8. 노드 정보 확인
ros2 node info /turtlesim
ros2 node info /teleop_turtle
# 둘 다 정보 주루룩 떠야함
9. 노드 개념 정리
- 노드 : 최소 단위의 실행 가능한 프로세스
- 메시지 통신을 통한 노드 사이 입출력 데이터 유기적으로 송수신 ( 토픽, 서비스, 액션, 파라미터 구분 )
10. 토픽 목록 확인
# 실행시키고
ros2 run turtlesim turtlesim_node
# 목록 확인
ros2 node info /turtlesim
# 간단하게 목록 확인
ros2 topic list -t
# 그래프 뷰 확인 전 실행
ros2 run turtlesim turtle_teleop_key
# 그래프 뷰도 확인
rqt_graph
- 밑의 사진처럼 설정해주면 다른 그림을 볼 수 있다.
11. 토픽 정보 확인
ros2 topic info /turtle1/cmd_vel
Type: geometry_msgs/msg/Twist
Publisher count: 1
Subscriber count: 1
12. 토픽 확인
# 내용 확인
ros2 topic echo /turtle1/cmd_vel
# 대역폭 확인
ros2 topic bw /turtle1/cmd_vel
# 주기 확인
ros2 topic hz /turtle1/cmd_vel
# 지연 시간 확인
ros2 topic delay /TOPIC_NAME
13. 토픽 발행
- ros2 topic pub <topic_name> <msg_type> "<args>"
- 밑의 코드를 실행시키면 거북이가 움직인다.
ros2 topic pub --once /turtle1/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.8}}"
- 한 바퀴를 돌게 해보았다.
14. bag 기록 (ros2 bag record)
- 파일 형태로 저장하고 필요할 때 파일을 불러와 재생시킬 수 있다.
- 기록할 때 제대로 안되는 경우가 있으니 똑같은 동작을 몇 번 더 해야할 때가 있으니 주의하자
- 창 하나를 더 만들어서 입력 !
ros2 bag record /turtle1/cmd_vel
15. bag 정보 (ros2 bag info)
ros2 bag info rosbag2_2020_09_04-08_31_06/
16. bag 재생 (ros2 bag play)
ros2 bag play rosbag2_2020_09_04-08_31_06/
- tab을 이용해서 더 적지 않아도 불러오게 할 수 있다.
- 이런 식으로 개고생해서 창 네 개를 해놓고 돌리면 기록도 되고 다시 재생시킬 수 있다.
17. 토픽 개념 정리
- 토픽 : 비동기식 단방향 메시지 송수신 방식
18. 토픽 - 메시지 인터페이스 확인
- ROS 노드간 송수신시 : 토픽, 서비스, 액션 사용 > 데이터 형태를 ROS interface
ros2 interface show geometry_msgs/msg/Twist
ros2 interface show geometry_msgs/msg/Vector3
ros2 interface list
ros2 interface packages
ros2 interface package turtlesim
ros2 interface proto geometry_msgs/msg/Twist
19. 서비스 확인
# 서비스 목록 확인 (ros2 service list)
ros2 service list
# 서비스 형태 확인 (ros2 service type)
ros2 service type /clear
ros2 service type /kill
ros2 service type /spawn
# 형태를 서비스 목록과 함꼐
ros2 service list -t
# 서비스 찾기 (ros2 service find)
ros2 service find std_srvs/srv/Empty
ros2 service find turtlesim/srv/Kill
20. 서비스 요청 (ros2 service call)
- ros2 service call <service_name> <service_type> "<arguments>"
(1) 원래 그렸던 선들이 다 없어지고 거북이만 그 자리대로 남는다.
ros2 service call /clear std_srvs/srv/Empty
(2) 이름을 설정해주고 거북이를 없애보았다.
ros2 service call /kill turtlesim/srv/Kill "name: 'turtle1'"
(3) 다시 거북이를 살리고
ros2 service call /reset std_srvs/srv/Empty
(4) 궤적 색과 크기를 바꿔보자 ( 화살표로 움직이면 된다)
ros2 service call /turtle1/set_pen turtlesim/srv/SetPen "{r: 255, g: 255, b: 255, width: 10}"
(5) 거북이 네마리를 불러오려면?
ros2 service call /kill turtlesim/srv/Kill "name: 'turtle1'"
ros2 service call /spawn turtlesim/srv/Spawn "{x: 5.5, y: 9, theta: 1.57, name: 'leonardo'}"
ros2 service call /spawn turtlesim/srv/Spawn "{x: 5.5, y: 7, theta: 1.57, name: 'raffaello'}"
ros2 service call /spawn turtlesim/srv/Spawn "{x: 5.5, y: 5, theta: 1.57, name: 'michelangelo'}"
ros2 service call /spawn turtlesim/srv/Spawn "{x: 5.5, y: 3, theta: 1.57, name: 'donatello'}"
# 목록 확인
ros2 topic list
21. 서비스 인터페이스
ros2 interface show turtlesim/srv/Spawn.srv
22. 서비스 개념 정리 : 서버 - 클라이언트 관계와 비슷
23. 액션 서버 및 클라이언트
- F키(멈춤)를 중심으로 버튼은 거북이를 절대 각도로 회전하도록 목표 값이 설정
- 성공, 실패를 확인할 수 있음
24. 노드 정보 확인 (액션 부분만 참고해라?)
ros2 node info /turtlesim
ros2 node info /teleop_turtle
25. 액션 확인
# 액션 목록
ros2 action list -t
# 액션 정보
ros2 action info /turtle1/rotate_absolute
26. 액션 목표 전달
- ros2 action send_goal <action_name> <action_type> "<values>"
- 거북이를 12시 방향인 값으로 주게 되면?
ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "{theta: 1.5708}"
- 피드백을 포함시키기 위해서는 --feedback 옵션 붙이기 ( 마이너스 붙이니까 이번엔 6시 방향 )
ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "{theta: -1.5708}" --feedback
27. 액션 인터페이스
ros2 interface show turtlesim/action/RotateAbsolute.action
28. 액션 개념 정리
- 비동기식 + 동기식 양방향 메시지 송수신 방향
- 액션 클라이언트 : 액션 목표 지정 / 액션 서버 : 목표 받아 중간 결괏값 + 피드백, 최종 결괏값 해당 결과 전송
- 목표 전달, 목표 취소, 결과 받기를 서비스에 적용
29. 총 비교