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
54 extern uint32_t rcModeActivationMask
;
56 #define IS_RC_MODE_ACTIVE(modeId) ((1 << (modeId)) & rcModeActivationMask)
57 #define ACTIVATE_RC_MODE(modeId) (rcModeActivationMask |= (1 << modeId))
59 typedef enum rc_alias
{
79 #define ROL_LO (1 << (2 * ROLL))
80 #define ROL_CE (3 << (2 * ROLL))
81 #define ROL_HI (2 << (2 * ROLL))
82 #define PIT_LO (1 << (2 * PITCH))
83 #define PIT_CE (3 << (2 * PITCH))
84 #define PIT_HI (2 << (2 * PITCH))
85 #define YAW_LO (1 << (2 * YAW))
86 #define YAW_CE (3 << (2 * YAW))
87 #define YAW_HI (2 << (2 * YAW))
88 #define THR_LO (1 << (2 * THROTTLE))
89 #define THR_CE (3 << (2 * THROTTLE))
90 #define THR_HI (2 << (2 * THROTTLE))
92 #define MAX_MODE_ACTIVATION_CONDITION_COUNT 20
94 #define CHANNEL_RANGE_MIN 900
95 #define CHANNEL_RANGE_MAX 2100
97 #define MODE_STEP_TO_CHANNEL_VALUE(step) (CHANNEL_RANGE_MIN + 25 * step)
98 #define CHANNEL_VALUE_TO_STEP(channelValue) ((constrain(channelValue, CHANNEL_RANGE_MIN, CHANNEL_RANGE_MAX) - CHANNEL_RANGE_MIN) / 25)
100 #define MIN_MODE_RANGE_STEP 0
101 #define MAX_MODE_RANGE_STEP ((CHANNEL_RANGE_MAX - CHANNEL_RANGE_MIN) / 25)
103 // Roll/pitch rates are a proportion used for mixing, so it tops out at 1.0:
104 #define CONTROL_RATE_CONFIG_ROLL_PITCH_RATE_MAX 100
106 /* Meaningful yaw rates are effectively unbounded because they are treated as a rotation rate multiplier: */
107 #define CONTROL_RATE_CONFIG_YAW_RATE_MAX 255
109 #define CONTROL_RATE_CONFIG_TPA_MAX 100
111 // steps are 25 apart
112 // a value of 0 corresponds to a channel value of 900 or less
113 // a value of 48 corresponds to a channel value of 2100 or more
114 // 48 steps between 900 and 1200
115 typedef struct channelRange_s
{
120 typedef struct modeActivationCondition_s
{
122 uint8_t auxChannelIndex
;
123 channelRange_t range
;
124 } modeActivationCondition_t
;
126 #define IS_RANGE_USABLE(range) ((range)->startStep < (range)->endStep)
128 typedef struct controlRateConfig_s
{
136 uint16_t tpa_breakpoint
; // Breakpoint where TPA is activated
137 } controlRateConfig_t
;
139 extern int16_t rcCommand
[4];
141 typedef struct rcControlsConfig_s
{
142 uint8_t deadband
; // introduce a deadband around the stick center for pitch and roll axis. Must be greater than zero.
143 uint8_t yaw_deadband
; // introduce a deadband around the stick center for yaw axis. Must be greater than zero.
144 } rcControlsConfig_t
;
146 bool areUsingSticksToArm(void);
148 bool areSticksInApModePosition(uint16_t ap_mode
);
149 throttleStatus_e
calculateThrottleStatus(rxConfig_t
*rxConfig
, uint16_t deadband3d_throttle
);
150 void processRcStickPositions(rxConfig_t
*rxConfig
, throttleStatus_e throttleStatus
, bool retarded_arm
, bool disarm_kill_switch
);
152 void updateActivatedModes(modeActivationCondition_t
*modeActivationConditions
);
159 ADJUSTMENT_THROTTLE_EXPO
,
160 ADJUSTMENT_PITCH_ROLL_RATE
,
162 ADJUSTMENT_PITCH_ROLL_P
,
163 ADJUSTMENT_PITCH_ROLL_I
,
164 ADJUSTMENT_PITCH_ROLL_D
,
168 ADJUSTMENT_RATE_PROFILE
,
169 ADJUSTMENT_PITCH_RATE
,
170 ADJUSTMENT_ROLL_RATE
,
178 } adjustmentFunction_e
;
180 #define ADJUSTMENT_FUNCTION_COUNT 21
183 ADJUSTMENT_MODE_STEP
,
184 ADJUSTMENT_MODE_SELECT
187 typedef struct adjustmentStepConfig_s
{
189 } adjustmentStepConfig_t
;
191 typedef struct adjustmentSelectConfig_s
{
192 uint8_t switchPositions
;
193 } adjustmentSelectConfig_t
;
195 typedef union adjustmentConfig_u
{
196 adjustmentStepConfig_t stepConfig
;
197 adjustmentSelectConfig_t selectConfig
;
200 typedef struct adjustmentConfig_s
{
201 uint8_t adjustmentFunction
;
203 adjustmentData_t data
;
204 } adjustmentConfig_t
;
206 typedef struct adjustmentRange_s
{
207 // when aux channel is in range...
208 uint8_t auxChannelIndex
;
209 channelRange_t range
;
211 // ..then apply the adjustment function to the auxSwitchChannel ...
212 uint8_t adjustmentFunction
;
213 uint8_t auxSwitchChannelIndex
;
216 uint8_t adjustmentIndex
;
219 #define ADJUSTMENT_INDEX_OFFSET 1
221 typedef struct adjustmentState_s
{
222 uint8_t auxChannelIndex
;
223 const adjustmentConfig_t
*config
;
228 #ifndef MAX_SIMULTANEOUS_ADJUSTMENT_COUNT
229 #define MAX_SIMULTANEOUS_ADJUSTMENT_COUNT 4 // enough for 4 x 3position switches / 4 aux channel
232 #define MAX_ADJUSTMENT_RANGE_COUNT 12 // enough for 2 * 6pos switches.
234 void resetAdjustmentStates(void);
235 void configureAdjustment(uint8_t index
, uint8_t auxChannelIndex
, const adjustmentConfig_t
*adjustmentConfig
);
236 void updateAdjustmentStates(adjustmentRange_t
*adjustmentRanges
);
237 void processRcAdjustments(controlRateConfig_t
*controlRateConfig
, rxConfig_t
*rxConfig
);
239 bool isUsingSticksForArming(void);
241 int32_t getRcStickDeflection(int32_t axis
, uint16_t midrc
);
242 bool isModeActivationConditionPresent(modeActivationCondition_t
*modeActivationConditions
, boxId_e modeId
);