NinjaFlight
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Mixer

Enumerations

enum  mixer_flags { MIXER_FLAG_ARMED = (1 << 3) }
 

Functions

void mixer_init (struct mixer *self, const struct config const *config, const struct system_calls_pwm *pwm)
 
void mixer_clear_rules (struct mixer *self)
 saves motor mixer into cleanflight motor mixer format More...
 
void mixer_input_command (struct mixer *self, mixer_input_t channel, int16_t value)
 inputs a command to one of the input channels of the mixer More...
 
void mixer_set_throttle_range (struct mixer *self, int16_t mid, int16_t min, int16_t max)
 sets throttle range of the mixer (can be used to set 3d throttle range too) More...
 
void mixer_update (struct mixer *self)
 calculates outputs from all mixer inputs and mixing rules More...
 
void mixer_enable_armed (struct mixer *self, bool on)
 arms/disarms the mixer (when disarmed, motor outputs will be set to disarmed pwm values. These are reset to either midrc when in 3d mode or to mincommand when not in 3d mode) More...
 
bool mixer_motor_limit_reached (struct mixer *self)
 returns true if mixer has determined that motor limit has been reached More...
 
uint8_t mixer_get_motor_count (struct mixer *self)
 returns the number of motors that are currently being controlled by mixer profile More...
 
uint8_t mixer_get_servo_count (struct mixer *self)
 returns number of servos that are used by the mixer. More...
 

Detailed Description

The rewritten universal aircraft mixer

Mixer

Author
Rewrite: Martin Schröder mksch.nosp@m.rede.nosp@m.r.uk@.nosp@m.gmai.nosp@m.l.com
Original: Cleanflight

The primary job of a mixer is to translate inputs from the flight controller into linear or angular movement of the aircraft body. The mixer does this by taking into account frame and thrust configuration and generating actuator values for required control surfaces.

Inputs to the mixer

Mixer inputs are divided into 4 groups:

  • MIXER_INPUT_GROUP_FC: group 0, flight controller stabilization inputs
  • MIXER_INPUT_GROUP_1: group 1, reserved
  • MIXER_INPUT_GROUP_GIMBAL: group 2, gimbal controls (also used by tilt drone)
  • MIXER_INPUT_GROUP_RC: group 3, rc controls
  • MIXER_INPUT_GROUP_MOTOR_PASSTHROUGH: group 4, motor passthrough
Each input group contains 8 inputs and can be referenced by the mixer rules.All inputs must be in range -500 to +500.

Outputs of the mixer

Mixer outputs are divided into 2 groups:

  • Motors
  • Servos
Motor outpus are constrained by minthrottle and maxthrottle and centered at midthrottle value.Mixer will automatically forward servo outputs from RC_AUX1 channel and onwards into servo slots that come after the servos that are used by the mixer.Servo outputs are scaled and limited according to the ninjaflight servo configuration.

Mixer rules

All mixer rules are additive to the given output channel. Each rule defines a scale operation for a particular input to the mixer.

Mixer Unit Tests

This is a summary of automatic tests that are done against the mixer module to guarantee that the module behaves according to the requirements set forth below.
  • When mixer is started and not armed it will output G4 inputs as passthrough to the motors and will output midrc values on servos. When armed, mixer shall output minimum value that was set by mixer_set_throttle_range.
  • 3d mode is set in mixer using mixer_set_throttle_range(). TODO: this test needs to be improved.
  • When mixer is disarmed it should pass MIXER_INPUT_G4_Mx inputs to the motors and should keep servos at midpoint.
  • Inputs in group G3 that correspond to AUX channels should always be automatically forwarded to servos that are not controlled by the mixer (starting with the next servo after the last one that is controlled by the mixer rules). TODO: make sure that this output is mixed according to servo configuration rules.
  • Mixer scales motor output such that differential thrust is maintained as much as possible. If some motors are above maximum output range, mixer moves all motors down such that the difference between motor with least thrust and motor with most thrust is maintained. If both top and bottom limits are exceeded then all motors are scaled to fit in the allowed output range.
  • Motors that are unused by the mixer are always held at mincommand setting as specified in the mixer configuration. This only applies to motor outputs (not servos).
  • Mixer has basic tolerance against invalid configuration values. Values are constrained in some places. Do keep configuration valid for best result.

Enumeration Type Documentation

Enumerator
MIXER_FLAG_ARMED 

mixer has to be armed in order to make motor calculations. Motor values are set to either mincommand or minthrottle depending on whether motor stop is enabled

Function Documentation

void mixer_clear_rules ( struct mixer self)

saves motor mixer into cleanflight motor mixer format

loads a set of motor mixing rules from cleanflight format into current ruleset save servo mixer into cleanflight servo mixer format (sets some fields to defaults) loads servo mixing rules from cleanflight format into internal format clears all mixing rules

void mixer_enable_armed ( struct mixer self,
bool  on 
)

arms/disarms the mixer (when disarmed, motor outputs will be set to disarmed pwm values. These are reset to either midrc when in 3d mode or to mincommand when not in 3d mode)

puts mixer into armed state so that outputs are calculated (TODO: this should probably be placed outside of the mixer!)

uint8_t mixer_get_motor_count ( struct mixer self)

returns the number of motors that are currently being controlled by mixer profile

returns total number of motors that are being actively mixed by the mixer as part of current profile

uint8_t mixer_get_servo_count ( struct mixer self)

returns number of servos that are used by the mixer.

returns total number of servos that are being actively mxier by the mixer as part of current profile

void mixer_init ( struct mixer self,
const struct config const *  config,
const struct system_calls_pwm pwm 
)

Initializes an empty mixer objects clearing memory first.

Here is the call graph for this function:

void mixer_input_command ( struct mixer self,
mixer_input_t  channel,
int16_t  value 
)

inputs a command to one of the input channels of the mixer

Inputs a command into the mixer. Valid range is [-500 to 500];

Parameters
channelthe channel to set
valuethe value of the channel. Zero centered and between -500 to 500

Here is the call graph for this function:

bool mixer_motor_limit_reached ( struct mixer self)

returns true if mixer has determined that motor limit has been reached

tests if any of the motors have reached their limit (usually maxthrottle)

void mixer_set_throttle_range ( struct mixer self,
int16_t  mid,
int16_t  min,
int16_t  max 
)

sets throttle range of the mixer (can be used to set 3d throttle range too)

Sets throttle range for scaling motor values. All outputs will be centered at mid throttle and will be clipped to min/max range (this works because all inputs are -500 to 500).

Parameters
midthe middle throttle value on which outputs will be centered.
minminimum possible output value
maxmaximum possible output value

Here is the call graph for this function:

void mixer_update ( struct mixer self)

calculates outputs from all mixer inputs and mixing rules

Updates the outputs based on mixing rules from the inputs. Expects inputs to be set using mixer_input_* command.

If mixer is in disarmed state then it will forward group 4 inputs (motor passthrough) to the outputs. This feature can be used to test motors when mixer is not mixing (without changing mixing mode).

Here is the call graph for this function: