Rev 2015 | Rev 2018 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2015 | Rev 2017 | ||
---|---|---|---|
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 10 |
7 | #define MAX_CHANNELS 10 |
8 | #define MAX_MOTORS 12 |
8 | #define MAX_MOTORS 12 |
9 | 9 | ||
10 | typedef struct { |
10 | typedef struct { |
11 | // IMU |
11 | // IMU |
12 | /*PMM*/uint8_t gyroP; |
12 | /*PMM*/uint8_t gyroP; |
13 | /* P */uint8_t gyroD; |
13 | /* P */uint8_t gyroD; |
14 | /* P */uint8_t gyroI; |
14 | /* P */uint8_t gyroI; |
15 | /* P */uint8_t IFactor; |
15 | /* P */uint8_t IFactor; |
16 | uint8_t yawIFactor; |
16 | uint8_t yawIFactor; |
17 | /* P */uint8_t compassYawEffect; |
17 | /* P */uint8_t compassYawEffect; |
18 | 18 | ||
19 | // Control |
19 | // Control |
20 | /* P */uint8_t externalControl; |
20 | /* P */uint8_t externalControl; |
21 | 21 | ||
22 | /* P */uint8_t axisCoupling1; |
22 | /* P */uint8_t axisCoupling1; |
23 | /* P */uint8_t axisCoupling2; |
23 | /* P */uint8_t axisCoupling2; |
24 | /* P */uint8_t axisCouplingYawCorrection; |
24 | /* P */uint8_t axisCouplingYawCorrection; |
25 | /* P */uint8_t dynamicStability; |
25 | /* P */uint8_t dynamicStability; |
26 | uint8_t maxAccVector; |
26 | uint8_t maxAccVector; |
27 | 27 | ||
28 | // Height control |
28 | // Height control |
29 | /*PMM*/uint8_t heightP; |
29 | /*PMM*/uint8_t heightP; |
30 | /*PMM*/uint8_t heightD; |
30 | /*PMM*/uint8_t heightD; |
31 | /* P */uint8_t heightSetting; |
31 | /* P */uint8_t heightSetting; |
32 | /* P */uint8_t heightACCEffect; |
32 | /* P */uint8_t heightACCEffect; |
33 | 33 | ||
34 | uint8_t attitudeControl; |
34 | uint8_t attitudeControl; |
35 | 35 | ||
36 | // The rest... |
36 | // The rest... |
37 | /* P */uint8_t userParams[8]; |
37 | /* P */uint8_t userParams[8]; |
38 | /*PMM*/uint8_t output0Timing; |
38 | /*PMM*/uint8_t output0Timing; |
39 | /*PMM*/uint8_t output1Timing; |
39 | /*PMM*/uint8_t output1Timing; |
40 | 40 | ||
41 | uint8_t servoManualControl[2]; |
41 | uint8_t servoManualControl[2]; |
42 | 42 | ||
43 | uint8_t motorSmoothing; |
43 | uint8_t motorSmoothing; |
44 | uint8_t levelCorrection[2]; |
44 | uint8_t levelCorrection[2]; |
45 | } dynamicParam_t; |
45 | } dynamicParam_t; |
46 | 46 | ||
47 | extern volatile dynamicParam_t dynamicParams; |
47 | extern volatile dynamicParam_t dynamicParams; |
48 | 48 | ||
49 | typedef struct { |
49 | typedef struct { |
50 | uint8_t sourceIdx, targetIdx; |
50 | uint8_t sourceIdx, targetIdx; |
51 | uint8_t min, max; |
51 | uint8_t min, max; |
52 | } MMXLATION; |
52 | } MMXLATION; |
53 | 53 | ||
54 | typedef struct { |
54 | typedef struct { |
55 | uint8_t sourceIdx, targetIdx; |
55 | uint8_t sourceIdx, targetIdx; |
56 | } XLATION; |
56 | } XLATION; |
57 | 57 | ||
58 | typedef struct { |
58 | typedef struct { |
59 | uint8_t channels[MAX_CHANNELS]; |
59 | uint8_t channels[MAX_CHANNELS]; |
60 | } channelMap_t; |
60 | } channelMap_t; |
61 | extern channelMap_t channelMap; |
61 | extern channelMap_t channelMap; |
62 | 62 | ||
63 | typedef struct { |
63 | typedef struct { |
64 | int8_t name[12]; |
64 | char name[12]; |
65 | int8_t motor[MAX_MOTORS][4]; |
65 | int8_t motor[MAX_MOTORS][4]; |
66 | }__attribute__((packed)) mixerMatrix_t; |
66 | }__attribute__((packed)) mixerMatrix_t; |
67 | extern mixerMatrix_t mixerMatrix; |
67 | extern mixerMatrix_t mixerMatrix; |
68 | 68 | ||
69 | typedef struct { |
69 | typedef struct { |
70 | int16_t offsets[3]; |
70 | int16_t offsets[3]; |
71 | } sensorOffset_t; |
71 | } sensorOffset_t; |
72 | 72 | ||
73 | typedef struct { |
73 | typedef struct { |
74 | uint8_t manualControl; |
74 | uint8_t manualControl; |
75 | uint8_t stabilizationFactor; |
75 | uint8_t stabilizationFactor; |
76 | uint8_t minValue; |
76 | uint8_t minValue; |
77 | uint8_t maxValue; |
77 | uint8_t maxValue; |
78 | uint8_t flags; |
78 | uint8_t flags; |
79 | } servo_t; |
79 | } servo_t; |
80 | 80 | ||
81 | #define SERVO_STABILIZATION_REVERSE 1 |
81 | #define SERVO_STABILIZATION_REVERSE 1 |
82 | 82 | ||
83 | typedef struct { |
83 | typedef struct { |
84 | uint8_t bitmask; |
84 | uint8_t bitmask; |
85 | uint8_t timing; |
85 | uint8_t timing; |
86 | } output_flash_t; |
86 | } output_flash_t; |
87 | 87 | ||
88 | // values above 250 representing poti1 to poti4 |
88 | // values above 250 representing poti1 to poti4 |
89 | typedef struct { |
89 | typedef struct { |
90 | // Global bitflags |
90 | // Global bitflags |
91 | uint8_t bitConfig; // see upper defines for bitcoding |
91 | uint8_t bitConfig; // see upper defines for bitcoding |
92 | 92 | ||
93 | // Height Control |
93 | // Height Control |
94 | uint8_t heightP; // Value : 0-32 |
94 | uint8_t heightP; // Value : 0-32 |
95 | uint8_t heightD; // Value : 0-250 |
95 | uint8_t heightD; // Value : 0-250 |
96 | uint8_t heightSetting; // Value : 0-32 |
96 | uint8_t heightSetting; // Value : 0-32 |
97 | uint8_t heightControlMaxThrottleChange; // Value : 0-100 |
97 | uint8_t heightControlMaxThrottleChange; // Value : 0-100 |
98 | uint8_t heightSlewRate; // Value : 0-50 |
98 | uint8_t heightSlewRate; // Value : 0-50 |
99 | 99 | ||
100 | // Attitude Control |
100 | // Attitude Control |
101 | uint8_t attitudeControl; |
101 | uint8_t attitudeControl; |
102 | 102 | ||
103 | // Control |
103 | // Control |
104 | uint8_t stickP; // Value : 1-6 |
104 | uint8_t stickP; // Value : 1-6 |
105 | uint8_t stickD; // Value : 0-64 |
105 | uint8_t stickD; // Value : 0-64 |
106 | uint8_t stickYawP; // Value : 1-20 |
106 | uint8_t stickYawP; // Value : 1-20 |
107 | uint8_t stickThrottleD; |
107 | uint8_t stickThrottleD; |
108 | uint8_t minThrottle; // Value : 0-32 |
108 | uint8_t minThrottle; // Value : 0-32 |
109 | uint8_t maxThrottle; // Value : 33-250 |
109 | uint8_t maxThrottle; // Value : 33-250 |
110 | uint8_t externalControl; // for serial Control |
110 | uint8_t externalControl; // for serial Control |
111 | uint8_t maxAccVector; |
111 | uint8_t maxAccVector; |
112 | uint8_t maxControlActivity; |
112 | uint8_t maxControlActivity; |
113 | uint8_t motorSmoothing; |
113 | uint8_t motorSmoothing; |
114 | 114 | ||
115 | // IMU |
115 | // IMU |
116 | // IMU stuff |
- | |
117 | uint8_t gyroQuadrant; |
116 | uint8_t gyroQuadrant; |
118 | uint8_t accQuadrant; |
117 | uint8_t accQuadrant; |
119 | uint8_t imuReversedFlags; |
118 | uint8_t imuReversedFlags; |
120 | 119 | ||
121 | uint8_t gyroPIDFilterConstant; |
120 | uint8_t gyroPIDFilterConstant; |
122 | uint8_t gyroATTFilterConstant; |
121 | uint8_t gyroATTFilterConstant; |
123 | uint8_t gyroDFilterConstant; |
122 | uint8_t gyroDFilterConstant; |
124 | uint8_t accFilterConstant; |
123 | uint8_t accFilterConstant; |
125 | 124 | ||
126 | uint8_t gyroP; // Value : 10-250 |
125 | uint8_t gyroP; // Value : 10-250 |
127 | uint8_t gyroI; // Value : 0-250 |
126 | uint8_t gyroI; // Value : 0-250 |
128 | uint8_t gyroD; // Value : 0-250 |
127 | uint8_t gyroD; // Value : 0-250 |
129 | 128 | ||
130 | uint8_t zerothOrderCorrection; // Value : 1-64 |
129 | uint8_t zerothOrderCorrection; // Value : 1-64 |
131 | uint8_t driftCompDivider; // 1/k (Koppel_ACC_Wirkung) |
130 | uint8_t driftCompDivider; // 1/k (Koppel_ACC_Wirkung) |
132 | uint8_t driftCompLimit; // limit for gyrodrift compensation |
131 | uint8_t driftCompLimit; // limit for gyrodrift compensation |
133 | 132 | ||
134 | uint8_t axisCoupling1; // Value: 0-250 Faktor, mit dem Yaw die Achsen Roll und Nick koppelt (NickRollMitkopplung) |
133 | uint8_t axisCoupling1; // Value: 0-250 Faktor, mit dem Yaw die Achsen Roll und Nick koppelt (NickRollMitkopplung) |
135 | uint8_t axisCoupling2; // Value: 0-250 Faktor, mit dem Nick und Roll verkoppelt werden |
134 | uint8_t axisCoupling2; // Value: 0-250 Faktor, mit dem Nick und Roll verkoppelt werden |
136 | uint8_t axisCouplingYawCorrection;// Value: 0-250 Faktor, mit dem Nick und Roll verkoppelt werden |
135 | uint8_t axisCouplingYawCorrection;// Value: 0-250 Faktor, mit dem Nick und Roll verkoppelt werden |
137 | 136 | ||
138 | uint8_t dynamicStability; // PID limit for Attitude controller |
137 | uint8_t dynamicStability; // PID limit for Attitude controller |
139 | uint8_t IFactor; // Value : 0-250 |
138 | uint8_t IFactor; // Value : 0-250 |
140 | uint8_t yawIFactor; |
139 | uint8_t yawIFactor; |
141 | uint8_t compassYawEffect; // Value : 0-32 |
140 | uint8_t compassYawEffect; // Value : 0-32 |
142 | uint8_t levelCorrection[2]; |
141 | uint8_t levelCorrection[2]; |
143 | 142 | ||
144 | // Servos |
143 | // Servos |
145 | uint8_t servoCount; |
144 | uint8_t servoCount; |
146 | uint8_t servoManualMaxSpeed; |
145 | uint8_t servoManualMaxSpeed; |
147 | servo_t servoConfigurations[2]; // [PITCH, ROLL] |
146 | servo_t servoConfigurations[2]; // [PITCH, ROLL] |
148 | 147 | ||
149 | // Battery warning and emergency flight |
148 | // Battery warning and emergency flight |
150 | uint8_t batteryVoltageWarning; // Value : 0-250 |
149 | uint8_t batteryVoltageWarning; // Value : 0-250 |
151 | uint8_t emergencyThrottle; // Value : 0-250 |
150 | uint8_t emergencyThrottle; // Value : 0-250 |
152 | uint8_t emergencyFlightDuration; // Value : 0-250 |
151 | uint8_t emergencyFlightDuration; // Value : 0-250 |
153 | 152 | ||
154 | // Outputs |
153 | // Outputs |
155 | output_flash_t outputFlash[2]; |
154 | output_flash_t outputFlash[2]; |
156 | uint8_t outputDebugMask; |
155 | uint8_t outputDebugMask; |
157 | uint8_t outputFlags; |
156 | uint8_t outputFlags; |
158 | 157 | ||
159 | // User params |
158 | // User params |
160 | uint8_t userParams[8]; // Value : 0-250 |
159 | uint8_t userParams[8]; // Value : 0-250 |
161 | 160 | ||
162 | // Name |
161 | // Name |
163 | uint8_t name[12]; |
162 | char name[12]; |
164 | } paramset_t; |
163 | } paramset_t; |
165 | extern paramset_t staticParams; |
164 | extern paramset_t staticParams; |
166 | 165 | ||
167 | // MKFlags |
166 | // MKFlags |
168 | #define MKFLAG_MOTOR_RUN (1<<0) |
167 | #define MKFLAG_MOTOR_RUN (1<<0) |
169 | #define MKFLAG_FLY (1<<1) |
168 | #define MKFLAG_FLY (1<<1) |
170 | #define MKFLAG_CALIBRATE (1<<2) |
169 | #define MKFLAG_CALIBRATE (1<<2) |
171 | #define MKFLAG_START (1<<3) |
170 | #define MKFLAG_START (1<<3) |
172 | #define MKFLAG_EMERGENCY_FLIGHT (1<<4) |
171 | #define MKFLAG_EMERGENCY_FLIGHT (1<<4) |
173 | #define MKFLAG_RESERVE1 (1<<5) |
172 | #define MKFLAG_RESERVE1 (1<<5) |
174 | #define MKFLAG_RESERVE2 (1<<6) |
173 | #define MKFLAG_RESERVE2 (1<<6) |
175 | #define MKFLAG_RESERVE3 (1<<7) |
174 | #define MKFLAG_RESERVE3 (1<<7) |
176 | 175 | ||
177 | // bit mask for staticParams.bitConfig |
176 | // bit mask for staticParams.bitConfig |
178 | #define CFG_SIMPLE_HEIGHT_CONTROL (1<<0) |
177 | #define CFG_SIMPLE_HEIGHT_CONTROL (1<<0) |
179 | #define CFG_SIMPLE_HC_HOLD_SWITCH (1<<1) |
178 | #define CFG_SIMPLE_HC_HOLD_SWITCH (1<<1) |
180 | #define CFG_HEADING_HOLD (1<<2) |
179 | #define CFG_HEADING_HOLD (1<<2) |
181 | #define CFG_COMPASS_ACTIVE (1<<3) |
180 | #define CFG_COMPASS_ACTIVE (1<<3) |
182 | #define CFG_COMPASS_FIX (1<<4) |
181 | #define CFG_COMPASS_FIX (1<<4) |
183 | #define CFG_GPS_ACTIVE (1<<5) |
182 | #define CFG_GPS_ACTIVE (1<<5) |
184 | #define CFG_AXIS_COUPLING_ACTIVE (1<<6) |
183 | #define CFG_AXIS_COUPLING_ACTIVE (1<<6) |
185 | #define CFG_GYRO_SATURATION_PREVENTION (1<<7) |
184 | #define CFG_GYRO_SATURATION_PREVENTION (1<<7) |
186 | 185 | ||
187 | #define ATMEGA644 0 |
186 | #define ATMEGA644 0 |
188 | #define ATMEGA644P 1 |
187 | #define ATMEGA644P 1 |
189 | #define SYSCLK F_CPU |
188 | #define SYSCLK F_CPU |
190 | 189 | ||
191 | // Not really a part of configuration, but LEDs and HW version test are the same. |
190 | // Not really a part of configuration, but LEDs and HW version test are the same. |
192 | #define RED_OFF {if((boardRelease == 10) || (boardRelease == 20)) PORTB &=~(1<<PORTB0); else PORTB |= (1<<PORTB0);} |
191 | #define RED_OFF {if((boardRelease == 10) || (boardRelease == 20)) PORTB &=~(1<<PORTB0); else PORTB |= (1<<PORTB0);} |
193 | #define RED_ON {if((boardRelease == 10) || (boardRelease == 20)) PORTB |= (1<<PORTB0); else PORTB &=~(1<<PORTB0);} |
192 | #define RED_ON {if((boardRelease == 10) || (boardRelease == 20)) PORTB |= (1<<PORTB0); else PORTB &=~(1<<PORTB0);} |
194 | #define RED_FLASH PORTB ^= (1<<PORTB0) |
193 | #define RED_FLASH PORTB ^= (1<<PORTB0) |
195 | #define GRN_OFF {if(boardRelease < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);} |
194 | #define GRN_OFF {if(boardRelease < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);} |
196 | #define GRN_ON {if(boardRelease < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);} |
195 | #define GRN_ON {if(boardRelease < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);} |
197 | #define GRN_FLASH PORTB ^= (1<<PORTB1) |
196 | #define GRN_FLASH PORTB ^= (1<<PORTB1) |
198 | 197 | ||
199 | // Mixer table |
198 | // Mixer table |
200 | #define MIX_THROTTLE 0 |
199 | #define MIX_THROTTLE 0 |
201 | #define MIX_PITCH 1 |
200 | #define MIX_PITCH 1 |
202 | #define MIX_ROLL 2 |
201 | #define MIX_ROLL 2 |
203 | #define MIX_YAW 3 |
202 | #define MIX_YAW 3 |
204 | 203 | ||
205 | #define VARIABLE_COUNT 8 |
204 | #define VARIABLE_COUNT 8 |
206 | 205 | ||
207 | extern volatile uint8_t MKFlags; |
206 | extern volatile uint8_t MKFlags; |
208 | extern uint8_t requiredMotors; |
207 | extern uint8_t requiredMotors; |
209 | extern int16_t variables[VARIABLE_COUNT]; // The "Poti"s. |
208 | extern int16_t variables[VARIABLE_COUNT]; // The "Poti"s. |
210 | extern uint8_t boardRelease; |
209 | extern uint8_t boardRelease; |
211 | extern uint8_t CPUType; |
210 | extern uint8_t CPUType; |
212 | 211 | ||
213 | extern volatile uint8_t MKFlags; |
212 | extern volatile uint8_t MKFlags; |
214 | extern uint16_t isFlying; |
213 | extern uint16_t isFlying; |
215 | 214 | ||
216 | void channelMap_default(void); |
215 | void channelMap_default(void); |
217 | void paramSet_default(uint8_t setnumber); |
216 | void paramSet_default(uint8_t setnumber); |
218 | void mixerMatrix_default(void); |
217 | void mixerMatrix_default(void); |
219 | 218 | ||
220 | void configuration_applyVariablesToParams(void); |
219 | void configuration_applyVariablesToParams(void); |
221 | uint8_t getCPUType(void); |
220 | uint8_t getCPUType(void); |
222 | uint8_t getBoardRelease(void); |
221 | uint8_t getBoardRelease(void); |
223 | 222 | ||
224 | #endif // _CONFIGURATION_H |
223 | #endif // _CONFIGURATION_H |
225 | 224 |