Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

432 new mixing system #438

Draft
wants to merge 45 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
a45aa08
Adds option to use mixer based on motor positions and motor parameters.
JMoore5353 Aug 5, 2024
8ddf21e
Adds option to use mixer based on motor positions and motor parameters.
JMoore5353 Aug 5, 2024
4750c9c
Merge branch '432-new-mixing-system' of github.com:rosflight/rosfligh…
JMoore5353 Aug 5, 2024
70e7c9b
changed controller to output forces and torques
JMoore5353 Aug 8, 2024
f41077f
added parameters for the new mixing matrix calculations
JMoore5353 Aug 8, 2024
2caff09
Added custom mixer that uses Ch. 14 mixer equations. Also uses Ch. 4 …
JMoore5353 Aug 8, 2024
ab5ec00
added maximum throttle param from RC controller to maintain controlla…
JMoore5353 Aug 12, 2024
20e5d63
Scales thrust commands by RC_MAX_THROTTLE to maintain controllability
JMoore5353 Aug 14, 2024
c068882
Computes the mixing matrix using the SVD, which doesn't dynamically a…
JMoore5353 Aug 14, 2024
fbc2fe3
fixing code style
JMoore5353 Aug 14, 2024
69dc3af
return type qualifier fix
JMoore5353 Aug 14, 2024
cc75f32
added libeigen3-dev to workflow runs
JMoore5353 Aug 15, 2024
04d14e3
Added Eigen dependency to all boards.
JMoore5353 Aug 15, 2024
b28b910
Moved Eigen package to common/CMakeLists.txt
JMoore5353 Aug 15, 2024
b76ede7
Added hardcoded, precomputed mixing matrices for standard aircraft
JMoore5353 Aug 15, 2024
ef17b47
fixed include error
JMoore5353 Aug 15, 2024
a6ced22
Added find eigen call back
JMoore5353 Aug 15, 2024
6c5e163
Moved Eigen dependency back to the rosflight_firmware CMakeLists.txt
JMoore5353 Aug 27, 2024
6821d10
removed the quadplane mixing matrix to avoid confusion since it doesn…
JMoore5353 Oct 9, 2024
537d75b
added flag to switch between fixedwing mixing and multirotor mixing.
JMoore5353 Oct 14, 2024
10ebc1d
default F behavior for fixedwings is passthrough to mixer instead of …
JMoore5353 Oct 14, 2024
a571d4b
refactored some names and got rid of unused dependencies
JMoore5353 Oct 15, 2024
e0ece54
changed the mixer pwm outputs to be compatible with Varmint and Pixra…
JMoore5353 Oct 15, 2024
ed08c3b
recomputed canned mixers and added mixer parameters to the firmware
JMoore5353 Oct 29, 2024
a3ac22b
removed unused parameters and fixed mixing matrix paramter names
JMoore5353 Oct 29, 2024
3d62203
Update the input forces to include Fx and Fy
JMoore5353 Nov 7, 2024
180a3cb
added mixer header values to the parameter list
JMoore5353 Nov 7, 2024
8816fd8
fixed Fz for the canned mixers, since we are in NED frame
JMoore5353 Nov 11, 2024
274df44
changed mixer indices for clarity and fixed some bugs when using cust…
JMoore5353 Nov 11, 2024
bcd88bd
fixed aux channels not getting initialized. Changed the way servos ar…
JMoore5353 Nov 11, 2024
c6c66db
Added parameter to choose which axis the RC throttle corresponds to
JMoore5353 Nov 12, 2024
9d85c98
added support for secondary mixer
JMoore5353 Nov 26, 2024
be8a43a
some updates to the unit tests
JMoore5353 Nov 26, 2024
8dfbba3
minor code cleanup
JMoore5353 Dec 6, 2024
935548d
added descriptions to some parameters
JMoore5353 Dec 11, 2024
9416b66
changed eigen dependency to be fetch content so it is more platform i…
JMoore5353 Dec 16, 2024
0ee7dde
removed iostream dependency and dead function calls
JMoore5353 Dec 16, 2024
4173d59
removed air density as a parameter. Using ideal gas law
JMoore5353 Dec 17, 2024
ff54382
renamed NONE to AUX since it is only used for AUX channels
JMoore5353 Dec 17, 2024
e0eee63
added error checking for RC F axis selection
JMoore5353 Dec 17, 2024
1f01b73
reworked the way mixers were assigned to use the enums instead of the…
JMoore5353 Dec 17, 2024
100fe33
replaced the load parameter methods with a loop
JMoore5353 Dec 17, 2024
9552981
eigen now a git submodule
JMoore5353 Dec 31, 2024
af4b8da
fixed the calculation for air density
JMoore5353 Dec 31, 2024
e0a9a7d
Merge branch 'main' into 432-new-mixing-system
JMoore5353 Dec 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: checkout submodules
run: git submodule update --init --recursive
- name: install toolchain
run: sudo apt -y install gcc-arm-none-eabi
run: sudo apt -y install gcc-arm-none-eabi libeigen3-dev
- name: check toolchain
run: arm-none-eabi-gcc --version
- name: build varmint
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: checkout submodules
run: git submodule update --init --recursive
- name: install toolchain
run: sudo apt -y install gcc-arm-none-eabi
run: sudo apt -y install gcc-arm-none-eabi libeigen3-dev
- name: check toolchain
run: arm-none-eabi-gcc --version
- name: build varmint
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/varmint_firmware.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: checkout submodules
run: git submodule update --init --recursive
- name: install toolchain
run: sudo apt -y install gcc-arm-none-eabi
run: sudo apt -y install gcc-arm-none-eabi libeigen3-dev
- name: check toolchain
run: arm-none-eabi-gcc --version
- name: build varmint
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ if("${GIT_VERSION_HASH}" STREQUAL "")
endif()

