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