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/>.
55 extern uint32_t rcModeActivationMask
;
57 #define IS_RC_MODE_ACTIVE(modeId) ((1 << (modeId)) & rcModeActivationMask)
58 #define ACTIVATE_RC_MODE(modeId) (rcModeActivationMask |= (1 << modeId))
60 typedef enum rc_alias
{
80 #define AIRMODEDEADBAND 10
87 #define ROL_LO (1 << (2 * ROLL))
88 #define ROL_CE (3 << (2 * ROLL))
89 #define ROL_HI (2 << (2 * ROLL))
90 #define PIT_LO (1 << (2 * PITCH))
91 #define PIT_CE (3 << (2 * PITCH))
92 #define PIT_HI (2 << (2 * PITCH))
93 #define YAW_LO (1 << (2 * YAW))
94 #define YAW_CE (3 << (2 * YAW))
95 #define YAW_HI (2 << (2 * YAW))
96 #define THR_LO (1 << (2 * THROTTLE))
97 #define THR_CE (3 << (2 * THROTTLE))
98 #define THR_HI (2 << (2 * THROTTLE))
100 #define MAX_MODE_ACTIVATION_CONDITION_COUNT 20
102 #define CHANNEL_RANGE_MIN 900
103 #define CHANNEL_RANGE_MAX 2100
105 #define MODE_STEP_TO_CHANNEL_VALUE(step) (CHANNEL_RANGE_MIN + 25 * step)
106 #define CHANNEL_VALUE_TO_STEP(channelValue) ((constrain(channelValue, CHANNEL_RANGE_MIN, CHANNEL_RANGE_MAX) - CHANNEL_RANGE_MIN) / 25)
108 #define MIN_MODE_RANGE_STEP 0
109 #define MAX_MODE_RANGE_STEP ((CHANNEL_RANGE_MAX - CHANNEL_RANGE_MIN) / 25)
111 // Roll/pitch rates are a proportion used for mixing, so it tops out at 1.0:
112 #define CONTROL_RATE_CONFIG_ROLL_PITCH_RATE_MAX 100
114 /* Meaningful yaw rates are effectively unbounded because they are treated as a rotation rate multiplier: */
115 #define CONTROL_RATE_CONFIG_YAW_RATE_MAX 255
117 #define CONTROL_RATE_CONFIG_TPA_MAX 100
119 // steps are 25 apart
120 // a value of 0 corresponds to a channel value of 900 or less
121 // a value of 48 corresponds to a channel value of 2100 or more
122 // 48 steps between 900 and 1200
123 typedef struct channelRange_s
{
128 typedef struct modeActivationCondition_s
{
130 uint8_t auxChannelIndex
;
131 channelRange_t range
;
132 } modeActivationCondition_t
;
134 #define IS_RANGE_USABLE(range) ((range)->startStep < (range)->endStep)
136 typedef struct controlRateConfig_s
{
144 uint16_t tpa_breakpoint
; // Breakpoint where TPA is activated
145 } controlRateConfig_t
;
147 extern int16_t rcCommand
[4];
149 typedef struct rcControlsConfig_s
{
150 uint8_t deadband
; // introduce a deadband around the stick center for pitch and roll axis. Must be greater than zero.
151 uint8_t yaw_deadband
; // introduce a deadband around the stick center for yaw axis. Must be greater than zero.
152 uint8_t alt_hold_deadband
; // defines the neutral zone of throttle stick during altitude hold, default setting is +/-40
153 uint8_t alt_hold_fast_change
; // when disabled, turn off the althold when throttle stick is out of deadband defined with alt_hold_deadband; when enabled, altitude changes slowly proportional to stick movement
154 } rcControlsConfig_t
;
156 bool areUsingSticksToArm(void);
158 bool areSticksInApModePosition(uint16_t ap_mode
);
159 throttleStatus_e
calculateThrottleStatus(rxConfig_t
*rxConfig
, uint16_t deadband3d_throttle
);
160 void processRcStickPositions(rxConfig_t
*rxConfig
, throttleStatus_e throttleStatus
, bool retarded_arm
, bool disarm_kill_switch
);
162 void updateActivatedModes(modeActivationCondition_t
*modeActivationConditions
);
169 ADJUSTMENT_THROTTLE_EXPO
,
170 ADJUSTMENT_PITCH_ROLL_RATE
,
172 ADJUSTMENT_PITCH_ROLL_P
,
173 ADJUSTMENT_PITCH_ROLL_I
,
174 ADJUSTMENT_PITCH_ROLL_D
,
178 ADJUSTMENT_RATE_PROFILE
,
179 ADJUSTMENT_PITCH_RATE
,
180 ADJUSTMENT_ROLL_RATE
,
188 } adjustmentFunction_e
;
190 #define ADJUSTMENT_FUNCTION_COUNT 21
193 ADJUSTMENT_MODE_STEP
,
194 ADJUSTMENT_MODE_SELECT
197 typedef struct adjustmentStepConfig_s
{
199 } adjustmentStepConfig_t
;
201 typedef struct adjustmentSelectConfig_s
{
202 uint8_t switchPositions
;
203 } adjustmentSelectConfig_t
;
205 typedef union adjustmentConfig_u
{
206 adjustmentStepConfig_t stepConfig
;
207 adjustmentSelectConfig_t selectConfig
;
210 typedef struct adjustmentConfig_s
{
211 uint8_t adjustmentFunction
;
213 adjustmentData_t data
;
214 } adjustmentConfig_t
;
216 typedef struct adjustmentRange_s
{
217 // when aux channel is in range...
218 uint8_t auxChannelIndex
;
219 channelRange_t range
;
221 // ..then apply the adjustment function to the auxSwitchChannel ...
222 uint8_t adjustmentFunction
;
223 uint8_t auxSwitchChannelIndex
;
226 uint8_t adjustmentIndex
;
229 #define ADJUSTMENT_INDEX_OFFSET 1
231 typedef struct adjustmentState_s
{
232 uint8_t auxChannelIndex
;
233 const adjustmentConfig_t
*config
;
238 #ifndef MAX_SIMULTANEOUS_ADJUSTMENT_COUNT
239 #define MAX_SIMULTANEOUS_ADJUSTMENT_COUNT 4 // enough for 4 x 3position switches / 4 aux channel
242 #define MAX_ADJUSTMENT_RANGE_COUNT 12 // enough for 2 * 6pos switches.
244 void resetAdjustmentStates(void);
245 void configureAdjustment(uint8_t index
, uint8_t auxChannelIndex
, const adjustmentConfig_t
*adjustmentConfig
);
246 void updateAdjustmentStates(adjustmentRange_t
*adjustmentRanges
);
247 void processRcAdjustments(controlRateConfig_t
*controlRateConfig
, rxConfig_t
*rxConfig
);
249 bool isUsingSticksForArming(void);
251 int32_t getRcStickDeflection(int32_t axis
, uint16_t midrc
);
252 bool isModeActivationConditionPresent(modeActivationCondition_t
*modeActivationConditions
, boxId_e modeId
);
253 rollPitchStatus_e
calculateRollPitchCenterStatus(rxConfig_t
*rxConfig
);