### source files ###
find_package(Eigen3 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIRS})

include_directories(
include
Expand Down
4 changes: 2 additions & 2 deletions include/command_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ typedef enum
{
RATE, // Channel is is in rate mode (mrad/s)
ANGLE, // Channel command is in angle mode (mrad)
THROTTLE, // Channel is direcly controlling throttle max/1000
THROTTLE, // Channel is controlling throttle setting, which will be converted to force
PASSTHROUGH, // Channel directly passes PWM input to the mixer
} control_type_t;

Expand Down Expand Up @@ -108,7 +108,7 @@ class CommandManager : public ParamListenerInterface
{true, PASSTHROUGH, 0.0},
{true, PASSTHROUGH, 0.0},
{true, PASSTHROUGH, 0.0},
{true, THROTTLE, 0.0}};
{true, PASSTHROUGH, 0.0}};
// clang-format on

typedef enum
Expand Down
9 changes: 7 additions & 2 deletions include/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ class Controller : public ParamListenerInterface
Controller(ROSflight & rf);

inline const Output & output() const { return output_; }
inline float max_thrust() const { return max_thrust_; }

void init();
void run();

void calculate_max_thrust();
void calculate_equilbrium_torque_from_rc();
void param_change_callback(uint16_t param_id) override;

Expand Down Expand Up @@ -92,8 +94,8 @@ class Controller : public ParamListenerInterface

ROSflight & RF_;

turbomath::Vector run_pid_loops(uint32_t dt, const Estimator::State & state,
const control_t & command, bool update_integrators);
Controller::Output run_pid_loops(uint32_t dt, const Estimator::State & state,
const control_t & command, bool update_integrators);

Output output_;

Expand All @@ -103,6 +105,9 @@ class Controller : public ParamListenerInterface
PID pitch_rate_;
PID yaw_rate_;

float max_thrust_;
float max_throttle_;

uint64_t prev_time_us_;
};

