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