?古月21講/2.6_通信接口
官方文檔:Interfaces — ROS 2 Documentation: Humble documentation
官方接口代碼實戰:https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Single-Package-Define-And-Use-Interface.html
?ROS 2使用簡化的描述語言,即接口定義語言(?interface definition language,IDL)來描述這些接口。此描述使ROS工具可以輕松地以幾種目標語言為接口類型生成源代碼 (自動跨語言)。。不同通信接口,接口文件后綴不同,
話題(.msg),
服務(.srv),
動作(.action)
接口語言定義語法
所有的語言,都有統一的內置類型(built-in-type)表示
也可單獨定義類型名稱,例如“ geometry_msgs/posestamped”
內部固有類型 (與跨語言對應關系)
Type name | C++ | Python | DDS type |
---|---|---|---|
bool | bool | builtins.bool | boolean |
byte | uint8_t | builtins.bytes* | octet |
char | char | builtins.int* | char |
float32 | float | builtins.float* | float |
float64 | double | builtins.float* | double |
int8 | int8_t | builtins.int* | octet |
uint8 | uint8_t | builtins.int* | octet |
int16 | int16_t | builtins.int* | short |
uint16 | uint16_t | builtins.int* | unsigned short |
int32 | int32_t | builtins.int* | long |
uint32 | uint32_t | builtins.int* | unsigned long |
int64 | int64_t | builtins.int* | long long |
uint64 | uint64_t | builtins.int* | unsigned long long |
string | std::string | builtins.str | string |
wstring | std::u16string | builtins.str | wstring |
話題(topics? 發布/訂閱信息模型)
消息是ROS 2節點將網絡上的數據發送到其他ROS節點的一種方式,而沒有響應(單向信息傳遞)。例如,如果一個ROS 2節點從傳感器讀取溫度數據,則可以使用溫度消息在ROS 2網絡上發布該數據。 ROS 2網絡上的其他節點可以訂閱該數據并接收溫度消息。
每個字段由一個類型和名稱組成,被空格隔開,即
fieldtype1 fieldname1
fieldtype2 fieldname2
例如
int32 my_int
string my_string
帶有默認值的示例
uint8 x 42
int16 y -2000
string full_name "John Doe"
int32[] samples [-200, -100, 0, 100, 200]
?常數示例,無法更改(有=號)
int32 X=123
int32 Y=-123
string FOO="foo"
string EXAMPLE='bar'
服務接口
在ROS軟件包的 srv/ 路徑中,在.srv文件中描述和定義了服務。
服務描述文件由請求和響應MSG類型組成,該類型由使用 ---?區分
語法
string str
---
string str
示例
# request constants
int8 FOO=1
int8 BAR=2
# request fields
int8 foobar
another_pkg/AnotherMessage msg
---
# response constants
uint32 SECRET=123456
# response fields
another_pkg/YetAnotherMessage val
CustomMessageDefinedInThisPackage value
uint32 an_integer
動作通信接口?
有三個參數需要定義
使用2個?--- 和?---?區分
<request_type> <request_fieldname>
---
<response_type> <response_fieldname>
---
<feedback_type> <feedback_fieldname>
示例
int32 order
---
int32[] sequence
---
int32[] sequence