Rev 2035 | Rev 2045 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2035 | Rev 2039 | ||
---|---|---|---|
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 compassYawEffect; |
45 | /* P */uint8_t compassYawEffect; |
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 | // The rest... |
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 | ||
- | 66 | // Correction |
|
65 | uint8_t levelCorrection[2]; |
67 | uint8_t levelCorrection[2]; |
- | 68 | ||
- | 69 | // Simple direct navigation |
|
- | 70 | uint8_t directGPSMode; |
|
66 | 71 | ||
67 | /* P */uint8_t userParams[8]; |
72 | /* P */uint8_t userParams[8]; |
68 | } dynamicParam_t; |
73 | } dynamicParam_t; |
69 | 74 | ||
70 | extern volatile dynamicParam_t dynamicParams; |
75 | extern volatile dynamicParam_t dynamicParams; |
71 | 76 | ||
72 | typedef struct { |
77 | typedef struct { |
73 | uint8_t sourceIdx, targetIdx; |
78 | uint8_t sourceIdx, targetIdx; |
74 | uint8_t min, max; |
79 | uint8_t min, max; |
75 | } MMXLATION; |
80 | } MMXLATION; |
76 | 81 | ||
77 | typedef struct { |
82 | typedef struct { |
78 | uint8_t sourceIdx, targetIdx; |
83 | uint8_t sourceIdx, targetIdx; |
79 | } XLATION; |
84 | } XLATION; |
80 | 85 | ||
81 | typedef struct { |
86 | typedef struct { |
82 | uint8_t channels[MAX_CHANNELS]; |
87 | uint8_t channels[MAX_CHANNELS]; |
83 | } channelMap_t; |
88 | } channelMap_t; |
84 | extern channelMap_t channelMap; |
89 | extern channelMap_t channelMap; |
85 | 90 | ||
86 | typedef struct { |
91 | typedef struct { |
87 | char name[12]; |
92 | char name[12]; |
88 | int8_t motor[MAX_MOTORS][4]; |
93 | int8_t motor[MAX_MOTORS][4]; |
89 | }__attribute__((packed)) mixerMatrix_t; |
94 | }__attribute__((packed)) mixerMatrix_t; |
90 | extern mixerMatrix_t mixerMatrix; |
95 | extern mixerMatrix_t mixerMatrix; |
91 | 96 | ||
92 | typedef struct { |
97 | typedef struct { |
93 | int16_t offsets[3]; |
98 | int16_t offsets[3]; |
94 | } sensorOffset_t; |
99 | } sensorOffset_t; |
95 | 100 | ||
96 | typedef struct { |
101 | typedef struct { |
97 | uint8_t manualControl; |
102 | uint8_t manualControl; |
98 | uint8_t stabilizationFactor; |
103 | uint8_t stabilizationFactor; |
99 | uint8_t minValue; |
104 | uint8_t minValue; |
100 | uint8_t maxValue; |
105 | uint8_t maxValue; |
101 | uint8_t flags; |
106 | uint8_t flags; |
102 | } servo_t; |
107 | } servo_t; |
103 | 108 | ||
104 | #define SERVO_STABILIZATION_REVERSE 1 |
109 | #define SERVO_STABILIZATION_REVERSE 1 |
105 | 110 | ||
106 | typedef struct { |
111 | typedef struct { |
107 | uint8_t bitmask; |
112 | uint8_t bitmask; |
108 | uint8_t timing; |
113 | uint8_t timing; |
109 | } output_flash_t; |
114 | } output_flash_t; |
110 | 115 | ||
111 | // values above 250 representing poti1 to poti4 |
116 | // values above 250 representing poti1 to poti4 |
112 | typedef struct { |
117 | typedef struct { |
113 | // Global bitflags |
118 | // Global bitflags |
114 | uint8_t bitConfig; // see upper defines for bitcoding |
119 | uint8_t bitConfig; // see upper defines for bitcoding |
115 | 120 | ||
116 | // IMU |
121 | // IMU |
117 | uint8_t gyroQuadrant; |
122 | uint8_t gyroQuadrant; |
118 | uint8_t accQuadrant; |
123 | uint8_t accQuadrant; |
119 | uint8_t imuReversedFlags; |
124 | uint8_t imuReversedFlags; |
120 | 125 | ||
121 | uint8_t gyroPIDFilterConstant; |
126 | uint8_t gyroPIDFilterConstant; |
122 | uint8_t gyroATTFilterConstant; |
127 | uint8_t gyroATTFilterConstant; |
123 | uint8_t gyroDFilterConstant; |
128 | uint8_t gyroDFilterConstant; |
124 | uint8_t accFilterConstant; |
129 | uint8_t accFilterConstant; |
125 | 130 | ||
126 | uint8_t maxAccVector; |
131 | uint8_t maxAccVector; |
127 | uint8_t maxControlActivity; |
132 | uint8_t maxControlActivity; |
128 | uint8_t zerothOrderCorrection; |
133 | uint8_t zerothOrderCorrection; |
129 | uint8_t driftCompDivider; // 1/k (Koppel_ACC_Wirkung) |
134 | uint8_t driftCompDivider; // 1/k (Koppel_ACC_Wirkung) |
130 | uint8_t driftCompLimit; // limit for gyrodrift compensation |
135 | uint8_t driftCompLimit; // limit for gyrodrift compensation |
131 | 136 | ||
132 | 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) |
133 | 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 |
134 | 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 |
135 | 140 | ||
136 | uint8_t levelCorrection[2]; |
141 | uint8_t levelCorrection[2]; |
137 | 142 | ||
138 | // Control |
143 | // Control |
139 | uint8_t gyroP; |
144 | uint8_t gyroP; |
140 | uint8_t gyroI; |
145 | uint8_t gyroI; |
141 | uint8_t gyroD; |
146 | uint8_t gyroD; |
142 | 147 | ||
143 | uint8_t attitudeControl; |
148 | uint8_t attitudeControl; |
144 | uint8_t stickP; |
149 | uint8_t stickP; |
145 | uint8_t stickD; |
150 | uint8_t stickD; |
146 | uint8_t stickYawP; |
151 | uint8_t stickYawP; |
147 | uint8_t stickThrottleD; |
152 | uint8_t stickThrottleD; |
148 | uint8_t minThrottle; |
153 | uint8_t minThrottle; |
149 | uint8_t maxThrottle; |
154 | uint8_t maxThrottle; |
150 | uint8_t externalControl; // for serial Control |
155 | uint8_t externalControl; // for serial Control |
151 | uint8_t motorSmoothing; |
156 | uint8_t motorSmoothing; |
152 | uint8_t dynamicStability; // PID limit for Attitude controller |
157 | uint8_t dynamicStability; // PID limit for Attitude controller |
153 | uint8_t IFactor; |
158 | uint8_t IFactor; |
154 | uint8_t yawIFactor; |
159 | uint8_t yawIFactor; |
155 | uint8_t compassYawEffect; |
160 | uint8_t compassYawEffect; |
156 | uint8_t batteryVoltageWarning; |
161 | uint8_t batteryVoltageWarning; |
157 | uint8_t emergencyThrottle; |
162 | uint8_t emergencyThrottle; |
158 | uint8_t emergencyFlightDuration; |
163 | uint8_t emergencyFlightDuration; |
159 | 164 | ||
160 | // Height Control |
165 | // Height Control |
161 | uint8_t airpressureFilterConstant; |
166 | uint8_t airpressureFilterConstant; |
162 | uint8_t airpressureWindowLength; // 0 means: Use filter. |
167 | uint8_t airpressureWindowLength; // 0 means: Use filter. |
163 | uint8_t airpressureAccZCorrection; |
168 | uint8_t airpressureAccZCorrection; |
164 | uint8_t heightP; |
169 | uint8_t heightP; |
165 | uint8_t heightI; |
170 | uint8_t heightI; |
166 | uint8_t heightD; |
171 | uint8_t heightD; |
167 | uint8_t heightSetting; |
172 | uint8_t heightSetting; |
168 | uint8_t heightControlMaxIntegral; |
173 | uint8_t heightControlMaxIntegral; |
169 | uint8_t heightControlMaxThrottleChange; |
174 | uint8_t heightControlMaxThrottleChange; |
170 | uint8_t heightSlewRate; |
175 | uint8_t heightSlewRate; |
171 | 176 | ||
172 | // Servos |
177 | // Servos |
173 | uint8_t servoCount; |
178 | uint8_t servoCount; |
174 | uint8_t servoManualMaxSpeed; |
179 | uint8_t servoManualMaxSpeed; |
175 | servo_t servoConfigurations[2]; // [PITCH, ROLL] |
180 | servo_t servoConfigurations[2]; // [PITCH, ROLL] |
176 | 181 | ||
177 | // Outputs |
182 | // Outputs |
178 | output_flash_t outputFlash[2]; |
183 | output_flash_t outputFlash[2]; |
179 | uint8_t outputDebugMask; |
184 | uint8_t outputDebugMask; |
180 | uint8_t outputFlags; |
185 | uint8_t outputFlags; |
- | 186 | ||
- | 187 | // Simple direct navigation |
|
- | 188 | uint8_t directNaviMode; |
|
- | 189 | ||
- | 190 | // NaviCtrl navigation |
|
- | 191 | ||
- | 192 | ||
- | 193 | // Shared for both modes of navigation |
|
- | 194 | uint8_t naviStickThreshold; |
|
- | 195 | uint8_t GPSMininumSatellites; |
|
- | 196 | uint8_t naviP; |
|
- | 197 | uint8_t naviI; |
|
- | 198 | uint8_t naviD; |
|
181 | 199 | ||
182 | // User params |
200 | // User params |
183 | uint8_t userParams[8]; |
201 | uint8_t userParams[8]; |
184 | 202 | ||
185 | // Name |
203 | // Name |
186 | char name[12]; |
204 | char name[12]; |
187 | } paramset_t; |
205 | } ParamSet_t; |
- | 206 | ||
188 | extern paramset_t staticParams; |
207 | extern ParamSet_t staticParams; |
189 | 208 | ||
190 | // MKFlags |
209 | // MKFlags |
191 | #define MKFLAG_MOTOR_RUN (1<<0) |
210 | #define MKFLAG_MOTOR_RUN (1<<0) |
192 | #define MKFLAG_FLY (1<<1) |
211 | #define MKFLAG_FLY (1<<1) |
193 | #define MKFLAG_CALIBRATE (1<<2) |
212 | #define MKFLAG_CALIBRATE (1<<2) |
194 | #define MKFLAG_START (1<<3) |
213 | #define MKFLAG_START (1<<3) |
195 | #define MKFLAG_EMERGENCY_FLIGHT (1<<4) |
214 | #define MKFLAG_EMERGENCY_FLIGHT (1<<4) |
196 | #define MKFLAG_LOWBAT (1<<5) |
215 | #define MKFLAG_LOWBAT (1<<5) |
197 | #define MKFLAG_RESERVE2 (1<<6) |
216 | #define MKFLAG_RESERVE2 (1<<6) |
198 | #define MKFLAG_RESERVE3 (1<<7) |
217 | #define MKFLAG_RESERVE3 (1<<7) |
199 | 218 | ||
200 | // bit mask for staticParams.bitConfig |
219 | // bit mask for staticParams.bitConfig |
201 | #define CFG_SIMPLE_HEIGHT_CONTROL (1<<0) |
220 | #define CFG_SIMPLE_HEIGHT_CONTROL (1<<0) |
202 | #define CFG_SIMPLE_HC_HOLD_SWITCH (1<<1) |
221 | #define CFG_SIMPLE_HC_HOLD_SWITCH (1<<1) |
203 | #define CFG_HEADING_HOLD (1<<2) |
222 | #define CFG_HEADING_HOLD (1<<2) |
204 | #define CFG_COMPASS_ACTIVE (1<<3) |
223 | #define CFG_COMPASS_ACTIVE (1<<3) |
205 | #define CFG_COMPASS_FIX (1<<4) |
224 | #define CFG_COMPASS_FIX (1<<4) |
206 | #define CFG_GPS_ACTIVE (1<<5) |
225 | #define CFG_GPS_ACTIVE (1<<5) |
207 | #define CFG_AXIS_COUPLING_ACTIVE (1<<6) |
226 | #define CFG_AXIS_COUPLING_ACTIVE (1<<6) |
208 | #define CFG_GYRO_SATURATION_PREVENTION (1<<7) |
227 | #define CFG_GYRO_SATURATION_PREVENTION (1<<7) |
209 | 228 | ||
210 | #define IMU_REVERSE_GYRO_PR (1<<0) |
229 | #define IMU_REVERSE_GYRO_PR (1<<0) |
211 | #define IMU_REVERSE_GYRO_YAW (1<<1) |
230 | #define IMU_REVERSE_GYRO_YAW (1<<1) |
212 | #define IMU_REVERSE_ACC_XY (1<<2) |
231 | #define IMU_REVERSE_ACC_XY (1<<2) |
213 | #define IMU_REVERSE_ACC_Z (1<<3) |
232 | #define IMU_REVERSE_ACC_Z (1<<3) |
214 | 233 | ||
215 | #define ATMEGA644 0 |
234 | #define ATMEGA644 0 |
216 | #define ATMEGA644P 1 |
235 | #define ATMEGA644P 1 |
217 | #define SYSCLK F_CPU |
236 | #define SYSCLK F_CPU |
218 | 237 | ||
219 | // Not really a part of configuration, but LEDs and HW s test are the same. |
238 | // Not really a part of configuration, but LEDs and HW s test are the same. |
220 | #define RED_OFF {if((boardRelease == 10) || (boardRelease == 20)) PORTB &=~(1<<PORTB0); else PORTB |= (1<<PORTB0);} |
239 | #define RED_OFF {if((boardRelease == 10) || (boardRelease == 20)) PORTB &=~(1<<PORTB0); else PORTB |= (1<<PORTB0);} |
221 | #define RED_ON {if((boardRelease == 10) || (boardRelease == 20)) PORTB |= (1<<PORTB0); else PORTB &=~(1<<PORTB0);} |
240 | #define RED_ON {if((boardRelease == 10) || (boardRelease == 20)) PORTB |= (1<<PORTB0); else PORTB &=~(1<<PORTB0);} |
222 | #define RED_FLASH PORTB ^= (1<<PORTB0) |
241 | #define RED_FLASH PORTB ^= (1<<PORTB0) |
223 | #define GRN_OFF {if(boardRelease < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);} |
242 | #define GRN_OFF {if(boardRelease < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);} |
224 | #define GRN_ON {if(boardRelease < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);} |
243 | #define GRN_ON {if(boardRelease < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);} |
225 | #define GRN_FLASH PORTB ^= (1<<PORTB1) |
244 | #define GRN_FLASH PORTB ^= (1<<PORTB1) |
226 | 245 | ||
227 | // Mixer table |
246 | // Mixer table |
228 | #define MIX_THROTTLE 0 |
247 | #define MIX_THROTTLE 0 |
229 | #define MIX_PITCH 1 |
248 | #define MIX_PITCH 1 |
230 | #define MIX_ROLL 2 |
249 | #define MIX_ROLL 2 |
231 | #define MIX_YAW 3 |
250 | #define MIX_YAW 3 |
232 | 251 | ||
233 | #define VARIABLE_COUNT 8 |
252 | #define VARIABLE_COUNT 8 |
234 | 253 | ||
235 | extern volatile uint8_t MKFlags; |
254 | extern volatile uint8_t MKFlags; |
236 | extern uint8_t requiredMotors; |
255 | extern uint8_t requiredMotors; |
237 | extern int16_t variables[VARIABLE_COUNT]; // The "Poti"s. |
256 | extern int16_t variables[VARIABLE_COUNT]; // The "Poti"s. |
238 | extern uint8_t boardRelease; |
257 | extern uint8_t boardRelease; |
239 | extern uint8_t CPUType; |
258 | extern uint8_t CPUType; |
240 | 259 | ||
241 | extern volatile uint8_t MKFlags; |
260 | extern volatile uint8_t MKFlags; |
242 | extern uint16_t isFlying; |
261 | extern uint16_t isFlying; |
243 | 262 | ||
244 | void channelMap_default(void); |
263 | void channelMap_default(void); |
245 | void paramSet_default(uint8_t setnumber); |
264 | void paramSet_default(uint8_t setnumber); |
246 | void mixerMatrix_default(void); |
265 | void mixerMatrix_default(void); |
247 | 266 | ||
248 | void configuration_applyVariablesToParams(void); |
267 | void configuration_applyVariablesToParams(void); |
249 | uint8_t getCPUType(void); |
268 | uint8_t getCPUType(void); |
250 | uint8_t getBoardRelease(void); |
269 | uint8_t getBoardRelease(void); |
251 | 270 | ||
252 | #endif // _CONFIGURATION_H |
271 | #endif // _CONFIGURATION_H |
253 | 272 |