How mixer work

Ok guys,

Sorry in advance, but I really have struggle to understand how the mixing is handled by the pixhawk midleware.

I’ve read the dev guide on mixing, but I still don’t understand what is written there. I don’t see how a simple file like this where there is only definition can convert attitude value like roll pitch and yaw into pwm value to motors… Maybe I am just dumb :sweat:

There is mutliple cpp file that are related to mixing “fmu.cpp” “mixer.cpp” etc… and I don’t see the link between mixing file quad_x.main and high level cpp file.

Can someone explain me simply the work-flow from publishing value into actuator_control topic like roll, pitch yaw and throttle and at the end sending to ioctl() function the pwm value to motors.

Is there any matematical expression like:
output_pwm_actuator1=function_of(pitch,roll,yaw,throttle)
output_pwm_actuator2=function_of(pitch,roll,yaw,throttle)
output_pwm_actuator3=function_of(pitch,roll,yaw,throttle)
output_pwm_actuator4=function_of(pitch,roll,yaw,throttle)

it should be trigonometric relation right ?

Thank in advance,

2 Likes

How I understand it .

     Throttle       Pitch       Roll        Yaw    
M1     100%          100%        100%        100%
M2     100%          100%      - 100%      - 100%
M3     100%        - 100%      - 100%        100%
M4     100%        - 100%        100%      - 100%

So with that we make the mixing file:
R: 4x 10000 10000 10000 0
M: 1
O: 10000 10000 0 -10000 10000
S: 3 5 10000 10000 0 -10000 10000
M: 1
O: 10000 10000 0 -10000 10000
S: 3 6 10000 10000 0 -10000 10000

Right ?
But after ? How is it handle by the middleware

You’re missing the autopilot. For quadcopters, it is handled by this and
[this] (https://github.com/PX4/Firmware/tree/master/src/modules/mc_pos_control) depending on which flight mode you use.

In the most basic case of manual RC control, the stick input is processed in mc_att_control and output to _actuators_0_pub topic. This is then used by the mixer to output PWM value.

I’m using pixhawk for fixed wing application, and not too familiar with MC, but I believe the main idea should be right. For the details, please look inside the linked files.

[This] (http://uav-lab.org/2016/08/15/px4-research-log-7-a-closer-look-at-mc_att_control/) might also be useful

Hi @Darkus3,
The control allocation matrices (“mixer tables”) are generated by the python script px_generate_mixers.py given the geometries of the vehicles.
After this, the matrix is used here to create the thrust output of each motor with the following expression:
thrust = roll*roll_scale + pitch*pitch_scale + yaw*yaw_scale + collective_thrust*thrust_scale
Where the output scale is used when you have a different prop/motor (tricopter for example).
Then, in the same file are implemented some strategies (called Airmode) to avoid loss of control when some actuators reach saturation.
For more details, check this control allocation repository where the algorithm as been prototyped in Python. This Python script is also used here to verify the C++ implementation.

EDIT: updated comment for v1.9 release

7 Likes

hi
thx for your description
would you please update your explanation links they are dead

Hi @ghasem20 ,

I updated the links and the description since the multicopter mixer had a complete rewrite between v1.8 and v1.9.

Description of the new algorithm here.

1 Like

hi again
thx for your description
I still have some questions about the topic that i will ask when i take the background

Hi @bresch,

The roll pitch and yaw value in your formula are roll pitch and yaw torques right ? These values are between -1 and 1 but what is the maximum torque corresponding to 1 ? I have the same question for collective_trhust variable. Then the output is thrust that is the thrust of one motor and that is also a value between 0 and 1. But how it his value then transformed into a motor command like a PWM ?

@Daniel_Blanquez Everything is normalized, so 1 = maximum positive torque , -1 = maximum negative torque. For a motor, 1 is full power (maximum pwm command, e.g.: 2ms) and 0 is minimum power/idle speed (minimum pwm command, e.g.: 1ms).

@bresch ok tank you ! And then how can I know this value of maximum positive and negative torque for roll pitch and yaw ?

@Daniel_Blanquez That depends on the propulsion system of your drone, you have to measure it if you want to know the value non-normalized units.

@bresch And if I am working with SITL in gazebo with the 3DR Iris Quadrotor ? I do not have the real drone

1 Like

Hi, i’m still dont understand, how can we estimate value of PWM that has to generated to reach the normalized torque given the parameter of each copter can be different resulted to produce same value of thrust for different value of PWM.