011 ROS 2 액션 (action)

‍정승우·2021년 4월 9일

참고 링크 : 오로카 11강

1. 액션

  • goal, feedback, result, 양방향 메시지 송수신 방식 (action 인터페이스)

  • Action Client는 Service Client 3개와 Topic Subscriber 2개로 구성

  • Action Server는 Service Server 3개와 Topic Publisher 2개로 구성

2. 액션 서버 및 클라이언트

  • turtle bot예제를 이용한 액션 실습

전에 키보드 화살표 방향으로 작동하는 방법과 달리 ertdgcvb는 방향에 따라 '액션'을 수행하도록한다.

$ ros2 run turtlesim turtlesim_node

$ ros2 run turtlesim turtle_teleop_key
Reading from keyboard
---------------------------
Use arrow keys to move the turtle.
Use G|B|V|C|D|E|R|T keys to rotate to absolute orientations. 'F' to cancel a rotation.
'Q' to quit.

%%%% goal이 완료되었을때
[INFO]: Rotation goal completed successfully
%%%% f키를 눌러 취소를 시켰을때
[INFO]: Rotation goal canceled

3. 노드, 액션, 정보 확인 명령어

1) 노드 정보 확인 : ros2 node info <노드>

ex)

  • turtlesim은 Action Server역할을 하는것을 의미
$ ros2 node info /turtlesim
/turtlesim
(생략)
  Action Servers:
    /turtle1/rotate_absolute: turtlesim/action/RotateAbsolute
  Action Clients:
  • teleop_turtle 노드는 /turtle1/rotate_absolute의 액션의 Action Client 역할
$ ros2 node info /teleop_turtle
/teleop_turtle
(생략)
  Action Servers:

  Action Clients:
    /turtle1/rotate_absolute: turtlesim/action/RotateAbsolute

2) 액션 목록 : ros2 action list -t

현재 실행중인 액션을 전부 확인하는 명령어

$ ros2 action list -t
/turtle1/rotate_absolute [turtlesim/action/RotateAbsolute]

3) 액션 정보 : ros2 action info <액션이름>

액션 이름은 액션목록을 통해서 확인할 수 있고, 이를 이용하여 info 검색

$ ros2 action info /turtle1/rotate_absolute
Action: /turtle1/rotate_absolute
Action clients: 1
    /teleop_turtle
Action servers: 1
    /turtlesim

4. 액션 목표(action goal) 전달

ros2 action send_goal <action_name> <action_type> "{target_value : value}"

$ ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "{theta: 1.5708}"
Waiting for an action server to become available...
Sending goal:
     theta: 1.5708

Goal accepted with ID: b991078e96324fc994752b01bc896f49

Result:
    delta: -1.5520002841949463

Goal finished with status: SUCCEEDED

feedback을 화면에 표시하기 위해서는 아래와 같이 --feedback 옵션을 붙여주면 된다.

$ ros2 action send_goal /turtle1/rotate_absolute \
turtlesim/action/RotateAbsolute "{theta: -1.5708}" --feedback
Waiting for an action server to become available...
Sending goal:
     theta: -1.5708

Goal accepted with ID: ad7dc695c07c499782d3ad024fa0f3d2

Feedback:
    remaining: -3.127622127532959

Feedback:
    remaining: -3.111621856689453

Feedback:
    remaining: -3.0956220626831055

(생략)

Feedback:
    remaining: -0.03962135314941406

Feedback:
    remaining: -0.023621320724487305

Feedback:
    remaining: -0.007621288299560547

Result:
    delta: 3.1040005683898926

Goal finished with status: SUCCEEDED

0개의 댓글