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 16
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,
69 // target servo channels
71 SERVO_GIMBAL_PITCH
= 0,
72 SERVO_GIMBAL_ROLL
= 1,
74 SERVO_FLAPPERON_1
= 3,
75 SERVO_FLAPPERON_2
= 4,
78 SERVO_BICOPTER_LEFT
= 4,
79 SERVO_BICOPTER_RIGHT
= 5,
81 SERVO_DUALCOPTER_LEFT
= 4,
82 SERVO_DUALCOPTER_RIGHT
= 5,
84 SERVO_SINGLECOPTER_1
= 3,
85 SERVO_SINGLECOPTER_2
= 4,
86 SERVO_SINGLECOPTER_3
= 5,
87 SERVO_SINGLECOPTER_4
= 6,
89 } servoIndex_e
; // FIXME rename to servoChannel_e
91 #define SERVO_PLANE_INDEX_MIN SERVO_ELEVATOR
92 #define SERVO_PLANE_INDEX_MAX SERVO_RUDDER
94 #define SERVO_DUALCOPTER_INDEX_MIN SERVO_DUALCOPTER_LEFT
95 #define SERVO_DUALCOPTER_INDEX_MAX SERVO_DUALCOPTER_RIGHT
97 #define SERVO_SINGLECOPTER_INDEX_MIN SERVO_SINGLECOPTER_1
98 #define SERVO_SINGLECOPTER_INDEX_MAX SERVO_SINGLECOPTER_4
100 #define SERVO_FLAPPERONS_MIN SERVO_FLAPPERON_1
101 #define SERVO_FLAPPERONS_MAX SERVO_FLAPPERON_2
103 #define FLAPERON_THROW_DEFAULT 200
104 #define FLAPERON_THROW_MIN 50
105 #define FLAPERON_THROW_MAX 450
107 typedef struct servoMixer_s
{
108 uint8_t targetChannel
; // servo that receives the output of the rule
109 uint8_t inputSource
; // input channel for this rule
110 int16_t rate
; // range [-1000;+1000] ; can be used to adjust a rate 0-1000% and a direction
111 uint8_t speed
; // reduces the speed of the rule, 0=unlimited speed
112 #ifdef USE_PROGRAMMING_FRAMEWORK
117 #define MAX_SERVO_RULES (2 * MAX_SUPPORTED_SERVOS)
118 #define MAX_SERVO_SPEED UINT8_MAX
119 #define SERVO_OUTPUT_MAX 2500
120 #define SERVO_OUTPUT_MIN 500
122 PG_DECLARE_ARRAY(servoMixer_t
, MAX_SERVO_RULES
, customServoMixers
);
124 typedef struct servoParam_s
{
125 int16_t min
; // servo min
126 int16_t max
; // servo max
127 int16_t middle
; // servo middle
128 int8_t rate
; // range [-125;+125] ; can be used to adjust a rate 0-125% and a direction
131 PG_DECLARE_ARRAY(servoParam_t
, MAX_SUPPORTED_SERVOS
, servoParams
);
133 typedef struct servoConfig_s
{
134 // PWM values, in milliseconds, common range is 1000-2000 (1ms to 2ms)
135 uint16_t servoCenterPulse
; // This is the value for servos when they should be in the middle. e.g. 1500.
136 uint16_t servoPwmRate
; // The update rate of servo outputs (50-498Hz)
137 int16_t servo_lowpass_freq
; // lowpass servo filter frequency selection; 1/1000ths of loop freq
138 uint16_t flaperon_throw_offset
;
139 uint8_t servo_protocol
; // See servoProtocolType_e
140 uint8_t tri_unarmed_servo
; // send tail servo correction pulses even when unarmed
141 uint8_t servo_autotrim_rotation_limit
; // Max rotation for servo midpoints to be updated
142 uint8_t servo_autotrim_iterm_threshold
; // How much of the Iterm is carried over to the servo midpoints on each update
145 PG_DECLARE(servoConfig_t
, servoConfig
);
147 typedef struct servoMetadata_s
{
152 extern int16_t servo
[MAX_SUPPORTED_SERVOS
];
154 void Reset_servoMixers(servoMixer_t
* instance
);
155 bool isServoOutputEnabled(void);
156 void setServoOutputEnabled(bool flag
);
157 bool isMixerUsingServos(void);
158 void writeServos(void);
159 void loadCustomServoMixer(void);
160 void servoMixer(float dT
);
161 void servoComputeScalingFactors(uint8_t servoIndex
);
162 void servosInit(void);
163 int getServoCount(void);