这几天在看自主无人机的一些代码,如下:
mavros_msgs::PositionTarget PositionSetpoint
PositionSetpoint.type_mask = 0b100111000000 看到这几句代码不是很懂,然后网上查询了下。
首先看该消息的说明:
# Message for SET_POSITION_TARGET_LOCAL_NED
#
# Some complex system requires all feautures that mavlink
# message provide. See issue #402.
std_msgs/Header header
uint8 coordinate_frame
uint8 FRAME_LOCAL_NED = 1
uint8 FRAME_LOCAL_OFFSET_NED = 7
uint8 FRAME_BODY_NED = 8
uint8 FRAME_BODY_OFFSET_NED = 9
uint16 type_mask
uint16 IGNORE_PX = 1 # Position ignore flags
uint16 IGNORE_PY = 2
uint16 IGNORE_PZ = 4
uint16 IGNORE_VX = 8 # Velocity vector ignore flags
uint16 IGNORE_VY = 16
uint16 IGNORE_VZ = 32
uint16 IGNORE_AFX = 64 # Acceleration/Force vector ignore flags
uint16 IGNORE_AFY = 128
uint16 IGNORE_AFZ = 256
uint16 FORCE = 512 # Force in af vector flag
uint16 IGNORE_YAW = 1024
uint16 IGNORE_YAW_RATE = 2048
geometry_msgs/Point position
geometry_msgs/Vector3 velocity
geometry_msgs/Vector3 acceleration_or_force
float32 yaw
float32 yaw_rate
可以看到type_mask下的键的值都是2的次方(即二进制的位数),由此我们不难得出
PositionSetpoint.type_mask = 0b100111000000(二进制)代表了
uint16 IGNORE_AFX = 64(1000000)
uint16 IGNORE_AFY = 128(10000000)
uint16 IGNORE_AFZ = 256(100000000)
uint16 IGNORE_YAW_RATE = 2048(100000000000) 生效
这样就可以简要表明那些参数生效了。