Using C++ mavlinkV2 to control the yaw

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);
}

Is the copter in GUIDED mode? See guided options and auto options and WP_YAW_BEHAVIOR

1 Like

It’s a GUIDED mode, I only set the speed and mask other parameters such as angle and acceleration, but there will be rotation when flying backwards, on the left, and on the right.

Hi @gaha,

You’ve probably already seen it but we have this wiki page with examples of how to control a vehicle using various mavlink commands. there are even copy-paste-able examples that can be copied in the mavproxy terminal to test with.

The set-position-target-local-ned message includes yaw and yaw-rate fields which should allow you to stop the vehicle from yawing. If instead you never want the vehicle to yaw while moving, then @amilcarlucas’s advice is good, set the WP_YAW_BEHAVIOR parameter to zero. You’re right that we should probably make the parameter description more clear to clarify that it applies to Guided mode as well

Thank you, I will try modifying the WP_YAWOBEHAVIOR parameter