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
96 #if PERIODIC_TELEMETRY
100 int16_t motors[MOTOR_MIXING_NB_MOTOR];
101 for (
uint8_t i = 0; i < MOTOR_MIXING_NB_MOTOR; i++)
105 pprz_msg_send_MOTOR_MIXING(trans, dev, AC_ID , MOTOR_MIXING_NB_MOTOR, motors);
112 for (i = 0; i < MOTOR_MIXING_NB_MOTOR; i++) {
123 #if PERIODIC_TELEMETRY
131 for (j = 0; j < MOTOR_MIXING_NB_MOTOR; j++) {
139 for (j = 0; j < MOTOR_MIXING_NB_MOTOR; j++) {
146 #ifdef MOTOR_MIXING_USE_MAX_MOTOR_STEP_BINDING
148 static int32_t prev_commands[MOTOR_MIXING_NB_MOTOR];
149 static uint8_t initialized = 0;
151 if (initialized == 1) {
152 for (j = 0; j < MOTOR_MIXING_NB_MOTOR; j++) {
154 Bound(new_command_diff,
155 MOTOR_MIXING_MAX_NEGATIVE_MOTOR_STEP, MOTOR_MIXING_MAX_POSITIVE_MOTOR_STEP);
162 for (j = 0; j < MOTOR_MIXING_NB_MOTOR; j++) {
171 for (i = 0; i < MOTOR_MIXING_NB_MOTOR; i++) {
172 #ifdef MOTOR_MIXING_STARTUP_DELAY
173 if (counter > i * max_counter / (MOTOR_MIXING_NB_MOTOR + MOTOR_MIXING_STARTUP_DELAY)) {
174 if (counter > MOTOR_MIXING_NB_MOTOR * max_counter /
175 (MOTOR_MIXING_NB_MOTOR + MOTOR_MIXING_STARTUP_DELAY))
186 if (counter < i * max_counter / MOTOR_MIXING_NB_MOTOR) {
209 for (i = 0; i < MOTOR_MIXING_NB_MOTOR; i++) {
217 tmp_cmd /= MOTOR_MIXING_SCALE;
220 if (-tmp_cmd > max_overflow) {
221 max_overflow = -tmp_cmd;
223 else if (tmp_cmd -
MAX_PPRZ > max_overflow) {
229 int32_t yaw_authority = ABS(in_cmd[COMMAND_YAW]) - max_overflow;
231 int32_t bounded_yaw_cmd = in_cmd[COMMAND_YAW];
232 BoundAbs(bounded_yaw_cmd, yaw_authority);
239 for (i = 0; i < MOTOR_MIXING_NB_MOTOR; i++) {
260 if (max_cmd > MOTOR_MIXING_MAX_MOTOR) {
261 int32_t saturation_offset = MOTOR_MIXING_MAX_MOTOR - max_cmd;
273 if (motors_on && override_on) {
274 for (i = 0; i < MOTOR_MIXING_NB_MOTOR; i++) {
283 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)
bool override_enabled[MOTOR_MIXING_NB_MOTOR]
void motor_mixing_run(bool motors_on, bool override_on, pprz_t in_cmd[])
Periodic telemetry system header (includes downlink utility and generated code).
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
static const float offset[]
void motor_mixing_init(void)
#define DefaultPeriodic
Set default periodic telemetry.
static const int32_t yaw_coef[MOTOR_MIXING_NB_MOTOR]
#define MOTOR_MIXING_TRIM_YAW
static const struct usb_device_descriptor dev
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
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
static void send_motor_mixing(struct transport_tx *trans, struct link_device *dev)