Expand Down
140 changes: 77 additions & 63 deletions include/mixer.h
JMoore5353 marked this conversation as resolved.
Show resolved Hide resolved
JMoore5353 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@

#include "interface/param_listener.h"

#include <Eigen/Dense>
#include <Eigen/SVD>

#include <cstdbool>
#include <cstdint>

Expand Down Expand Up @@ -61,9 +64,8 @@ class Mixer : public ParamListenerInterface
TRICOPTER = 9,
FIXEDWING = 10,
PASSTHROUGH = 11,
VTAIL = 12,
QUADPLANE = 13,
CUSTOM = 14,
INVERTED_VTAIL = 12,
CUSTOM = 13,
NUM_MIXERS,
INVALID_MIXER = 255
};
Expand Down Expand Up @@ -121,74 +123,74 @@ class Mixer : public ParamListenerInterface
const mixer_t quadcopter_plus_mixing = {
{ M, M, M, M, NONE, NONE, NONE, NONE, NONE, NONE}, // output_type
{ 490, 490, 490, 490, 50, 50, 50, 50, 50, 50}, // Rate (Hz)
{1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // F Mix
{0.0f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // X Mix
{1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // Y Mix
{1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}}; // Z Mix
{5098.031218379775, 5098.0312183797805, 5098.031218379778, 5098.0312183797805, 0, 0, 0, 0, 0, 0},
{0.0, -40784.24974703961, 0.0, 40784.24974703687, 0, 0, 0, 0, 0, 0},
{40784.249747038244, 0.0, -40784.24974703822, 0.0, 0, 0, 0, 0, 0, 0},
{223010.98943043666, -223010.98943043654, 223010.98943043666, -223010.98943043657, 0, 0, 0, 0, 0, 0}};

const mixer_t quadcopter_x_mixing = {
{ M, M, M, M, NONE, NONE, NONE, NONE, NONE, NONE}, // output_type
{ 490, 490, 490, 490, 50, 50, 50, 50, 50, 50}, // Rate (Hz)
{ 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // F Mix
{-1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // X Mix
{ 1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // Y Mix
{ 1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}}; // Z Mix
{5098.031218379779, 5098.03121837978, 5098.031218379777, 5098.031218379782, 0, 0, 0, 0, 0, 0},
{-28838.81956173643, -28838.819561736505, 28838.81956173648, 28838.819561736465, 0, 0, 0, 0, 0, 0},
{28838.819561736495, -28838.819561736498, -28838.819561736433, 28838.81956173645, 0, 0, 0, 0, 0, 0},
{223010.9894304366, -223010.9894304366, 223010.98943043666, -223010.9894304366, 0, 0, 0, 0, 0, 0}};

const mixer_t hex_plus_mixing = {
{ M, M, M, M, M, M, NONE, NONE, NONE, NONE}, // output_type
{ 490, 490, 490, 490, 490, 490, 50, 50, 50, 50}, // Rate (Hz)
{1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // F Mix
{0.0f, -0.866025f, -0.866025f, 0.0f, 0.866025f, 0.866025f, 0.0f, 0.0f, 0.0f, 0.0f}, // X Mix
{1.0f, 0.5f, -0.5f, -1.0f, -0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f}, // Y Mix
{1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f}}; // Z Mix
{3398.687478919854, 3398.6874789198537, 3398.6874789198537, 3398.6874789198523, 3398.6874789198537, 3398.6874789198537, 0, 0, 0, 0},
{0.0, -23546.797570149454, -23546.797570149447, 0.0, 23546.797570149443, 23546.79757014946, 0, 0, 0, 0},
{27189.49983135882, 13594.749915679433, -13594.749915679424, -27189.49983135882, -13594.749915679417, 13594.749915679415, 0, 0, 0, 0},
{148673.99295362437, -148673.99295362443, 148673.99295362437, -148673.99295362437, 148673.9929536245, -148673.9929536244, 0, 0, 0, 0}};

const mixer_t hex_x_mixing = {
{ M, M, M, M, M, M, NONE, NONE, NONE, NONE}, // output_type
{ 490, 490, 490, 490, 490, 490, 50, 50, 50, 50}, // Rate (Hz)
{ 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // F Mix
{ -0.5f, -1.0f, -0.5f, 0.5f, 1.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f}, // X Mix
{0.866025f, 0.0f, -0.866025f, -0.866025f, 0.0f, 0.866025f, 0.0f, 0.0f, 0.0f, 0.0f}, // Y Mix
{ 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f}}; // Z Mix
{M, M, M, M, M, M, NONE, NONE, NONE, NONE},
{490, 490, 490, 490, 490, 490, 50, 50, 50, 50},
{3398.687478919854, 3398.687478919853, 3398.687478919853, 3398.6874789198523, 3398.687478919854, 3398.687478919854, 0, 0, 0, 0},
{-13594.749915679407, -27189.49983135883, -13594.74991567941, 13594.749915679384, 27189.49983135884, 13594.74991567942, 0, 0, 0, 0},
{23546.797570149465, 0.0, -23546.797570149454, -23546.797570149472, 0.0, 23546.797570149465, 0, 0, 0, 0},
{148673.99295362426, -148673.9929536243, 148673.99295362443, -148673.99295362443, 148673.99295362446, -148673.99295362437, 0, 0, 0, 0}};

const mixer_t octocopter_plus_mixing = {
{ M, M, M, M, M, M, M, M, NONE, NONE}, // output_type
{ 490, 490, 490, 490, 490, 490, 490, 490, 50, 50}, // Rate (Hz)
{1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f}, // F Mix
{0.0f, -0.707f, -1.0f, -0.707f, 0.0f, 0.707f, 1.0f, 0.707f, 0.0f, 0.0f}, // X Mix
{1.0f, 0.707f, 0.0f, -0.707f, -1.0f, -0.707f, 0.0f, 0.707f, 0.0f, 0.0f}, // Y Mix
{1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 0.0f}}; // Z Mix
{M, M, M, M, M, M, M, M, NONE, NONE},
{490, 490, 490, 490, 490, 490, 490, 490, 50, 50},
{2549.0156091898907, 2549.0156091898903, 2549.01560918989, 2549.0156091898893, 2549.015609189889, 2549.0156091898893, 2549.01560918989, 2549.0156091898903, 0, 0},
{0.0, -14419.409780868224, -20392.124873519115, -14419.409780868233, 0.0, 14419.409780868235, 20392.124873519115, 14419.409780868242, 0, 0},
{20392.124873519126, 14419.409780868244, 0.0, -14419.409780868249, -20392.124873519126, -14419.409780868249, 0.0, 14419.409780868238, 0, 0},
{111505.49471521821, -111505.4947152183, 111505.49471521829, -111505.49471521829, 111505.49471521827, -111505.49471521826, 111505.49471521827, -111505.49471521827, 0, 0}};

const mixer_t octocopter_x_mixing = {
{ M, M, M, M, M, M, M, M, NONE, NONE}, // output_type
{ 490, 490, 490, 490, 490, 490, 490, 490, 50, 50}, // Rate (Hz)
{ 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f}, // F Mix
{-0.414f, -1.0f, -1.0f, -0.414f, 0.414f, 1.0f, 1.0f, 0.414, 0.0f, 0.0f}, // X Mix
{ 1.0f, 0.414f, -0.414f, -1.0f, -1.0f, -0.414f, 0.414f, 1.0, 0.0f, 0.0f}, // Y Mix
{ 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 0.0f}}; // Z Mix
{M, M, M, M, M, M, M, M, NONE, NONE},
{490, 490, 490, 490, 490, 490, 490, 490, 50, 50},
{2549.0156091898893, 2549.01560918989, 2549.01560918989, 2549.0156091898903, 2549.0156091898903, 2549.01560918989, 2549.01560918989, 2549.0156091898893, 0, 0},
{-7803.728339815821, -18839.866795058642, -18839.86679505863, -7803.728339815828, 7803.728339815823, 18839.86679505863, 18839.86679505864, 7803.728339815834, 0, 0},
{18839.86679505862, 7803.728339815822, -7803.728339815816, -18839.866795058624, -18839.86679505863, -7803.728339815828, 7803.728339815817, 18839.86679505862, 0, 0},
{111505.49471521824, -111505.49471521845, 111505.49471521832, -111505.49471521827, 111505.49471521837, -111505.49471521827, 111505.49471521833, -111505.49471521836, 0, 0}};

const mixer_t Y6_mixing = {
{ M, M, M, M, M, M, NONE, NONE, NONE, NONE}, // output_type
{ 490, 490, 490, 490, 490, 490, 50, 50, 50, 50}, // Rate (Hz)
{ 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // F Mix
{ -1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // X Mix
{0.667f, 0.667f, -1.333f, -1.333f, 0.667f, 0.667f, 0.0f, 0.0f, 0.0f, 0.0f}, // Y Mix
{ 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f}}; // Z Mix
{M, M, M, M, M, M, NONE, NONE, NONE, NONE},
{490, 490, 490, 490, 490, 490, 50, 50, 50, 50},
{3398.6874789198546, 3398.6874789198523, 3398.6874789198537, 3398.6874789198546, 3398.687478919853, 3398.6874789198528, 0, 0, 0, 0},
{-23546.79757014947, 0.0, 23546.797570149454, -23546.79757014944, 0.0, 23546.79757014947, 0, 0, 0, 0},
{13594.749915679397, -27189.499831358822, 13594.749915679413, 13594.749915679437, -27189.499831358844, 13594.749915679426, 0, 0, 0, 0},
{148673.9929536246, -148673.9929536245, 148673.9929536245, -148673.99295362452, 148673.99295362446, -148673.9929536245, 0, 0, 0, 0}};

const mixer_t X8_mixing = {
{ M, M, M, M, M, M, M, M, NONE, NONE}, // output_type
{ 490, 490, 490, 490, 490, 490, 490, 490, 50, 50}, // Rate (Hz)
{ 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f}, // F Mix
{-1.0f, -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f}, // X Mix
{ 1.0f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f}, // Y Mix
{ 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 0.0f}}; // Z Mix
{M, M, M, M, M, M, M, M, NONE, NONE},
{490, 490, 490, 490, 490, 490, 490, 490, 50, 50},
{2549.01560918989, 2549.01560918989, 2549.0156091898893, 2549.0156091898893, 2549.01560918989, 2549.01560918989, 2549.0156091898903, 2549.0156091898903, 0, 0},
{-14419.409780868245, -14419.409780868247, -14419.40978086824, -14419.409780868236, 14419.409780868244, 14419.409780868247, 14419.40978086824, 14419.409780868244, 0, 0},
{14419.409780868236, 14419.40978086824, -14419.409780868247, -14419.409780868247, -14419.40978086824, -14419.409780868244, 14419.409780868249, 14419.409780868245, 0, 0},
{111505.49471521829, -111505.49471521827, 111505.49471521823, -111505.49471521829, 111505.49471521827, -111505.49471521826, 111505.49471521829, -111505.49471521823, 0, 0}};

const mixer_t tricopter_mixing = {
{ M, M, M, NONE, S, NONE, NONE, NONE, NONE, NONE}, // output_type
{ 490, 490, 490, 50, 50, 50, 50, 50, 50, 50}, // Rate (Hz)
{ 1.000f, 0.000f, 1.000f, 0.000f, 1.000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // F Mix
{-1.000f, 0.000f, 0.000f, 0.000f, 1.000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // X Mix
{ 0.667f, 0.000f, 0.667f, 0.000f, -1.333f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // Y Mix
{ 0.000f, 1.000f, 0.000f, 0.000f, 0.000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f} }; // Z Mix
{M, M, M, M, M, M, NONE, NONE, NONE, NONE},
{490, 490, 490, 490, 490, 490, 50, 50, 50, 50},
{3398.687478919855, 3398.687478919855, 3398.6874789198528, 3398.687478919852, 3398.6874789198537, 3398.6874789198528, 0, 0, 0, 0},
{-23546.797570149458, -23546.797570149447, 0.0, 0.0, 23546.797570149454, 23546.797570149465, 0, 0, 0, 0},
{13594.749915679417, 13594.74991567943, -27189.499831358844, -27189.49983135883, 13594.749915679406, 13594.749915679418, 0, 0, 0, 0},
{148673.99295362437, -148673.99295362429, 148673.99295362443, -148673.9929536245, 148673.9929536244, -148673.99295362443, 0, 0, 0, 0}};

const mixer_t fixedwing_mixing = {
{ S, S, S, NONE, M, NONE, NONE, NONE, NONE, NONE}, // output type
Expand All @@ -198,22 +200,14 @@ class Mixer : public ParamListenerInterface
{0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // Y Mix
{0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}}; // Z Mix

const mixer_t fixedwing_vtail_mixing = {
const mixer_t fixedwing_inverted_vtail_mixing = {
{ S, NONE, NONE, S, S, M, NONE, NONE, NONE, NONE}, // Ailerons, LRuddervator, RRuddervator, Motor
{ 50, 50, 50, 50, 50, 50, 50, 50, 50, 50}, // Rate (Hz)
{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // F Mix
{1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // X Mix
{0.0f, 0.0f, 0.0f, -0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // Y Mix
{0.0f, 0.0f, 0.0f, 0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}}; // Z Mix

const mixer_t quadplane_mixing = {
{ S, S, S, M, M, M, M, M, NONE, NONE}, // Ailerons, Rudder, Elevator, Tractor Motor, Quadrotors
{ 50, 50, 50, 50, 490, 490, 490, 490, 50, 50}, // Rate (Hz)
{0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f}, // F Mix
{1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f}, // X Mix
{0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f}, // Y Mix
{0.0f, 0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 0.0f}}; // Z Mix

const mixer_t passthrough_mixing = {
{NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE},
{ 50, 50, 50, 50, 50, 50, 50, 50, 50, 50}, // Rate (Hz or kHz)
Expand All @@ -230,6 +224,8 @@ class Mixer : public ParamListenerInterface
{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // Y Mix
{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}}; // Z Mix

mixer_t custom_mixer_;

const mixer_t * mixer_to_use_;

const mixer_t* array_of_mixers_[NUM_MIXERS] = {
Expand All @@ -245,22 +241,40 @@ class Mixer : public ParamListenerInterface
&tricopter_mixing,
&fixedwing_mixing,
&passthrough_mixing,
&fixedwing_vtail_mixing,
&quadplane_mixing,
&custom_mixing
&fixedwing_inverted_vtail_mixing,
&custom_mixing,
};

// clang-format on

// Define parameters for the mixer
float R_; // Motor resistance
float rho_; // Air density
float K_V_; // Motor back-emf constant
float K_Q_ = 0.01706; // Motor torque constant
JMoore5353 marked this conversation as resolved.
Show resolved Hide resolved
float i_0_; // Motor no-load current
float D_; // Propeller diameter
float C_T_; // Thrust coefficient
float C_Q_; // Torque coefficient
int num_motors_; // Number of motors
float V_max_; // Maximum battery voltage
float l_[NUM_MIXER_OUTPUTS]; // Radial distance from center of mass to motor
float psi_[NUM_MIXER_OUTPUTS]; // Angle of motor from body x-axis

public:
Mixer(ROSflight & _rf);
void init();
void init_PWM();
void init_mixing();
void update_parameters();
void mix_output();
void param_change_callback(uint16_t param_id) override;
void set_new_aux_command(aux_command_t new_aux_command);
inline const float * get_outputs() const { return raw_outputs_; }

void calculate_mixer_values();
void mix_multirotor();
void mix_fixedwing();
};

} // namespace rosflight_firmware
Expand Down
36 changes: 34 additions & 2 deletions include/param.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,39 @@ enum : uint16_t
PARAM_BAUD_RATE = 0,
PARAM_SERIAL_DEVICE,

PARAM_AIR_DENSITY,

PARAM_NUM_MOTORS,
PARAM_MOTOR_RESISTANCE,
PARAM_MOTOR_KV,
PARAM_NO_LOAD_CURRENT,
PARAM_PROP_DIAMETER,
PARAM_PROP_CT,
PARAM_PROP_CQ,
PARAM_VOLT_MAX,

PARAM_MOTOR_0_POS,
PARAM_MOTOR_1_POS,
PARAM_MOTOR_2_POS,
PARAM_MOTOR_3_POS,
PARAM_MOTOR_4_POS,
PARAM_MOTOR_5_POS,
PARAM_MOTOR_6_POS,
PARAM_MOTOR_7_POS,
PARAM_MOTOR_8_POS,
PARAM_MOTOR_9_POS,

PARAM_MOTOR_0_PSI,
PARAM_MOTOR_1_PSI,
PARAM_MOTOR_2_PSI,
PARAM_MOTOR_3_PSI,
PARAM_MOTOR_4_PSI,
PARAM_MOTOR_5_PSI,
PARAM_MOTOR_6_PSI,
PARAM_MOTOR_7_PSI,
PARAM_MOTOR_8_PSI,
PARAM_MOTOR_9_PSI,

/*****************************/
/*** MAVLINK CONFIGURATION ***/
/*****************************/
Expand All @@ -70,8 +103,6 @@ enum : uint16_t
/********************************/
/*** CONTROLLER CONFIGURATION ***/
/********************************/
PARAM_MAX_COMMAND,

PARAM_PID_ROLL_RATE_P,
PARAM_PID_ROLL_RATE_I,
PARAM_PID_ROLL_RATE_D,
Expand Down Expand Up @@ -175,6 +206,7 @@ enum : uint16_t
PARAM_RC_OVERRIDE_DEVIATION,
PARAM_OVERRIDE_LAG_TIME,
PARAM_RC_OVERRIDE_TAKE_MIN_THROTTLE,
PARAM_RC_MAX_THROTTLE,

PARAM_RC_ATTITUDE_MODE,
PARAM_RC_MAX_ROLL,
Expand Down
5 changes: 3 additions & 2 deletions src/comm_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ void CommManager::offboard_control_callback(const CommLinkInterface::OffboardCon
new_offboard_command.x.type = PASSTHROUGH;
new_offboard_command.y.type = PASSTHROUGH;
new_offboard_command.z.type = PASSTHROUGH;
new_offboard_command.F.type = THROTTLE;
new_offboard_command.F.type = PASSTHROUGH;
break;
case CommLinkInterface::OffboardControl::Mode::ROLLRATE_PITCHRATE_YAWRATE_THROTTLE:
new_offboard_command.x.type = RATE;
Expand Down Expand Up @@ -350,7 +350,8 @@ void CommManager::send_status(void)
if (!initialized_) { return; }

uint8_t control_mode = 0;
if (RF_.params_.get_param_int(PARAM_FIXED_WING) || RF_.command_manager_.combined_control().x.type == PASSTHROUGH) {
if (RF_.params_.get_param_int(PARAM_FIXED_WING)
|| RF_.command_manager_.combined_control().x.type == PASSTHROUGH) {
control_mode = MODE_PASS_THROUGH;
} else if (RF_.command_manager_.combined_control().x.type == ANGLE) {
control_mode = MODE_ROLL_PITCH_YAWRATE_THROTTLE;
Expand Down
Loading
Loading