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