SET_ATTITUDE_TARGET with Attitude quaternion and Body yaw rate mixup

Hi,

I’m operating the drone using the SET_ATTITUDE_TARGET command, wherein I input the Attitude quaternion. However, I’ve observed that when the yaw changes and I extract yaw values from the Attitude at 40Hz to incorporate them into the quaternion, there’s a notable increase in oscillations over time.

Currently, I’m attempting to control pitch and roll through quaternions while managing yaw with the body_yaw_rate. Despite this approach, it appears that the drone is not responding to the body rate adjustments and instead drifts towards a yaw angle of zero. MAV_FRAME_LOCAL_NED

time_boot_ms uint32_t ms Timestamp (time since system boot).
target_system uint8_t System ID
target_component uint8_t Component ID
type_mask uint8_t ATTITUDE_TARGET_TYPEMASK Bitmap to indicate which dimensions should be ignored by the vehicle.
q float[4] Attitude quaternion (w, x, y, z order, zero-rotation is 1, 0, 0, 0) from MAV_FRAME_LOCAL_NED to MAV_FRAME_BODY_FRD
body_roll_rate float rad/s Body roll rate
body_pitch_rate float rad/s Body pitch rate
body_yaw_rate float rad/s Body yaw rate
thrust float Collective thrust, normalized to 0 … 1 (-1 … 1 for vehicles capable of reverse trust)
thrust_body ** float[3] 3D thrust setpoint in the body NED frame, normalized to -1 … 1

I have tryed setting up the bitmask 0b00000011, which is 3 accoridng the list below, but there is no effect. I am currently working with GUIDED mode, expecing to support GUIDED_noGPS

1 ATTITUDE_TARGET_TYPEMASK_BODY_ROLL_RATE_IGNORE Ignore body roll rate
2 ATTITUDE_TARGET_TYPEMASK_BODY_PITCH_RATE_IGNORE Ignore body pitch rate
4 ATTITUDE_TARGET_TYPEMASK_BODY_YAW_RATE_IGNORE Ignore body yaw rate
32 ATTITUDE_TARGET_TYPEMASK_THRUST_BODY_SET Use 3D body thrust setpoint instead of throttle
64 ATTITUDE_TARGET_TYPEMASK_THROTTLE_IGNORE Ignore throttle
128 ATTITUDE_TARGET_TYPEMASK_ATTITUDE_IGNORE Ignore attitude
1 Like

Please clarify if my understanding is accurate. Can I directly control movement using body rate? Alternatively, does it involve setting a yaw target angle in quaternion and controlling the yaw rate to determine the speed at which I reach that yaw target angle?

    // Sets guided's angular target submode: Using a rotation quaternion, angular velocity, and climbrate or thrust (depends on user option)
    // attitude_quat: IF zero: ang_vel (angular velocity) must be provided even if all zeroes
    //                IF non-zero: attitude_control is performed using both the attitude quaternion and angular velocity
    // ang_vel: angular velocity (rad/s)
    // climb_rate_cms_or_thrust: represents either the climb_rate (cm/s) or thrust scaled from [0, 1], unitless
    // use_thrust: IF true: climb_rate_cms_or_thrust represents thrust
    //             IF false: climb_rate_cms_or_thrust represents climb_rate (cm/s)
    void set_angle(const Quaternion &attitude_quat, const Vector3f &ang_vel, float climb_rate_cms_or_thrust, bool use_thrust);

I can see this - Copter: in angle control GUIDED mode the drone keeps rotating on its yaw axis when told not to do so · Issue #741 · dronekit/dronekit-python · GitHub

So why when i set yaw angle 0, with rate of 10 degree, nothing happens?

I can see as well that body rate for yaw is not supported, was it removed at some point? Or is the documentation outdated?

body_yaw_rate 	float 	Body yaw rate not supported

https://ardupilot.org/dev/docs/copter-commands-in-guided-mode.html#copter-commands-in-guided-mode-set-attitude-target

All I know is that you can control attitude accurately and quickly by requesting a specific yaw/roll/pitch. I am not using quaternions or rates alas. When I do set a particular pitch or whatever, the drone is very quick to respond.

Also, you must always set the throttle otherwise the command will do nothing. Don’t ask me why! :slight_smile:

So, are you using SET_ATTITUDE_TARGET?

The command accepts either quaternions or rates

1 Like

Sorry, I just realised my post was rubbish.

I am of course using quaternions because you have to, but I am first converting Euler angles to quaternions using a clone of the Arducopter ToQuaternion() function. I have these fields also set in the message:

mavlink_set_attitude_target_t

thrust = 0.5
type_mask = TYPEMASK_BODY_ROLL_RATE_IGNORE | TYPEMASK_BODY_PITCH_RATE_IGNORE | TYPEMASK_BODY_YAW_RATE_IGNORE;