1 The data type of the interface
type name | C++ | Python | DDS type |
---|---|---|---|
bool | bool | bool | boolean |
byte | uint8_t | bytes | octet |
char | char | str | char |
float32 | float | float | float |
float64 | double | float | double |
int8 | int8_t | int | octet |
uint8 | uint8_t | int | octet |
int16 | int16_t | int | short |
uint16 | uint16_t | int | unsigned short |
int32 | int32_t | int | long |
uint32 | uint32_t | int | unsigned long |
int64 | int64_t | int | long long |
uint64 | uint64_t | int | unsigned long long |
string | std::string | str | string |
wstring | std::u16string | str | wstring |
1.1 Naming rules
1.Field names must be lowercase alphanumeric characters with underscores to separate words. 2.Field names must start with an alphabetic character, cannot end with an underscore, and can never have two consecutive underscores.
1.2 Set default values
uint8 x 42
int16 y -2000
string full_name "John Doe"
int32[] samples [-200, -100, 0, 100, 200]
1.3 Setting constants
int32 X=123
int32 Y=-123
string FOO="foo"
string EXAMPLE='bar'
2 Create an interface package
ros2 pkg create --build-type ament_cmake tutorial_interfaces
3 Create an interface directory
mkdir msg
mkdir srv
mkdir action
4 Define the interface
4.1 Num.msg file in the msg directory
int num
4.2 AddThreeInts.srv file in the srv directory
int64 a
int64 b
int64 c
---
int64 sum
4.3 The Fibonacci.action file in the action directory
int32 order
---
int32[] sequence
---
int32[] partial_sequence
5 CMakeLists.txt build
find_package(rosidl_default_generators REQUIRED)
rosidl_generate_interfaces(${PROJECT_NAME}
"msg/Num.msg"
"srv/AddThreeInts.srv"
"action/Fibonacci.action"
)
6 package.xml add dependencies
<build_depend>rosidl_default_generators</build_depend>
<exec_depend>rosidl_default_runtime</exec_depend>
<depend>action_msgs</depend>
<member_of_group>rosidl_interface_packages</member_of_group>
7 Build the package
colcon build --packages-select tutorial_interfaces