Rev 2017 | Rev 2020 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2017 | Rev 2018 | ||
---|---|---|---|
1 | #ifndef _CONFIGURATION_H |
1 | #ifndef _CONFIGURATION_H |
2 | #define _CONFIGURATION_H |
2 | #define _CONFIGURATION_H |
3 | 3 | ||
4 | #include <inttypes.h> |
4 | #include <inttypes.h> |
5 | #include <avr/io.h> |
5 | #include <avr/io.h> |
6 | 6 | ||
7 | #define MAX_CHANNELS 10 |
7 | #define MAX_CHANNELS 10 |
8 | #define MAX_MOTORS 12 |
8 | #define MAX_MOTORS 12 |
- | 9 | ||
- | 10 | // bitmask for VersionInfo_t.HardwareError[0] |
|
- | 11 | #define FC_ERROR0_GYRO_PITCH 0x01 |
|
- | 12 | #define FC_ERROR0_GYRO_ROLL 0x02 |
|
- | 13 | #define FC_ERROR0_GYRO_YAW 0x04 |
|
- | 14 | #define FC_ERROR0_ACC_X 0x08 |
|
- | 15 | #define FC_ERROR0_ACC_Y 0x10 |
|
- | 16 | #define FC_ERROR0_ACC_Z 0x20 |
|
- | 17 | #define FC_ERROR0_PRESSURE 0x40 |
|
- | 18 | #define FC_ERROR1_RES0 0x80 |
|
- | 19 | // bitmask for VersionInfo_t.HardwareError[1] |
|
- | 20 | #define FC_ERROR1_I2C 0x01 |
|
- | 21 | #define FC_ERROR1_BL_MISSING 0x02 |
|
- | 22 | #define FC_ERROR1_SPI_RX 0x04 |
|
- | 23 | #define FC_ERROR1_PPM 0x08 |
|
- | 24 | #define FC_ERROR1_MIXER 0x10 |
|
- | 25 | #define FC_ERROR1_RES1 0x20 |
|
- | 26 | #define FC_ERROR1_RES2 0x40 |
|
- | 27 | #define FC_ERROR1_RES3 0x80 |
|
- | 28 | ||
- | 29 | typedef struct { |
|
- | 30 | uint8_t SWMajor; |
|
- | 31 | uint8_t SWMinor; |
|
- | 32 | uint8_t protoMajor; |
|
- | 33 | uint8_t protoMinor; |
|
- | 34 | uint8_t SWPatch; |
|
- | 35 | uint8_t hardwareErrors[5]; |
|
- | 36 | }__attribute__((packed)) VersionInfo_t; |
|
- | 37 | ||
- | 38 | extern VersionInfo_t versionInfo; |
|
9 | 39 | ||
10 | typedef struct { |
40 | typedef struct { |
11 | // IMU |
41 | // IMU |
12 | /*PMM*/uint8_t gyroP; |
42 | /*PMM*/uint8_t gyroP; |
13 | /* P */uint8_t gyroD; |
43 | /* P */uint8_t gyroD; |
14 | /* P */uint8_t gyroI; |
44 | /* P */uint8_t gyroI; |
15 | /* P */uint8_t IFactor; |
45 | /* P */uint8_t IFactor; |
16 | uint8_t yawIFactor; |
46 | uint8_t yawIFactor; |
17 | /* P */uint8_t compassYawEffect; |
47 | /* P */uint8_t compassYawEffect; |
18 | 48 | ||
19 | // Control |
49 | // Control |
20 | /* P */uint8_t externalControl; |
50 | /* P */uint8_t externalControl; |
21 | 51 | ||
22 | /* P */uint8_t axisCoupling1; |
52 | /* P */uint8_t axisCoupling1; |
23 | /* P */uint8_t axisCoupling2; |
53 | /* P */uint8_t axisCoupling2; |
24 | /* P */uint8_t axisCouplingYawCorrection; |
54 | /* P */uint8_t axisCouplingYawCorrection; |
25 | /* P */uint8_t dynamicStability; |
55 | /* P */uint8_t dynamicStability; |
26 | uint8_t maxAccVector; |
56 | uint8_t maxAccVector; |
27 | 57 | ||
28 | // Height control |
58 | // Height control |
29 | /*PMM*/uint8_t heightP; |
59 | /*PMM*/uint8_t heightP; |
30 | /*PMM*/uint8_t heightD; |
60 | /*PMM*/uint8_t heightD; |
31 | /* P */uint8_t heightSetting; |
61 | /* P */uint8_t heightSetting; |
32 | /* P */uint8_t heightACCEffect; |
62 | /* P */uint8_t heightACCEffect; |
33 | 63 | ||
34 | uint8_t attitudeControl; |
64 | uint8_t attitudeControl; |
35 | 65 | ||
36 | // The rest... |
66 | // The rest... |
37 | /* P */uint8_t userParams[8]; |
67 | /* P */uint8_t userParams[8]; |
38 | /*PMM*/uint8_t output0Timing; |
68 | /*PMM*/uint8_t output0Timing; |
39 | /*PMM*/uint8_t output1Timing; |
69 | /*PMM*/uint8_t output1Timing; |
40 | 70 | ||
41 | uint8_t servoManualControl[2]; |
71 | uint8_t servoManualControl[2]; |
42 | 72 | ||
43 | uint8_t motorSmoothing; |
73 | uint8_t motorSmoothing; |
44 | uint8_t levelCorrection[2]; |
74 | uint8_t levelCorrection[2]; |
45 | } dynamicParam_t; |
75 | } dynamicParam_t; |
46 | 76 | ||
47 | extern volatile dynamicParam_t dynamicParams; |
77 | extern volatile dynamicParam_t dynamicParams; |
48 | 78 | ||
49 | typedef struct { |
79 | typedef struct { |
50 | uint8_t sourceIdx, targetIdx; |
80 | uint8_t sourceIdx, targetIdx; |
51 | uint8_t min, max; |
81 | uint8_t min, max; |
52 | } MMXLATION; |
82 | } MMXLATION; |
53 | 83 | ||
54 | typedef struct { |
84 | typedef struct { |
55 | uint8_t sourceIdx, targetIdx; |
85 | uint8_t sourceIdx, targetIdx; |
56 | } XLATION; |
86 | } XLATION; |
57 | 87 | ||
58 | typedef struct { |
88 | typedef struct { |
59 | uint8_t channels[MAX_CHANNELS]; |
89 | uint8_t channels[MAX_CHANNELS]; |
60 | } channelMap_t; |
90 | } channelMap_t; |
61 | extern channelMap_t channelMap; |
91 | extern channelMap_t channelMap; |
62 | 92 | ||
63 | typedef struct { |
93 | typedef struct { |
64 | char name[12]; |
94 | char name[12]; |
65 | int8_t motor[MAX_MOTORS][4]; |
95 | int8_t motor[MAX_MOTORS][4]; |
66 | }__attribute__((packed)) mixerMatrix_t; |
96 | }__attribute__((packed)) mixerMatrix_t; |
67 | extern mixerMatrix_t mixerMatrix; |
97 | extern mixerMatrix_t mixerMatrix; |
68 | 98 | ||
69 | typedef struct { |
99 | typedef struct { |
70 | int16_t offsets[3]; |
100 | int16_t offsets[3]; |
71 | } sensorOffset_t; |
101 | } sensorOffset_t; |
72 | 102 | ||
73 | typedef struct { |
103 | typedef struct { |
74 | uint8_t manualControl; |
104 | uint8_t manualControl; |
75 | uint8_t stabilizationFactor; |
105 | uint8_t stabilizationFactor; |
76 | uint8_t minValue; |
106 | uint8_t minValue; |
77 | uint8_t maxValue; |
107 | uint8_t maxValue; |
78 | uint8_t flags; |
108 | uint8_t flags; |
79 | } servo_t; |
109 | } servo_t; |
80 | 110 | ||
81 | #define SERVO_STABILIZATION_REVERSE 1 |
111 | #define SERVO_STABILIZATION_REVERSE 1 |
82 | 112 | ||
83 | typedef struct { |
113 | typedef struct { |
84 | uint8_t bitmask; |
114 | uint8_t bitmask; |
85 | uint8_t timing; |
115 | uint8_t timing; |
86 | } output_flash_t; |
116 | } output_flash_t; |
87 | 117 | ||
88 | // values above 250 representing poti1 to poti4 |
118 | // values above 250 representing poti1 to poti4 |
89 | typedef struct { |
119 | typedef struct { |
90 | // Global bitflags |
120 | // Global bitflags |
91 | uint8_t bitConfig; // see upper defines for bitcoding |
121 | uint8_t bitConfig; // see upper defines for bitcoding |
92 | 122 | ||
93 | // Height Control |
123 | // Height Control |
- | 124 | uint8_t airpressureFilter; |
|
94 | uint8_t heightP; // Value : 0-32 |
125 | uint8_t heightP; |
95 | uint8_t heightD; // Value : 0-250 |
126 | uint8_t heightD; |
96 | uint8_t heightSetting; // Value : 0-32 |
127 | uint8_t heightSetting; |
97 | uint8_t heightControlMaxThrottleChange; // Value : 0-100 |
128 | uint8_t heightControlMaxThrottleChange; |
98 | uint8_t heightSlewRate; // Value : 0-50 |
129 | uint8_t heightSlewRate; |
99 | 130 | ||
100 | // Attitude Control |
131 | // Attitude Control |
101 | uint8_t attitudeControl; |
132 | uint8_t attitudeControl; |
102 | 133 | ||
103 | // Control |
134 | // Control |
104 | uint8_t stickP; // Value : 1-6 |
135 | uint8_t stickP; |
105 | uint8_t stickD; // Value : 0-64 |
136 | uint8_t stickD; |
106 | uint8_t stickYawP; // Value : 1-20 |
137 | uint8_t stickYawP; |
107 | uint8_t stickThrottleD; |
138 | uint8_t stickThrottleD; |
108 | uint8_t minThrottle; // Value : 0-32 |
139 | uint8_t minThrottle; |
109 | uint8_t maxThrottle; // Value : 33-250 |
140 | uint8_t maxThrottle; |
110 | uint8_t externalControl; // for serial Control |
141 | uint8_t externalControl; // for serial Control |
111 | uint8_t maxAccVector; |
142 | uint8_t maxAccVector; |
112 | uint8_t maxControlActivity; |
143 | uint8_t maxControlActivity; |
113 | uint8_t motorSmoothing; |
144 | uint8_t motorSmoothing; |
114 | 145 | ||
115 | // IMU |
146 | // IMU |
116 | uint8_t gyroQuadrant; |
147 | uint8_t gyroQuadrant; |
117 | uint8_t accQuadrant; |
148 | uint8_t accQuadrant; |
118 | uint8_t imuReversedFlags; |
149 | uint8_t imuReversedFlags; |
119 | 150 | ||
120 | uint8_t gyroPIDFilterConstant; |
151 | uint8_t gyroPIDFilterConstant; |
121 | uint8_t gyroATTFilterConstant; |
152 | uint8_t gyroATTFilterConstant; |
122 | uint8_t gyroDFilterConstant; |
153 | uint8_t gyroDFilterConstant; |
123 | uint8_t accFilterConstant; |
154 | uint8_t accFilterConstant; |
124 | 155 | ||
125 | uint8_t gyroP; // Value : 10-250 |
156 | uint8_t gyroP; |
126 | uint8_t gyroI; // Value : 0-250 |
157 | uint8_t gyroI; |
127 | uint8_t gyroD; // Value : 0-250 |
158 | uint8_t gyroD; |
128 | 159 | ||
129 | uint8_t zerothOrderCorrection; // Value : 1-64 |
160 | uint8_t zerothOrderCorrection; |
130 | uint8_t driftCompDivider; // 1/k (Koppel_ACC_Wirkung) |
161 | uint8_t driftCompDivider; // 1/k (Koppel_ACC_Wirkung) |
131 | uint8_t driftCompLimit; // limit for gyrodrift compensation |
162 | uint8_t driftCompLimit; // limit for gyrodrift compensation |
132 | 163 | ||
133 | uint8_t axisCoupling1; // Value: 0-250 Faktor, mit dem Yaw die Achsen Roll und Nick koppelt (NickRollMitkopplung) |
164 | uint8_t axisCoupling1; // Value: 0-250 Faktor, mit dem Yaw die Achsen Roll und Nick koppelt (NickRollMitkopplung) |
134 | uint8_t axisCoupling2; // Value: 0-250 Faktor, mit dem Nick und Roll verkoppelt werden |
165 | uint8_t axisCoupling2; // Value: 0-250 Faktor, mit dem Nick und Roll verkoppelt werden |
135 | uint8_t axisCouplingYawCorrection;// Value: 0-250 Faktor, mit dem Nick und Roll verkoppelt werden |
166 | uint8_t axisCouplingYawCorrection;// Value: 0-250 Faktor, mit dem Nick und Roll verkoppelt werden |
136 | 167 | ||
137 | uint8_t dynamicStability; // PID limit for Attitude controller |
168 | uint8_t dynamicStability; // PID limit for Attitude controller |
138 | uint8_t IFactor; // Value : 0-250 |
169 | uint8_t IFactor; |
139 | uint8_t yawIFactor; |
170 | uint8_t yawIFactor; |
140 | uint8_t compassYawEffect; // Value : 0-32 |
171 | uint8_t compassYawEffect; |
141 | uint8_t levelCorrection[2]; |
172 | uint8_t levelCorrection[2]; |
142 | 173 | ||
143 | // Servos |
174 | // Servos |
144 | uint8_t servoCount; |
175 | uint8_t servoCount; |
145 | uint8_t servoManualMaxSpeed; |
176 | uint8_t servoManualMaxSpeed; |
146 | servo_t servoConfigurations[2]; // [PITCH, ROLL] |
177 | servo_t servoConfigurations[2]; // [PITCH, ROLL] |
147 | 178 | ||
148 | // Battery warning and emergency flight |
179 | // Battery warning and emergency flight |
149 | uint8_t batteryVoltageWarning; // Value : 0-250 |
180 | uint8_t batteryVoltageWarning; |
150 | uint8_t emergencyThrottle; // Value : 0-250 |
181 | uint8_t emergencyThrottle; |
151 | uint8_t emergencyFlightDuration; // Value : 0-250 |
182 | uint8_t emergencyFlightDuration; |
152 | 183 | ||
153 | // Outputs |
184 | // Outputs |
154 | output_flash_t outputFlash[2]; |
185 | output_flash_t outputFlash[2]; |
155 | uint8_t outputDebugMask; |
186 | uint8_t outputDebugMask; |
156 | uint8_t outputFlags; |
187 | uint8_t outputFlags; |
157 | 188 | ||
158 | // User params |
189 | // User params |
159 | uint8_t userParams[8]; // Value : 0-250 |
190 | uint8_t userParams[8]; |
160 | 191 | ||
161 | // Name |
192 | // Name |
162 | char name[12]; |
193 | char name[12]; |
163 | } paramset_t; |
194 | } paramset_t; |
164 | extern paramset_t staticParams; |
195 | extern paramset_t staticParams; |
165 | 196 | ||
166 | // MKFlags |
197 | // MKFlags |
167 | #define MKFLAG_MOTOR_RUN (1<<0) |
198 | #define MKFLAG_MOTOR_RUN (1<<0) |
168 | #define MKFLAG_FLY (1<<1) |
199 | #define MKFLAG_FLY (1<<1) |
169 | #define MKFLAG_CALIBRATE (1<<2) |
200 | #define MKFLAG_CALIBRATE (1<<2) |
170 | #define MKFLAG_START (1<<3) |
201 | #define MKFLAG_START (1<<3) |
171 | #define MKFLAG_EMERGENCY_FLIGHT (1<<4) |
202 | #define MKFLAG_EMERGENCY_FLIGHT (1<<4) |
172 | #define MKFLAG_RESERVE1 (1<<5) |
203 | #define MKFLAG_RESERVE1 (1<<5) |
173 | #define MKFLAG_RESERVE2 (1<<6) |
204 | #define MKFLAG_RESERVE2 (1<<6) |
174 | #define MKFLAG_RESERVE3 (1<<7) |
205 | #define MKFLAG_RESERVE3 (1<<7) |
175 | 206 | ||
176 | // bit mask for staticParams.bitConfig |
207 | // bit mask for staticParams.bitConfig |
177 | #define CFG_SIMPLE_HEIGHT_CONTROL (1<<0) |
208 | #define CFG_SIMPLE_HEIGHT_CONTROL (1<<0) |
178 | #define CFG_SIMPLE_HC_HOLD_SWITCH (1<<1) |
209 | #define CFG_SIMPLE_HC_HOLD_SWITCH (1<<1) |
179 | #define CFG_HEADING_HOLD (1<<2) |
210 | #define CFG_HEADING_HOLD (1<<2) |
180 | #define CFG_COMPASS_ACTIVE (1<<3) |
211 | #define CFG_COMPASS_ACTIVE (1<<3) |
181 | #define CFG_COMPASS_FIX (1<<4) |
212 | #define CFG_COMPASS_FIX (1<<4) |
182 | #define CFG_GPS_ACTIVE (1<<5) |
213 | #define CFG_GPS_ACTIVE (1<<5) |
183 | #define CFG_AXIS_COUPLING_ACTIVE (1<<6) |
214 | #define CFG_AXIS_COUPLING_ACTIVE (1<<6) |
184 | #define CFG_GYRO_SATURATION_PREVENTION (1<<7) |
215 | #define CFG_GYRO_SATURATION_PREVENTION (1<<7) |
185 | 216 | ||
186 | #define ATMEGA644 0 |
217 | #define ATMEGA644 0 |
187 | #define ATMEGA644P 1 |
218 | #define ATMEGA644P 1 |
188 | #define SYSCLK F_CPU |
219 | #define SYSCLK F_CPU |
189 | 220 | ||
190 | // Not really a part of configuration, but LEDs and HW version test are the same. |
221 | // Not really a part of configuration, but LEDs and HW version test are the same. |
191 | #define RED_OFF {if((boardRelease == 10) || (boardRelease == 20)) PORTB &=~(1<<PORTB0); else PORTB |= (1<<PORTB0);} |
222 | #define RED_OFF {if((boardRelease == 10) || (boardRelease == 20)) PORTB &=~(1<<PORTB0); else PORTB |= (1<<PORTB0);} |
192 | #define RED_ON {if((boardRelease == 10) || (boardRelease == 20)) PORTB |= (1<<PORTB0); else PORTB &=~(1<<PORTB0);} |
223 | #define RED_ON {if((boardRelease == 10) || (boardRelease == 20)) PORTB |= (1<<PORTB0); else PORTB &=~(1<<PORTB0);} |
193 | #define RED_FLASH PORTB ^= (1<<PORTB0) |
224 | #define RED_FLASH PORTB ^= (1<<PORTB0) |
194 | #define GRN_OFF {if(boardRelease < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);} |
225 | #define GRN_OFF {if(boardRelease < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);} |
195 | #define GRN_ON {if(boardRelease < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);} |
226 | #define GRN_ON {if(boardRelease < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);} |
196 | #define GRN_FLASH PORTB ^= (1<<PORTB1) |
227 | #define GRN_FLASH PORTB ^= (1<<PORTB1) |
197 | 228 | ||
198 | // Mixer table |
229 | // Mixer table |
199 | #define MIX_THROTTLE 0 |
230 | #define MIX_THROTTLE 0 |
200 | #define MIX_PITCH 1 |
231 | #define MIX_PITCH 1 |
201 | #define MIX_ROLL 2 |
232 | #define MIX_ROLL 2 |
202 | #define MIX_YAW 3 |
233 | #define MIX_YAW 3 |
203 | 234 | ||
204 | #define VARIABLE_COUNT 8 |
235 | #define VARIABLE_COUNT 8 |
205 | 236 | ||
206 | extern volatile uint8_t MKFlags; |
237 | extern volatile uint8_t MKFlags; |
207 | extern uint8_t requiredMotors; |
238 | extern uint8_t requiredMotors; |
208 | extern int16_t variables[VARIABLE_COUNT]; // The "Poti"s. |
239 | extern int16_t variables[VARIABLE_COUNT]; // The "Poti"s. |
209 | extern uint8_t boardRelease; |
240 | extern uint8_t boardRelease; |
210 | extern uint8_t CPUType; |
241 | extern uint8_t CPUType; |
211 | 242 | ||
212 | extern volatile uint8_t MKFlags; |
243 | extern volatile uint8_t MKFlags; |
213 | extern uint16_t isFlying; |
244 | extern uint16_t isFlying; |
214 | 245 | ||
215 | void channelMap_default(void); |
246 | void channelMap_default(void); |
216 | void paramSet_default(uint8_t setnumber); |
247 | void paramSet_default(uint8_t setnumber); |
217 | void mixerMatrix_default(void); |
248 | void mixerMatrix_default(void); |
218 | 249 | ||
219 | void configuration_applyVariablesToParams(void); |
250 | void configuration_applyVariablesToParams(void); |
220 | uint8_t getCPUType(void); |
251 | uint8_t getCPUType(void); |
221 | uint8_t getBoardRelease(void); |
252 | uint8_t getBoardRelease(void); |
222 | 253 | ||
223 | #endif // _CONFIGURATION_H |
254 | #endif // _CONFIGURATION_H |
224 | 255 |