위 레파지토리는 ROS2공식 문서를 공부한 뒤 정리하는 공간입니다.
25.07.18
https://docs.ros.org/en/rolling/Tutorials/Beginner-CLI-Tools/Introducing-Turtlesim/Introducing-Turtlesim.html
25.07.21
https://docs.ros.org/en/rolling/Tutorials/Beginner-CLI-Tools/Understanding-ROS2-Topics/Understanding-ROS2-Topics.html#ros2-topic-echo
25.07.23
https://www.youtube.com/watch?v=aFMDvkCr9vY&list=PL0xYz_4oqpvhj4JaPSTeGI2k5GQEE36oi&index=36
25.07.24
https://youtu.be/aFMDvkCr9vY?si=E21GxEVJ9kKe_RSY
- 1. VSCODE 설정
- 2. 파이썬 가상환경
- 3. 도메인
- 4. service
- 5. topic
- 6. pose 구독 노드 만들기
- 6. Using Turtlesim And rqt
- 7. Node
- 8. Understanding Topic
아래코드는 공식문서에서 제시한 예시코드이다.
ros2 run turtlesim turtlesim_node아래 코드를 추가하자
{
...
"terminal.integrated.env.linux": {
"GTK_PATH": ""
},
...
}1. 가상환경을 만들기 위한 venv 설치
2. 가상환경 생성
3. 해당 환경에서 파이프 업그레이트
4. jupyter설치
$ sudo apt install python3.12-venv$ python3 -m venv ~/venv
$ source ~/venv/bin/activate$ pip install --upgrade pip$ pip install jupyter즉 도메인이 같은 디바이스끼리 연결됨
alias sz="source ~/.zshrc; echo \"bashrc is reloaded\""
alias ros_domain="export ROS_DOMAIN_ID=13; echo \"ROS_DOMAIN_ID=13\""
alias rolling="source /opt/ros/rolling/setup.zsh; ros_domain; echo \"ROS2 rolling is activated!\""ROS_DOMAIN_ID를 13번으로 함
1. 서비스 조회하기
2. 서비스 타입 조회하기
3. 요청타입과 응답타입 조회하기
4. 서비스 호출하기
5. 리셋 서비스 호출하기
6. 추가 거북이를 스폰하기
╰─ ros2 service list
/clear
/kill
/reset
/spawn
/turtle1/set_pen
/turtle1/teleport_absolute
/turtle1/teleport_relative
/turtlesim/describe_parameters
/turtlesim/get_parameter_types
/turtlesim/get_parameters
/turtlesim/get_type_description
/turtlesim/list_parameters
/turtlesim/set_parameters
/turtlesim/set_parameters_atomically
╰─ ros2 service type /turtle1/teleport_absolute
turtlesim_msgs/srv/TeleportAbsolute╰─ ros2 interface show turtlesim_msgs/srv/TeleportAbsolute
float32 x
float32 y
float32 theta╰─ ros2 service call /turtle1/teleport_absolute turtlesim_msgs/srv/TeleportAbsolute "{x: 2, y: 2, theta: 1.57}"
waiting for service to become available...
requester: making request: turtlesim_msgs.srv.TeleportAbsolute_Request(x=2.0, y=2.0, theta=1.57)
response:
turtlesim_msgs.srv.TeleportAbsolute_Response()
현재 위치가 바뀐것을 확인 할 수 있다. theta값은 거북이가 바라보는 방향을 의미한다.
╰─ ros2 service call /reset std_srvs/srv/Empty
waiting for service to become available...
requester: making request: std_srvs.srv.Empty_Request()
response:
std_srvs.srv.Empty_Response()리셋 시 초기위치로 바뀐것을 확인할 수 있다.
╭─ │ ~ ··························································································· ✔ │ at 17:23:46
╰─ ros2 service type /spawn
turtlesim_msgs/srv/Spawn
╭─ │ ~ ··························································································· ✔ │ at 17:25:49
╰─ ros2 interface show turtlesim_msgs/srv/Spawn
float32 x
float32 y
float32 theta
string name # Optional. A unique name will be created and returned if this is empty
---
string name
╭─ │ ~ ··························································································· ✔ │ at 17:26:04
╰─ ros2 service call /spawn turtlesim_msgs/srv/Spawn "{x: 1, y: 1, theta: 0, name: ''}"
waiting for service to become available...
requester: making request: turtlesim_msgs.srv.Spawn_Request(x=1.0, y=1.0, theta=0.0, name='')
response:
turtlesim_msgs.srv.Spawn_Response(name='turtle2')Published topics는 터틀이 발행하는 토픽들이며 Subscribed topics는 터틀이 구독하는 토픽이다.
╰─ ros2 topic list -v
Published topics:
* /parameter_events [rcl_interfaces/msg/ParameterEvent] 2 publishers
* /rosout [rcl_interfaces/msg/Log] 2 publishers
* /turtle1/color_sensor [turtlesim_msgs/msg/Color] 1 publisher
* /turtle1/pose [turtlesim_msgs/msg/Pose] 1 publisher
* /turtle2/color_sensor [turtlesim_msgs/msg/Color] 1 publisher
* /turtle2/pose [turtlesim_msgs/msg/Pose] 1 publisher
Subscribed topics:
* /parameter_events [rcl_interfaces/msg/ParameterEvent] 1 subscriber
* /turtle1/cmd_vel [geometry_msgs/msg/Twist] 1 subscriber
* /turtle2/cmd_vel [geometry_msgs/msg/Twist] 1 subscriber
╰─ ros2 topic info /turtle1/pose
Type: turtlesim_msgs/msg/Pose
Publisher count: 1
Subscription count: 0╰─ ros2 topic echo /turtle1/pose
x: 5.544444561004639
y: 5.544444561004639
theta: 0.0
linear_velocity: 0.0
angular_velocity: 0.0$ rqt╰─ ros2 service call /turtle1/teleport_absolute turtlesim_msgs/srv/TeleportAbsolute "{x: 5, y: 5, theta: 1.1}"
waiting for service to become available...
requester: making request: turtlesim_msgs.srv.TeleportAbsolute_Request(x=5.0, y=5.0, theta=1.1)
response:
turtlesim_msgs.srv.TeleportAbsolute_Response()
╰─ ros2 topic echo /turtle1/pose
x: 5.0
y: 5.0
theta: 1.100000023841858
linear_velocity: 0.0
angular_velocity: 0.0teleport_absolute service를 호출하여 위치를 변경시키면 pose를 구독하는 터미널에서 변경된 pose값을 얻을 수 있다.
bash code below
$ ros2 run turtlesim turtlesim_node
$ ros2 run turtlesim turtle_teleop_keybash code below
$ sudo apt update
$ sudo apt install '~nros-rolling-rqt*'Click on the Service dropdown list to see turtlesim's services, and select the /spawn service.
ros2 node listros2 node info <node_name>ros2 node info구독자, 게시자, 서비스 및 작업 목록을 반환합니다. 즉, 해당 노드와 상호 작용하는 ROS 그래프 연결입니다.
ROS 2는 복잡한 시스템을 여러 모듈형 노드로 나눕니다. 토픽은 노드 간 메시지 교환을 위한 버스 역할을 하는 ROS 그래프의 핵심 요소입니다.
We can use rqt, opening plugin > introspection > node grpah.
rqtThe graph is depicting how the /turtlesim node and the /teleop_turtle node are communicating with each other over a topic. The /teleop_turtle node is publishing data (the keystrokes you enter to move the turtle around) to the /turtle1/cmd_vel topic, and the /turtlesim node is subscribed to that topic to receive the data.







