Blackbox device type 'file' (SITL) considered working when file handler is available
[inav.git] / src / main / flight / servos.h
blob4f6e5777967a374e991bf550900f494fc6d84809
1 /*
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/>.
18 #pragma once
20 #include "config/parameter_group.h"
21 #include "programming/logic_condition.h"
23 #define MAX_SUPPORTED_SERVOS 18
25 // These must be consecutive
26 typedef enum {
27 INPUT_STABILIZED_ROLL = 0,
28 INPUT_STABILIZED_PITCH = 1,
29 INPUT_STABILIZED_YAW = 2,
30 INPUT_STABILIZED_THROTTLE = 3,
31 INPUT_RC_ROLL = 4,
32 INPUT_RC_PITCH = 5,
33 INPUT_RC_YAW = 6,
34 INPUT_RC_THROTTLE = 7,
35 INPUT_RC_CH5 = 8,
36 INPUT_RC_CH6 = 9,
37 INPUT_RC_CH7 = 10,
38 INPUT_RC_CH8 = 11,
39 INPUT_GIMBAL_PITCH = 12,
40 INPUT_GIMBAL_ROLL = 13,
41 INPUT_FEATURE_FLAPS = 14,
42 INPUT_RC_CH9 = 15,
43 INPUT_RC_CH10 = 16,
44 INPUT_RC_CH11 = 17,
45 INPUT_RC_CH12 = 18,
46 INPUT_RC_CH13 = 19,
47 INPUT_RC_CH14 = 20,
48 INPUT_RC_CH15 = 21,
49 INPUT_RC_CH16 = 22,
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,
56 INPUT_MAX = 29,
57 INPUT_GVAR_0 = 30,
58 INPUT_GVAR_1 = 31,
59 INPUT_GVAR_2 = 32,
60 INPUT_GVAR_3 = 33,
61 INPUT_GVAR_4 = 34,
62 INPUT_GVAR_5 = 35,
63 INPUT_GVAR_6 = 36,
64 INPUT_GVAR_7 = 37,
65 INPUT_MIXER_TRANSITION = 38,
66 INPUT_HEADTRACKER_PAN = 39,
67 INPUT_HEADTRACKER_TILT = 40,
68 INPUT_HEADTRACKER_ROLL = 41,
69 INPUT_RC_CH17 = 42,
70 INPUT_RC_CH18 = 43,
71 #ifdef USE_24CHANNELS
72 INPUT_RC_CH19 = 44,
73 INPUT_RC_CH20 = 45,
74 INPUT_RC_CH21 = 46,
75 INPUT_RC_CH22 = 47,
76 INPUT_RC_CH23 = 48,
77 INPUT_RC_CH24 = 49,
78 #endif
79 INPUT_SOURCE_COUNT
80 } inputSource_e;
82 // target servo channels
83 typedef enum {
84 SERVO_GIMBAL_PITCH = 0,
85 SERVO_GIMBAL_ROLL = 1,
86 SERVO_ELEVATOR = 2,
87 SERVO_FLAPPERON_1 = 3,
88 SERVO_FLAPPERON_2 = 4,
89 SERVO_RUDDER = 5,
91 SERVO_BICOPTER_LEFT = 4,
92 SERVO_BICOPTER_RIGHT = 5,
94 SERVO_DUALCOPTER_LEFT = 4,
95 SERVO_DUALCOPTER_RIGHT = 5,
97 SERVO_SINGLECOPTER_1 = 3,
98 SERVO_SINGLECOPTER_2 = 4,
99 SERVO_SINGLECOPTER_3 = 5,
100 SERVO_SINGLECOPTER_4 = 6,
102 } servoIndex_e; // FIXME rename to servoChannel_e
104 #define SERVO_PLANE_INDEX_MIN SERVO_ELEVATOR
105 #define SERVO_PLANE_INDEX_MAX SERVO_RUDDER
107 #define SERVO_DUALCOPTER_INDEX_MIN SERVO_DUALCOPTER_LEFT
108 #define SERVO_DUALCOPTER_INDEX_MAX SERVO_DUALCOPTER_RIGHT
110 #define SERVO_SINGLECOPTER_INDEX_MIN SERVO_SINGLECOPTER_1
111 #define SERVO_SINGLECOPTER_INDEX_MAX SERVO_SINGLECOPTER_4
113 #define SERVO_FLAPPERONS_MIN SERVO_FLAPPERON_1
114 #define SERVO_FLAPPERONS_MAX SERVO_FLAPPERON_2
116 #define FLAPERON_THROW_DEFAULT 200
117 #define FLAPERON_THROW_MIN 50
118 #define FLAPERON_THROW_MAX 450
120 typedef struct servoMixer_s {
121 uint8_t targetChannel; // servo that receives the output of the rule
122 uint8_t inputSource; // input channel for this rule
123 int16_t rate; // range [-1000;+1000] ; can be used to adjust a rate 0-1000% and a direction
124 uint8_t speed; // reduces the speed of the rule, 0=unlimited speed
125 #ifdef USE_PROGRAMMING_FRAMEWORK
126 int8_t conditionId;
127 #endif
128 } servoMixer_t;
130 #define MAX_SERVO_RULES (2 * MAX_SUPPORTED_SERVOS)
131 #define MAX_SERVO_SPEED UINT8_MAX
132 #define SERVO_OUTPUT_MAX 2500
133 #define SERVO_OUTPUT_MIN 500
135 PG_DECLARE_ARRAY(servoMixer_t, MAX_SERVO_RULES, customServoMixers);
137 typedef struct servoParam_s {
138 int16_t min; // servo min
139 int16_t max; // servo max
140 int16_t middle; // servo middle
141 int8_t rate; // range [-125;+125] ; can be used to adjust a rate 0-125% and a direction
142 } servoParam_t;
144 PG_DECLARE_ARRAY(servoParam_t, MAX_SUPPORTED_SERVOS, servoParams);
146 typedef struct servoConfig_s {
147 // PWM values, in milliseconds, common range is 1000-2000 (1ms to 2ms)
148 uint16_t servoCenterPulse; // This is the value for servos when they should be in the middle. e.g. 1500.
149 uint16_t servoPwmRate; // The update rate of servo outputs (50-498Hz)
150 int16_t servo_lowpass_freq; // lowpass servo filter frequency selection; 1/1000ths of loop freq
151 uint16_t flaperon_throw_offset;
152 uint8_t servo_protocol; // See servoProtocolType_e
153 uint8_t tri_unarmed_servo; // send tail servo correction pulses even when unarmed
154 uint8_t servo_autotrim_rotation_limit; // Max rotation for servo midpoints to be updated
155 uint8_t servo_autotrim_iterm_threshold; // How much of the Iterm is carried over to the servo midpoints on each update
156 } servoConfig_t;
158 PG_DECLARE(servoConfig_t, servoConfig);
160 typedef struct servoMetadata_s {
161 float scaleMax;
162 float scaleMin;
163 } servoMetadata_t;
165 extern int16_t servo[MAX_SUPPORTED_SERVOS];
167 void Reset_servoMixers(servoMixer_t* instance);
168 bool isServoOutputEnabled(void);
169 void setServoOutputEnabled(bool flag);
170 bool isMixerUsingServos(void);
171 void writeServos(void);
172 void loadCustomServoMixer(void);
173 void servoMixer(float dT);
174 void servoComputeScalingFactors(uint8_t servoIndex);
175 void servosInit(void);
176 int getServoCount(void);