Rev 2099 | Rev 2104 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1910 | - | 1 | #ifndef _CONFIGURATION_H |
2 | #define _CONFIGURATION_H |
||
3 | |||
4 | #include <inttypes.h> |
||
5 | #include <avr/io.h> |
||
6 | |||
2099 | - | 7 | #define MAX_CHANNELS 10 |
8 | #define MAX_MOTORS 12 |
||
9 | |||
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 | |||
2102 | - | 29 | typedef enum { |
30 | FLIGHT_MODE_NONE, |
||
31 | FLIGHT_MODE_MANUAL, |
||
32 | FLIGHT_MODE_RATE, |
||
33 | FLIGHT_MODE_ANGLES |
||
34 | } FlightMode_t; |
||
35 | |||
36 | #define CONTROL_SERVO_REVERSE_ELEVATOR 1 |
||
37 | #define CONTROL_SERVO_REVERSE_AILERONS 2 |
||
38 | #define CONTROL_SERVO_REVERSE_RUDDER 4 |
||
39 | |||
1910 | - | 40 | typedef struct { |
2099 | - | 41 | uint8_t SWMajor; |
42 | uint8_t SWMinor; |
||
43 | uint8_t protoMajor; |
||
44 | uint8_t protoMinor; |
||
45 | uint8_t SWPatch; |
||
46 | uint8_t hardwareErrors[5]; |
||
47 | }__attribute__((packed)) VersionInfo_t; |
||
1910 | - | 48 | |
2099 | - | 49 | extern VersionInfo_t versionInfo; |
1910 | - | 50 | |
2099 | - | 51 | typedef struct { |
52 | /*PMM*/uint8_t gyroPitchD; |
||
2102 | - | 53 | /* P */uint8_t gyroRollD;\ |
2099 | - | 54 | /* P */uint8_t gyroYawD; |
1910 | - | 55 | |
2099 | - | 56 | // Control |
57 | /* P */uint8_t externalControl; |
||
1910 | - | 58 | |
2099 | - | 59 | // Output and servo |
60 | /*PMM*/uint8_t output0Timing; |
||
61 | /*PMM*/uint8_t output1Timing; |
||
62 | |||
63 | uint8_t servoManualControl[2]; |
||
64 | |||
65 | /* P */uint8_t userParams[8]; |
||
66 | } DynamicParams_t; |
||
67 | |||
68 | extern volatile DynamicParams_t dynamicParams; |
||
69 | |||
1910 | - | 70 | typedef struct { |
71 | uint8_t sourceIdx, targetIdx; |
||
72 | uint8_t min, max; |
||
73 | } MMXLATION; |
||
74 | |||
2099 | - | 75 | /* |
1910 | - | 76 | typedef struct { |
77 | uint8_t sourceIdx, targetIdx; |
||
78 | } XLATION; |
||
2099 | - | 79 | */ |
1910 | - | 80 | |
81 | typedef struct { |
||
2099 | - | 82 | uint8_t channels[MAX_CHANNELS]; |
83 | } channelMap_t; |
||
84 | extern channelMap_t channelMap; |
||
1910 | - | 85 | |
2099 | - | 86 | typedef struct { |
87 | char name[12]; |
||
88 | int8_t motor[MAX_MOTORS][4]; |
||
89 | }__attribute__((packed)) mixerMatrix_t; |
||
90 | extern mixerMatrix_t mixerMatrix; |
||
1910 | - | 91 | |
2099 | - | 92 | typedef struct { |
93 | int16_t offsets[3]; |
||
94 | } sensorOffset_t; |
||
95 | |||
96 | typedef struct { |
||
97 | uint8_t manualControl; |
||
98 | uint8_t stabilizationFactor; |
||
99 | uint8_t minValue; |
||
100 | uint8_t maxValue; |
||
101 | uint8_t flags; |
||
102 | } servo_t; |
||
103 | |||
104 | #define SERVO_STABILIZATION_REVERSE 1 |
||
105 | |||
106 | typedef struct { |
||
107 | uint8_t bitmask; |
||
108 | uint8_t timing; |
||
109 | } output_flash_t; |
||
110 | |||
111 | typedef struct { |
||
112 | uint8_t gyroQuadrant; |
||
113 | uint8_t accQuadrant; |
||
114 | uint8_t imuReversedFlags; |
||
2025 | - | 115 | |
2099 | - | 116 | uint8_t gyroPIDFilterConstant; |
117 | uint8_t gyroDWindowLength; |
||
118 | uint8_t gyroDFilterConstant; |
||
119 | uint8_t accFilterConstant; |
||
1910 | - | 120 | |
2099 | - | 121 | uint8_t zerothOrderCorrection; |
122 | uint8_t rateTolerance; |
||
1910 | - | 123 | |
2099 | - | 124 | uint8_t gyroActivityDamping; |
125 | uint8_t driftCompDivider; // 1/k (Koppel_ACC_Wirkung) |
||
126 | uint8_t driftCompLimit; // limit for gyrodrift compensation |
||
127 | } IMUConfig_t; |
||
2025 | - | 128 | |
2099 | - | 129 | extern IMUConfig_t IMUConfig; |
1926 | - | 130 | |
2102 | - | 131 | typedef struct { |
132 | uint8_t P; |
||
133 | uint8_t I; |
||
134 | uint8_t D; |
||
135 | } PID_t; |
||
136 | |||
2099 | - | 137 | // values above 250 representing poti1 to poti4 |
138 | typedef struct { |
||
139 | // Global bitflags |
||
140 | uint8_t bitConfig; // see upper defines for bitcoding |
||
1910 | - | 141 | |
2099 | - | 142 | // uint8_t axisCoupling1; // Value: 0-250 Faktor, mit dem Yaw die Achsen Roll und Nick koppelt (NickRollMitkopplung) |
143 | // uint8_t axisCoupling2; // Value: 0-250 Faktor, mit dem Nick und Roll verkoppelt werden |
||
144 | // uint8_t axisCouplingYawCorrection;// Value: 0-250 Faktor, mit dem Nick und Roll verkoppelt werden |
||
1910 | - | 145 | |
2099 | - | 146 | uint8_t levelCorrection[2]; |
1910 | - | 147 | |
2099 | - | 148 | // Control |
2102 | - | 149 | PID_t gyroPID[3]; |
1910 | - | 150 | |
2099 | - | 151 | uint8_t stickIElevator; |
152 | uint8_t stickIAilerons; |
||
153 | uint8_t stickIRudder; |
||
1910 | - | 154 | |
2099 | - | 155 | uint8_t externalControl; // for serial Control |
1910 | - | 156 | |
2099 | - | 157 | uint8_t IFactor; |
1910 | - | 158 | |
2099 | - | 159 | uint8_t batteryVoltageWarning; |
160 | uint8_t emergencyThrottle; |
||
161 | uint8_t emergencyFlightDuration; |
||
1910 | - | 162 | |
2099 | - | 163 | // Servos |
2102 | - | 164 | uint8_t controlServosReverse; |
165 | |||
2099 | - | 166 | uint8_t servoCount; |
167 | uint8_t servoManualMaxSpeed; |
||
168 | servo_t servoConfigurations[2]; // [PITCH, ROLL] |
||
1910 | - | 169 | |
2099 | - | 170 | // Outputs |
171 | output_flash_t outputFlash[2]; |
||
172 | uint8_t outputDebugMask; |
||
173 | uint8_t outputFlags; |
||
174 | |||
175 | // User params |
||
176 | uint8_t userParams[8]; |
||
177 | |||
178 | // Name |
||
179 | char name[12]; |
||
180 | } ParamSet_t; |
||
181 | |||
182 | extern ParamSet_t staticParams; |
||
183 | |||
184 | // bit mask for staticParams.bitConfig |
||
185 | #define CFG_SIMPLE_HEIGHT_CONTROL (1<<0) |
||
186 | #define CFG_SIMPLE_HC_HOLD_SWITCH (1<<1) |
||
187 | #define CFG_HEADING_HOLD (1<<2) |
||
188 | #define CFG_COMPASS_ENABLED (1<<3) |
||
189 | #define CFG_UNUSED (1<<4) |
||
190 | #define CFG_NAVI_ENABLED (1<<5) |
||
191 | #define CFG_AXIS_COUPLING_ENABLED (1<<6) |
||
192 | #define CFG_GYRO_SATURATION_PREVENTION (1<<7) |
||
1910 | - | 193 | |
2099 | - | 194 | #define IMU_REVERSE_GYRO_PR (1<<0) |
195 | #define IMU_REVERSE_GYRO_YAW (1<<1) |
||
196 | #define IMU_REVERSE_ACC_XY (1<<2) |
||
197 | #define IMU_REVERSE_ACC_Z (1<<3) |
||
1910 | - | 198 | |
2099 | - | 199 | #define ATMEGA644 0 |
200 | #define ATMEGA644P 1 |
||
1910 | - | 201 | #define SYSCLK F_CPU |
202 | |||
2099 | - | 203 | // Not really a part of configuration, but LEDs and HW s test are the same. |
204 | #define RED_OFF {if((boardRelease == 10) || (boardRelease == 20)) PORTB &=~(1<<PORTB0); else PORTB |= (1<<PORTB0);} |
||
205 | #define RED_ON {if((boardRelease == 10) || (boardRelease == 20)) PORTB |= (1<<PORTB0); else PORTB &=~(1<<PORTB0);} |
||
1910 | - | 206 | #define RED_FLASH PORTB ^= (1<<PORTB0) |
2099 | - | 207 | #define GRN_OFF {if(boardRelease < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);} |
208 | #define GRN_ON {if(boardRelease < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);} |
||
1910 | - | 209 | #define GRN_FLASH PORTB ^= (1<<PORTB1) |
210 | |||
211 | // Mixer table |
||
2099 | - | 212 | #define MIX_THROTTLE 0 |
213 | #define MIX_PITCH 1 |
||
214 | #define MIX_ROLL 2 |
||
215 | #define MIX_YAW 3 |
||
1910 | - | 216 | |
2099 | - | 217 | #define VARIABLE_COUNT 8 |
218 | |||
219 | extern int16_t variables[VARIABLE_COUNT]; // The "Poti"s. |
||
220 | extern uint8_t boardRelease; |
||
1910 | - | 221 | extern uint8_t CPUType; |
222 | |||
2102 | - | 223 | extern volatile uint8_t isMotorRunning; |
224 | extern FlightMode_t currentFlightMode; |
||
1910 | - | 225 | |
2099 | - | 226 | void IMUConfig_default(void); |
227 | void channelMap_default(void); |
||
228 | void paramSet_default(uint8_t setnumber); |
||
229 | |||
2102 | - | 230 | void configuration_setFlightParameters(uint8_t newFlightMode); |
2099 | - | 231 | void configuration_applyVariablesToParams(void); |
232 | |||
233 | void setCPUType(void); |
||
234 | void setBoardRelease(void); |
||
235 | |||
236 | // Called after a change in configuration parameters, as a hook for modules to take over changes. |
||
237 | void configuration_paramSetDidChange(void); |
||
1910 | - | 238 | #endif // _CONFIGURATION_H |