Skip to content

消息指引#

格式#

所有消息都应遵循 ROS 消息描述规范.

接受的格式包括:

  • .msg
  • .srv
  • .action

命名#

正在施工中

在创建消息的复数类型时,使用 Array 作为后缀.此后缀常用于 common_interfaces.

默认单位#

默认情况下,所有字段都具有以下单位,具体取决于其类型:

类型 默认单位
距离(distance) 米(meter)(m)
角度(angle) 弧度(radians)(rad)
时间(time) 秒(second)(s)
速度(speed) 米/秒 (m/s)
速度(velocity) 米/秒 (m/s)
加速度(acceleration) 米/秒平方 (m/s²)
角速度(Angular Vel.) 弧度/秒 (rad/s)
角加速度(Angular accel.) 弧度/秒平方 (rad/s²)

如果消息中的字段具有这些默认单位中的任何一个,请不要添加任何后缀或前缀来表示该类型.

Non-default units#

对于非默认单位,请使用以下后缀:

类型 非默认单位 后缀
距离(distance) 纳米(nanometer) _nm
距离(distance) 微米(micrometer) _um
距离(distance) 毫米(millimeter) _mm
距离(distance) 千米(kilometer) _km
角度(angle) 度(degree) (deg) _deg
时间(time) 纳秒(nanosecond) _ns
时间(time) 微秒(microsecond) _us
时间(time) 毫秒(millisecond) _ms
时间(time) 分钟(minute) _min
时间(time) 小时(hour) (h) _hour
速度(velocity) 千米/小时(km/h) _kmph

如果您想要使用的单元在此处不存在,请 create an issue/PR 将其添加到此列表中.

消息字段类型#

有关 ROS 接口支持的类型列表 见这里.

为方便起见,还复制在此处:

消息字段类型 C++ 等效项
bool bool
byte uint8_t
char char
float32 float
float64 double
int8 int8_t
uint8 uint8_t
int16 int16_t
uint16 uint16_t
int32 int32_t
uint32 uint32_t
int64 int64_t
uint64 uint64_t
string std::string
wstring std::u16string

数组#

对于数组,请使用 unbounded dynamic array 类型.

例:

int32[] unbounded_integer_array

枚举#

ROS 2 接口不直接支持枚举.

可以定义整数常量并将它们分配给非常量整数参数.

常量以 CONSTANT_CASE 写入.

为常量的每个元素分配不同的值.

来自 shape_msgs/msg/SolidPrimitive.msg 的示例

uint8 BOX=1
uint8 SPHERE=2
uint8 CYLINDER=3
uint8 CONE=4
uint8 PRISM=5

# The type of the shape
uint8 type

评论#

在消息顶部,简要说明消息包含的内容和/或它的用途.有关示例,请参见 sensor_msgs/msg/Imu.msg.

如有必要,请在解释上下文和/或含义的字段之前添加行注释.

对于像 x, y, z, w 这样的简单字段,你可能不需要添加注释.

即使没有严格检查,也尽量不要在一行中传递 100 个字符.

例:

# Number of times the vehicle performed an emergency brake
uint32 count_emergency_brake

# Seconds passed since the last emergency brake
uint64 duration

用法示例#

  • 不要对默认类型使用单位后缀:
    • 坏: float32 path_length_m
    • 好: float32 path_length
  • 不要为单位添加前缀:
    • 坏:float32 kmph_velocity_vehicle
    • 好: float32 velocity_vehicle_kmph
  • 使用建议的后缀 如果表中可用
    • 差:float32 velocity_vehicle_km_h
    • 好: float32 velocity_vehicle_kmph