rename USE_24CHANELS to USE_34CHANNELS
[inav.git] / src / main / fc / rc_controls.h
blobf5b96f2d2391d50c203d202d943bf6ec0f9954e5
1 /*
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/>.
18 #pragma once
20 #include "config/parameter_group.h"
22 #define CONTROL_DEADBAND 10 // Used to check if sticks are centered
24 typedef enum rc_alias {
25 ROLL = 0,
26 PITCH,
27 YAW,
28 THROTTLE,
29 AUX1, // 5
30 AUX2, // 6
31 AUX3, // 7
32 AUX4, // 8
33 AUX5, // 9
34 AUX6, // 10
35 AUX7, // 11
36 AUX8, // 12
37 AUX9, // 13
38 AUX10, // 14
39 AUX11, // 15
40 AUX12, // 16
41 AUX13, // 17
42 AUX14, // 18
43 #ifdef USE_34CHANNELS
44 AUX15, // 19
45 AUX16, // 20
46 AUX17, // 21
47 AUX18, // 22
48 AUX19, // 23
49 AUX20, // 24
50 AUX21, // 25
51 AUX22, // 26
52 AUX23, // 27
53 AUX24, // 28
54 AUX25, // 29
55 AUX26, // 30
56 AUX27, // 31
57 AUX28, // 32
58 AUX29, // 33
59 AUX30, // 34
60 #endif
61 } rc_alias_e;
63 typedef enum {
64 THROTTLE_LOW = 0,
65 THROTTLE_HIGH
66 } throttleStatus_e;
68 typedef enum {
69 THROTTLE_STATUS_TYPE_RC = 0,
70 THROTTLE_STATUS_TYPE_COMMAND
71 } throttleStatusType_e;
73 typedef enum {
74 NOT_CENTERED = 0,
75 CENTERED
76 } rollPitchStatus_e;
78 typedef enum {
79 STICK_CENTER = 0,
80 THROTTLE_THRESHOLD,
81 STICK_CENTER_ONCE
82 } airmodeHandlingType_e;
84 typedef enum {
85 ROL_LO = (1 << (2 * ROLL)),
86 ROL_CE = (3 << (2 * ROLL)),
87 ROL_HI = (2 << (2 * ROLL)),
89 PIT_LO = (1 << (2 * PITCH)),
90 PIT_CE = (3 << (2 * PITCH)),
91 PIT_HI = (2 << (2 * PITCH)),
93 YAW_LO = (1 << (2 * YAW)),
94 YAW_CE = (3 << (2 * YAW)),
95 YAW_HI = (2 << (2 * YAW)),
97 THR_LO = (1 << (2 * THROTTLE)),
98 THR_CE = (3 << (2 * THROTTLE)),
99 THR_HI = (2 << (2 * THROTTLE))
100 } stickPositions_e;
102 extern int16_t rcCommand[4];
104 typedef struct rcControlsConfig_s {
105 uint8_t deadband; // introduce a deadband around the stick center for pitch and roll axis. Must be greater than zero.
106 uint8_t yaw_deadband; // introduce a deadband around the stick center for yaw axis. Must be greater than zero.
107 uint8_t pos_hold_deadband; // Deadband for position hold
108 uint8_t alt_hold_deadband; // Defines the neutral zone of throttle stick during altitude hold
109 uint16_t mid_throttle_deadband; // default throttle deadband from MIDRC
110 uint8_t airmodeHandlingType; // Defaults to ANTI_WINDUP triggered at sticks centered
111 uint16_t airmodeThrottleThreshold; // Throttle threshold for airmode initial activation
112 } rcControlsConfig_t;
114 PG_DECLARE(rcControlsConfig_t, rcControlsConfig);
116 typedef struct armingConfig_s {
117 bool fixed_wing_auto_arm; // Auto-arm fixed wing aircraft on throttle up and never disarm
118 bool disarm_always; // Disarm motors regardless of throttle value
119 uint16_t switchDisarmDelayMs; // additional delay between ARM box going off and actual disarm
120 uint16_t prearmTimeoutMs; // duration for which Prearm being activated is valid. after this, Prearm needs to be reset. 0 means Prearm does not timeout.
121 } armingConfig_t;
123 PG_DECLARE(armingConfig_t, armingConfig);
125 stickPositions_e getRcStickPositions(void);
126 bool checkStickPosition(stickPositions_e stickPos);
128 bool areSticksInApModePosition(uint16_t ap_mode);
129 bool areSticksDeflected(void);
130 bool isRollPitchStickDeflected(uint8_t deadband);
131 throttleStatus_e calculateThrottleStatus(throttleStatusType_e type);
132 int16_t throttleStickMixedValue(void);
133 rollPitchStatus_e calculateRollPitchCenterStatus(void);
134 void processRcStickPositions(bool isThrottleLow);
135 bool throttleStickIsLow(void);
137 int32_t getRcStickDeflection(int32_t axis);