Consultation on using C++mavlinkV2 to control the forward, backward, left, right, up and down flight of quadcopter drones
I want to use the following code to control a quadcopter drone, but I found that only forward, upward, and downward movements are effective. Why does the drone spin when flying backwards, left, or right? Can anyone help me?
void move_body_velocity(uint8_t sysid, uint8_t compid, float vx, float vy, float vz) {
mavlink_message_t msg;
uint8_t buf[MAVLINK_MAX_PACKET_LEN];
uint16_t type_mask = 0b0000111111000111; // 只控制速度
mavlink_msg_set_position_target_local_ned_pack(
sysid, compid, &msg, //自己系统id 组件id
get_time_boot_ms(), //自己实现该函数获取当前时间戳
1, 1, //目标系统id 组件id
MAV_FRAME_BODY_NED, // ✅ 关键坐标系设置
type_mask,
0, 0, 0,
vx, vy, vz,
0, 0, 0,
0, 0
);
// 发送消息
uint16_t len = mavlink_msg_to_send_buffer(buf, &msg);
send_serial_data(buf, len);
}