33 #define INT32_MIN (-2147483647-1)
37 #define INT32_MAX (2147483647)
40 #if defined MOTOR_MIXING_MIN_MOTOR || defined MOTOR_MIXING_MAX_MOTOR
41 #error MIN_MOTOR and MAX_MOTOR have to be set via neutral/max of the respective servo
43 #define MOTOR_MIXING_MIN_MOTOR 0
44 #define MOTOR_MIXING_MAX_MOTOR MAX_PPRZ
46 #ifndef MOTOR_MIXING_STOP_MOTOR
47 #define MOTOR_MIXING_STOP_MOTOR -MAX_PPRZ
50 #ifndef MOTOR_MIXING_TRIM_ROLL
51 #define MOTOR_MIXING_TRIM_ROLL 0
54 #ifndef MOTOR_MIXING_TRIM_PITCH
55 #define MOTOR_MIXING_TRIM_PITCH 0
58 #ifndef MOTOR_MIXING_TRIM_YAW
59 #define MOTOR_MIXING_TRIM_YAW 0
68 #ifndef MOTOR_MIXING_MAX_SATURATION_OFFSET
69 #define MOTOR_MIXING_MAX_SATURATION_OFFSET MAX_PPRZ/10
72 #ifndef MOTOR_MIXING_MIN_MOTOR_STARTUP
73 #define MOTOR_MIXING_MIN_MOTOR_STARTUP MOTOR_MIXING_MIN_MOTOR
76 #if defined (MOTOR_MIXING_MAX_NEGATIVE_MOTOR_STEP) || defined (MOTOR_MIXING_MAX_POSITIVE_MOTOR_STEP)
77 #define MOTOR_MIXING_USE_MAX_MOTOR_STEP_BINDING
79 #ifndef MOTOR_MIXING_MAX_NEGATIVE_MOTOR_STEP
80 #define MOTOR_MIXING_MAX_NEGATIVE_MOTOR_STEP INT32_MIN
99 for (i = 0; i < MOTOR_MIXING_NB_MOTOR; i++) {
115 for (j = 0; j < MOTOR_MIXING_NB_MOTOR; j++) {
123 for (j = 0; j < MOTOR_MIXING_NB_MOTOR; j++) {
130 #ifdef MOTOR_MIXING_USE_MAX_MOTOR_STEP_BINDING
132 static int32_t prev_commands[MOTOR_MIXING_NB_MOTOR];
133 static uint8_t initialized = 0;
135 if (initialized == 1) {
136 for (j = 0; j < MOTOR_MIXING_NB_MOTOR; j++) {
138 Bound(new_command_diff,
139 MOTOR_MIXING_MAX_NEGATIVE_MOTOR_STEP, MOTOR_MIXING_MAX_POSITIVE_MOTOR_STEP);
146 for (j = 0; j < MOTOR_MIXING_NB_MOTOR; j++) {
155 for (i = 0; i < MOTOR_MIXING_NB_MOTOR; i++) {
156 #ifdef MOTOR_MIXING_STARTUP_DELAY
157 if (counter > i * max_counter / (MOTOR_MIXING_NB_MOTOR + MOTOR_MIXING_STARTUP_DELAY)) {
158 if (counter > MOTOR_MIXING_NB_MOTOR * max_counter /
159 (MOTOR_MIXING_NB_MOTOR + MOTOR_MIXING_STARTUP_DELAY))
170 if (counter < i * max_counter / MOTOR_MIXING_NB_MOTOR) {
193 for (i = 0; i < MOTOR_MIXING_NB_MOTOR; i++) {
201 tmp_cmd /= MOTOR_MIXING_SCALE;
204 if (-tmp_cmd > max_overflow) {
205 max_overflow = -tmp_cmd;
207 else if (tmp_cmd -
MAX_PPRZ > max_overflow) {
213 int32_t yaw_authority = ABS(in_cmd[COMMAND_YAW]) - max_overflow;
215 int32_t bounded_yaw_cmd = in_cmd[COMMAND_YAW];
216 BoundAbs(bounded_yaw_cmd, yaw_authority);
223 for (i = 0; i < MOTOR_MIXING_NB_MOTOR; i++) {
244 if (max_cmd > MOTOR_MIXING_MAX_MOTOR) {
245 int32_t saturation_offset = MOTOR_MIXING_MAX_MOTOR - max_cmd;
257 if (motors_on && override_on) {
258 for (i = 0; i < MOTOR_MIXING_NB_MOTOR; i++) {
267 for (i = 0; i < MOTOR_MIXING_NB_MOTOR; i++) {
#define MOTOR_MIXING_MAX_MOTOR
static const int32_t roll_coef[MOTOR_MIXING_NB_MOTOR]
#define MOTOR_MIXING_MAX_SATURATION_OFFSET
Maximum offset in case of saturation.
int32_t trim[MOTOR_MIXING_NB_MOTOR]
static const int32_t thrust_coef[MOTOR_MIXING_NB_MOTOR]
static void bound_commands_step(void)
void motor_mixing_run(bool_t motors_on, bool_t override_on, pprz_t in_cmd[])
static const int32_t pitch_coef[MOTOR_MIXING_NB_MOTOR]
static void bound_commands(void)
static void offset_commands(int32_t offset)
int32_t override_value[MOTOR_MIXING_NB_MOTOR]
#define MOTOR_MIXING_STOP_MOTOR
void motor_mixing_init(void)
static const int32_t yaw_coef[MOTOR_MIXING_NB_MOTOR]
#define MOTOR_MIXING_TRIM_YAW
void motor_mixing_run_spinup(uint32_t counter, uint32_t max_counter)
#define MOTOR_MIXING_MIN_MOTOR_STARTUP
struct MotorMixing motor_mixing
#define MOTOR_MIXING_MIN_MOTOR
#define MOTOR_MIXING_TRIM_ROLL
int32_t commands[MOTOR_MIXING_NB_MOTOR]
#define MOTOR_MIXING_TRIM_PITCH
bool_t override_enabled[MOTOR_MIXING_NB_MOTOR]