1. 概要
前ページまでで、どうも、自前のインタフェースの作り方がわかりそうなので。
やってみます。
本ページは、下記のサイトを参考にさせていただきました。
「Creating custom ROS 2 msg and srv files — ROS 2 Documentation: Crystal documentation」
2. パッケージ作成
とりあえず、参考サイトの通りに進めてみます。
ワークスペースとパッケージを作成します。
mkdir -pv ~/dev_ws/src
cd ~/dev_ws/src
ros2 pkg create --build-type ament_cmake tutorial_interfaces
cd ~/dev_ws/src/tutorial_interfaces
mkdir msg
mkdir srv
3. ソース作成
vi ~/dev_ws/src/tutorial_interfaces/msg/Num.msg
int64 num
vi ~/dev_ws/src/tutorial_interfaces/srv/AddThreeInts.srv
int64 a
int64 b
int64 c
---
int64 sum
vi ~/dev_ws/src/tutorial_interfaces/CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(tutorial_interfaces)
find_package(rosidl_default_generators REQUIRED)
rosidl_generate_interfaces(${PROJECT_NAME}
"msg/Num.msg"
"srv/AddThreeInts.srv"
)
ament_package()
vi ~/dev_ws/src/tutorial_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>tutorial_interfaces</name>
<version>0.0.1</version>
<description>tutorial_interfaces</description>
<maintainer email="hogehoge@todo.todo">hogehoge</maintainer>
<license>Apache License 2.0</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<build_depend>rosidl_default_generators</build_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<exec_depend>rosidl_default_runtime</exec_depend>
<member_of_group>rosidl_interface_packages</member_of_group>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>
4. ビルド
cd ~/dev_ws
colcon build --packages-select tutorial_interfaces
反映します。
. install/setup.bash
出来上がりを確認するのは、「ros2」のコマンドで。
ros2 interface show tutorial_interfaces/msg/Num
int64 num
ros2 interface show tutorial_interfaces/srv/AddThreeInts
int64 a
int64 b
int64 c
---
int64 sum
できあがったものは、くそほどあるのですが、探ってみると。
~/dev_ws/install/tutorial_interfaces/include/tutorial_interfaces/tutorial_interfaces/srv
|-- add_three_ints.h
|-- add_three_ints.hpp
`-- detail
|-- add_three_ints__builder.hpp
|-- add_three_ints__description.c
|-- add_three_ints__functions.c
|-- add_three_ints__functions.h
|-- add_three_ints__rosidl_typesupport_fastrtps_c.h
|-- add_three_ints__rosidl_typesupport_fastrtps_cpp.hpp
|-- add_three_ints__rosidl_typesupport_introspection_c.h
|-- add_three_ints__rosidl_typesupport_introspection_cpp.hpp
|-- add_three_ints__struct.h
|-- add_three_ints__struct.hpp
|-- add_three_ints__traits.hpp
|-- add_three_ints__type_support.c
|-- add_three_ints__type_support.cpp
|-- add_three_ints__type_support.h
|-- add_three_ints__type_support.hpp
`-- dds_fastrtps
ちゅうのがありまして。
なるほど、この「add_three_ints.hpp」ちゅうのを、インクルードすれば、使えそうだわ。