Rev 2088 | Rev 2092 | 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 | |||
1960 | - | 7 | #define MAX_CHANNELS 10 |
8 | #define MAX_MOTORS 12 |
||
9 | |||
2018 | - | 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 | |||
1612 | dongfang | 29 | typedef struct { |
2018 | - | 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; |
||
39 | |||
40 | typedef struct { |
||
1960 | - | 41 | // IMU |
42 | /*PMM*/uint8_t gyroP; |
||
2032 | - | 43 | /* P */uint8_t gyroI; |
1960 | - | 44 | /* P */uint8_t gyroD; |
2052 | - | 45 | /* P */uint8_t compassControlHeading; |
1960 | - | 46 | |
47 | // Control |
||
48 | /* P */uint8_t externalControl; |
||
49 | /* P */uint8_t dynamicStability; |
||
50 | |||
51 | // Height control |
||
52 | /*PMM*/uint8_t heightP; |
||
2032 | - | 53 | /* P */uint8_t heightI; |
1960 | - | 54 | /*PMM*/uint8_t heightD; |
55 | /* P */uint8_t heightSetting; |
||
56 | |||
57 | uint8_t attitudeControl; |
||
58 | |||
2039 | - | 59 | // Output and servo |
1960 | - | 60 | /*PMM*/uint8_t output0Timing; |
61 | /*PMM*/uint8_t output1Timing; |
||
62 | |||
63 | uint8_t servoManualControl[2]; |
||
2039 | - | 64 | |
65 | // Correction |
||
2032 | - | 66 | uint8_t levelCorrection[2]; |
1960 | - | 67 | |
2039 | - | 68 | // Simple direct navigation |
2045 | - | 69 | uint8_t naviMode; |
2039 | - | 70 | |
2032 | - | 71 | /* P */uint8_t userParams[8]; |
2059 | - | 72 | } DynamicParams_t; |
1960 | - | 73 | |
2059 | - | 74 | extern volatile DynamicParams_t dynamicParams; |
1612 | dongfang | 75 | |
1775 | - | 76 | typedef struct { |
1864 | - | 77 | uint8_t sourceIdx, targetIdx; |
78 | uint8_t min, max; |
||
1775 | - | 79 | } MMXLATION; |
1612 | dongfang | 80 | |
2059 | - | 81 | /* |
1775 | - | 82 | typedef struct { |
1864 | - | 83 | uint8_t sourceIdx, targetIdx; |
1775 | - | 84 | } XLATION; |
2059 | - | 85 | */ |
1775 | - | 86 | |
1960 | - | 87 | typedef struct { |
88 | uint8_t channels[MAX_CHANNELS]; |
||
89 | } channelMap_t; |
||
90 | extern channelMap_t channelMap; |
||
91 | |||
92 | typedef struct { |
||
2017 | - | 93 | char name[12]; |
1960 | - | 94 | int8_t motor[MAX_MOTORS][4]; |
95 | }__attribute__((packed)) mixerMatrix_t; |
||
96 | extern mixerMatrix_t mixerMatrix; |
||
97 | |||
98 | typedef struct { |
||
1965 | - | 99 | int16_t offsets[3]; |
100 | } sensorOffset_t; |
||
101 | |||
102 | typedef struct { |
||
1960 | - | 103 | uint8_t manualControl; |
1980 | - | 104 | uint8_t stabilizationFactor; |
1960 | - | 105 | uint8_t minValue; |
106 | uint8_t maxValue; |
||
107 | uint8_t flags; |
||
108 | } servo_t; |
||
109 | |||
1980 | - | 110 | #define SERVO_STABILIZATION_REVERSE 1 |
1977 | - | 111 | |
1960 | - | 112 | typedef struct { |
113 | uint8_t bitmask; |
||
114 | uint8_t timing; |
||
115 | } output_flash_t; |
||
116 | |||
1612 | dongfang | 117 | // values above 250 representing poti1 to poti4 |
118 | typedef struct { |
||
1960 | - | 119 | // Global bitflags |
120 | uint8_t bitConfig; // see upper defines for bitcoding |
||
121 | |||
122 | // IMU |
||
2015 | - | 123 | uint8_t gyroQuadrant; |
124 | uint8_t accQuadrant; |
||
125 | uint8_t imuReversedFlags; |
||
126 | |||
1960 | - | 127 | uint8_t gyroPIDFilterConstant; |
128 | uint8_t gyroDFilterConstant; |
||
129 | uint8_t accFilterConstant; |
||
130 | |||
2018 | - | 131 | uint8_t zerothOrderCorrection; |
2089 | - | 132 | uint8_t rateTolerance; |
133 | uint8_t yawRateFactor; |
||
2062 | - | 134 | |
1960 | - | 135 | uint8_t driftCompDivider; // 1/k (Koppel_ACC_Wirkung) |
136 | uint8_t driftCompLimit; // limit for gyrodrift compensation |
||
137 | |||
2051 | - | 138 | // uint8_t axisCoupling1; // Value: 0-250 Faktor, mit dem Yaw die Achsen Roll und Nick koppelt (NickRollMitkopplung) |
139 | // uint8_t axisCoupling2; // Value: 0-250 Faktor, mit dem Nick und Roll verkoppelt werden |
||
140 | // uint8_t axisCouplingYawCorrection;// Value: 0-250 Faktor, mit dem Nick und Roll verkoppelt werden |
||
1960 | - | 141 | |
2032 | - | 142 | uint8_t levelCorrection[2]; |
143 | |||
144 | // Control |
||
145 | uint8_t gyroP; |
||
146 | uint8_t gyroI; |
||
147 | uint8_t gyroD; |
||
148 | |||
149 | uint8_t attitudeControl; |
||
2051 | - | 150 | |
2032 | - | 151 | uint8_t stickP; |
152 | uint8_t stickD; |
||
153 | uint8_t stickYawP; |
||
154 | uint8_t stickThrottleD; |
||
2051 | - | 155 | |
2032 | - | 156 | uint8_t minThrottle; |
157 | uint8_t maxThrottle; |
||
2051 | - | 158 | |
2032 | - | 159 | uint8_t externalControl; // for serial Control |
160 | uint8_t motorSmoothing; |
||
1960 | - | 161 | uint8_t dynamicStability; // PID limit for Attitude controller |
2051 | - | 162 | |
2018 | - | 163 | uint8_t IFactor; |
1960 | - | 164 | uint8_t yawIFactor; |
2051 | - | 165 | |
2052 | - | 166 | uint8_t compassMode; // bitflag thing. |
2051 | - | 167 | uint8_t compassYawCorrection; |
2052 | - | 168 | uint8_t compassBendingReturnSpeed; |
169 | uint8_t compassP; |
||
2051 | - | 170 | |
2032 | - | 171 | uint8_t batteryVoltageWarning; |
172 | uint8_t emergencyThrottle; |
||
173 | uint8_t emergencyFlightDuration; |
||
1612 | dongfang | 174 | |
2032 | - | 175 | // Height Control |
2035 | - | 176 | uint8_t airpressureFilterConstant; |
177 | uint8_t airpressureWindowLength; // 0 means: Use filter. |
||
2073 | - | 178 | uint8_t airpressureDWindowLength; // values 1..5 are legal. |
2032 | - | 179 | uint8_t airpressureAccZCorrection; |
2074 | - | 180 | |
2032 | - | 181 | uint8_t heightP; |
182 | uint8_t heightI; |
||
183 | uint8_t heightD; |
||
2074 | - | 184 | |
2032 | - | 185 | uint8_t heightSetting; |
2073 | - | 186 | uint8_t heightControlMaxIntegralIn; |
187 | uint8_t heightControlMaxIntegralOut; |
||
2032 | - | 188 | uint8_t heightControlMaxThrottleChange; |
189 | |||
2074 | - | 190 | uint8_t heightControlTestOscPeriod; |
191 | uint8_t heightControlTestOscAmplitude; |
||
192 | |||
1960 | - | 193 | // Servos |
1980 | - | 194 | uint8_t servoCount; |
195 | uint8_t servoManualMaxSpeed; |
||
1960 | - | 196 | servo_t servoConfigurations[2]; // [PITCH, ROLL] |
1612 | dongfang | 197 | |
1960 | - | 198 | // Outputs |
199 | output_flash_t outputFlash[2]; |
||
200 | uint8_t outputDebugMask; |
||
1986 | - | 201 | uint8_t outputFlags; |
1612 | dongfang | 202 | |
2039 | - | 203 | // Shared for both modes of navigation |
2045 | - | 204 | uint8_t naviMode; |
2039 | - | 205 | uint8_t naviStickThreshold; |
2047 | - | 206 | uint8_t naviStickLimit; |
2039 | - | 207 | uint8_t GPSMininumSatellites; |
208 | uint8_t naviP; |
||
209 | uint8_t naviI; |
||
210 | uint8_t naviD; |
||
211 | |||
2086 | - | 212 | uint8_t naviTestOscPeriod; |
213 | uint8_t naviTestOscAmplitude; |
||
214 | |||
1960 | - | 215 | // User params |
2018 | - | 216 | uint8_t userParams[8]; |
1612 | dongfang | 217 | |
1960 | - | 218 | // Name |
2017 | - | 219 | char name[12]; |
2039 | - | 220 | } ParamSet_t; |
1960 | - | 221 | |
2039 | - | 222 | extern ParamSet_t staticParams; |
223 | |||
1612 | dongfang | 224 | // MKFlags |
225 | #define MKFLAG_MOTOR_RUN (1<<0) |
||
2055 | - | 226 | //#define MKFLAG_FLY (1<<1) |
1612 | dongfang | 227 | #define MKFLAG_CALIBRATE (1<<2) |
228 | #define MKFLAG_START (1<<3) |
||
1960 | - | 229 | #define MKFLAG_EMERGENCY_FLIGHT (1<<4) |
2035 | - | 230 | #define MKFLAG_LOWBAT (1<<5) |
1612 | dongfang | 231 | #define MKFLAG_RESERVE2 (1<<6) |
232 | #define MKFLAG_RESERVE3 (1<<7) |
||
233 | |||
1960 | - | 234 | // bit mask for staticParams.bitConfig |
1980 | - | 235 | #define CFG_SIMPLE_HEIGHT_CONTROL (1<<0) |
1961 | - | 236 | #define CFG_SIMPLE_HC_HOLD_SWITCH (1<<1) |
1980 | - | 237 | #define CFG_HEADING_HOLD (1<<2) |
2052 | - | 238 | #define CFG_COMPASS_ENABLED (1<<3) |
239 | #define CFG_UNUSED (1<<4) |
||
2088 | - | 240 | #define CFG_NAVI_ENABLED (1<<5) |
2058 | - | 241 | #define CFG_AXIS_COUPLING_ENABLED (1<<6) |
1960 | - | 242 | #define CFG_GYRO_SATURATION_PREVENTION (1<<7) |
1612 | dongfang | 243 | |
2020 | - | 244 | #define IMU_REVERSE_GYRO_PR (1<<0) |
245 | #define IMU_REVERSE_GYRO_YAW (1<<1) |
||
246 | #define IMU_REVERSE_ACC_XY (1<<2) |
||
247 | #define IMU_REVERSE_ACC_Z (1<<3) |
||
248 | |||
1612 | dongfang | 249 | #define ATMEGA644 0 |
250 | #define ATMEGA644P 1 |
||
251 | #define SYSCLK F_CPU |
||
252 | |||
2033 | - | 253 | // Not really a part of configuration, but LEDs and HW s test are the same. |
1960 | - | 254 | #define RED_OFF {if((boardRelease == 10) || (boardRelease == 20)) PORTB &=~(1<<PORTB0); else PORTB |= (1<<PORTB0);} |
255 | #define RED_ON {if((boardRelease == 10) || (boardRelease == 20)) PORTB |= (1<<PORTB0); else PORTB &=~(1<<PORTB0);} |
||
1612 | dongfang | 256 | #define RED_FLASH PORTB ^= (1<<PORTB0) |
1960 | - | 257 | #define GRN_OFF {if(boardRelease < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);} |
258 | #define GRN_ON {if(boardRelease < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);} |
||
1612 | dongfang | 259 | #define GRN_FLASH PORTB ^= (1<<PORTB1) |
260 | |||
261 | // Mixer table |
||
262 | #define MIX_THROTTLE 0 |
||
263 | #define MIX_PITCH 1 |
||
264 | #define MIX_ROLL 2 |
||
265 | #define MIX_YAW 3 |
||
266 | |||
1961 | - | 267 | #define VARIABLE_COUNT 8 |
268 | |||
1612 | dongfang | 269 | extern volatile uint8_t MKFlags; |
1960 | - | 270 | extern uint8_t requiredMotors; |
1961 | - | 271 | extern int16_t variables[VARIABLE_COUNT]; // The "Poti"s. |
1960 | - | 272 | extern uint8_t boardRelease; |
1612 | dongfang | 273 | extern uint8_t CPUType; |
274 | |||
1963 | - | 275 | extern volatile uint8_t MKFlags; |
276 | extern uint16_t isFlying; |
||
277 | |||
1960 | - | 278 | void channelMap_default(void); |
279 | void paramSet_default(uint8_t setnumber); |
||
280 | void mixerMatrix_default(void); |
||
281 | |||
2059 | - | 282 | void configuration_setNormalFlightParameters(void); |
283 | void configuration_setFailsafeFlightParameters(void); |
||
1612 | dongfang | 284 | void configuration_applyVariablesToParams(void); |
2059 | - | 285 | |
2088 | - | 286 | void setCPUType(void); |
287 | void setBoardRelease(void); |
||
1612 | dongfang | 288 | |
2059 | - | 289 | // Called after a change in configuration parameters, as a hook for modules to take over changes. |
290 | void configuration_paramSetDidChange(void); |
||
1612 | dongfang | 291 | #endif // _CONFIGURATION_H |