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_SERVOS 8
22 // These must be consecutive, see 'reversedSources'
24 INPUT_STABILIZED_ROLL
= 0,
25 INPUT_STABILIZED_PITCH
,
27 INPUT_STABILIZED_THROTTLE
,
41 // target servo channels
43 SERVO_GIMBAL_PITCH
= 0,
44 SERVO_GIMBAL_ROLL
= 1,
46 SERVO_FLAPPERON_1
= 3,
47 SERVO_FLAPPERON_2
= 4,
50 SERVO_THROTTLE
= 7, // for internal combustion (IC) planes
52 SERVO_BICOPTER_LEFT
= 4,
53 SERVO_BICOPTER_RIGHT
= 5,
55 SERVO_DUALCOPTER_LEFT
= 4,
56 SERVO_DUALCOPTER_RIGHT
= 5,
58 SERVO_SINGLECOPTER_1
= 3,
59 SERVO_SINGLECOPTER_2
= 4,
60 SERVO_SINGLECOPTER_3
= 5,
61 SERVO_SINGLECOPTER_4
= 6
62 } servoIndex_e
; // FIXME rename to servoChannel_e
64 #define SERVO_PLANE_INDEX_MIN SERVO_FLAPS
65 #define SERVO_PLANE_INDEX_MAX SERVO_THROTTLE
67 #define SERVO_DUALCOPTER_INDEX_MIN SERVO_DUALCOPTER_LEFT
68 #define SERVO_DUALCOPTER_INDEX_MAX SERVO_DUALCOPTER_RIGHT
70 #define SERVO_SINGLECOPTER_INDEX_MIN SERVO_SINGLECOPTER_1
71 #define SERVO_SINGLECOPTER_INDEX_MAX SERVO_SINGLECOPTER_4
73 #define SERVO_FLAPPERONS_MIN SERVO_FLAPPERON_1
74 #define SERVO_FLAPPERONS_MAX SERVO_FLAPPERON_2
76 typedef struct servoMixer_s
{
77 uint8_t targetChannel
; // servo that receives the output of the rule
78 uint8_t inputSource
; // input channel for this rule
79 int8_t rate
; // range [-125;+125] ; can be used to adjust a rate 0-125% and a direction
80 uint8_t speed
; // reduces the speed of the rule, 0=unlimited speed
81 int8_t min
; // lower bound of rule range [0;100]% of servo max-min
82 int8_t max
; // lower bound of rule range [0;100]% of servo max-min
83 uint8_t box
; // active rule if box is enabled, range [0;3], 0=no box, 1=BOXSERVO1, 2=BOXSERVO2, 3=BOXSERVO3
86 #define MAX_SERVO_RULES (2 * MAX_SUPPORTED_SERVOS)
87 #define MAX_SERVO_SPEED UINT8_MAX
88 #define MAX_SERVO_BOXES 3
90 // Custom mixer configuration
91 typedef struct mixerRules_s
{
92 uint8_t servoRuleCount
;
93 const servoMixer_t
*rule
;
96 typedef struct servoParam_s
{
97 int16_t min
; // servo min
98 int16_t max
; // servo max
99 int16_t middle
; // servo middle
100 int8_t rate
; // range [-125;+125] ; can be used to adjust a rate 0-125% and a direction
101 uint8_t angleAtMin
; // range [0;180] the measured angle in degrees from the middle when the servo is at the 'min' value.
102 uint8_t angleAtMax
; // range [0;180] the measured angle in degrees from the middle when the servo is at the 'max' value.
103 int8_t forwardFromChannel
; // RX channel index, 0 based. See CHANNEL_FORWARDING_DISABLED
104 uint32_t reversedSources
; // the direction of servo movement for each input source of the servo mixer, bit set=inverted
105 } __attribute__ ((__packed__
)) servoParam_t
;
107 typedef struct servoMixerConfig_s
{
108 uint8_t tri_unarmed_servo
; // send tail servo correction pulses even when unarmed
109 uint16_t servo_lowpass_freq
; // lowpass servo filter frequency selection; 1/1000ths of loop freq
110 int8_t servo_lowpass_enable
; // enable/disable lowpass filter
111 } servoMixerConfig_t
;
113 typedef struct servoProfile_s
{
114 servoParam_t servoConf
[MAX_SUPPORTED_SERVOS
];
117 extern int16_t servo
[MAX_SUPPORTED_SERVOS
];
119 void servoTable(void);
120 bool isMixerUsingServos(void);
121 void writeServos(void);
122 void filterServos(void);
124 void servoMixerInit(servoMixer_t
*customServoMixers
);
125 struct gimbalConfig_s
;
126 void servoUseConfigs(servoMixerConfig_t
*servoConfigToUse
, servoParam_t
*servoParamsToUse
, struct gimbalConfig_s
*gimbalConfigToUse
);
127 void servoMixerLoadMix(int index
, servoMixer_t
*customServoMixers
);
128 void loadCustomServoMixer(void);
129 void servoConfigureOutput(void);
130 int servoDirection(int servoIndex
, int fromChannel
);