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/>.
26 BOXNAVALTHOLD
, // old BOXBARO
33 BOXNAVRTH
, // old GPSHOME
34 BOXNAVPOSHOLD
, // old GPSHOLD
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 ROL_LO (1 << (2 * ROLL))
81 #define ROL_CE (3 << (2 * ROLL))
82 #define ROL_HI (2 << (2 * ROLL))
83 #define PIT_LO (1 << (2 * PITCH))
84 #define PIT_CE (3 << (2 * PITCH))
85 #define PIT_HI (2 << (2 * PITCH))
86 #define YAW_LO (1 << (2 * YAW))
87 #define YAW_CE (3 << (2 * YAW))
88 #define YAW_HI (2 << (2 * YAW))
89 #define THR_LO (1 << (2 * THROTTLE))
90 #define THR_CE (3 << (2 * THROTTLE))
91 #define THR_HI (2 << (2 * THROTTLE))
93 #define MAX_MODE_ACTIVATION_CONDITION_COUNT 20
95 #define CHANNEL_RANGE_MIN 900
96 #define CHANNEL_RANGE_MAX 2100
98 #define MODE_STEP_TO_CHANNEL_VALUE(step) (CHANNEL_RANGE_MIN + 25 * step)
99 #define CHANNEL_VALUE_TO_STEP(channelValue) ((constrain(channelValue, CHANNEL_RANGE_MIN, CHANNEL_RANGE_MAX) - CHANNEL_RANGE_MIN) / 25)
101 #define MIN_MODE_RANGE_STEP 0
102 #define MAX_MODE_RANGE_STEP ((CHANNEL_RANGE_MAX - CHANNEL_RANGE_MIN) / 25)
104 // Roll/pitch rates are a proportion used for mixing, so it tops out at 1.0:
105 #define CONTROL_RATE_CONFIG_ROLL_PITCH_RATE_MAX 100
107 /* Meaningful yaw rates are effectively unbounded because they are treated as a rotation rate multiplier: */
108 #define CONTROL_RATE_CONFIG_YAW_RATE_MAX 255
110 #define CONTROL_RATE_CONFIG_TPA_MAX 100
112 // steps are 25 apart
113 // a value of 0 corresponds to a channel value of 900 or less
114 // a value of 48 corresponds to a channel value of 2100 or more
115 // 48 steps between 900 and 1200
116 typedef struct channelRange_s
{
121 typedef struct modeActivationCondition_s
{
123 uint8_t auxChannelIndex
;
124 channelRange_t range
;
125 } modeActivationCondition_t
;
127 #define IS_RANGE_USABLE(range) ((range)->startStep < (range)->endStep)
129 #define SHOULD_RESET_ERRORS ((throttleStatus == THROTTLE_LOW && !(IS_RC_MODE_ACTIVE(BOXAIRMODE))) || !(ARMING_FLAG(ARMED)) || ((throttleStatus == THROTTLE_LOW && feature(FEATURE_MOTOR_STOP))))
131 typedef struct controlRateConfig_s
{
139 uint16_t tpa_breakpoint
; // Breakpoint where TPA is activated
140 } controlRateConfig_t
;
142 extern int16_t rcCommand
[4];
144 typedef struct rcControlsConfig_s
{
145 uint8_t deadband
; // introduce a deadband around the stick center for pitch and roll axis. Must be greater than zero.
146 uint8_t yaw_deadband
; // introduce a deadband around the stick center for yaw axis. Must be greater than zero.
147 uint8_t pos_hold_deadband
; // Adds ability to adjust the Hold-position when moving the sticks (assisted mode)
148 uint8_t alt_hold_deadband
; // Defines the neutral zone of throttle stick during altitude hold
149 } rcControlsConfig_t
;
151 bool areUsingSticksToArm(void);
153 bool areSticksInApModePosition(uint16_t ap_mode
);
154 throttleStatus_e
calculateThrottleStatus(rxConfig_t
*rxConfig
, uint16_t deadband3d_throttle
);
155 void processRcStickPositions(rxConfig_t
*rxConfig
, throttleStatus_e throttleStatus
, bool disarm_kill_switch
);
157 void updateActivatedModes(modeActivationCondition_t
*modeActivationConditions
);
164 ADJUSTMENT_THROTTLE_EXPO
,
165 ADJUSTMENT_PITCH_ROLL_RATE
,
167 ADJUSTMENT_PITCH_ROLL_P
,
168 ADJUSTMENT_PITCH_ROLL_I
,
169 ADJUSTMENT_PITCH_ROLL_D
,
173 ADJUSTMENT_RATE_PROFILE
,
174 ADJUSTMENT_PITCH_RATE
,
175 ADJUSTMENT_ROLL_RATE
,
183 } adjustmentFunction_e
;
185 #define ADJUSTMENT_FUNCTION_COUNT 21
188 ADJUSTMENT_MODE_STEP
,
189 ADJUSTMENT_MODE_SELECT
192 typedef struct adjustmentStepConfig_s
{
194 } adjustmentStepConfig_t
;
196 typedef struct adjustmentSelectConfig_s
{
197 uint8_t switchPositions
;
198 } adjustmentSelectConfig_t
;
200 typedef union adjustmentConfig_u
{
201 adjustmentStepConfig_t stepConfig
;
202 adjustmentSelectConfig_t selectConfig
;
205 typedef struct adjustmentConfig_s
{
206 uint8_t adjustmentFunction
;
208 adjustmentData_t data
;
209 } adjustmentConfig_t
;
211 typedef struct adjustmentRange_s
{
212 // when aux channel is in range...
213 uint8_t auxChannelIndex
;
214 channelRange_t range
;
216 // ..then apply the adjustment function to the auxSwitchChannel ...
217 uint8_t adjustmentFunction
;
218 uint8_t auxSwitchChannelIndex
;
221 uint8_t adjustmentIndex
;
224 #define ADJUSTMENT_INDEX_OFFSET 1
226 typedef struct adjustmentState_s
{
227 uint8_t auxChannelIndex
;
228 const adjustmentConfig_t
*config
;
233 #ifndef MAX_SIMULTANEOUS_ADJUSTMENT_COUNT
234 #define MAX_SIMULTANEOUS_ADJUSTMENT_COUNT 4 // enough for 4 x 3position switches / 4 aux channel
237 #define MAX_ADJUSTMENT_RANGE_COUNT 12 // enough for 2 * 6pos switches.
239 void resetAdjustmentStates(void);
240 void configureAdjustment(uint8_t index
, uint8_t auxChannelIndex
, const adjustmentConfig_t
*adjustmentConfig
);
241 void updateAdjustmentStates(adjustmentRange_t
*adjustmentRanges
);
242 void processRcAdjustments(controlRateConfig_t
*controlRateConfig
, rxConfig_t
*rxConfig
);
244 bool isUsingSticksForArming(void);
245 bool isUsingNavigationModes(void);
247 int32_t getRcStickDeflection(int32_t axis
, uint16_t midrc
);
248 bool isModeActivationConditionPresent(modeActivationCondition_t
*modeActivationConditions
, boxId_e modeId
);