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/>.
25 #include "common/filter.h"
28 typedef enum rc_alias
{
43 #define PRIMARY_CHANNEL_COUNT (THROTTLE + 1)
50 #define AIRMODEDEADBAND 12
65 RC_SMOOTHING_TYPE_INTERPOLATION
,
66 RC_SMOOTHING_TYPE_FILTER
70 RC_SMOOTHING_INPUT_PT1
,
71 RC_SMOOTHING_INPUT_BIQUAD
72 } rcSmoothingInputFilter_e
;
75 RC_SMOOTHING_DERIVATIVE_OFF
,
76 RC_SMOOTHING_DERIVATIVE_PT1
,
77 RC_SMOOTHING_DERIVATIVE_BIQUAD
78 } rcSmoothingDerivativeFilter_e
;
81 RC_SMOOTHING_VALUE_INPUT_ACTIVE
,
82 RC_SMOOTHING_VALUE_DERIVATIVE_ACTIVE
,
83 RC_SMOOTHING_VALUE_AVERAGE_FRAME
84 } rcSmoothingInfoType_e
;
86 #define ROL_LO (1 << (2 * ROLL))
87 #define ROL_CE (3 << (2 * ROLL))
88 #define ROL_HI (2 << (2 * ROLL))
89 #define PIT_LO (1 << (2 * PITCH))
90 #define PIT_CE (3 << (2 * PITCH))
91 #define PIT_HI (2 << (2 * PITCH))
92 #define YAW_LO (1 << (2 * YAW))
93 #define YAW_CE (3 << (2 * YAW))
94 #define YAW_HI (2 << (2 * YAW))
95 #define THR_LO (1 << (2 * THROTTLE))
96 #define THR_CE (3 << (2 * THROTTLE))
97 #define THR_HI (2 << (2 * THROTTLE))
99 #define CONTROL_RATE_CONFIG_RC_EXPO_MAX 100
101 #define CONTROL_RATE_CONFIG_RC_RATES_MAX 255
103 // (Super) rates are constrained to [0, 100] for Betaflight rates, so values higher than 100 won't make a difference. Range extended for RaceFlight rates.
104 #define CONTROL_RATE_CONFIG_RATE_MAX 255
106 #define CONTROL_RATE_CONFIG_TPA_MAX 100
108 extern float rcCommand
[4];
110 typedef struct rcSmoothingFilterTraining_s
{
115 } rcSmoothingFilterTraining_t
;
117 typedef struct rcSmoothingFilter_s
{
118 bool filterInitialized
;
119 biquadFilter_t filterBiquad
[4];
120 pt1Filter_t filterPt1
[4];
121 uint16_t inputCutoffFrequency
;
122 uint16_t derivativeCutoffFrequency
;
123 int averageFrameTimeUs
;
124 rcSmoothingFilterTraining_t training
;
125 } rcSmoothingFilter_t
;
127 typedef struct rcControlsConfig_s
{
128 uint8_t deadband
; // introduce a deadband around the stick center for pitch and roll axis. Must be greater than zero.
129 uint8_t yaw_deadband
; // introduce a deadband around the stick center for yaw axis. Must be greater than zero.
130 uint8_t alt_hold_deadband
; // defines the neutral zone of throttle stick during altitude hold, default setting is +/-40
131 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
132 bool yaw_control_reversed
; // invert control direction of yaw
133 } rcControlsConfig_t
;
135 PG_DECLARE(rcControlsConfig_t
, rcControlsConfig
);
137 typedef struct flight3DConfig_s
{
138 uint16_t deadband3d_low
; // min 3d value
139 uint16_t deadband3d_high
; // max 3d value
140 uint16_t neutral3d
; // center 3d value
141 uint16_t deadband3d_throttle
; // default throttle deadband from MIDRC
142 uint16_t limit3d_low
; // pwm output value for max negative thrust
143 uint16_t limit3d_high
; // pwm output value for max positive thrust
144 uint8_t switched_mode3d
; // enable '3D Switched Mode'
147 PG_DECLARE(flight3DConfig_t
, flight3DConfig
);
149 typedef struct armingConfig_s
{
150 uint8_t gyro_cal_on_first_arm
; // allow disarm/arm on throttle down + roll left/right
151 uint8_t auto_disarm_delay
; // allow automatically disarming multicopters after auto_disarm_delay seconds of zero throttle. Disabled when 0
154 PG_DECLARE(armingConfig_t
, armingConfig
);
156 bool areUsingSticksToArm(void);
158 bool areSticksInApModePosition(uint16_t ap_mode
);
159 throttleStatus_e
calculateThrottleStatus(void);
160 void processRcStickPositions();
162 bool isUsingSticksForArming(void);
164 int32_t getRcStickDeflection(int32_t axis
, uint16_t midrc
);
166 struct modeActivationCondition_s
;
167 void useRcControlsConfig(struct pidProfile_s
*pidProfileToUse
);