Understanding multicopter output mixing

Hi guys. I need help understanding multicopter mixing. The comments in the code says mixing roll, pitch and thrust without yaw first. If some outputs violate range [0,1] then try to shift all outputs to minimize violation. If after the shift some outputs still violate the bounds then scale roll & pitch.

Why we mix roll, pitch and thrust first, without yaw? And why we scale only roll and pitch if after the shift some outputs still violate? Is it because thrust and yaw are more important?

Why the roll and pitch scale is calculated the way in the code? For example,

if (min_out < 0.0f && max_out < 1.0f && -min_out > 1.0f - max_out) {
	float max_thrust_diff = thrust * thrust_increase_factor - thrust;
	boost = constrain(-min_out - (1.0f - max_out) / 2.0f, 0.0f, max_thrust_diff);
	**roll_pitch_scale = (thrust + boost) / (thrust - min_out);**
}

What’s the principle we calculate it this way?

The most important commands for a multicopter are roll and pitch. Indeed, the pitch and roll controller is the one enabling the MC to hover in a stable way. Therefore the mixer privileges to keep a correct attitude (roll and pitch angles) and this is why first a correction on thrust is given. It will try by increasing/decreasing the thrust to keep the correct differential of force in the motors to achieve the needed moment (roll or pitch).

So for example, let’s say you have a quad in a + config, and it is banking hard right when the command is at roll angle = 0. Then the controller will increase the output on the right motor and decrease it on the left motor. It is plausible that the right motor will achieve a commanded output higher to one, and so the controller will first try to decrease the global thrust a certain amount in order to see if the output is not saturated anymore. If it keeps saturating then for security purposes (not crashing your drone on the ground because you had zero thrust, or avoiding to do a barrel) the thrust can not decrease more and then it scales the pitch and roll values.

Note that so far we have not taken care of yaw. Indeed yaw is not as important for stability. it is for sure when you when to head your vehicle in one direction, but when you want to stabilize in hover it is not crucial. So once the controller has performed the limitations I have exposed before, it will try to add the yaw command. Following the example, imagine after the limitations you have a command for the right motor of 0.9 and the yaw command is of 0.2 for this motor, then the controller will only add 0.1 in order to just reach saturation and still have some yaw response. If instead of 0.9 the right motor command would have been of 1 (just saturated) then in order to have some yaw response the controller would decrease the thrust a bit more.

As a conclusion: the controller gives full priority to the control of pitch and roll angles, which are the most important states for the vehicle stability. Yaw is the less important state, because usually the dynamics related to this state are way slower than the dynamics of roll and pitch. Thrust is as well a really important parameter but the control law gives some priority to pitch and roll above thrust.

Hope it helps.

Cheers,

Nacho.

1 Like

Thanks Nacho. Your reply really helps me understand mixing.

I still have questions on calculating roll_pitch_scale. It seems to me the reason that we multiply roll_pitch_scale with the mix of roll and pitch is adding boost is not enough to bring the output to the valid range. So we have to adjust roll and pitch further. But why the roll_pitch_scale is (thrust + boost) / (thrust - min_out) or (1 - (thrust + boost)) / (max_out - thrust)? Are we trying to adjust roll and pitch at the same scale of we adjust the thrust? If so, it seems the scale should be boost/(max_out - 1) if max_out is over the limit or boost/(1 + min_out) if min_out is over the limit.