1. 概要
インタフェースを作成します。
2. インタフェース作成
mkdir -pv ~/workspace/src/my_interfaces/action
vi ~/workspace/src/my_interfaces/action/Interfaces.action
このファイル名、実は、くせ者のようです。
「my_action/action」とか「myAction.action」とかのファイル名にすると、以降の「colcon build」でエラーになったりします。
下記を記述します。
# Goal
int32 request
---
# Result
int32[] result
---
# Feedback
int32[] feedback
「CMakeList.txt」「package.xml」を下記のように記述します。
vi ~/workspace/src/my_interfaces/CMakeLists.txt
cmake_minimum_required(VERSION 3.8)
project(my_interfaces)
find_package(ament_cmake REQUIRED)
find_package(rosidl_default_generators REQUIRED)
set(action_files
"action/Interfaces.action"
)
rosidl_generate_interfaces(${PROJECT_NAME}
${action_files}
)
ament_package()
vi ~/workspace/src/my_interfaces/package.xml
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>my_interfaces</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="hogehoge@todo.todo">hogehoge</maintainer>
<license>TODO: License declaration</license>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<buildtool_depend>rosidl_default_generators</buildtool_depend>
<depend>action_msgs</depend>
<member_of_group>rosidl_interface_packages</member_of_group>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>
3. ビルド
ビルドして、インストールします。
cd ~/workspace
colcon build --packages-select my_interfaces
下記のようなメッセージが表示されます。
Starting >>> my_interfaces
Finished <<< my_interfaces [13.8s]
Summary: 1 package finished [14.3s]
インストール。
. install/setup.bash
4. 確認
「action」が登録されていることを確認します。
ros2 interface show my_interfaces/action/Interfaces
下記のメッセージが、表示されます。
# Goal
int32 request
---
# Result
int32[] result
---
# Feedback
int32[] feedback
5. 備考
本ページは、下記のサイトを参考にさせていただきました。
「ROS入門 (15) - ROS2 のアクションによる通信」
「About ROS 2 interfaces — ROS 2 Documentation: Foxy documentation」
「実習 ROS2 Action通信 #ROS2」