Rev 2160 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1612 | dongfang | 1 | #ifndef _CONFIGURATION_H |
2 | #define _CONFIGURATION_H |
||
3 | |||
4 | #include <inttypes.h> |
||
5 | #include <avr/io.h> |
||
6 | |||
2189 | - | 7 | #define MAX_CONTROLCHANNELS 8 |
8 | #define MAX_I2CCHANNELS 8 |
||
9 | #define MAX_PWMCHANNELS 8 |
||
1960 | - | 10 | |
2018 | - | 11 | // bitmask for VersionInfo_t.HardwareError[0] |
2189 | - | 12 | #define FC_ERROR0_GYRO_X 0x01 |
13 | #define FC_ERROR0_GYRO_Y 0x02 |
||
14 | #define FC_ERROR0_GYRO_Z 0x04 |
||
15 | #define FC_ERROR0_ACCEL_X 0x08 |
||
16 | #define FC_ERROR0_ACCEL_Y 0x10 |
||
17 | #define FC_ERROR0_ACCEL_Z 0x20 |
||
2018 | - | 18 | #define FC_ERROR0_PRESSURE 0x40 |
19 | #define FC_ERROR1_RES0 0x80 |
||
20 | // bitmask for VersionInfo_t.HardwareError[1] |
||
21 | #define FC_ERROR1_I2C 0x01 |
||
22 | #define FC_ERROR1_BL_MISSING 0x02 |
||
23 | #define FC_ERROR1_SPI_RX 0x04 |
||
24 | #define FC_ERROR1_PPM 0x08 |
||
25 | #define FC_ERROR1_MIXER 0x10 |
||
26 | #define FC_ERROR1_RES1 0x20 |
||
27 | #define FC_ERROR1_RES2 0x40 |
||
28 | #define FC_ERROR1_RES3 0x80 |
||
29 | |||
2189 | - | 30 | #define PID_NORMAL_VALUE 100 |
31 | |||
1612 | dongfang | 32 | typedef struct { |
2018 | - | 33 | uint8_t SWMajor; |
34 | uint8_t SWMinor; |
||
2189 | - | 35 | uint8_t SWPatch; |
2018 | - | 36 | uint8_t protoMajor; |
37 | uint8_t protoMinor; |
||
38 | uint8_t hardwareErrors[5]; |
||
39 | }__attribute__((packed)) VersionInfo_t; |
||
40 | |||
41 | extern VersionInfo_t versionInfo; |
||
42 | |||
43 | typedef struct { |
||
2189 | - | 44 | uint8_t flightMode; |
45 | |||
46 | uint8_t attGyroP; // Attitude mode Proportional (attitude error to control) |
||
47 | uint8_t attGyroI; // Attitude mode Integral (attitude error integral to control. Serves to eliminate permanent attitude errors) |
||
48 | uint8_t attGyroD; // Attitude mode rate |
||
49 | |||
50 | uint8_t rateGyroP; // Rate mode Proportional |
||
51 | uint8_t rateGyroI; // Rate mode Integral (serves to eliminate slow rotation errors in rate mode) |
||
52 | uint8_t rateGyroD; // Rate mode Differential (GyroD) |
||
1960 | - | 53 | |
2189 | - | 54 | uint8_t yawGyroP; |
55 | uint8_t yawGyroI; |
||
56 | uint8_t yawGyroD; |
||
57 | |||
1960 | - | 58 | // Control |
2189 | - | 59 | uint8_t externalControl; |
60 | uint8_t attitudeControl; |
||
61 | |||
1960 | - | 62 | // Height control |
2189 | - | 63 | uint8_t heightP; |
64 | uint8_t heightI; |
||
65 | uint8_t heightD; |
||
66 | uint8_t heightSetting; |
||
1960 | - | 67 | |
68 | |||
2039 | - | 69 | // Output and servo |
2189 | - | 70 | uint8_t output0Timing; |
71 | uint8_t output1Timing; |
||
1960 | - | 72 | |
73 | uint8_t servoManualControl[2]; |
||
2039 | - | 74 | |
75 | // Correction |
||
2032 | - | 76 | uint8_t levelCorrection[2]; |
1960 | - | 77 | |
2039 | - | 78 | // Simple direct navigation |
2045 | - | 79 | uint8_t naviMode; |
2039 | - | 80 | |
2032 | - | 81 | /* P */uint8_t userParams[8]; |
2059 | - | 82 | } DynamicParams_t; |
1960 | - | 83 | |
2059 | - | 84 | extern volatile DynamicParams_t dynamicParams; |
1612 | dongfang | 85 | |
1775 | - | 86 | typedef struct { |
1864 | - | 87 | uint8_t sourceIdx, targetIdx; |
88 | uint8_t min, max; |
||
1775 | - | 89 | } MMXLATION; |
1612 | dongfang | 90 | |
2059 | - | 91 | /* |
1775 | - | 92 | typedef struct { |
1864 | - | 93 | uint8_t sourceIdx, targetIdx; |
1775 | - | 94 | } XLATION; |
2059 | - | 95 | */ |
1775 | - | 96 | |
1960 | - | 97 | typedef struct { |
2160 | - | 98 | uint8_t RCPolarity; // 1=positive, 0=negative. Use positive with Futaba receiver, negative with FrSky. |
99 | uint8_t HWTrim; |
||
2117 | - | 100 | uint8_t variableOffset; |
2189 | - | 101 | uint8_t channels[MAX_CONTROLCHANNELS]; |
2117 | - | 102 | } ChannelMap_t; |
2160 | - | 103 | |
2117 | - | 104 | extern ChannelMap_t channelMap; |
1960 | - | 105 | |
2189 | - | 106 | #define LOG_MOTOR_MIXER_UNIT 6 |
107 | #define LOG_DYNAMIC_STABILITY_SCALER 6 |
||
108 | |||
109 | typedef enum { |
||
110 | MIXER_SOURCE_ROLL = 0, |
||
111 | MIXER_SOURCE_PITCH = 1, |
||
112 | MIXER_SOURCE_THROTTLE = 2, |
||
113 | MIXER_SOURCE_YAW = 3 |
||
114 | } MixerSource_Control; |
||
115 | |||
116 | typedef enum { |
||
117 | MIXER_SOURCE_AUX_GIMBAL_ROLL = 0, |
||
118 | MIXER_SOURCE_AUX_GIMBAL_PITCH = 1, |
||
119 | MIXER_SOURCE_AUX_RCCHANNEL = 2, |
||
120 | MIXER_SOURCE_AUX_END = 2 + MAX_CONTROLCHANNELS |
||
121 | } MixerSourceAux; |
||
122 | |||
123 | typedef enum { |
||
124 | I2C0 = 0, |
||
125 | I2C1 = 1, |
||
126 | I2C2 = 2, |
||
127 | I2C3 = 3, |
||
128 | I2C4 = 4, |
||
129 | I2C5 = 5, |
||
130 | I2C6 = 6, |
||
131 | I2C7 = 7, |
||
132 | SERVO0 = MAX_I2CCHANNELS, |
||
133 | NUM_OUTPUTS = 8 + MAX_PWMCHANNELS |
||
134 | } MixerDestination; |
||
135 | |||
1960 | - | 136 | typedef struct { |
2189 | - | 137 | uint8_t outputType; |
138 | uint8_t minValue; |
||
139 | uint8_t maxValue; |
||
140 | int8_t flightControls[4]; |
||
141 | uint8_t auxSource; // for selecting a gimbal axis or an RC channel. |
||
142 | uint8_t oppositeMotor; // only relevant where used to control a multicopter motor. |
||
143 | }__attribute__((packed)) MixerMatrixRow_t; |
||
1960 | - | 144 | |
2189 | - | 145 | typedef MixerMatrixRow_t OutputMixer_t[NUM_OUTPUTS]; |
146 | extern OutputMixer_t outputMixer; |
||
147 | |||
148 | typedef enum { |
||
149 | OUTPUT_TYPE_UNDEFINED, |
||
150 | OUTPUT_TYPE_MOTOR, |
||
151 | OUTPUT_TYPE_SERVO |
||
152 | } outputTypes; |
||
153 | |||
1960 | - | 154 | typedef struct { |
1965 | - | 155 | int16_t offsets[3]; |
156 | } sensorOffset_t; |
||
157 | |||
158 | typedef struct { |
||
1960 | - | 159 | uint8_t manualControl; |
1980 | - | 160 | uint8_t stabilizationFactor; |
1960 | - | 161 | uint8_t flags; |
2117 | - | 162 | } Servo_t; |
1960 | - | 163 | |
1980 | - | 164 | #define SERVO_STABILIZATION_REVERSE 1 |
1977 | - | 165 | |
1960 | - | 166 | typedef struct { |
167 | uint8_t bitmask; |
||
168 | uint8_t timing; |
||
169 | } output_flash_t; |
||
170 | |||
1612 | dongfang | 171 | typedef struct { |
2189 | - | 172 | /* Set up so that |
173 | * Nose-up is positive on pitch |
||
174 | * Roll-right is positive on roll |
||
175 | * Turn-ccw is positive on yaw |
||
176 | */ |
||
2015 | - | 177 | uint8_t gyroQuadrant; |
2189 | - | 178 | /* |
179 | * Set up so that: |
||
180 | * Acc. Z is +1g in normal attitude |
||
181 | * Acc. X gets positive in a left roll |
||
182 | * Acc. Y gets positive in a nose-up attitude. |
||
183 | */ |
||
2015 | - | 184 | uint8_t accQuadrant; |
185 | uint8_t imuReversedFlags; |
||
1960 | - | 186 | uint8_t gyroPIDFilterConstant; |
2095 | - | 187 | uint8_t gyroDWindowLength; |
1960 | - | 188 | uint8_t accFilterConstant; |
189 | |||
2092 | - | 190 | } IMUConfig_t; |
1960 | - | 191 | |
2092 | - | 192 | extern IMUConfig_t IMUConfig; |
193 | |||
194 | // values above 250 representing poti1 to poti4 |
||
195 | typedef struct { |
||
196 | // Global bitflags |
||
197 | uint8_t bitConfig; // see upper defines for bitcoding |
||
198 | |||
2189 | - | 199 | uint8_t flightMode; |
200 | |||
2051 | - | 201 | // uint8_t axisCoupling1; // Value: 0-250 Faktor, mit dem Yaw die Achsen Roll und Nick koppelt (NickRollMitkopplung) |
202 | // uint8_t axisCoupling2; // Value: 0-250 Faktor, mit dem Nick und Roll verkoppelt werden |
||
203 | // uint8_t axisCouplingYawCorrection;// Value: 0-250 Faktor, mit dem Nick und Roll verkoppelt werden |
||
1960 | - | 204 | |
2032 | - | 205 | uint8_t levelCorrection[2]; |
206 | |||
207 | // Control |
||
2189 | - | 208 | uint8_t attGyroP; // Attitude mode Proportional (attitude error to control) |
209 | uint8_t attGyroI; // Attitude mode Integral (attitude error integral to control. Serves to eliminate permanent attitude errors) |
||
210 | uint8_t attGyroIMax; // Attitude mode Integral max. limit |
||
211 | uint8_t attGyroD; // Attitude mode rate |
||
212 | |||
213 | uint8_t rateGyroP; // Rate mode Proportional |
||
214 | uint8_t rateGyroI; // Rate mode Integral (serves to eliminate slow rotation errors in rate mode) |
||
215 | uint8_t rateGyroIMax; // Rate mode Integral max. limit |
||
216 | uint8_t rateGyroD; // Rate mode Differential (GyroD) |
||
2032 | - | 217 | |
2189 | - | 218 | uint8_t yawGyroP; |
219 | uint8_t yawGyroI; |
||
220 | uint8_t yawGyroD; |
||
221 | |||
222 | uint8_t externalControl; // for serial Control |
||
2032 | - | 223 | uint8_t attitudeControl; |
2189 | - | 224 | uint8_t dynamicStability; |
2051 | - | 225 | |
2032 | - | 226 | uint8_t stickP; |
227 | uint8_t stickD; |
||
228 | uint8_t stickYawP; |
||
229 | uint8_t stickThrottleD; |
||
2051 | - | 230 | |
2189 | - | 231 | // Idle throttle. Affects the throttle stick only. |
2032 | - | 232 | uint8_t minThrottle; |
2189 | - | 233 | // Value of max. throttle stick. |
2032 | - | 234 | uint8_t maxThrottle; |
2051 | - | 235 | |
2052 | - | 236 | uint8_t compassMode; // bitflag thing. |
2051 | - | 237 | uint8_t compassYawCorrection; |
2052 | - | 238 | uint8_t compassBendingReturnSpeed; |
239 | uint8_t compassP; |
||
2051 | - | 240 | |
2032 | - | 241 | uint8_t batteryVoltageWarning; |
242 | uint8_t emergencyThrottle; |
||
243 | uint8_t emergencyFlightDuration; |
||
1612 | dongfang | 244 | |
2032 | - | 245 | // Height Control |
2035 | - | 246 | uint8_t airpressureFilterConstant; |
247 | uint8_t airpressureWindowLength; // 0 means: Use filter. |
||
2073 | - | 248 | uint8_t airpressureDWindowLength; // values 1..5 are legal. |
2032 | - | 249 | uint8_t airpressureAccZCorrection; |
2074 | - | 250 | |
2032 | - | 251 | uint8_t heightP; |
252 | uint8_t heightI; |
||
253 | uint8_t heightD; |
||
2074 | - | 254 | |
2032 | - | 255 | uint8_t heightSetting; |
2073 | - | 256 | uint8_t heightControlMaxIntegralIn; |
257 | uint8_t heightControlMaxIntegralOut; |
||
2032 | - | 258 | uint8_t heightControlMaxThrottleChange; |
259 | |||
2074 | - | 260 | uint8_t heightControlTestOscPeriod; |
261 | uint8_t heightControlTestOscAmplitude; |
||
262 | |||
1960 | - | 263 | // Servos |
1980 | - | 264 | uint8_t servoCount; |
265 | uint8_t servoManualMaxSpeed; |
||
2117 | - | 266 | Servo_t servoConfigurations[2]; // [PITCH, ROLL] |
1612 | dongfang | 267 | |
1960 | - | 268 | // Outputs |
269 | output_flash_t outputFlash[2]; |
||
270 | uint8_t outputDebugMask; |
||
1986 | - | 271 | uint8_t outputFlags; |
1612 | dongfang | 272 | |
2039 | - | 273 | // Shared for both modes of navigation |
2045 | - | 274 | uint8_t naviMode; |
2039 | - | 275 | uint8_t naviStickThreshold; |
2047 | - | 276 | uint8_t naviStickLimit; |
2039 | - | 277 | uint8_t GPSMininumSatellites; |
278 | uint8_t naviP; |
||
279 | uint8_t naviI; |
||
280 | uint8_t naviD; |
||
281 | |||
2086 | - | 282 | uint8_t naviTestOscPeriod; |
283 | uint8_t naviTestOscAmplitude; |
||
284 | |||
1960 | - | 285 | // User params |
2018 | - | 286 | uint8_t userParams[8]; |
1612 | dongfang | 287 | |
1960 | - | 288 | // Name |
2017 | - | 289 | char name[12]; |
2039 | - | 290 | } ParamSet_t; |
1960 | - | 291 | |
2039 | - | 292 | extern ParamSet_t staticParams; |
293 | |||
1612 | dongfang | 294 | // MKFlags |
2189 | - | 295 | #define MKFLAG_MOTOR_RUN (1<<0) |
2055 | - | 296 | //#define MKFLAG_FLY (1<<1) |
2189 | - | 297 | //#define MKFLAG_CALIBRATE (1<<2) |
1960 | - | 298 | #define MKFLAG_EMERGENCY_FLIGHT (1<<4) |
2189 | - | 299 | #define MKFLAG_LOWBAT (1<<5) |
300 | //#define MKFLAG_RESERVE2 (1<<6) |
||
301 | //#define MKFLAG_RESERVE3 (1<<7) |
||
1612 | dongfang | 302 | |
1960 | - | 303 | // bit mask for staticParams.bitConfig |
1980 | - | 304 | #define CFG_SIMPLE_HEIGHT_CONTROL (1<<0) |
1961 | - | 305 | #define CFG_SIMPLE_HC_HOLD_SWITCH (1<<1) |
2189 | - | 306 | #define CFG_UNUSED (1<<2) |
2052 | - | 307 | #define CFG_COMPASS_ENABLED (1<<3) |
2189 | - | 308 | #define CFG_UNUSED2 (1<<4) |
2088 | - | 309 | #define CFG_NAVI_ENABLED (1<<5) |
2189 | - | 310 | #define CFG_UNUSED3 (1<<6) |
1960 | - | 311 | #define CFG_GYRO_SATURATION_PREVENTION (1<<7) |
1612 | dongfang | 312 | |
2189 | - | 313 | #define IMU_REVERSE_GYRO_XY (1<<0) |
314 | #define IMU_REVERSE_GYRO_Z (1<<1) |
||
315 | #define IMU_REVERSE_ACCEL_XY (1<<2) |
||
316 | #define IMU_REVERSE_ACCEL_Z (1<<3) |
||
2020 | - | 317 | |
1612 | dongfang | 318 | #define ATMEGA644 0 |
319 | #define ATMEGA644P 1 |
||
320 | |||
2033 | - | 321 | // Not really a part of configuration, but LEDs and HW s test are the same. |
1960 | - | 322 | #define RED_OFF {if((boardRelease == 10) || (boardRelease == 20)) PORTB &=~(1<<PORTB0); else PORTB |= (1<<PORTB0);} |
323 | #define RED_ON {if((boardRelease == 10) || (boardRelease == 20)) PORTB |= (1<<PORTB0); else PORTB &=~(1<<PORTB0);} |
||
1612 | dongfang | 324 | #define RED_FLASH PORTB ^= (1<<PORTB0) |
1960 | - | 325 | #define GRN_OFF {if(boardRelease < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);} |
326 | #define GRN_ON {if(boardRelease < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);} |
||
1612 | dongfang | 327 | #define GRN_FLASH PORTB ^= (1<<PORTB1) |
328 | |||
329 | // Mixer table |
||
330 | |||
2158 | - | 331 | #define VARIABLE_COUNT 8 |
1961 | - | 332 | |
1612 | dongfang | 333 | extern volatile uint8_t MKFlags; |
1961 | - | 334 | extern int16_t variables[VARIABLE_COUNT]; // The "Poti"s. |
1960 | - | 335 | extern uint8_t boardRelease; |
1612 | dongfang | 336 | extern uint8_t CPUType; |
337 | |||
1963 | - | 338 | extern volatile uint8_t MKFlags; |
339 | extern uint16_t isFlying; |
||
340 | |||
2092 | - | 341 | void IMUConfig_default(void); |
1960 | - | 342 | void channelMap_default(void); |
343 | void paramSet_default(uint8_t setnumber); |
||
2189 | - | 344 | void outputMixer_default(void); |
1960 | - | 345 | |
2189 | - | 346 | void configuration_setNormalFlightMode(void); |
347 | void configuration_setFailsafeFlightMode(void); |
||
1612 | dongfang | 348 | void configuration_applyVariablesToParams(void); |
2059 | - | 349 | |
2088 | - | 350 | void setCPUType(void); |
351 | void setBoardRelease(void); |
||
1612 | dongfang | 352 | |
2059 | - | 353 | // Called after a change in configuration parameters, as a hook for modules to take over changes. |
354 | void configuration_paramSetDidChange(void); |
||
1612 | dongfang | 355 | #endif // _CONFIGURATION_H |