ROS2

[ROS2] Tutorial Beginner : CLI tools - Understanding actions

씨주 2024. 10. 9. 14:45

Understanding actions

Background

action 또한 ROS2에서 communication하는 방법 중 하나이다.

action은 goal, feedback, result 3파트로 구성되어 있다.

action은 취소할 수 있다는 것 외에는 service와 유사하다.

또한 single response를 return하는 service와 달리 꾸준히 feedback을 한다.

 

action은 client-server model, topic은 publisher-subscriber model이다.

action client노드는 action server노드(goal을 승인해줌)로 goal을 보내고 feedback과 result를 받는다.

 

  topic service action
model publisher-subscriber call-response client-server
관련 image
특징 연속 update 가능 client가 call할 때만 data 제공 client가 server로 goal을 보내고
feedback, result를 받음

 

Tasks

setup

ros2 run turtlesim turtlesim_node
ros2 run turtlesim turtle_teleop_key

 

use actions

/teleop_turtle을 보면 F키를 주변으로 G|B|V|C|D|E|R|T가 있다.

 

이 중 하나로 회전을 시키면 action server(/turtlesim 노드)에 goal이 보내지고,

이것이 완료되면 메세지를 볼 수 있다.

 

이 때 F키로 회전과정 중에 취소할 수 있다.

 

client(teleop)에서 stop goal을 보낼 수 있고 server(turtlesim)에서도 보낼 수 있다.

D키로 회전하는 중에 G키를 누르면 'abort' goal이 뜨면서 G키의 회전을 수행한다.

 

node info

/turtlesim의 subscriber, publisher, service, action srver, action client list를 볼 수 있다.

ros2 node info /turtlesim

/turtle1/rotate_absolute_action은 action server 아래에 있고,

이는 turtlesim은 turtle1/rotate_absolute action에 대해 반응하고 feedback한다는 것을 의미한다.

 

ros2 node info /teleop_turtle

/teleop_turtle은 /turtle1/rotate_absolute_action이 action client(goal을 보냄) 아래에 있다.

 

action list

ros2 action list

 

action type을 확인할 수 있고, caction을 code로 구현할 때 필요하다.

ros2 action list -t

 

action info

ros2 action info /turtle1/rotate_absolute

 

/turtle1/rotate_absolute액션에 대해 /teleop_turtle은 action client를, /turtlesim은 action server를 가진다.

 

interface show

ros2 interface show turtlesim/action/RotateAbsolute

 

1번째는 goal request의 data type, name, 2번째는 result, 3번째는 feedback 구조이다.

 

action send_goal

action goal을 CLI로 보낼 수 있다. 이 때 value는 YAML 형식이어야 한다.

# ros2 action send_goal <action_name> <action_type> <values>
ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "{theta: 1.57}"

 

모든 goal을 unique ID를 가지고 message를 보낸다.

또한 result, field(delta)를 볼 수 있다.

 

feedback을 보고 싶다면 --feedback을 더하면 된다.

ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "{theta: -1.57}" --feedback

 

 

 

ROS2_Humble Documentation : https://docs.ros.org/en/humble/Tutorials/Beginner-CLI-Tools.html