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