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 #include "config/parameter_group.h"
21 #include "programming/logic_condition.h"
23 #define MAX_SUPPORTED_SERVOS 18
25 // These must be consecutive
27 INPUT_STABILIZED_ROLL
= 0,
28 INPUT_STABILIZED_PITCH
= 1,
29 INPUT_STABILIZED_YAW
= 2,
30 INPUT_STABILIZED_THROTTLE
= 3,
34 INPUT_RC_THROTTLE
= 7,
39 INPUT_GIMBAL_PITCH
= 12,
40 INPUT_GIMBAL_ROLL
= 13,
41 INPUT_FEATURE_FLAPS
= 14,
50 INPUT_STABILIZED_ROLL_PLUS
= 23,
51 INPUT_STABILIZED_ROLL_MINUS
= 24,
52 INPUT_STABILIZED_PITCH_PLUS
= 25,
53 INPUT_STABILIZED_PITCH_MINUS
= 26,
54 INPUT_STABILIZED_YAW_PLUS
= 27,
55 INPUT_STABILIZED_YAW_MINUS
= 28,
65 INPUT_MIXER_TRANSITION
= 38,
66 INPUT_HEADTRACKER_PAN
= 39,
67 INPUT_HEADTRACKER_TILT
= 40,
68 INPUT_HEADTRACKER_ROLL
= 41,
90 // target servo channels
92 SERVO_GIMBAL_PITCH
= 0,
93 SERVO_GIMBAL_ROLL
= 1,
95 SERVO_FLAPPERON_1
= 3,
96 SERVO_FLAPPERON_2
= 4,
99 SERVO_BICOPTER_LEFT
= 4,
100 SERVO_BICOPTER_RIGHT
= 5,
102 SERVO_DUALCOPTER_LEFT
= 4,
103 SERVO_DUALCOPTER_RIGHT
= 5,
105 SERVO_SINGLECOPTER_1
= 3,
106 SERVO_SINGLECOPTER_2
= 4,
107 SERVO_SINGLECOPTER_3
= 5,
108 SERVO_SINGLECOPTER_4
= 6,
110 } servoIndex_e
; // FIXME rename to servoChannel_e
112 #define SERVO_PLANE_INDEX_MIN SERVO_ELEVATOR
113 #define SERVO_PLANE_INDEX_MAX SERVO_RUDDER
115 #define SERVO_DUALCOPTER_INDEX_MIN SERVO_DUALCOPTER_LEFT
116 #define SERVO_DUALCOPTER_INDEX_MAX SERVO_DUALCOPTER_RIGHT
118 #define SERVO_SINGLECOPTER_INDEX_MIN SERVO_SINGLECOPTER_1
119 #define SERVO_SINGLECOPTER_INDEX_MAX SERVO_SINGLECOPTER_4
121 #define SERVO_FLAPPERONS_MIN SERVO_FLAPPERON_1
122 #define SERVO_FLAPPERONS_MAX SERVO_FLAPPERON_2
124 #define FLAPERON_THROW_DEFAULT 200
125 #define FLAPERON_THROW_MIN 50
126 #define FLAPERON_THROW_MAX 450
128 typedef struct servoMixer_s
{
129 uint8_t targetChannel
; // servo that receives the output of the rule
130 uint8_t inputSource
; // input channel for this rule
131 int16_t rate
; // range [-1000;+1000] ; can be used to adjust a rate 0-1000% and a direction
132 uint8_t speed
; // reduces the speed of the rule, 0=unlimited speed
133 #ifdef USE_PROGRAMMING_FRAMEWORK
138 #define MAX_SERVO_RULES (2 * MAX_SUPPORTED_SERVOS)
139 #define MAX_SERVO_SPEED UINT8_MAX
140 #define SERVO_OUTPUT_MAX 2500
141 #define SERVO_OUTPUT_MIN 500
143 PG_DECLARE_ARRAY(servoMixer_t
, MAX_SERVO_RULES
, customServoMixers
);
145 typedef struct servoParam_s
{
146 int16_t min
; // servo min
147 int16_t max
; // servo max
148 int16_t middle
; // servo middle
149 int8_t rate
; // range [-125;+125] ; can be used to adjust a rate 0-125% and a direction
152 PG_DECLARE_ARRAY(servoParam_t
, MAX_SUPPORTED_SERVOS
, servoParams
);
154 typedef struct servoConfig_s
{
155 // PWM values, in milliseconds, common range is 1000-2000 (1ms to 2ms)
156 uint16_t servoCenterPulse
; // This is the value for servos when they should be in the middle. e.g. 1500.
157 uint16_t servoPwmRate
; // The update rate of servo outputs (50-498Hz)
158 int16_t servo_lowpass_freq
; // lowpass servo filter frequency selection; 1/1000ths of loop freq
159 uint16_t flaperon_throw_offset
;
160 uint8_t servo_protocol
; // See servoProtocolType_e
161 uint8_t tri_unarmed_servo
; // send tail servo correction pulses even when unarmed
162 uint8_t servo_autotrim_rotation_limit
; // Max rotation for servo midpoints to be updated
163 uint8_t servo_autotrim_iterm_threshold
; // How much of the Iterm is carried over to the servo midpoints on each update
166 PG_DECLARE(servoConfig_t
, servoConfig
);
168 typedef struct servoMetadata_s
{
173 extern int16_t servo
[MAX_SUPPORTED_SERVOS
];
175 void Reset_servoMixers(servoMixer_t
* instance
);
176 bool isServoOutputEnabled(void);
177 void setServoOutputEnabled(bool flag
);
178 bool isMixerUsingServos(void);
179 void writeServos(void);
180 void loadCustomServoMixer(void);
181 void servoMixer(float dT
);
182 void servoComputeScalingFactors(uint8_t servoIndex
);
183 void servosInit(void);
184 int getServoCount(void);