Overview
The mixer can be found in mixer.c
. The mixer is responsible for converting inputs from the RC-controller or PID controller into motor outputs.
Inputs
The mixer appears to take inputs in two different ways based on the state of FIXED_WING_LEGACY
and MANUAL_MODE
for flight.
The first method of input is through the rcCommand
array, defined in rc_controls.h
. (src/main/fc/rc_controls.h:82
).
The second is through the axisPID
array, defined in pid.h
. (src/main/flight/pid.h:171
).
Outputs
The mixer uses the function pwmWriteMotor()
to output to the motors. This function is defined in pwm_output.c
(src/main/drivers/pwm_output.c:185
).
Mixer Table Multiplication
Array of structs contains all the mixer parameters. Each struct is equivalent to an additional motor. We can add pusher X,Y,Z components to this struct.
// motors for non-servo mixes
for (int i = 0; i < motorCount; i++) {
//Mixer dot product
rpyMix[i] =
(input[PITCH] * currentMixer[i].pitch +
input[ROLL] * currentMixer[i].roll +
-motorYawMultiplier * input[YAW] * currentMixer[i].yaw) * mixerScale;
if (rpyMix[i] > rpyMixMax) rpyMixMax = rpyMix[i];
if (rpyMix[i] < rpyMixMin) rpyMixMin = rpyMix[i];
}
currentMixer
Population
currentMixer
appears to be loaded in loadPrimaryMotorMixer()
on line 626 of mixer.c
. primaryMotorMixer
is an array that is registered through PG_REGISTER_ARRAY
and declared through PG_DECLARE_ARRAY
. The registration occurs on line 116 of mixer.c
, and declaration occurs on line 63 of mixer.h
.
primaryMotorMixer
More on The declaration of primaryMotorMixer
also appears to create another array called primaryMotorMixerMutable
based on the definition of PG_DECLARE_ARRAY
(src/main/config/parameter_group.h:114
). primaryMotorMixer
is never explicitly written to, and primaryMotorMixerMutable
is never explicitly read from. More research needs to be done to determine how these two relate to each other. It is not clear whether data written to primaryMotorMixerMutable
is also affecting primaryMotorMixer
. These configuration variables are stored on the microcontroller through the PG_DECLARE
and PG_REGISTER
family of macros that are defined in src/main/config/parameter_group.h
.
primaryMotorMixerMutable
primaryMotorMixerMutable
appears to mainly be written to in the files, cli.c
(src/main/fc/cli.c:1071
) and fc_msp.c
(src/main/fc/fc_msp.c:2022
). The function in fc_msp.c
that writes to primaryMotorMixerMutable
is mspFcProcessInCommand()
.