Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • D deltaflight
  • Project information
    • Project information
    • Activity
    • Labels
    • Planning hierarchy
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • deltaflight
  • deltaflight
  • Wiki
  • Mixer Code

Last edited by dbui7 Mar 14, 2021
Page history

Mixer Code

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.

More on primaryMotorMixer

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().

Clone repository
  • Example Wiki
  • Flashing Firmware
  • Home
  • Mixer Code
  • Position Controller Code