ROS2

[ROS2] Tutorial Intermediate - Creating an action

씨주 2024. 11. 16. 20:58

Creating an action

Task

Defining an action

Action은 .action파일에서 정의된다.

# Request
---
# Result
---
# Feedback

 

action은 ---로 구분된 3가지 메세지 정의로 이루어져있다.

request message는 새로운 목표를 시작할 때 server에게 client가 보내는 것이다.

result message는 목표를 끝냈을 때, client에게 server가 보내는 것이다.

feedback message는 주기적으로 client에게 server가 목표에 대한 정보를 update하는 것이다.

 

피보나치수열을 계산하는 'Fibonacci'라는 새로운 action을 정의해보자.

action_tutorials_interfaces 패키지 안에 action 경로를 생성한다.

cd action_tutorials_interfaces
mkdir action

 

action경로 안에 Fibonacci.action 파일을 만들어 아래의 내용을 추가한다.

int32 order
---
int32[] sequence
---
int32[] partial_sequence

 

request는 피보나치수열의 order이고, result는 최종 sequence, feedback은 partial_sequence이다.

 

Building an action

새로운 피보나치 action을 사용하기 전, rosidl code를 파이프라인에 정의해야 한다.

이는 action_tutorials_interfaces의 CMakeLists.txt ament_package()줄 앞에 추가함으로써 가능하다.

find_package(rosidl_default_generators REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
  "action/Fibonacci.action"
)

 

package.xml에 아래 내용도 추가해야 한다.

<buildtool_depend>rosidl_default_generators</buildtool_depend>

<depend>action_msgs</depend>

<member_of_group>rosidl_interface_packages</member_of_group>

 

action 정의가 추가적인 metadata를 포함하기 때문에 action_msgs에 의존해야 한다.

이제 Fibonacci action을 build해보자.

# Change to the root of the workspace
cd ~/ros2_ws
# Build
colcon build

 

action type은 패키지이름과 action이라는 단어로 접두사가 붙는다. 그래서 새로운 액션을 참고할 때, action_tutorials_interfaces/actionn/Fibonacci가 된다.

 

built한 action을 체크해보면 성공적으로 수행되는 것을 볼 수 있다.

# Source our workspace
# On Windows: call install/setup.bat
. install/setup.bash
# Check that our action definition exists
ros2 interface show action_tutorials_interfaces/action/Fibonacci

 

 

 

ROS2_Humble Documentation : https://docs.ros.org/en/humble/Tutorials/Intermediate.html