Adding more servos
[inav.git] / src / main / fc / rc_adjustments.h
blobd5119ae927e67eaf40bd738fa493238005a732e3
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 #include "fc/rc_controls.h"
23 #include "fc/rc_modes.h"
25 //#define USE_INFLIGHT_PROFILE_ADJUSTMENT - not currently enabled
27 typedef enum {
28 ADJUSTMENT_NONE = 0,
29 ADJUSTMENT_RC_RATE = 1,
30 ADJUSTMENT_RC_EXPO = 2,
31 ADJUSTMENT_THROTTLE_EXPO = 3,
32 ADJUSTMENT_PITCH_ROLL_RATE = 4,
33 ADJUSTMENT_YAW_RATE = 5,
34 ADJUSTMENT_PITCH_ROLL_P = 6,
35 ADJUSTMENT_PITCH_ROLL_I = 7,
36 ADJUSTMENT_PITCH_ROLL_D = 8,
37 ADJUSTMENT_PITCH_ROLL_FF = 9,
38 ADJUSTMENT_PITCH_P = 10,
39 ADJUSTMENT_PITCH_I = 11,
40 ADJUSTMENT_PITCH_D = 12,
41 ADJUSTMENT_PITCH_FF = 13,
42 ADJUSTMENT_ROLL_P = 14,
43 ADJUSTMENT_ROLL_I = 15,
44 ADJUSTMENT_ROLL_D = 16,
45 ADJUSTMENT_ROLL_FF = 17,
46 ADJUSTMENT_YAW_P = 18,
47 ADJUSTMENT_YAW_I = 19,
48 ADJUSTMENT_YAW_D = 20,
49 ADJUSTMENT_YAW_FF = 21,
50 ADJUSTMENT_RATE_PROFILE = 22, // Unused, placeholder for compatibility
51 ADJUSTMENT_PITCH_RATE = 23,
52 ADJUSTMENT_ROLL_RATE = 24,
53 ADJUSTMENT_RC_YAW_EXPO = 25,
54 ADJUSTMENT_MANUAL_RC_EXPO = 26,
55 ADJUSTMENT_MANUAL_RC_YAW_EXPO = 27,
56 ADJUSTMENT_MANUAL_PITCH_ROLL_RATE = 28,
57 ADJUSTMENT_MANUAL_ROLL_RATE = 29,
58 ADJUSTMENT_MANUAL_PITCH_RATE = 30,
59 ADJUSTMENT_MANUAL_YAW_RATE = 31,
60 ADJUSTMENT_NAV_FW_CRUISE_THR = 32,
61 ADJUSTMENT_NAV_FW_PITCH2THR = 33,
62 ADJUSTMENT_ROLL_BOARD_ALIGNMENT = 34,
63 ADJUSTMENT_PITCH_BOARD_ALIGNMENT = 35,
64 ADJUSTMENT_LEVEL_P = 36,
65 ADJUSTMENT_LEVEL_I = 37,
66 ADJUSTMENT_LEVEL_D = 38,
67 ADJUSTMENT_POS_XY_P = 39,
68 ADJUSTMENT_POS_XY_I = 40,
69 ADJUSTMENT_POS_XY_D = 41,
70 ADJUSTMENT_POS_Z_P = 42,
71 ADJUSTMENT_POS_Z_I = 43,
72 ADJUSTMENT_POS_Z_D = 44,
73 ADJUSTMENT_HEADING_P = 45,
74 ADJUSTMENT_VEL_XY_P = 46,
75 ADJUSTMENT_VEL_XY_I = 47,
76 ADJUSTMENT_VEL_XY_D = 48,
77 ADJUSTMENT_VEL_Z_P = 49,
78 ADJUSTMENT_VEL_Z_I = 50,
79 ADJUSTMENT_VEL_Z_D = 51,
80 ADJUSTMENT_FW_MIN_THROTTLE_DOWN_PITCH_ANGLE = 52,
81 ADJUSTMENT_VTX_POWER_LEVEL = 53,
82 ADJUSTMENT_TPA = 54,
83 ADJUSTMENT_TPA_BREAKPOINT = 55,
84 ADJUSTMENT_NAV_FW_CONTROL_SMOOTHNESS = 56,
85 ADJUSTMENT_FW_TPA_TIME_CONSTANT = 57,
86 ADJUSTMENT_FW_LEVEL_TRIM = 58,
87 ADJUSTMENT_NAV_WP_MULTI_MISSION_INDEX = 59,
88 ADJUSTMENT_FUNCTION_COUNT // must be last
89 } adjustmentFunction_e;
91 typedef enum {
92 ADJUSTMENT_MODE_STEP,
93 ADJUSTMENT_MODE_SELECT
94 } adjustmentMode_e;
96 typedef struct adjustmentStepConfig_s {
97 uint8_t step;
98 } adjustmentStepConfig_t;
100 typedef struct adjustmentSelectConfig_s {
101 uint8_t switchPositions;
102 } adjustmentSelectConfig_t;
104 typedef union adjustmentConfig_u {
105 adjustmentStepConfig_t stepConfig;
106 adjustmentSelectConfig_t selectConfig;
107 } adjustmentData_t;
109 typedef struct adjustmentConfig_s {
110 uint8_t adjustmentFunction;
111 uint8_t mode;
112 adjustmentData_t data;
113 } adjustmentConfig_t;
115 typedef struct adjustmentRange_s {
116 // when aux channel is in range...
117 channelRange_t range;
118 uint8_t auxChannelIndex;
120 // ..then apply the adjustment function to the auxSwitchChannel ...
121 uint8_t adjustmentFunction;
122 uint8_t auxSwitchChannelIndex;
124 // ... via slot
125 uint8_t adjustmentIndex;
126 } adjustmentRange_t;
128 #define ADJUSTMENT_INDEX_OFFSET 1
130 typedef struct adjustmentState_s {
131 const adjustmentConfig_t *config;
132 uint32_t timeoutAt;
133 uint8_t auxChannelIndex;
134 } adjustmentState_t;
137 #ifndef MAX_SIMULTANEOUS_ADJUSTMENT_COUNT
138 #define MAX_SIMULTANEOUS_ADJUSTMENT_COUNT 4 // enough for 4 x 3position switches / 4 aux channel
139 #endif
141 #define MAX_ADJUSTMENT_RANGE_COUNT 20 // enough for 2 * 6pos switches.
143 PG_DECLARE_ARRAY(adjustmentRange_t, MAX_ADJUSTMENT_RANGE_COUNT, adjustmentRanges);
145 void resetAdjustmentStates(void);
146 void updateAdjustmentStates(bool canUseRxData);
147 struct controlRateConfig_s;
148 void processRcAdjustments(struct controlRateConfig_s *controlRateConfig, bool canUseRxData);
149 bool isAdjustmentFunctionSelected(uint8_t adjustmentFunction);
150 uint8_t getActiveAdjustmentFunctions(uint8_t *adjustmentFunctions);