Position hold depends on GPS (#14101)
[betaflight.git] / src / main / flight / mixer.h
blob7371f9bdee3501865f8cf29be8ea3e04c0865766
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #pragma once
23 #include <stdbool.h>
24 #include <stdint.h>
26 #include "platform.h"
28 #include "common/time.h"
30 #include "pg/pg.h"
32 #include "drivers/io_types.h"
33 #include "drivers/pwm_output.h"
35 #define QUAD_MOTOR_COUNT 4
37 // Note: this is called MultiType/MULTITYPE_* in baseflight.
38 typedef enum mixerMode
40 MIXER_TRI = 1,
41 MIXER_QUADP = 2,
42 MIXER_QUADX = 3,
43 MIXER_BICOPTER = 4,
44 MIXER_GIMBAL = 5,
45 MIXER_Y6 = 6,
46 MIXER_HEX6 = 7,
47 MIXER_FLYING_WING = 8,
48 MIXER_Y4 = 9,
49 MIXER_HEX6X = 10,
50 MIXER_OCTOX8 = 11,
51 MIXER_OCTOFLATP = 12,
52 MIXER_OCTOFLATX = 13,
53 MIXER_AIRPLANE = 14, // airplane / singlecopter / dualcopter (not yet properly supported)
54 MIXER_HELI_120_CCPM = 15,
55 MIXER_HELI_90_DEG = 16,
56 MIXER_VTAIL4 = 17,
57 MIXER_HEX6H = 18,
58 MIXER_PPM_TO_SERVO = 19, // PPM -> servo relay
59 MIXER_DUALCOPTER = 20,
60 MIXER_SINGLECOPTER = 21,
61 MIXER_ATAIL4 = 22,
62 MIXER_CUSTOM = 23,
63 MIXER_CUSTOM_AIRPLANE = 24,
64 MIXER_CUSTOM_TRI = 25,
65 MIXER_QUADX_1234 = 26,
66 MIXER_OCTOX8P = 27
67 } mixerMode_e;
69 typedef enum mixerType
71 MIXER_LEGACY = 0,
72 MIXER_LINEAR = 1,
73 MIXER_DYNAMIC = 2,
74 MIXER_EZLANDING = 3,
75 } mixerType_e;
77 // Custom mixer data per motor
78 typedef struct motorMixer_s {
79 float throttle;
80 float roll;
81 float pitch;
82 float yaw;
83 } motorMixer_t;
85 PG_DECLARE_ARRAY(motorMixer_t, MAX_SUPPORTED_MOTORS, customMotorMixer);
87 // Custom mixer configuration
88 typedef struct mixer_s {
89 uint8_t motorCount;
90 uint8_t useServo;
91 const motorMixer_t *motor;
92 } mixer_t;
94 typedef struct mixerConfig_s {
95 uint8_t mixerMode;
96 bool yaw_motors_reversed;
97 uint8_t crashflip_motor_percent;
98 uint8_t crashflip_rate;
99 uint8_t mixer_type;
100 #ifdef USE_RPM_LIMIT
101 bool rpm_limit;
102 uint16_t rpm_limit_p;
103 uint16_t rpm_limit_i;
104 uint16_t rpm_limit_d;
105 uint16_t rpm_limit_value;
106 #endif
107 } mixerConfig_t;
109 PG_DECLARE(mixerConfig_t, mixerConfig);
111 #define CHANNEL_FORWARDING_DISABLED (uint8_t)0xFF
113 #ifdef USE_RPM_LIMIT
114 #define RPM_LIMIT_ACTIVE mixerConfig()->rpm_limit
115 #else
116 #define RPM_LIMIT_ACTIVE false
117 #endif
119 extern const mixer_t mixers[];
120 extern float motor[MAX_SUPPORTED_MOTORS];
121 extern float motor_disarmed[MAX_SUPPORTED_MOTORS];
122 struct rxConfig_s;
124 bool hasServos(void);
125 uint8_t getMotorCount(void);
126 float getMotorMixRange(void);
127 bool areMotorsRunning(void);
128 bool areMotorsSaturated(void);
130 void mixerLoadMix(int index, motorMixer_t *customMixers);
131 void initEscEndpoints(void);
132 void mixerInit(mixerMode_e mixerMode);
133 void mixerInitProfile(void);
134 void mixerResetRpmLimiter(void);
135 void mixerResetDisarmedMotors(void);
136 void mixTable(timeUs_t currentTimeUs);
137 void stopMotors(void);
138 void writeMotors(void);
140 bool mixerIsTricopter(void);
142 void mixerSetThrottleAngleCorrection(int correctionValue);
143 float mixerGetThrottle(void);
144 float mixerGetRcThrottle(void);
145 mixerMode_e getMixerMode(void);
146 bool mixerModeIsFixedWing(mixerMode_e mixerMode);
147 bool isFixedWing(void);
149 float getMotorOutputLow(void);
150 float getMotorOutputHigh(void);
152 bool crashFlipSuccessful(void);
154 #ifdef USE_WING
155 float getMotorOutputRms(void);
156 #endif