2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
24 #include "drivers/io_types.h"
25 #include "drivers/pwm_output.h"
27 // These must be consecutive, see 'reversedSources'
29 INPUT_STABILIZED_ROLL
= 0,
30 INPUT_STABILIZED_PITCH
,
32 INPUT_STABILIZED_THROTTLE
,
46 // target servo channels
48 SERVO_GIMBAL_PITCH
= 0,
49 SERVO_GIMBAL_ROLL
= 1,
51 SERVO_FLAPPERON_1
= 3,
52 SERVO_FLAPPERON_2
= 4,
55 SERVO_THROTTLE
= 7, // for internal combustion (IC) planes
57 SERVO_BICOPTER_LEFT
= 4,
58 SERVO_BICOPTER_RIGHT
= 5,
60 SERVO_DUALCOPTER_LEFT
= 4,
61 SERVO_DUALCOPTER_RIGHT
= 5,
63 SERVO_SINGLECOPTER_1
= 3,
64 SERVO_SINGLECOPTER_2
= 4,
65 SERVO_SINGLECOPTER_3
= 5,
66 SERVO_SINGLECOPTER_4
= 6,
73 } servoIndex_e
; // FIXME rename to servoChannel_e
75 #define SERVO_PLANE_INDEX_MIN SERVO_FLAPS
76 #define SERVO_PLANE_INDEX_MAX SERVO_THROTTLE
78 #define SERVO_DUALCOPTER_INDEX_MIN SERVO_DUALCOPTER_LEFT
79 #define SERVO_DUALCOPTER_INDEX_MAX SERVO_DUALCOPTER_RIGHT
81 #define SERVO_SINGLECOPTER_INDEX_MIN SERVO_SINGLECOPTER_1
82 #define SERVO_SINGLECOPTER_INDEX_MAX SERVO_SINGLECOPTER_4
84 #define SERVO_FLAPPERONS_MIN SERVO_FLAPPERON_1
85 #define SERVO_FLAPPERONS_MAX SERVO_FLAPPERON_2
87 #define MAX_SERVO_RULES (2 * MAX_SUPPORTED_SERVOS)
89 typedef struct servoMixer_s
{
90 uint8_t targetChannel
; // servo that receives the output of the rule
91 uint8_t inputSource
; // input channel for this rule
92 int8_t rate
; // range [-125;+125] ; can be used to adjust a rate 0-125% and a direction
93 uint8_t speed
; // reduces the speed of the rule, 0=unlimited speed
94 int8_t min
; // lower bound of rule range [0;100]% of servo max-min
95 int8_t max
; // lower bound of rule range [0;100]% of servo max-min
96 uint8_t box
; // active rule if box is enabled, range [0;3], 0=no box, 1=BOXSERVO1, 2=BOXSERVO2, 3=BOXSERVO3
99 PG_DECLARE_ARRAY(servoMixer_t
, MAX_SERVO_RULES
, customServoMixers
);
101 #define MAX_SERVO_SPEED UINT8_MAX
102 #define MAX_SERVO_BOXES 3
104 // Custom mixer configuration
105 typedef struct mixerRules_s
{
106 uint8_t servoRuleCount
;
107 const servoMixer_t
*rule
;
110 extern const mixerRules_t servoMixers
[];
112 typedef struct servoParam_s
{
113 uint32_t reversedSources
; // the direction of servo movement for each input source of the servo mixer, bit set=inverted
114 int16_t min
; // servo min
115 int16_t max
; // servo max
116 int16_t middle
; // servo middle
117 int8_t rate
; // range [-125;+125] ; can be used to adjust a rate 0-125% and a direction
118 int8_t forwardFromChannel
; // RX channel index, 0 based. See CHANNEL_FORWARDING_DISABLED
121 PG_DECLARE_ARRAY(servoParam_t
, MAX_SUPPORTED_SERVOS
, servoParams
);
123 typedef struct servoConfig_s
{
124 servoDevConfig_t dev
;
125 uint16_t servo_lowpass_freq
; // lowpass servo filter frequency selection; 1/1000ths of loop freq
126 uint8_t tri_unarmed_servo
; // send tail servo correction pulses even when unarmed
127 uint8_t channelForwardingStartChannel
;
130 PG_DECLARE(servoConfig_t
, servoConfig
);
132 typedef struct servoProfile_s
{
133 servoParam_t servoConf
[MAX_SUPPORTED_SERVOS
];
136 extern int16_t servo
[MAX_SUPPORTED_SERVOS
];
138 bool isMixerUsingServos(void);
139 void writeServos(void);
140 void servoMixerLoadMix(int index
);
141 void loadCustomServoMixer(void);
142 int servoDirection(int servoIndex
, int fromChannel
);
143 void servosInit(void);
144 void servosFilterInit(void);
145 void servoMixer(void);
146 // tricopter specific
147 void servosTricopterInit(void);
148 void servosTricopterMixer(void);
149 bool servosTricopterIsEnabledServoUnarmed(void);