2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
20 #define MAX_SUPPORTED_MOTORS 12
21 #define MAX_SUPPORTED_SERVOS 8
22 #define YAW_JUMP_PREVENTION_LIMIT_LOW 80
23 #define YAW_JUMP_PREVENTION_LIMIT_HIGH 500
26 // Note: this is called MultiType/MULTITYPE_* in baseflight.
27 typedef enum mixerMode
36 MIXER_FLYING_WING
= 8,
42 MIXER_AIRPLANE
= 14, // airplane / singlecopter / dualcopter (not yet properly supported)
43 MIXER_HELI_120_CCPM
= 15,
44 MIXER_HELI_90_DEG
= 16,
47 MIXER_PPM_TO_SERVO
= 19, // PPM -> servo relay
48 MIXER_DUALCOPTER
= 20,
49 MIXER_SINGLECOPTER
= 21,
52 MIXER_CUSTOM_AIRPLANE
= 24,
53 MIXER_CUSTOM_TRI
= 25,
57 // Custom mixer data per motor
58 typedef struct motorMixer_s
{
65 // Custom mixer configuration
66 typedef struct mixer_s
{
69 const motorMixer_t
*motor
;
72 typedef struct mixerConfig_s
{
73 int8_t yaw_motor_direction
;
74 uint16_t yaw_jump_prevention_limit
; // make limit configurable (original fixed value was 100)
76 uint8_t tri_unarmed_servo
; // send tail servo correction pulses even when unarmed
77 uint16_t servo_lowpass_freq
; // lowpass servo filter frequency selection; 1/1000ths of loop freq
78 int8_t servo_lowpass_enable
; // enable/disable lowpass filter
82 typedef struct flight3DConfig_s
{
83 uint16_t deadband3d_low
; // min 3d value
84 uint16_t deadband3d_high
; // max 3d value
85 uint16_t neutral3d
; // center 3d value
86 uint16_t deadband3d_throttle
; // default throttle deadband from MIDRC
89 typedef struct airplaneConfig_s
{
90 int8_t fixedwing_althold_dir
; // +1 or -1 for pitch/althold gain. later check if need more than just sign
93 #define CHANNEL_FORWARDING_DISABLED (uint8_t)0xFF
97 // These must be consecutive, see 'reversedSources'
99 INPUT_STABILIZED_ROLL
= 0,
100 INPUT_STABILIZED_PITCH
,
101 INPUT_STABILIZED_YAW
,
102 INPUT_STABILIZED_THROTTLE
,
117 // target servo channels
119 SERVO_GIMBAL_PITCH
= 0,
120 SERVO_GIMBAL_ROLL
= 1,
122 SERVO_FLAPPERON_1
= 3,
123 SERVO_FLAPPERON_2
= 4,
126 SERVO_THROTTLE
= 7, // for internal combustion (IC) planes
128 SERVO_BICOPTER_LEFT
= 4,
129 SERVO_BICOPTER_RIGHT
= 5,
131 SERVO_DUALCOPTER_LEFT
= 4,
132 SERVO_DUALCOPTER_RIGHT
= 5,
134 SERVO_SINGLECOPTER_1
= 3,
135 SERVO_SINGLECOPTER_2
= 4,
136 SERVO_SINGLECOPTER_3
= 5,
137 SERVO_SINGLECOPTER_4
= 6,
139 } servoIndex_e
; // FIXME rename to servoChannel_e
141 #define SERVO_PLANE_INDEX_MIN SERVO_FLAPS
142 #define SERVO_PLANE_INDEX_MAX SERVO_THROTTLE
144 #define SERVO_DUALCOPTER_INDEX_MIN SERVO_DUALCOPTER_LEFT
145 #define SERVO_DUALCOPTER_INDEX_MAX SERVO_DUALCOPTER_RIGHT
147 #define SERVO_SINGLECOPTER_INDEX_MIN SERVO_SINGLECOPTER_1
148 #define SERVO_SINGLECOPTER_INDEX_MAX SERVO_SINGLECOPTER_4
150 #define SERVO_FLAPPERONS_MIN SERVO_FLAPPERON_1
151 #define SERVO_FLAPPERONS_MAX SERVO_FLAPPERON_2
153 typedef struct servoMixer_s
{
154 uint8_t targetChannel
; // servo that receives the output of the rule
155 uint8_t inputSource
; // input channel for this rule
156 int8_t rate
; // range [-125;+125] ; can be used to adjust a rate 0-125% and a direction
157 uint8_t speed
; // reduces the speed of the rule, 0=unlimited speed
158 int8_t min
; // lower bound of rule range [0;100]% of servo max-min
159 int8_t max
; // lower bound of rule range [0;100]% of servo max-min
160 uint8_t box
; // active rule if box is enabled, range [0;3], 0=no box, 1=BOXSERVO1, 2=BOXSERVO2, 3=BOXSERVO3
163 #define MAX_SERVO_RULES (2 * MAX_SUPPORTED_SERVOS)
164 #define MAX_SERVO_SPEED UINT8_MAX
165 #define MAX_SERVO_BOXES 3
167 // Custom mixer configuration
168 typedef struct mixerRules_s
{
169 uint8_t servoRuleCount
;
170 const servoMixer_t
*rule
;
173 typedef struct servoParam_s
{
174 int16_t min
; // servo min
175 int16_t max
; // servo max
176 int16_t middle
; // servo middle
177 int8_t rate
; // range [-125;+125] ; can be used to adjust a rate 0-125% and a direction
178 uint8_t angleAtMin
; // range [0;180] the measured angle in degrees from the middle when the servo is at the 'min' value.
179 uint8_t angleAtMax
; // range [0;180] the measured angle in degrees from the middle when the servo is at the 'max' value.
180 int8_t forwardFromChannel
; // RX channel index, 0 based. See CHANNEL_FORWARDING_DISABLED
181 uint32_t reversedSources
; // the direction of servo movement for each input source of the servo mixer, bit set=inverted
182 } __attribute__ ((__packed__
)) servoParam_t
;
184 struct gimbalConfig_s
;
185 struct escAndServoConfig_s
;
188 extern int16_t servo
[MAX_SUPPORTED_SERVOS
];
189 bool isMixerUsingServos(void);
190 void writeServos(void);
191 void filterServos(void);
192 bool motorLimitReached
;
195 extern int16_t motor
[MAX_SUPPORTED_MOTORS
];
196 extern int16_t motor_disarmed
[MAX_SUPPORTED_MOTORS
];
198 struct escAndServoConfig_s
;
201 void mixerUseConfigs(
203 servoParam_t
*servoConfToUse
,
204 struct gimbalConfig_s
*gimbalConfigToUse
,
206 flight3DConfig_t
*flight3DConfigToUse
,
207 struct escAndServoConfig_s
*escAndServoConfigToUse
,
208 mixerConfig_t
*mixerConfigToUse
,
209 airplaneConfig_t
*airplaneConfigToUse
,
210 struct rxConfig_s
*rxConfigToUse
);
212 void writeAllMotors(int16_t mc
);
213 void mixerLoadMix(int index
, motorMixer_t
*customMixers
);
215 void servoMixerLoadMix(int index
, servoMixer_t
*customServoMixers
);
216 void loadCustomServoMixer(void);
217 int servoDirection(int servoIndex
, int fromChannel
);
219 void mixerResetDisarmedMotors(void);
221 void writeMotors(uint8_t unsyncedPwm
);
222 void stopMotors(void);
223 void StopPwmAllMotors(void);