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