Rev 2132 | Rev 2142 | 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 | |||
2124 | - | 7 | #define MAX_CHANNELS 8 |
2099 | - | 8 | |
9 | // bitmask for VersionInfo_t.HardwareError[0] |
||
10 | #define FC_ERROR0_GYRO_PITCH 0x01 |
||
11 | #define FC_ERROR0_GYRO_ROLL 0x02 |
||
12 | #define FC_ERROR0_GYRO_YAW 0x04 |
||
13 | #define FC_ERROR0_ACC_X 0x08 |
||
14 | #define FC_ERROR0_ACC_Y 0x10 |
||
15 | #define FC_ERROR0_ACC_Z 0x20 |
||
16 | #define FC_ERROR0_PRESSURE 0x40 |
||
17 | #define FC_ERROR1_RES0 0x80 |
||
18 | // bitmask for VersionInfo_t.HardwareError[1] |
||
19 | #define FC_ERROR1_I2C 0x01 |
||
20 | #define FC_ERROR1_BL_MISSING 0x02 |
||
21 | #define FC_ERROR1_SPI_RX 0x04 |
||
22 | #define FC_ERROR1_PPM 0x08 |
||
23 | #define FC_ERROR1_MIXER 0x10 |
||
24 | #define FC_ERROR1_RES1 0x20 |
||
25 | #define FC_ERROR1_RES2 0x40 |
||
26 | #define FC_ERROR1_RES3 0x80 |
||
27 | |||
2104 | - | 28 | typedef struct { |
29 | uint8_t gyroQuadrant; |
||
30 | uint8_t accQuadrant; |
||
31 | uint8_t imuReversedFlags; |
||
32 | |||
33 | uint8_t gyroPIDFilterConstant; |
||
34 | uint8_t gyroDWindowLength; |
||
35 | uint8_t gyroDFilterConstant; |
||
36 | uint8_t accFilterConstant; |
||
37 | |||
38 | uint8_t zerothOrderCorrection; |
||
39 | uint8_t rateTolerance; |
||
40 | |||
41 | uint8_t gyroActivityDamping; |
||
42 | uint8_t driftCompDivider; // 1/k (Koppel_ACC_Wirkung) |
||
43 | uint8_t driftCompLimit; // limit for gyrodrift compensation |
||
44 | } IMUConfig_t; |
||
45 | |||
46 | extern IMUConfig_t IMUConfig; |
||
47 | |||
48 | typedef struct { |
||
49 | uint8_t P; |
||
50 | uint8_t I; |
||
51 | uint8_t D; |
||
52 | } PID_t; |
||
53 | |||
54 | typedef struct { |
||
55 | uint8_t P; |
||
56 | uint8_t I; |
||
57 | uint8_t D; |
||
58 | uint8_t iMax; |
||
59 | } PIDIM_t; |
||
60 | |||
2102 | - | 61 | typedef enum { |
62 | FLIGHT_MODE_NONE, |
||
63 | FLIGHT_MODE_MANUAL, |
||
64 | FLIGHT_MODE_RATE, |
||
65 | FLIGHT_MODE_ANGLES |
||
66 | } FlightMode_t; |
||
67 | |||
68 | #define CONTROL_SERVO_REVERSE_ELEVATOR 1 |
||
69 | #define CONTROL_SERVO_REVERSE_AILERONS 2 |
||
70 | #define CONTROL_SERVO_REVERSE_RUDDER 4 |
||
71 | |||
1910 | - | 72 | typedef struct { |
2099 | - | 73 | uint8_t SWMajor; |
74 | uint8_t SWMinor; |
||
75 | uint8_t protoMajor; |
||
76 | uint8_t protoMinor; |
||
77 | uint8_t SWPatch; |
||
78 | uint8_t hardwareErrors[5]; |
||
79 | }__attribute__((packed)) VersionInfo_t; |
||
1910 | - | 80 | |
2099 | - | 81 | extern VersionInfo_t versionInfo; |
1910 | - | 82 | |
2099 | - | 83 | typedef struct { |
2104 | - | 84 | // IMU stuff: |
85 | PID_t gyroPID[3]; |
||
1910 | - | 86 | |
2099 | - | 87 | // Control |
88 | /* P */uint8_t externalControl; |
||
1910 | - | 89 | |
2099 | - | 90 | // Output and servo |
91 | /*PMM*/uint8_t output0Timing; |
||
92 | /*PMM*/uint8_t output1Timing; |
||
93 | |||
2119 | - | 94 | uint8_t gimbalServoManualControl[2]; |
2099 | - | 95 | |
96 | /* P */uint8_t userParams[8]; |
||
97 | } DynamicParams_t; |
||
98 | |||
99 | extern volatile DynamicParams_t dynamicParams; |
||
100 | |||
1910 | - | 101 | typedef struct { |
102 | uint8_t sourceIdx, targetIdx; |
||
103 | uint8_t min, max; |
||
104 | } MMXLATION; |
||
105 | |||
2099 | - | 106 | /* |
1910 | - | 107 | typedef struct { |
108 | uint8_t sourceIdx, targetIdx; |
||
109 | } XLATION; |
||
2099 | - | 110 | */ |
1910 | - | 111 | |
112 | typedef struct { |
||
2119 | - | 113 | uint8_t RCPolarity; // 1=positive, 0=negative. Use positive with Futaba receiver, negative with FrSky. |
2122 | - | 114 | uint8_t HWTrim; |
2119 | - | 115 | uint8_t variableOffset; |
2099 | - | 116 | uint8_t channels[MAX_CHANNELS]; |
2116 | - | 117 | } ChannelMap_t; |
118 | extern ChannelMap_t channelMap; |
||
1910 | - | 119 | |
2122 | - | 120 | // With fixed wing, we need some way to trim the plane. This is done during a trim flight without gyros activated, |
121 | // and then save in a succeeding gyro calibration command. |
||
2099 | - | 122 | typedef struct { |
2122 | - | 123 | int16_t trim[MAX_CHANNELS]; |
124 | } RCTrim_t; |
||
125 | extern RCTrim_t rcTrim; |
||
126 | |||
127 | typedef struct { |
||
2099 | - | 128 | int16_t offsets[3]; |
129 | } sensorOffset_t; |
||
130 | |||
131 | typedef struct { |
||
132 | uint8_t manualControl; |
||
133 | uint8_t stabilizationFactor; |
||
134 | uint8_t minValue; |
||
135 | uint8_t maxValue; |
||
136 | uint8_t flags; |
||
2116 | - | 137 | } Servo_t; |
2099 | - | 138 | |
2119 | - | 139 | #define SERVO_STABILIZATION_REVERSE 1 |
2099 | - | 140 | |
141 | typedef struct { |
||
142 | uint8_t bitmask; |
||
143 | uint8_t timing; |
||
144 | } output_flash_t; |
||
145 | |||
146 | // values above 250 representing poti1 to poti4 |
||
147 | typedef struct { |
||
148 | // Global bitflags |
||
149 | uint8_t bitConfig; // see upper defines for bitcoding |
||
1910 | - | 150 | |
2099 | - | 151 | // Control |
2104 | - | 152 | PIDIM_t gyroPID[3]; |
1910 | - | 153 | |
2099 | - | 154 | uint8_t stickIElevator; |
155 | uint8_t stickIAilerons; |
||
156 | uint8_t stickIRudder; |
||
1910 | - | 157 | |
2129 | - | 158 | uint8_t externalControl; // for serial Control |
159 | |||
2099 | - | 160 | uint8_t IFactor; |
2132 | - | 161 | |
2118 | - | 162 | uint8_t batteryWarningVoltage; |
1910 | - | 163 | |
2105 | - | 164 | // Airspeed |
165 | uint8_t airspeedCorrection; |
||
2109 | - | 166 | uint8_t isFlyingThreshold; |
2105 | - | 167 | |
2099 | - | 168 | // Servos |
169 | uint8_t servoCount; |
||
2119 | - | 170 | uint8_t servosReverse; |
2118 | - | 171 | |
2116 | - | 172 | uint8_t controlServoMinValue; |
173 | uint8_t controlServoMaxValue; |
||
174 | |||
2118 | - | 175 | uint8_t gimbalServoMaxManualSpeed; |
176 | Servo_t gimbalServoConfigurations[2]; // [PITCH, ROLL] |
||
1910 | - | 177 | |
2099 | - | 178 | // Outputs |
179 | output_flash_t outputFlash[2]; |
||
180 | uint8_t outputDebugMask; |
||
181 | uint8_t outputFlags; |
||
182 | |||
183 | // User params |
||
184 | uint8_t userParams[8]; |
||
185 | |||
186 | // Name |
||
187 | char name[12]; |
||
188 | } ParamSet_t; |
||
189 | |||
190 | extern ParamSet_t staticParams; |
||
191 | |||
192 | // bit mask for staticParams.bitConfig |
||
2104 | - | 193 | #define CFG_GYRO_SATURATION_PREVENTION (1<<0) |
194 | #define CFG_USE_AIRSPEED_PID (1<<1) |
||
1910 | - | 195 | |
2099 | - | 196 | #define IMU_REVERSE_GYRO_PR (1<<0) |
197 | #define IMU_REVERSE_GYRO_YAW (1<<1) |
||
198 | #define IMU_REVERSE_ACC_XY (1<<2) |
||
199 | #define IMU_REVERSE_ACC_Z (1<<3) |
||
1910 | - | 200 | |
2099 | - | 201 | #define ATMEGA644 0 |
202 | #define ATMEGA644P 1 |
||
1910 | - | 203 | #define SYSCLK F_CPU |
204 | |||
2099 | - | 205 | // Not really a part of configuration, but LEDs and HW s test are the same. |
206 | #define RED_OFF {if((boardRelease == 10) || (boardRelease == 20)) PORTB &=~(1<<PORTB0); else PORTB |= (1<<PORTB0);} |
||
207 | #define RED_ON {if((boardRelease == 10) || (boardRelease == 20)) PORTB |= (1<<PORTB0); else PORTB &=~(1<<PORTB0);} |
||
1910 | - | 208 | #define RED_FLASH PORTB ^= (1<<PORTB0) |
2099 | - | 209 | #define GRN_OFF {if(boardRelease < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);} |
210 | #define GRN_ON {if(boardRelease < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);} |
||
1910 | - | 211 | #define GRN_FLASH PORTB ^= (1<<PORTB1) |
212 | |||
213 | // Mixer table |
||
2099 | - | 214 | #define MIX_THROTTLE 0 |
215 | #define MIX_PITCH 1 |
||
216 | #define MIX_ROLL 2 |
||
217 | #define MIX_YAW 3 |
||
1910 | - | 218 | |
2099 | - | 219 | #define VARIABLE_COUNT 8 |
220 | |||
221 | extern int16_t variables[VARIABLE_COUNT]; // The "Poti"s. |
||
222 | extern uint8_t boardRelease; |
||
1910 | - | 223 | extern uint8_t CPUType; |
224 | |||
2108 | - | 225 | extern volatile uint16_t isFlying; |
2102 | - | 226 | extern FlightMode_t currentFlightMode; |
1910 | - | 227 | |
2099 | - | 228 | void IMUConfig_default(void); |
229 | void channelMap_default(void); |
||
2122 | - | 230 | void rcTrim_setZero(void); |
2099 | - | 231 | void paramSet_default(uint8_t setnumber); |
232 | |||
2102 | - | 233 | void configuration_setFlightParameters(uint8_t newFlightMode); |
2099 | - | 234 | void configuration_applyVariablesToParams(void); |
235 | |||
236 | void setCPUType(void); |
||
237 | void setBoardRelease(void); |
||
238 | |||
239 | // Called after a change in configuration parameters, as a hook for modules to take over changes. |
||
240 | void configuration_paramSetDidChange(void); |
||
1910 | - | 241 | #endif // _CONFIGURATION_H |