Rev 909 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 909 | Rev 916 | ||
---|---|---|---|
Line 74... | Line 74... | ||
74 | #endif |
74 | #endif |
75 | #include "led.h" |
75 | #include "led.h" |
Line 76... | Line 76... | ||
76 | 76 | ||
77 | volatile uint16_t I2CTimeout = 100; |
77 | volatile uint16_t I2CTimeout = 100; |
78 | // gyro readings |
78 | // gyro readings |
79 | volatile int16_t Reading_GyroPitch, Reading_GyroRoll, Reading_GyroYaw; |
79 | volatile int16_t Reading_GyroNick, Reading_GyroRoll, Reading_GyroYaw; |
80 | // gyro neutral readings |
80 | // gyro neutral readings |
81 | volatile int16_t AdNeutralPitch = 0, AdNeutralRoll = 0, AdNeutralYaw = 0; |
81 | volatile int16_t AdNeutralNick = 0, AdNeutralRoll = 0, AdNeutralYaw = 0; |
82 | volatile int16_t StartNeutralRoll = 0, StartNeutralPitch = 0; |
82 | volatile int16_t StartNeutralRoll = 0, StartNeutralNick = 0; |
83 | // mean accelerations |
83 | // mean accelerations |
Line 84... | Line 84... | ||
84 | volatile int16_t Mean_AccPitch, Mean_AccRoll, Mean_AccTop; |
84 | volatile int16_t Mean_AccNick, Mean_AccRoll, Mean_AccTop; |
85 | 85 | ||
86 | // neutral acceleration readings |
86 | // neutral acceleration readings |
Line 87... | Line 87... | ||
87 | volatile int16_t NeutralAccX=0, NeutralAccY=0; |
87 | volatile int16_t NeutralAccX=0, NeutralAccY=0; |
88 | volatile float NeutralAccZ = 0; |
88 | volatile float NeutralAccZ = 0; |
89 | 89 | ||
90 | // attitude gyro integrals |
90 | // attitude gyro integrals |
91 | volatile int32_t IntegralPitch = 0,IntegralPitch2 = 0; |
91 | volatile int32_t IntegralNick = 0,IntegralNick2 = 0; |
92 | volatile int32_t IntegralRoll = 0,IntegralRoll2 = 0; |
92 | volatile int32_t IntegralRoll = 0,IntegralRoll2 = 0; |
93 | volatile int32_t IntegralYaw = 0; |
93 | volatile int32_t IntegralYaw = 0; |
94 | volatile int32_t Reading_IntegralGyroPitch = 0, Reading_IntegralGyroPitch2 = 0; |
94 | volatile int32_t Reading_IntegralGyroNick = 0, Reading_IntegralGyroNick2 = 0; |
95 | volatile int32_t Reading_IntegralGyroRoll = 0, Reading_IntegralGyroRoll2 = 0; |
95 | volatile int32_t Reading_IntegralGyroRoll = 0, Reading_IntegralGyroRoll2 = 0; |
Line 96... | Line 96... | ||
96 | volatile int32_t Reading_IntegralGyroYaw = 0; |
96 | volatile int32_t Reading_IntegralGyroYaw = 0; |
97 | volatile int32_t MeanIntegralPitch; |
97 | volatile int32_t MeanIntegralNick; |
98 | volatile int32_t MeanIntegralRoll; |
98 | volatile int32_t MeanIntegralRoll; |
Line 99... | Line 99... | ||
99 | 99 | ||
100 | // attitude acceleration integrals |
100 | // attitude acceleration integrals |
101 | volatile int32_t IntegralAccPitch = 0, IntegralAccRoll = 0; |
101 | volatile int32_t IntegralAccNick = 0, IntegralAccRoll = 0; |
Line 110... | Line 110... | ||
110 | uint16_t BadCompassHeading = 500; |
110 | uint16_t BadCompassHeading = 500; |
111 | int32_t YawGyroHeading; |
111 | int32_t YawGyroHeading; |
112 | int16_t YawGyroDrift; |
112 | int16_t YawGyroDrift; |
Line 113... | Line 113... | ||
113 | 113 | ||
Line 114... | Line 114... | ||
114 | 114 | ||
115 | int16_t NaviAccPitch = 0, NaviAccRoll = 0, NaviCntAcc = 0; |
115 | int16_t NaviAccNick = 0, NaviAccRoll = 0, NaviCntAcc = 0; |
116 | 116 | ||
117 | 117 | ||
Line 118... | Line 118... | ||
118 | // flags |
118 | // flags |
Line 119... | Line 119... | ||
119 | uint8_t MotorsOn = 0; |
119 | uint8_t MotorsOn = 0; |
120 | uint8_t EmergencyLanding = 0; |
120 | uint8_t EmergencyLanding = 0; |
Line 121... | Line 121... | ||
121 | uint16_t Model_Is_Flying = 0; |
121 | uint16_t Model_Is_Flying = 0; |
Line 122... | Line 122... | ||
122 | 122 | ||
Line 123... | Line 123... | ||
123 | int32_t TurnOver180Pitch = 250000L, TurnOver180Roll = 250000L; |
123 | int32_t TurnOver180Nick = 250000L, TurnOver180Roll = 250000L; |
124 | 124 | ||
Line 135... | Line 135... | ||
135 | #else |
135 | #else |
136 | volatile uint8_t Motor_Front, Motor_Rear, Motor_Right, Motor_Left; //used by twimaster isr |
136 | volatile uint8_t Motor_Front, Motor_Rear, Motor_Right, Motor_Left; //used by twimaster isr |
137 | #endif |
137 | #endif |
Line 138... | Line 138... | ||
138 | 138 | ||
139 | // stick values derived by rc channels readings |
139 | // stick values derived by rc channels readings |
140 | int16_t StickPitch = 0, StickRoll = 0, StickYaw = 0, StickThrust = 0; |
140 | int16_t StickNick = 0, StickRoll = 0, StickYaw = 0, StickGas = 0; |
Line 141... | Line 141... | ||
141 | int16_t GPS_Pitch = 0, GPS_Roll = 0; |
141 | int16_t GPS_Nick = 0, GPS_Roll = 0; |
142 | 142 | ||
143 | int16_t MaxStickPitch = 0, MaxStickRoll = 0; |
143 | int16_t MaxStickNick = 0, MaxStickRoll = 0; |
Line 144... | Line 144... | ||
144 | // stick values derived by uart inputs |
144 | // stick values derived by uart inputs |
145 | int16_t ExternStickPitch = 0, ExternStickRoll = 0, ExternStickYaw = 0, ExternHeightValue = -20; |
145 | int16_t ExternStickNick = 0, ExternStickRoll = 0, ExternStickYaw = 0, ExternHeightValue = -20; |
Line 146... | Line 146... | ||
146 | 146 | ||
Line 147... | Line 147... | ||
147 | 147 | ||
Line 148... | Line 148... | ||
148 | 148 | ||
149 | 149 | ||
Line 150... | Line 150... | ||
150 | int16_t ReadingHeight = 0; |
150 | int16_t ReadingHeight = 0; |
Line 182... | Line 182... | ||
182 | void SetNeutral(void) |
182 | void SetNeutral(void) |
183 | { |
183 | { |
184 | NeutralAccX = 0; |
184 | NeutralAccX = 0; |
185 | NeutralAccY = 0; |
185 | NeutralAccY = 0; |
186 | NeutralAccZ = 0; |
186 | NeutralAccZ = 0; |
187 | AdNeutralPitch = 0; |
187 | AdNeutralNick = 0; |
188 | AdNeutralRoll = 0; |
188 | AdNeutralRoll = 0; |
189 | AdNeutralYaw = 0; |
189 | AdNeutralYaw = 0; |
190 | FCParam.Yaw_PosFeedback = 0; |
190 | FCParam.Yaw_PosFeedback = 0; |
191 | FCParam.Yaw_NegFeedback = 0; |
191 | FCParam.Yaw_NegFeedback = 0; |
192 | CalibMean(); |
192 | CalibMean(); |
Line 194... | Line 194... | ||
194 | CalibMean(); |
194 | CalibMean(); |
195 | if((ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL)) // Height Control activated? |
195 | if((ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL)) // Height Control activated? |
196 | { |
196 | { |
197 | if((ReadingAirPressure > 950) || (ReadingAirPressure < 750)) SearchAirPressureOffset(); |
197 | if((ReadingAirPressure > 950) || (ReadingAirPressure < 750)) SearchAirPressureOffset(); |
198 | } |
198 | } |
199 | AdNeutralPitch = AdValueGyrPitch; |
199 | AdNeutralNick = AdValueGyrNick; |
200 | AdNeutralRoll = AdValueGyrRoll; |
200 | AdNeutralRoll = AdValueGyrRoll; |
201 | AdNeutralYaw = AdValueGyrYaw; |
201 | AdNeutralYaw = AdValueGyrYaw; |
202 | StartNeutralRoll = AdNeutralRoll; |
202 | StartNeutralRoll = AdNeutralRoll; |
203 | StartNeutralPitch = AdNeutralPitch; |
203 | StartNeutralNick = AdNeutralNick; |
204 | if(GetParamWord(PID_ACC_PITCH) > 1023) |
204 | if(GetParamWord(PID_ACC_NICK) > 1023) |
205 | { |
205 | { |
206 | NeutralAccY = abs(Mean_AccRoll) / ACC_AMPLIFY; |
206 | NeutralAccY = abs(Mean_AccRoll) / ACC_AMPLIFY; |
207 | NeutralAccX = abs(Mean_AccPitch) / ACC_AMPLIFY; |
207 | NeutralAccX = abs(Mean_AccNick) / ACC_AMPLIFY; |
208 | NeutralAccZ = Current_AccZ; |
208 | NeutralAccZ = Current_AccZ; |
209 | } |
209 | } |
210 | else |
210 | else |
211 | { |
211 | { |
212 | NeutralAccX = (int16_t)GetParamWord(PID_ACC_PITCH); |
212 | NeutralAccX = (int16_t)GetParamWord(PID_ACC_NICK); |
213 | NeutralAccY = (int16_t)GetParamWord(PID_ACC_ROLL); |
213 | NeutralAccY = (int16_t)GetParamWord(PID_ACC_ROLL); |
214 | NeutralAccZ = (int16_t)GetParamWord(PID_ACC_Z); |
214 | NeutralAccZ = (int16_t)GetParamWord(PID_ACC_Z); |
215 | } |
215 | } |
216 | Reading_IntegralGyroPitch = 0; |
216 | Reading_IntegralGyroNick = 0; |
217 | Reading_IntegralGyroPitch2 = 0; |
217 | Reading_IntegralGyroNick2 = 0; |
218 | Reading_IntegralGyroRoll = 0; |
218 | Reading_IntegralGyroRoll = 0; |
219 | Reading_IntegralGyroRoll2 = 0; |
219 | Reading_IntegralGyroRoll2 = 0; |
220 | Reading_IntegralGyroYaw = 0; |
220 | Reading_IntegralGyroYaw = 0; |
221 | Reading_GyroPitch = 0; |
221 | Reading_GyroNick = 0; |
222 | Reading_GyroRoll = 0; |
222 | Reading_GyroRoll = 0; |
223 | Reading_GyroYaw = 0; |
223 | Reading_GyroYaw = 0; |
224 | StartAirPressure = AirPressure; |
224 | StartAirPressure = AirPressure; |
225 | HeightD = 0; |
225 | HeightD = 0; |
226 | Reading_Integral_Top = 0; |
226 | Reading_Integral_Top = 0; |
227 | CompassCourse = CompassHeading; |
227 | CompassCourse = CompassHeading; |
228 | BeepTime = 50; |
228 | BeepTime = 50; |
229 | TurnOver180Pitch = ((int32_t) ParamSet.AngleTurnOverPitch * 2500L) +15000L; |
229 | TurnOver180Nick = ((int32_t) ParamSet.AngleTurnOverNick * 2500L) +15000L; |
230 | TurnOver180Roll = ((int32_t) ParamSet.AngleTurnOverRoll * 2500L) +15000L; |
230 | TurnOver180Roll = ((int32_t) ParamSet.AngleTurnOverRoll * 2500L) +15000L; |
231 | ExternHeightValue = 0; |
231 | ExternHeightValue = 0; |
232 | GPS_Pitch = 0; |
232 | GPS_Nick = 0; |
233 | GPS_Roll = 0; |
233 | GPS_Roll = 0; |
234 | YawGyroHeading = CompassHeading * YAW_GYRO_DEG_FACTOR; |
234 | YawGyroHeading = CompassHeading * YAW_GYRO_DEG_FACTOR; |
235 | YawGyroDrift = 0; |
235 | YawGyroDrift = 0; |
236 | } |
236 | } |
Line 243... | Line 243... | ||
243 | static int32_t tmpl,tmpl2; |
243 | static int32_t tmpl,tmpl2; |
Line 244... | Line 244... | ||
244 | 244 | ||
245 | // Get offset corrected gyro readings (~ to angular velocity) |
245 | // Get offset corrected gyro readings (~ to angular velocity) |
246 | Reading_GyroYaw = AdNeutralYaw - AdValueGyrYaw; |
246 | Reading_GyroYaw = AdNeutralYaw - AdValueGyrYaw; |
247 | Reading_GyroRoll = AdValueGyrRoll - AdNeutralRoll; |
247 | Reading_GyroRoll = AdValueGyrRoll - AdNeutralRoll; |
Line 248... | Line 248... | ||
248 | Reading_GyroPitch = AdValueGyrPitch - AdNeutralPitch; |
248 | Reading_GyroNick = AdValueGyrNick - AdNeutralNick; |
249 | 249 | ||
250 | // Acceleration Sensor |
250 | // Acceleration Sensor |
251 | // sliding average sensor readings |
251 | // sliding average sensor readings |
252 | Mean_AccPitch = ((int32_t)Mean_AccPitch * 1 + ((ACC_AMPLIFY * (int32_t)AdValueAccPitch))) / 2L; |
252 | Mean_AccNick = ((int32_t)Mean_AccNick * 1 + ((ACC_AMPLIFY * (int32_t)AdValueAccNick))) / 2L; |
Line 253... | Line 253... | ||
253 | Mean_AccRoll = ((int32_t)Mean_AccRoll * 1 + ((ACC_AMPLIFY * (int32_t)AdValueAccRoll))) / 2L; |
253 | Mean_AccRoll = ((int32_t)Mean_AccRoll * 1 + ((ACC_AMPLIFY * (int32_t)AdValueAccRoll))) / 2L; |
254 | Mean_AccTop = ((int32_t)Mean_AccTop * 1 + ((int32_t)AdValueAccTop)) / 2L; |
254 | Mean_AccTop = ((int32_t)Mean_AccTop * 1 + ((int32_t)AdValueAccTop)) / 2L; |
255 | 255 | ||
Line 256... | Line 256... | ||
256 | // sum sensor readings for later averaging |
256 | // sum sensor readings for later averaging |
257 | IntegralAccPitch += ACC_AMPLIFY * AdValueAccPitch; |
257 | IntegralAccNick += ACC_AMPLIFY * AdValueAccNick; |
258 | IntegralAccRoll += ACC_AMPLIFY * AdValueAccRoll; |
258 | IntegralAccRoll += ACC_AMPLIFY * AdValueAccRoll; |
Line 259... | Line 259... | ||
259 | 259 | ||
260 | NaviAccPitch += AdValueAccPitch; |
260 | NaviAccNick += AdValueAccNick; |
Line 268... | Line 268... | ||
268 | if(YawGyroHeading >= (360L * YAW_GYRO_DEG_FACTOR)) YawGyroHeading -= 360L * YAW_GYRO_DEG_FACTOR; // 360° Wrap |
268 | if(YawGyroHeading >= (360L * YAW_GYRO_DEG_FACTOR)) YawGyroHeading -= 360L * YAW_GYRO_DEG_FACTOR; // 360° Wrap |
269 | if(YawGyroHeading < 0) YawGyroHeading += 360L * YAW_GYRO_DEG_FACTOR; |
269 | if(YawGyroHeading < 0) YawGyroHeading += 360L * YAW_GYRO_DEG_FACTOR; |
Line 270... | Line 270... | ||
270 | 270 | ||
271 | 271 | ||
272 | // Coupling fraction |
272 | // Coupling fraction |
273 | if(!Looping_Pitch && !Looping_Roll && (ParamSet.GlobalConfig & CFG_AXIS_COUPLING_ACTIVE)) |
273 | if(!Looping_Nick && !Looping_Roll && (ParamSet.GlobalConfig & CFG_AXIS_COUPLING_ACTIVE)) |
274 | { |
274 | { |
275 | tmpl = (Reading_GyroYaw * Reading_IntegralGyroPitch) / 2048L; |
275 | tmpl = (Reading_GyroYaw * Reading_IntegralGyroNick) / 2048L; |
276 | tmpl *= FCParam.Yaw_PosFeedback; |
276 | tmpl *= FCParam.Yaw_PosFeedback; |
277 | tmpl /= 4096L; |
277 | tmpl /= 4096L; |
278 | tmpl2 = ( Reading_GyroYaw * Reading_IntegralGyroRoll) / 2048L; |
278 | tmpl2 = ( Reading_GyroYaw * Reading_IntegralGyroRoll) / 2048L; |
Line 307... | Line 307... | ||
307 | else |
307 | else |
308 | { |
308 | { |
309 | if(AdValueGyrRoll > 2020) Reading_GyroRoll = +1000; |
309 | if(AdValueGyrRoll > 2020) Reading_GyroRoll = +1000; |
310 | if(AdValueGyrRoll > 2034) Reading_GyroRoll = +2000; |
310 | if(AdValueGyrRoll > 2034) Reading_GyroRoll = +2000; |
311 | } |
311 | } |
312 | // Pitch |
312 | // Nick |
313 | Reading_GyroPitch -= tmpl2; |
313 | Reading_GyroNick -= tmpl2; |
314 | Reading_GyroPitch -= (tmpl*FCParam.Yaw_NegFeedback) / 512L; |
314 | Reading_GyroNick -= (tmpl*FCParam.Yaw_NegFeedback) / 512L; |
315 | Reading_IntegralGyroPitch2 += Reading_GyroPitch; |
315 | Reading_IntegralGyroNick2 += Reading_GyroNick; |
316 | Reading_IntegralGyroPitch += Reading_GyroPitch - AttitudeCorrectionPitch; |
316 | Reading_IntegralGyroNick += Reading_GyroNick - AttitudeCorrectionNick; |
317 | if(Reading_IntegralGyroPitch > TurnOver180Pitch) |
317 | if(Reading_IntegralGyroNick > TurnOver180Nick) |
318 | { |
318 | { |
319 | Reading_IntegralGyroPitch = -(TurnOver180Pitch - 25000L); |
319 | Reading_IntegralGyroNick = -(TurnOver180Nick - 25000L); |
320 | Reading_IntegralGyroPitch2 = Reading_IntegralGyroPitch; |
320 | Reading_IntegralGyroNick2 = Reading_IntegralGyroNick; |
321 | } |
321 | } |
322 | if(Reading_IntegralGyroPitch < -TurnOver180Pitch) |
322 | if(Reading_IntegralGyroNick < -TurnOver180Nick) |
323 | { |
323 | { |
324 | Reading_IntegralGyroPitch = (TurnOver180Pitch - 25000L); |
324 | Reading_IntegralGyroNick = (TurnOver180Nick - 25000L); |
325 | Reading_IntegralGyroPitch2 = Reading_IntegralGyroPitch; |
325 | Reading_IntegralGyroNick2 = Reading_IntegralGyroNick; |
326 | } |
326 | } |
327 | if(AdValueGyrPitch < 15) Reading_GyroPitch = -1000; |
327 | if(AdValueGyrNick < 15) Reading_GyroNick = -1000; |
328 | if(AdValueGyrPitch < 7) Reading_GyroPitch = -2000; |
328 | if(AdValueGyrNick < 7) Reading_GyroNick = -2000; |
329 | if(BoardRelease == 10) |
329 | if(BoardRelease == 10) |
330 | { |
330 | { |
331 | if(AdValueGyrPitch > 1010) Reading_GyroPitch = +1000; |
331 | if(AdValueGyrNick > 1010) Reading_GyroNick = +1000; |
332 | if(AdValueGyrPitch > 1017) Reading_GyroPitch = +2000; |
332 | if(AdValueGyrNick > 1017) Reading_GyroNick = +2000; |
333 | } |
333 | } |
334 | else |
334 | else |
335 | { |
335 | { |
336 | if(AdValueGyrPitch > 2020) Reading_GyroPitch = +1000; |
336 | if(AdValueGyrNick > 2020) Reading_GyroNick = +1000; |
337 | if(AdValueGyrPitch > 2034) Reading_GyroPitch = +2000; |
337 | if(AdValueGyrNick > 2034) Reading_GyroNick = +2000; |
338 | } |
338 | } |
Line 339... | Line 339... | ||
339 | 339 | ||
340 | // start ADC again to capture measurement values for the next loop |
340 | // start ADC again to capture measurement values for the next loop |
Line 341... | Line 341... | ||
341 | ADC_Enable(); |
341 | ADC_Enable(); |
342 | 342 | ||
343 | IntegralYaw = Reading_IntegralGyroYaw; |
343 | IntegralYaw = Reading_IntegralGyroYaw; |
344 | IntegralPitch = Reading_IntegralGyroPitch; |
344 | IntegralNick = Reading_IntegralGyroNick; |
345 | IntegralRoll = Reading_IntegralGyroRoll; |
345 | IntegralRoll = Reading_IntegralGyroRoll; |
Line 346... | Line 346... | ||
346 | IntegralPitch2 = Reading_IntegralGyroPitch2; |
346 | IntegralNick2 = Reading_IntegralGyroNick2; |
347 | IntegralRoll2 = Reading_IntegralGyroRoll2; |
347 | IntegralRoll2 = Reading_IntegralGyroRoll2; |
348 | 348 | ||
349 | if((ParamSet.GlobalConfig & CFG_ROTARY_RATE_LIMITER) && !Looping_Pitch && !Looping_Roll) |
349 | if((ParamSet.GlobalConfig & CFG_ROTARY_RATE_LIMITER) && !Looping_Nick && !Looping_Roll) |
350 | { |
350 | { |
351 | if(Reading_GyroPitch > 200) Reading_GyroPitch += 4 * (Reading_GyroPitch - 200); |
351 | if(Reading_GyroNick > 200) Reading_GyroNick += 4 * (Reading_GyroNick - 200); |
352 | else if(Reading_GyroPitch < -200) Reading_GyroPitch += 4 * (Reading_GyroPitch + 200); |
352 | else if(Reading_GyroNick < -200) Reading_GyroNick += 4 * (Reading_GyroNick + 200); |
353 | if(Reading_GyroRoll > 200) Reading_GyroRoll += 4 * (Reading_GyroRoll - 200); |
353 | if(Reading_GyroRoll > 200) Reading_GyroRoll += 4 * (Reading_GyroRoll - 200); |
Line 361... | Line 361... | ||
361 | void CalibMean(void) |
361 | void CalibMean(void) |
362 | { |
362 | { |
363 | // stop ADC to avoid changing values during calculation |
363 | // stop ADC to avoid changing values during calculation |
364 | ADC_Disable(); |
364 | ADC_Disable(); |
Line 365... | Line 365... | ||
365 | 365 | ||
366 | Reading_GyroPitch = AdValueGyrPitch; |
366 | Reading_GyroNick = AdValueGyrNick; |
367 | Reading_GyroRoll = AdValueGyrRoll; |
367 | Reading_GyroRoll = AdValueGyrRoll; |
Line 368... | Line 368... | ||
368 | Reading_GyroYaw = AdValueGyrYaw; |
368 | Reading_GyroYaw = AdValueGyrYaw; |
369 | 369 | ||
370 | Mean_AccPitch = ACC_AMPLIFY * (int32_t)AdValueAccPitch; |
370 | Mean_AccNick = ACC_AMPLIFY * (int32_t)AdValueAccNick; |
371 | Mean_AccRoll = ACC_AMPLIFY * (int32_t)AdValueAccRoll; |
371 | Mean_AccRoll = ACC_AMPLIFY * (int32_t)AdValueAccRoll; |
372 | Mean_AccTop = (int32_t)AdValueAccTop; |
372 | Mean_AccTop = (int32_t)AdValueAccTop; |
373 | // start ADC (enables internal trigger so that the ISR in analog.c |
373 | // start ADC (enables internal trigger so that the ISR in analog.c |
Line 374... | Line 374... | ||
374 | // updates the readings once) |
374 | // updates the readings once) |
375 | ADC_Enable(); |
375 | ADC_Enable(); |
376 | 376 | ||
Line 377... | Line 377... | ||
377 | TurnOver180Pitch = (int32_t) ParamSet.AngleTurnOverPitch * 2500L; |
377 | TurnOver180Nick = (int32_t) ParamSet.AngleTurnOverNick * 2500L; |
378 | TurnOver180Roll = (int32_t) ParamSet.AngleTurnOverRoll * 2500L; |
378 | TurnOver180Roll = (int32_t) ParamSet.AngleTurnOverRoll * 2500L; |
Line 443... | Line 443... | ||
443 | CHK_POTI(FCParam.UserParam4,ParamSet.UserParam4,0,255); |
443 | CHK_POTI(FCParam.UserParam4,ParamSet.UserParam4,0,255); |
444 | CHK_POTI(FCParam.UserParam5,ParamSet.UserParam5,0,255); |
444 | CHK_POTI(FCParam.UserParam5,ParamSet.UserParam5,0,255); |
445 | CHK_POTI(FCParam.UserParam6,ParamSet.UserParam6,0,255); |
445 | CHK_POTI(FCParam.UserParam6,ParamSet.UserParam6,0,255); |
446 | CHK_POTI(FCParam.UserParam7,ParamSet.UserParam7,0,255); |
446 | CHK_POTI(FCParam.UserParam7,ParamSet.UserParam7,0,255); |
447 | CHK_POTI(FCParam.UserParam8,ParamSet.UserParam8,0,255); |
447 | CHK_POTI(FCParam.UserParam8,ParamSet.UserParam8,0,255); |
448 | CHK_POTI(FCParam.ServoPitchControl,ParamSet.ServoPitchControl,0,255); |
448 | CHK_POTI(FCParam.ServoNickControl,ParamSet.ServoNickControl,0,255); |
449 | CHK_POTI(FCParam.LoopThrustLimit,ParamSet.LoopThrustLimit,0,255); |
449 | CHK_POTI(FCParam.LoopGasLimit,ParamSet.LoopGasLimit,0,255); |
450 | CHK_POTI(FCParam.Yaw_PosFeedback,ParamSet.Yaw_PosFeedback,0,255); |
450 | CHK_POTI(FCParam.Yaw_PosFeedback,ParamSet.Yaw_PosFeedback,0,255); |
451 | CHK_POTI(FCParam.Yaw_NegFeedback,ParamSet.Yaw_NegFeedback,0,255); |
451 | CHK_POTI(FCParam.Yaw_NegFeedback,ParamSet.Yaw_NegFeedback,0,255); |
452 | CHK_POTI(FCParam.DynamicStability,ParamSet.DynamicStability,0,255); |
452 | CHK_POTI(FCParam.DynamicStability,ParamSet.DynamicStability,0,255); |
453 | Ki = (float) FCParam.I_Factor * FACTOR_I; |
453 | Ki = (float) FCParam.I_Factor * FACTOR_I; |
454 | } |
454 | } |
Line 457... | Line 457... | ||
457 | 457 | ||
458 | void SetCompassCalState(void) |
458 | void SetCompassCalState(void) |
459 | { |
459 | { |
Line 460... | Line 460... | ||
460 | static uint8_t stick = 1; |
460 | static uint8_t stick = 1; |
461 | 461 | ||
462 | // if pitch is centered or top set stick to zero |
462 | // if nick is centered or top set stick to zero |
463 | if(PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] > -20) stick = 0; |
463 | if(PPM_in[ParamSet.ChannelAssignment[CH_NICK]] > -20) stick = 0; |
464 | // if pitch is down trigger to next cal state |
464 | // if nick is down trigger to next cal state |
465 | if((PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] < -70) && !stick) |
465 | if((PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < -70) && !stick) |
466 | { |
466 | { |
467 | stick = 1; |
467 | stick = 1; |
468 | CompassCalState++; |
468 | CompassCalState++; |
Line 477... | Line 477... | ||
477 | /* MotorControl */ |
477 | /* MotorControl */ |
478 | /************************************************************************/ |
478 | /************************************************************************/ |
479 | void MotorControl(void) |
479 | void MotorControl(void) |
480 | { |
480 | { |
481 | int16_t MotorValue, pd_result, h, tmp_int; |
481 | int16_t MotorValue, pd_result, h, tmp_int; |
482 | int16_t YawMixFraction, ThrustMixFraction, PitchMixFraction, RollMixFraction; |
482 | int16_t YawMixFraction, GasMixFraction, NickMixFraction, RollMixFraction; |
483 | static int32_t SumPitch = 0, SumRoll = 0; |
483 | static int32_t SumNick = 0, SumRoll = 0; |
484 | static int32_t SetPointYaw = 0; |
484 | static int32_t SetPointYaw = 0; |
485 | static int32_t IntegralErrorPitch = 0; |
485 | static int32_t IntegralErrorNick = 0; |
486 | static int32_t IntegralErrorRoll = 0; |
486 | static int32_t IntegralErrorRoll = 0; |
487 | static uint16_t RcLostTimer; |
487 | static uint16_t RcLostTimer; |
488 | static uint8_t delay_neutral = 0, delay_startmotors = 0, delay_stopmotors = 0; |
488 | static uint8_t delay_neutral = 0, delay_startmotors = 0, delay_stopmotors = 0; |
489 | static uint8_t HeightControlActive = 0; |
489 | static uint8_t HeightControlActive = 0; |
490 | static int16_t HeightControlThrust = 0; |
490 | static int16_t HeightControlGas = 0; |
491 | static int8_t TimerDebugOut = 0; |
491 | static int8_t TimerDebugOut = 0; |
492 | static uint16_t UpdateCompassCourse = 0; |
492 | static uint16_t UpdateCompassCourse = 0; |
493 | static int32_t CorrectionPitch, CorrectionRoll; |
493 | static int32_t CorrectionNick, CorrectionRoll; |
Line 494... | Line 494... | ||
494 | 494 | ||
495 | Mean(); |
495 | Mean(); |
Line 496... | Line 496... | ||
496 | GRN_ON; |
496 | GRN_ON; |
497 | 497 | ||
498 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
498 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
499 | // determine thrust value |
499 | // determine gas value |
500 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
500 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
501 | ThrustMixFraction = StickThrust; |
501 | GasMixFraction = StickGas; |
502 | if(ThrustMixFraction < ParamSet.Trust_Min + 10) ThrustMixFraction = ParamSet.Trust_Min + 10; |
502 | if(GasMixFraction < ParamSet.Gas_Min + 10) GasMixFraction = ParamSet.Gas_Min + 10; |
503 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
503 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
504 | // RC-signal is bad |
504 | // RC-signal is bad |
505 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
505 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Line 520... | Line 520... | ||
520 | EmergencyLanding = 0; // emergency landing is over |
520 | EmergencyLanding = 0; // emergency landing is over |
521 | } |
521 | } |
522 | ROT_ON; // set red led |
522 | ROT_ON; // set red led |
523 | if(Model_Is_Flying > 1000) // wahrscheinlich in der Luft --> langsam absenken |
523 | if(Model_Is_Flying > 1000) // wahrscheinlich in der Luft --> langsam absenken |
524 | { |
524 | { |
525 | ThrustMixFraction = ParamSet.EmergencyThrust; // set emergency thrust |
525 | GasMixFraction = ParamSet.EmergencyGas; // set emergency gas |
526 | EmergencyLanding = 1; // enable emergency landing |
526 | EmergencyLanding = 1; // enable emergency landing |
527 | // set neutral rc inputs |
527 | // set neutral rc inputs |
528 | PPM_diff[ParamSet.ChannelAssignment[CH_PITCH]] = 0; |
528 | PPM_diff[ParamSet.ChannelAssignment[CH_NICK]] = 0; |
529 | PPM_diff[ParamSet.ChannelAssignment[CH_ROLL]] = 0; |
529 | PPM_diff[ParamSet.ChannelAssignment[CH_ROLL]] = 0; |
530 | PPM_diff[ParamSet.ChannelAssignment[CH_YAW]] = 0; |
530 | PPM_diff[ParamSet.ChannelAssignment[CH_YAW]] = 0; |
531 | PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] = 0; |
531 | PPM_in[ParamSet.ChannelAssignment[CH_NICK]] = 0; |
532 | PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] = 0; |
532 | PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] = 0; |
533 | PPM_in[ParamSet.ChannelAssignment[CH_YAW]] = 0; |
533 | PPM_in[ParamSet.ChannelAssignment[CH_YAW]] = 0; |
534 | } |
534 | } |
535 | else MotorsOn = 0; // switch of all motors |
535 | else MotorsOn = 0; // switch of all motors |
536 | } // eof RC_Quality < 120 |
536 | } // eof RC_Quality < 120 |
Line 540... | Line 540... | ||
540 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
540 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
541 | if(RC_Quality > 140) |
541 | if(RC_Quality > 140) |
542 | { |
542 | { |
543 | EmergencyLanding = 0; // switch off emergency landing if RC-signal is okay |
543 | EmergencyLanding = 0; // switch off emergency landing if RC-signal is okay |
544 | // reset emergency timer |
544 | // reset emergency timer |
545 | RcLostTimer = ParamSet.EmergencyThrustDuration * 50; |
545 | RcLostTimer = ParamSet.EmergencyGasDuration * 50; |
546 | if(ThrustMixFraction > 40) |
546 | if(GasMixFraction > 40) |
547 | { |
547 | { |
548 | if(Model_Is_Flying < 0xFFFF) Model_Is_Flying++; |
548 | if(Model_Is_Flying < 0xFFFF) Model_Is_Flying++; |
549 | } |
549 | } |
550 | if(Model_Is_Flying < 256) |
550 | if(Model_Is_Flying < 256) |
551 | { |
551 | { |
552 | SumPitch = 0; |
552 | SumNick = 0; |
553 | SumRoll = 0; |
553 | SumRoll = 0; |
554 | StickYaw = 0; |
554 | StickYaw = 0; |
555 | if(Model_Is_Flying == 250) UpdateCompassCourse = 1; |
555 | if(Model_Is_Flying == 250) UpdateCompassCourse = 1; |
556 | } |
556 | } |
Line 573... | Line 573... | ||
573 | if(Poti5 < 0) Poti5 = 0; else if(Poti5 > 255) Poti5 = 255; |
573 | if(Poti5 < 0) Poti5 = 0; else if(Poti5 > 255) Poti5 = 255; |
574 | if(Poti6 < 0) Poti6 = 0; else if(Poti6 > 255) Poti6 = 255; |
574 | if(Poti6 < 0) Poti6 = 0; else if(Poti6 > 255) Poti6 = 255; |
575 | if(Poti7 < 0) Poti7 = 0; else if(Poti7 > 255) Poti7 = 255; |
575 | if(Poti7 < 0) Poti7 = 0; else if(Poti7 > 255) Poti7 = 255; |
576 | if(Poti8 < 0) Poti8 = 0; else if(Poti8 > 255) Poti8 = 255; |
576 | if(Poti8 < 0) Poti8 = 0; else if(Poti8 > 255) Poti8 = 255; |
Line -... | Line 577... | ||
- | 577 | ||
577 | 578 | ||
578 | // if motors are off and the thrust stick is in the upper position |
579 | // if motors are off and the gas stick is in the upper position |
579 | if(MotorsOn == 0 && (PPM_in[ParamSet.ChannelAssignment[CH_THRUST]] > 80)) |
580 | if((PPM_in[ParamSet.ChannelAssignment[CH_GAS]] > 80) && MotorsOn == 0) |
580 | { |
581 | { |
581 | // and if the yaw stick is in the leftmost position |
582 | // and if the yaw stick is in the leftmost position |
582 | if(PPM_in[ParamSet.ChannelAssignment[CH_YAW]] > 75) |
583 | if(PPM_in[ParamSet.ChannelAssignment[CH_YAW]] > 75) |
583 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
584 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
584 | // calibrate the neutral readings of all attitude sensors |
585 | // calibrate the neutral readings of all attitude sensors |
585 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
586 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
586 | { |
587 | { |
587 | // thrust/yaw joystick is top left |
588 | // gas/yaw joystick is top left |
588 | // _________ |
589 | // _________ |
589 | // |x | |
590 | // |x | |
590 | // | | |
591 | // | | |
591 | // | | |
592 | // | | |
Line 595... | Line 596... | ||
595 | if(++delay_neutral > 200) // not immediately (wait 200 loops = 200 * 2ms = 0.4 s) |
596 | if(++delay_neutral > 200) // not immediately (wait 200 loops = 200 * 2ms = 0.4 s) |
596 | { |
597 | { |
597 | delay_neutral = 0; |
598 | delay_neutral = 0; |
598 | GRN_OFF; |
599 | GRN_OFF; |
599 | Model_Is_Flying = 0; |
600 | Model_Is_Flying = 0; |
600 | // check roll/pitch stick position |
601 | // check roll/nick stick position |
601 | // if pitch stick is top or roll stick is left or right --> change parameter setting |
602 | // if nick stick is top or roll stick is left or right --> change parameter setting |
602 | // according to roll/pitch stick position |
603 | // according to roll/nick stick position |
603 | if(PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] > 70 || abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]) > 70) |
604 | if(PPM_in[ParamSet.ChannelAssignment[CH_NICK]] > 70 || abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]) > 70) |
604 | { |
605 | { |
605 | uint8_t setting = 1; // default |
606 | uint8_t setting = 1; // default |
606 | // pitch/roll joystick |
607 | // nick/roll joystick |
607 | // _________ |
608 | // _________ |
608 | // |2 3 4| |
609 | // |2 3 4| |
609 | // | | |
610 | // | | |
610 | // |1 5| |
611 | // |1 5| |
611 | // | | |
612 | // | | |
612 | // | | |
613 | // | | |
613 | // ¯¯¯¯¯¯¯¯¯ |
614 | // ¯¯¯¯¯¯¯¯¯ |
614 | // roll stick leftmost and pitch stick centered --> setting 1 |
615 | // roll stick leftmost and nick stick centered --> setting 1 |
615 | if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > 70 && PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] < 70) setting = 1; |
616 | if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > 70 && PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < 70) setting = 1; |
616 | // roll stick leftmost and pitch stick topmost --> setting 2 |
617 | // roll stick leftmost and nick stick topmost --> setting 2 |
617 | if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > 70 && PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] > 70) setting = 2; |
618 | if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > 70 && PPM_in[ParamSet.ChannelAssignment[CH_NICK]] > 70) setting = 2; |
618 | // roll stick centered an pitch stick topmost --> setting 3 |
619 | // roll stick centered an nick stick topmost --> setting 3 |
619 | if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] < 70 && PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] > 70) setting = 3; |
620 | if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] < 70 && PPM_in[ParamSet.ChannelAssignment[CH_NICK]] > 70) setting = 3; |
620 | // roll stick rightmost and pitch stick topmost --> setting 4 |
621 | // roll stick rightmost and nick stick topmost --> setting 4 |
621 | if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] <-70 && PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] > 70) setting = 4; |
622 | if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] <-70 && PPM_in[ParamSet.ChannelAssignment[CH_NICK]] > 70) setting = 4; |
622 | // roll stick rightmost and pitch stick centered --> setting 5 |
623 | // roll stick rightmost and nick stick centered --> setting 5 |
623 | if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] <-70 && PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] < 70) setting = 5; |
624 | if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] <-70 && PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < 70) setting = 5; |
624 | // update active parameter set in eeprom |
625 | // update active parameter set in eeprom |
625 | SetActiveParamSet(setting); |
626 | SetActiveParamSet(setting); |
626 | ParamSet_ReadFromEEProm(GetActiveParamSet()); |
627 | ParamSet_ReadFromEEProm(GetActiveParamSet()); |
627 | SetNeutral(); |
628 | SetNeutral(); |
628 | Beep(GetActiveParamSet()); |
629 | Beep(GetActiveParamSet()); |
629 | } |
630 | } |
630 | else |
631 | else |
631 | { |
632 | { |
632 | if((ParamSet.GlobalConfig & CFG_COMPASS_ACTIVE)) |
633 | if((ParamSet.GlobalConfig & CFG_COMPASS_ACTIVE)) |
633 | { |
634 | { |
634 | // if roll stick is centered and pitch stick is down |
635 | // if roll stick is centered and nick stick is down |
635 | if (abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]) < 20 && PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] < -70) |
636 | if (abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]) < 20 && PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < -70) |
636 | { |
637 | { |
637 | // pitch/roll joystick |
638 | // nick/roll joystick |
638 | // _________ |
639 | // _________ |
639 | // | | |
640 | // | | |
640 | // | | |
641 | // | | |
641 | // | | |
642 | // | | |
642 | // | | |
643 | // | | |
Line 644... | Line 645... | ||
644 | // ¯¯¯¯¯¯¯¯¯ |
645 | // ¯¯¯¯¯¯¯¯¯ |
645 | // enable calibration state of compass |
646 | // enable calibration state of compass |
646 | CompassCalState = 1; |
647 | CompassCalState = 1; |
647 | BeepTime = 1000; |
648 | BeepTime = 1000; |
648 | } |
649 | } |
649 | else // pitch and roll are centered |
650 | else // nick and roll are centered |
650 | { |
651 | { |
651 | ParamSet_ReadFromEEProm(GetActiveParamSet()); |
652 | ParamSet_ReadFromEEProm(GetActiveParamSet()); |
652 | SetNeutral(); |
653 | SetNeutral(); |
653 | Beep(GetActiveParamSet()); |
654 | Beep(GetActiveParamSet()); |
654 | } |
655 | } |
655 | } |
656 | } |
656 | else // pitch and roll are centered |
657 | else // nick and roll are centered |
657 | { |
658 | { |
658 | ParamSet_ReadFromEEProm(GetActiveParamSet()); |
659 | ParamSet_ReadFromEEProm(GetActiveParamSet()); |
659 | SetNeutral(); |
660 | SetNeutral(); |
660 | Beep(GetActiveParamSet()); |
661 | Beep(GetActiveParamSet()); |
661 | } |
662 | } |
Line 668... | Line 669... | ||
668 | { |
669 | { |
669 | if(++delay_neutral > 200) // not immediately (wait 200 loops = 200 * 2ms = 0.4 s) |
670 | if(++delay_neutral > 200) // not immediately (wait 200 loops = 200 * 2ms = 0.4 s) |
670 | { |
671 | { |
671 | delay_neutral = 0; |
672 | delay_neutral = 0; |
672 | GRN_OFF; |
673 | GRN_OFF; |
673 | SetParamWord(PID_ACC_PITCH, 0xFFFF); // make value invalid |
674 | SetParamWord(PID_ACC_NICK, 0xFFFF); // make value invalid |
674 | Model_Is_Flying = 0; |
675 | Model_Is_Flying = 0; |
675 | SetNeutral(); |
676 | SetNeutral(); |
676 | // Save ACC neutral settings to eeprom |
677 | // Save ACC neutral settings to eeprom |
677 | SetParamWord(PID_ACC_PITCH, (uint16_t)NeutralAccX); |
678 | SetParamWord(PID_ACC_NICK, (uint16_t)NeutralAccX); |
678 | SetParamWord(PID_ACC_ROLL, (uint16_t)NeutralAccY); |
679 | SetParamWord(PID_ACC_ROLL, (uint16_t)NeutralAccY); |
679 | SetParamWord(PID_ACC_Z, (uint16_t)NeutralAccZ); |
680 | SetParamWord(PID_ACC_Z, (uint16_t)NeutralAccZ); |
680 | Beep(GetActiveParamSet()); |
681 | Beep(GetActiveParamSet()); |
681 | } |
682 | } |
682 | } |
683 | } |
683 | else delay_neutral = 0; |
684 | else delay_neutral = 0; |
684 | } |
685 | } |
685 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
686 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
686 | // thrust stick is down |
687 | // gas stick is down |
687 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
688 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
688 | if(PPM_in[ParamSet.ChannelAssignment[CH_THRUST]] < -85) |
689 | if(PPM_in[ParamSet.ChannelAssignment[CH_GAS]] < -85) |
689 | { |
690 | { |
690 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
691 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
691 | // and yaw stick is rightmost --> start motors |
692 | // and yaw stick is rightmost --> start motors |
692 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
693 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
693 | if(PPM_in[ParamSet.ChannelAssignment[CH_YAW]] < -75) |
694 | if(PPM_in[ParamSet.ChannelAssignment[CH_YAW]] < -75) |
Line 697... | Line 698... | ||
697 | delay_startmotors = 0; // do not repeat if once executed |
698 | delay_startmotors = 0; // do not repeat if once executed |
698 | Model_Is_Flying = 1; |
699 | Model_Is_Flying = 1; |
699 | MotorsOn = 1; |
700 | MotorsOn = 1; |
700 | SetPointYaw = 0; |
701 | SetPointYaw = 0; |
701 | Reading_IntegralGyroYaw = 0; |
702 | Reading_IntegralGyroYaw = 0; |
702 | Reading_IntegralGyroPitch = 0; |
703 | Reading_IntegralGyroNick = 0; |
703 | Reading_IntegralGyroRoll = 0; |
704 | Reading_IntegralGyroRoll = 0; |
704 | Reading_IntegralGyroPitch2 = IntegralPitch; |
705 | Reading_IntegralGyroNick2 = IntegralNick; |
705 | Reading_IntegralGyroRoll2 = IntegralRoll; |
706 | Reading_IntegralGyroRoll2 = IntegralRoll; |
706 | SumPitch = 0; |
707 | SumNick = 0; |
707 | SumRoll = 0; |
708 | SumRoll = 0; |
708 | #if defined (USE_KILLAGREG) || defined (USE_MK3MAG) |
709 | #if defined (USE_KILLAGREG) || defined (USE_MK3MAG) |
709 | if(ParamSet.GlobalConfig & CFG_GPS_ACTIVE) |
710 | if(ParamSet.GlobalConfig & CFG_GPS_ACTIVE) |
710 | { |
711 | { |
711 | GPS_SetHomePosition(); |
712 | GPS_SetHomePosition(); |
Line 742... | Line 743... | ||
742 | if(!NewPpmData-- || EmergencyLanding) // NewData = 0 means new data from RC |
743 | if(!NewPpmData-- || EmergencyLanding) // NewData = 0 means new data from RC |
743 | { |
744 | { |
744 | int tmp_int; |
745 | int tmp_int; |
745 | ParameterMapping(); // remapping params (online poti replacement) |
746 | ParameterMapping(); // remapping params (online poti replacement) |
746 | // calculate Stick inputs by rc channels (P) and changing of rc channels (D) |
747 | // calculate Stick inputs by rc channels (P) and changing of rc channels (D) |
747 | StickPitch = (StickPitch * 3 + PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] * ParamSet.Stick_P) / 4; |
748 | StickNick = (StickNick * 3 + PPM_in[ParamSet.ChannelAssignment[CH_NICK]] * ParamSet.Stick_P) / 4; |
748 | StickPitch += PPM_diff[ParamSet.ChannelAssignment[CH_PITCH]] * ParamSet.Stick_D; |
749 | StickNick += PPM_diff[ParamSet.ChannelAssignment[CH_NICK]] * ParamSet.Stick_D; |
749 | StickPitch -= (GPS_Pitch); |
750 | StickNick -= (GPS_Nick); |
Line 750... | Line 751... | ||
750 | 751 | ||
751 | StickRoll = (StickRoll * 3 + PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] * ParamSet.Stick_P) / 4; |
752 | StickRoll = (StickRoll * 3 + PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] * ParamSet.Stick_P) / 4; |
752 | StickRoll += PPM_diff[ParamSet.ChannelAssignment[CH_ROLL]] * ParamSet.Stick_D; |
753 | StickRoll += PPM_diff[ParamSet.ChannelAssignment[CH_ROLL]] * ParamSet.Stick_D; |
Line 753... | Line 754... | ||
753 | StickRoll -= (GPS_Roll); |
754 | StickRoll -= (GPS_Roll); |
754 | 755 | ||
755 | // direct mapping of yaw and thrust |
756 | // direct mapping of yaw and gas |
Line 756... | Line 757... | ||
756 | StickYaw = -PPM_in[ParamSet.ChannelAssignment[CH_YAW]]; |
757 | StickYaw = -PPM_in[ParamSet.ChannelAssignment[CH_YAW]]; |
757 | StickThrust = PPM_in[ParamSet.ChannelAssignment[CH_THRUST]] + 120;// shift to positive numbers |
758 | StickGas = PPM_in[ParamSet.ChannelAssignment[CH_GAS]] + 120;// shift to positive numbers |
758 | 759 | ||
Line 767... | Line 768... | ||
767 | #define KEY_VALUE (FCParam.UserParam8 * 4) // step width |
768 | #define KEY_VALUE (FCParam.UserParam8 * 4) // step width |
768 | if(DubWiseKeys[1]) BeepTime = 10; |
769 | if(DubWiseKeys[1]) BeepTime = 10; |
769 | if(DubWiseKeys[1] & DUB_KEY_UP) tmp_int = KEY_VALUE; |
770 | if(DubWiseKeys[1] & DUB_KEY_UP) tmp_int = KEY_VALUE; |
770 | else if(DubWiseKeys[1] & DUB_KEY_DOWN) tmp_int = -KEY_VALUE; |
771 | else if(DubWiseKeys[1] & DUB_KEY_DOWN) tmp_int = -KEY_VALUE; |
771 | else tmp_int = 0; |
772 | else tmp_int = 0; |
772 | ExternStickPitch = (ExternStickPitch * 7 + tmp_int) / 8; |
773 | ExternStickNick = (ExternStickNick * 7 + tmp_int) / 8; |
773 | if(DubWiseKeys[1] & DUB_KEY_LEFT) tmp_int = KEY_VALUE; |
774 | if(DubWiseKeys[1] & DUB_KEY_LEFT) tmp_int = KEY_VALUE; |
774 | else if(DubWiseKeys[1] & DUB_KEY_RIGHT) tmp_int = -KEY_VALUE; |
775 | else if(DubWiseKeys[1] & DUB_KEY_RIGHT) tmp_int = -KEY_VALUE; |
775 | else tmp_int = 0; |
776 | else tmp_int = 0; |
776 | ExternStickRoll = (ExternStickRoll * 7 + tmp_int) / 8; |
777 | ExternStickRoll = (ExternStickRoll * 7 + tmp_int) / 8; |
Line 777... | Line 778... | ||
777 | 778 | ||
778 | if(DubWiseKeys[0] & 8) ExternStickYaw = 50;else |
779 | if(DubWiseKeys[0] & 8) ExternStickYaw = 50;else |
779 | if(DubWiseKeys[0] & 4) ExternStickYaw =-50;else ExternStickYaw = 0; |
780 | if(DubWiseKeys[0] & 4) ExternStickYaw =-50;else ExternStickYaw = 0; |
780 | if(DubWiseKeys[0] & 2) ExternHeightValue++; |
781 | if(DubWiseKeys[0] & 2) ExternHeightValue++; |
Line 781... | Line 782... | ||
781 | if(DubWiseKeys[0] & 16) ExternHeightValue--; |
782 | if(DubWiseKeys[0] & 16) ExternHeightValue--; |
782 | 783 | ||
783 | StickPitch += (STICK_GAIN * ExternStickPitch) / 8; |
784 | StickNick += (STICK_GAIN * ExternStickNick) / 8; |
Line 784... | Line 785... | ||
784 | StickRoll += (STICK_GAIN * ExternStickRoll) / 8; |
785 | StickRoll += (STICK_GAIN * ExternStickRoll) / 8; |
785 | StickYaw += (STICK_GAIN * ExternStickYaw); |
786 | StickYaw += (STICK_GAIN * ExternStickYaw); |
786 | 787 | ||
Line 787... | Line 788... | ||
787 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
788 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
788 | //+ Analog control via serial communication |
789 | //+ Analog control via serial communication |
789 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
790 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
790 | 791 | ||
791 | if(ExternControl.Config & 0x01 && FCParam.UserParam8 > 128) |
792 | if(ExternControl.Config & 0x01 && FCParam.UserParam8 > 128) |
792 | { |
793 | { |
793 | StickPitch += (int16_t) ExternControl.Pitch * (int16_t) ParamSet.Stick_P; |
794 | StickNick += (int16_t) ExternControl.Nick * (int16_t) ParamSet.Stick_P; |
794 | StickRoll += (int16_t) ExternControl.Roll * (int16_t) ParamSet.Stick_P; |
795 | StickRoll += (int16_t) ExternControl.Roll * (int16_t) ParamSet.Stick_P; |
795 | StickYaw += ExternControl.Yaw; |
796 | StickYaw += ExternControl.Yaw; |
Line 796... | Line 797... | ||
796 | ExternHeightValue = (int16_t) ExternControl.Height * (int16_t)ParamSet.Height_Gain; |
797 | ExternHeightValue = (int16_t) ExternControl.Height * (int16_t)ParamSet.Height_Gain; |
797 | if(ExternControl.Thrust < StickThrust) StickThrust = ExternControl.Thrust; |
798 | if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas; |
798 | } |
799 | } |
799 | if(StickThrust < 0) StickThrust = 0; |
800 | if(StickGas < 0) StickGas = 0; |
800 | 801 | ||
Line 801... | Line 802... | ||
801 | // disable I part of gyro control feedback |
802 | // disable I part of gyro control feedback |
Line 802... | Line 803... | ||
802 | if(ParamSet.GlobalConfig & CFG_HEADING_HOLD) Gyro_I_Factor = 0; |
803 | if(ParamSet.GlobalConfig & CFG_HEADING_HOLD) Gyro_I_Factor = 0; |
803 | // avoid negative scaling factors |
804 | // avoid negative scaling factors |
804 | if(Gyro_P_Factor < 0) Gyro_P_Factor = 0; |
805 | if(Gyro_P_Factor < 0) Gyro_P_Factor = 0; |
805 | if(Gyro_I_Factor < 0) Gyro_I_Factor = 0; |
806 | if(Gyro_I_Factor < 0) Gyro_I_Factor = 0; |
Line 806... | Line 807... | ||
806 | 807 | ||
807 | 808 | ||
Line 831... | Line 832... | ||
831 | { |
832 | { |
832 | if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > -(ParamSet.LoopThreshold - ParamSet.LoopHysteresis)) Looping_Right = 0; |
833 | if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > -(ParamSet.LoopThreshold - ParamSet.LoopHysteresis)) Looping_Right = 0; |
833 | } |
834 | } |
834 | } |
835 | } |
Line 835... | Line 836... | ||
835 | 836 | ||
836 | if((PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] > ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_UP) Looping_Top = 1; |
837 | if((PPM_in[ParamSet.ChannelAssignment[CH_NICK]] > ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_UP) Looping_Top = 1; |
837 | else |
838 | else |
838 | { |
839 | { |
839 | if(Looping_Top) // Hysteresis |
840 | if(Looping_Top) // Hysteresis |
840 | { |
841 | { |
841 | if((PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] < (ParamSet.LoopThreshold - ParamSet.LoopHysteresis))) Looping_Top = 0; |
842 | if((PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < (ParamSet.LoopThreshold - ParamSet.LoopHysteresis))) Looping_Top = 0; |
842 | } |
843 | } |
843 | } |
844 | } |
844 | if((PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] < -ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_DOWN) Looping_Down = 1; |
845 | if((PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < -ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_DOWN) Looping_Down = 1; |
845 | else |
846 | else |
846 | { |
847 | { |
847 | if(Looping_Down) // Hysteresis |
848 | if(Looping_Down) // Hysteresis |
848 | { |
849 | { |
849 | if(PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] > -(ParamSet.LoopThreshold - ParamSet.LoopHysteresis)) Looping_Down = 0; |
850 | if(PPM_in[ParamSet.ChannelAssignment[CH_NICK]] > -(ParamSet.LoopThreshold - ParamSet.LoopHysteresis)) Looping_Down = 0; |
850 | } |
851 | } |
Line 851... | Line 852... | ||
851 | } |
852 | } |
852 | 853 | ||
853 | if(Looping_Left || Looping_Right) Looping_Roll = 1; else Looping_Roll = 0; |
854 | if(Looping_Left || Looping_Right) Looping_Roll = 1; else Looping_Roll = 0; |
Line 854... | Line -... | ||
854 | if(Looping_Top || Looping_Down) {Looping_Pitch = 1; Looping_Roll = 0; Looping_Left = 0; Looping_Right = 0;} else Looping_Pitch = 0; |
- | |
855 | } // End of new RC-Values or Emergency Landing |
855 | if(Looping_Top || Looping_Down) {Looping_Nick = 1; Looping_Roll = 0; Looping_Left = 0; Looping_Right = 0;} else Looping_Nick = 0; |
856 | 856 | } // End of new RC-Values or Emergency Landing |
|
857 | 857 | ||
858 | if(Looping_Roll) BeepTime = 100; |
858 | |
Line 859... | Line 859... | ||
859 | if(Looping_Roll || Looping_Pitch) |
859 | if(Looping_Roll || Looping_Nick) |
860 | { |
860 | { |
Line 874... | Line 874... | ||
874 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
874 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
875 | // set all inputs to save values |
875 | // set all inputs to save values |
876 | if(EmergencyLanding) |
876 | if(EmergencyLanding) |
877 | { |
877 | { |
878 | StickYaw = 0; |
878 | StickYaw = 0; |
879 | StickPitch = 0; |
879 | StickNick = 0; |
880 | StickRoll = 0; |
880 | StickRoll = 0; |
881 | Gyro_P_Factor = (float) 100 / (256.0 / STICK_GAIN); |
881 | Gyro_P_Factor = (float) 100 / (256.0 / STICK_GAIN); |
882 | Gyro_I_Factor = (float) 120 / (44000 / STICK_GAIN); |
882 | Gyro_I_Factor = (float) 120 / (44000 / STICK_GAIN); |
883 | Looping_Roll = 0; |
883 | Looping_Roll = 0; |
884 | Looping_Pitch = 0; |
884 | Looping_Nick = 0; |
885 | MaxStickPitch = 0; |
885 | MaxStickNick = 0; |
886 | MaxStickRoll = 0; |
886 | MaxStickRoll = 0; |
887 | } |
887 | } |
Line 888... | Line 888... | ||
888 | 888 | ||
889 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
889 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
890 | // Trim Gyro-Integrals to ACC-Signals |
890 | // Trim Gyro-Integrals to ACC-Signals |
Line 891... | Line 891... | ||
891 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
891 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
892 | 892 | ||
893 | #define BALANCE_NUMBER 256L |
893 | #define BALANCE_NUMBER 256L |
894 | // sum for averaging |
894 | // sum for averaging |
Line 895... | Line 895... | ||
895 | MeanIntegralPitch += IntegralPitch; |
895 | MeanIntegralNick += IntegralNick; |
896 | MeanIntegralRoll += IntegralRoll; |
896 | MeanIntegralRoll += IntegralRoll; |
897 | 897 | ||
898 | if(Looping_Pitch || Looping_Roll) // if looping in any direction |
898 | if(Looping_Nick || Looping_Roll) // if looping in any direction |
Line 899... | Line 899... | ||
899 | { |
899 | { |
900 | // reset averaging for acc and gyro integral as well as gyro integral acc correction |
900 | // reset averaging for acc and gyro integral as well as gyro integral acc correction |
Line 901... | Line 901... | ||
901 | MeasurementCounter = 0; |
901 | MeasurementCounter = 0; |
902 | 902 | ||
Line 903... | Line 903... | ||
903 | IntegralAccPitch = 0; |
903 | IntegralAccNick = 0; |
904 | IntegralAccRoll = 0; |
904 | IntegralAccRoll = 0; |
Line 905... | Line 905... | ||
905 | 905 | ||
906 | MeanIntegralPitch = 0; |
906 | MeanIntegralNick = 0; |
907 | MeanIntegralRoll = 0; |
907 | MeanIntegralRoll = 0; |
Line 908... | Line 908... | ||
908 | 908 | ||
909 | Reading_IntegralGyroPitch2 = Reading_IntegralGyroPitch; |
909 | Reading_IntegralGyroNick2 = Reading_IntegralGyroNick; |
910 | Reading_IntegralGyroRoll2 = Reading_IntegralGyroRoll; |
910 | Reading_IntegralGyroRoll2 = Reading_IntegralGyroRoll; |
911 | 911 | ||
912 | AttitudeCorrectionPitch = 0; |
912 | AttitudeCorrectionNick = 0; |
913 | AttitudeCorrectionRoll = 0; |
913 | AttitudeCorrectionRoll = 0; |
914 | } |
914 | } |
915 | 915 | ||
916 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
916 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Line 917... | Line 917... | ||
917 | if(!Looping_Pitch && !Looping_Roll) // if not lopping in any direction |
917 | if(!Looping_Nick && !Looping_Roll) // if not lopping in any direction |
918 | { |
918 | { |
919 | int32_t tmp_long, tmp_long2; |
919 | int32_t tmp_long, tmp_long2; |
920 | // determine the deviation of gyro integral from averaged acceleration sensor |
920 | // determine the deviation of gyro integral from averaged acceleration sensor |
921 | tmp_long = (int32_t)(IntegralPitch / ParamSet.GyroAccFactor - (int32_t)Mean_AccPitch); |
921 | tmp_long = (int32_t)(IntegralNick / ParamSet.GyroAccFactor - (int32_t)Mean_AccNick); |
922 | tmp_long /= 16; |
922 | tmp_long /= 16; |
Line 939... | Line 939... | ||
939 | if(tmp_long > BALANCE) tmp_long = BALANCE; |
939 | if(tmp_long > BALANCE) tmp_long = BALANCE; |
940 | if(tmp_long < -BALANCE) tmp_long =-BALANCE; |
940 | if(tmp_long < -BALANCE) tmp_long =-BALANCE; |
941 | if(tmp_long2 > BALANCE) tmp_long2 = BALANCE; |
941 | if(tmp_long2 > BALANCE) tmp_long2 = BALANCE; |
942 | if(tmp_long2 <-BALANCE) tmp_long2 =-BALANCE; |
942 | if(tmp_long2 <-BALANCE) tmp_long2 =-BALANCE; |
943 | // correct current readings |
943 | // correct current readings |
944 | Reading_IntegralGyroPitch -= tmp_long; |
944 | Reading_IntegralGyroNick -= tmp_long; |
945 | Reading_IntegralGyroRoll -= tmp_long2; |
945 | Reading_IntegralGyroRoll -= tmp_long2; |
946 | } |
946 | } |
947 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
947 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
948 | // MeasurementCounter is incremented in the isr of analog.c |
948 | // MeasurementCounter is incremented in the isr of analog.c |
949 | if(MeasurementCounter >= BALANCE_NUMBER) // averaging number has reached |
949 | if(MeasurementCounter >= BALANCE_NUMBER) // averaging number has reached |
950 | { |
950 | { |
951 | static int16_t cnt = 0; |
951 | static int16_t cnt = 0; |
952 | static int8_t last_n_p, last_n_n, last_r_p, last_r_n; |
952 | static int8_t last_n_p, last_n_n, last_r_p, last_r_n; |
953 | static int32_t MeanIntegralPitch_old, MeanIntegralRoll_old; |
953 | static int32_t MeanIntegralNick_old, MeanIntegralRoll_old; |
Line 954... | Line 954... | ||
954 | 954 | ||
955 | // if not lopping in any direction (this should be alwais the case, |
955 | // if not lopping in any direction (this should be alwais the case, |
956 | // because the Measurement counter is reset to 0 if looping in any direction is active.) |
956 | // because the Measurement counter is reset to 0 if looping in any direction is active.) |
957 | if(!Looping_Pitch && !Looping_Roll && !FunnelCourse) |
957 | if(!Looping_Nick && !Looping_Roll && !FunnelCourse) |
958 | { |
958 | { |
959 | // Calculate mean value of the gyro integrals |
959 | // Calculate mean value of the gyro integrals |
960 | MeanIntegralPitch /= BALANCE_NUMBER; |
960 | MeanIntegralNick /= BALANCE_NUMBER; |
Line 961... | Line 961... | ||
961 | MeanIntegralRoll /= BALANCE_NUMBER; |
961 | MeanIntegralRoll /= BALANCE_NUMBER; |
962 | 962 | ||
963 | // Calculate mean of the acceleration values |
963 | // Calculate mean of the acceleration values |
Line 964... | Line 964... | ||
964 | IntegralAccPitch = (ParamSet.GyroAccFactor * IntegralAccPitch) / BALANCE_NUMBER; |
964 | IntegralAccNick = (ParamSet.GyroAccFactor * IntegralAccNick) / BALANCE_NUMBER; |
965 | IntegralAccRoll = (ParamSet.GyroAccFactor * IntegralAccRoll ) / BALANCE_NUMBER; |
965 | IntegralAccRoll = (ParamSet.GyroAccFactor * IntegralAccRoll ) / BALANCE_NUMBER; |
966 | 966 | ||
967 | // Pitch ++++++++++++++++++++++++++++++++++++++++++++++++ |
967 | // Nick ++++++++++++++++++++++++++++++++++++++++++++++++ |
968 | // Calculate deviation of the averaged gyro integral and the averaged acceleration integral |
968 | // Calculate deviation of the averaged gyro integral and the averaged acceleration integral |
969 | IntegralErrorPitch = (int32_t)(MeanIntegralPitch - (int32_t)IntegralAccPitch); |
969 | IntegralErrorNick = (int32_t)(MeanIntegralNick - (int32_t)IntegralAccNick); |
970 | CorrectionPitch = IntegralErrorPitch / ParamSet.GyroAccTrim; |
970 | CorrectionNick = IntegralErrorNick / ParamSet.GyroAccTrim; |
971 | AttitudeCorrectionPitch = CorrectionPitch / BALANCE_NUMBER; |
971 | AttitudeCorrectionNick = CorrectionNick / BALANCE_NUMBER; |
972 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
972 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
973 | // Calculate deviation of the averaged gyro integral and the averaged acceleration integral |
973 | // Calculate deviation of the averaged gyro integral and the averaged acceleration integral |
Line 974... | Line 974... | ||
974 | IntegralErrorRoll = (int32_t)(MeanIntegralRoll - (int32_t)IntegralAccRoll); |
974 | IntegralErrorRoll = (int32_t)(MeanIntegralRoll - (int32_t)IntegralAccRoll); |
975 | CorrectionRoll = IntegralErrorRoll / ParamSet.GyroAccTrim; |
975 | CorrectionRoll = IntegralErrorRoll / ParamSet.GyroAccTrim; |
976 | AttitudeCorrectionRoll = CorrectionRoll / BALANCE_NUMBER; |
976 | AttitudeCorrectionRoll = CorrectionRoll / BALANCE_NUMBER; |
977 | 977 | ||
978 | if((MaxStickPitch > 32) || (MaxStickRoll > 32) || (abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]) > 25)) |
978 | if((MaxStickNick > 32) || (MaxStickRoll > 32) || (abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]) > 25)) |
Line 979... | Line 979... | ||
979 | { |
979 | { |
980 | AttitudeCorrectionPitch /= 2; |
980 | AttitudeCorrectionNick /= 2; |
981 | AttitudeCorrectionRoll /= 2; |
981 | AttitudeCorrectionRoll /= 2; |
982 | } |
982 | } |
983 | 983 | ||
984 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
984 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
985 | // Gyro-Drift ermitteln |
985 | // Gyro-Drift ermitteln |
986 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
986 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
987 | // deviation of gyro pitch integral (IntegralPitch is corrected by averaged acc sensor) |
987 | // deviation of gyro nick integral (IntegralNick is corrected by averaged acc sensor) |
Line 988... | Line 988... | ||
988 | IntegralErrorPitch = IntegralPitch2 - IntegralPitch; |
988 | IntegralErrorNick = IntegralNick2 - IntegralNick; |
989 | Reading_IntegralGyroPitch2 -= IntegralErrorPitch; |
989 | Reading_IntegralGyroNick2 -= IntegralErrorNick; |
990 | // deviation of gyro pitch integral (IntegralPitch is corrected by averaged acc sensor) |
990 | // deviation of gyro nick integral (IntegralNick is corrected by averaged acc sensor) |
991 | IntegralErrorRoll = IntegralRoll2 - IntegralRoll; |
991 | IntegralErrorRoll = IntegralRoll2 - IntegralRoll; |
992 | Reading_IntegralGyroRoll2 -= IntegralErrorRoll; |
992 | Reading_IntegralGyroRoll2 -= IntegralErrorRoll; |
993 | 993 | ||
994 | if(YawGyroDrift > BALANCE_NUMBER/2) AdNeutralYaw++; |
994 | if(YawGyroDrift > BALANCE_NUMBER/2) AdNeutralYaw++; |
995 | if(YawGyroDrift < -BALANCE_NUMBER/2) AdNeutralYaw--; |
995 | if(YawGyroDrift < -BALANCE_NUMBER/2) AdNeutralYaw--; |
996 | YawGyroDrift = 0; |
996 | YawGyroDrift = 0; |
997 | /* |
997 | /* |
998 | DebugOut.Analog[17] = IntegralAccPitch / 26; |
998 | DebugOut.Analog[17] = IntegralAccNick / 26; |
999 | DebugOut.Analog[18] = IntegralAccRoll / 26; |
999 | DebugOut.Analog[18] = IntegralAccRoll / 26; |
1000 | DebugOut.Analog[19] = IntegralErrorPitch;// / 26; |
1000 | DebugOut.Analog[19] = IntegralErrorNick;// / 26; |
1001 | DebugOut.Analog[20] = IntegralErrorRoll;// / 26; |
1001 | DebugOut.Analog[20] = IntegralErrorRoll;// / 26; |
Line 1002... | Line 1002... | ||
1002 | DebugOut.Analog[21] = MeanIntegralPitch / 26; |
1002 | DebugOut.Analog[21] = MeanIntegralNick / 26; |
1003 | DebugOut.Analog[22] = MeanIntegralRoll / 26; |
1003 | DebugOut.Analog[22] = MeanIntegralRoll / 26; |
1004 | //DebugOut.Analog[28] = CorrectionPitch; |
1004 | //DebugOut.Analog[28] = CorrectionNick; |
1005 | DebugOut.Analog[29] = CorrectionRoll; |
1005 | DebugOut.Analog[29] = CorrectionRoll; |
1006 | DebugOut.Analog[30] = AttitudeCorrectionRoll * 10; |
1006 | DebugOut.Analog[30] = AttitudeCorrectionRoll * 10; |
1007 | */ |
1007 | */ |
1008 | 1008 | ||
1009 | #define ERROR_LIMIT (BALANCE_NUMBER * 4) |
1009 | #define ERROR_LIMIT (BALANCE_NUMBER * 4) |
1010 | #define ERROR_LIMIT2 (BALANCE_NUMBER * 16) |
1010 | #define ERROR_LIMIT2 (BALANCE_NUMBER * 16) |
1011 | #define MOVEMENT_LIMIT 20000 |
1011 | #define MOVEMENT_LIMIT 20000 |
1012 | // Pitch +++++++++++++++++++++++++++++++++++++++++++++++++ |
1012 | // Nick +++++++++++++++++++++++++++++++++++++++++++++++++ |
1013 | cnt = 1;// + labs(IntegralErrorPitch) / 4096; |
1013 | cnt = 1;// + labs(IntegralErrorNick) / 4096; |
1014 | CorrectionPitch = 0; |
1014 | CorrectionNick = 0; |
1015 | if(labs(MeanIntegralPitch_old - MeanIntegralPitch) < MOVEMENT_LIMIT) |
1015 | if(labs(MeanIntegralNick_old - MeanIntegralNick) < MOVEMENT_LIMIT) |
1016 | { |
1016 | { |
1017 | if(IntegralErrorPitch > ERROR_LIMIT2) |
1017 | if(IntegralErrorNick > ERROR_LIMIT2) |
1018 | { |
1018 | { |
1019 | if(last_n_p) |
1019 | if(last_n_p) |
1020 | { |
1020 | { |
1021 | cnt += labs(IntegralErrorPitch) / ERROR_LIMIT2; |
1021 | cnt += labs(IntegralErrorNick) / ERROR_LIMIT2; |
1022 | CorrectionPitch = IntegralErrorPitch / 8; |
1022 | CorrectionNick = IntegralErrorNick / 8; |
1023 | if(CorrectionPitch > 5000) CorrectionPitch = 5000; |
1023 | if(CorrectionNick > 5000) CorrectionNick = 5000; |
1024 | AttitudeCorrectionPitch += CorrectionPitch / BALANCE_NUMBER; |
1024 | AttitudeCorrectionNick += CorrectionNick / BALANCE_NUMBER; |
1025 | } |
1025 | } |
1026 | else last_n_p = 1; |
1026 | else last_n_p = 1; |
1027 | } |
1027 | } |
1028 | else last_n_p = 0; |
1028 | else last_n_p = 0; |
1029 | if(IntegralErrorPitch < -ERROR_LIMIT2) |
1029 | if(IntegralErrorNick < -ERROR_LIMIT2) |
1030 | { |
1030 | { |
1031 | if(last_n_n) |
1031 | if(last_n_n) |
1032 | { |
1032 | { |
1033 | cnt += labs(IntegralErrorPitch) / ERROR_LIMIT2; |
1033 | cnt += labs(IntegralErrorNick) / ERROR_LIMIT2; |
1034 | CorrectionPitch = IntegralErrorPitch / 8; |
1034 | CorrectionNick = IntegralErrorNick / 8; |
Line 1044... | Line 1044... | ||
1044 | cnt = 0; |
1044 | cnt = 0; |
1045 | BadCompassHeading = 500; |
1045 | BadCompassHeading = 500; |
1046 | } |
1046 | } |
1047 | if(cnt > ParamSet.DriftComp) cnt = ParamSet.DriftComp; |
1047 | if(cnt > ParamSet.DriftComp) cnt = ParamSet.DriftComp; |
1048 | // correct Gyro Offsets |
1048 | // correct Gyro Offsets |
1049 | if(IntegralErrorPitch > ERROR_LIMIT) AdNeutralPitch += cnt; |
1049 | if(IntegralErrorNick > ERROR_LIMIT) AdNeutralNick += cnt; |
1050 | if(IntegralErrorPitch < -ERROR_LIMIT) AdNeutralPitch -= cnt; |
1050 | if(IntegralErrorNick < -ERROR_LIMIT) AdNeutralNick -= cnt; |
Line 1051... | Line 1051... | ||
1051 | 1051 | ||
1052 | // Roll +++++++++++++++++++++++++++++++++++++++++++++++++ |
1052 | // Roll +++++++++++++++++++++++++++++++++++++++++++++++++ |
1053 | cnt = 1;// + labs(IntegralErrorPitch) / 4096; |
1053 | cnt = 1;// + labs(IntegralErrorNick) / 4096; |
1054 | CorrectionRoll = 0; |
1054 | CorrectionRoll = 0; |
1055 | if(labs(MeanIntegralRoll_old - MeanIntegralRoll) < MOVEMENT_LIMIT) |
1055 | if(labs(MeanIntegralRoll_old - MeanIntegralRoll) < MOVEMENT_LIMIT) |
1056 | { |
1056 | { |
1057 | if(IntegralErrorRoll > ERROR_LIMIT2) |
1057 | if(IntegralErrorRoll > ERROR_LIMIT2) |
Line 1088... | Line 1088... | ||
1088 | if(cnt > ParamSet.DriftComp) cnt = ParamSet.DriftComp; |
1088 | if(cnt > ParamSet.DriftComp) cnt = ParamSet.DriftComp; |
1089 | if(IntegralErrorRoll > ERROR_LIMIT) AdNeutralRoll += cnt; |
1089 | if(IntegralErrorRoll > ERROR_LIMIT) AdNeutralRoll += cnt; |
1090 | if(IntegralErrorRoll < -ERROR_LIMIT) AdNeutralRoll -= cnt; |
1090 | if(IntegralErrorRoll < -ERROR_LIMIT) AdNeutralRoll -= cnt; |
1091 | /* |
1091 | /* |
1092 | DebugOut.Analog[27] = CorrectionRoll; |
1092 | DebugOut.Analog[27] = CorrectionRoll; |
1093 | DebugOut.Analog[23] = AdNeutralPitch;//10*(AdNeutralPitch - StartNeutralPitch); |
1093 | DebugOut.Analog[23] = AdNeutralNick;//10*(AdNeutralNick - StartNeutralNick); |
1094 | DebugOut.Analog[24] = 10*(AdNeutralRoll - StartNeutralRoll); |
1094 | DebugOut.Analog[24] = 10*(AdNeutralRoll - StartNeutralRoll); |
1095 | */ |
1095 | */ |
1096 | } |
1096 | } |
1097 | else // looping is active |
1097 | else // looping is active |
1098 | { |
1098 | { |
1099 | AttitudeCorrectionRoll = 0; |
1099 | AttitudeCorrectionRoll = 0; |
1100 | AttitudeCorrectionPitch = 0; |
1100 | AttitudeCorrectionNick = 0; |
1101 | FunnelCourse = 0; |
1101 | FunnelCourse = 0; |
1102 | } |
1102 | } |
Line 1103... | Line 1103... | ||
1103 | 1103 | ||
1104 | // if Gyro_I_Factor == 0 , for example at Heading Hold, ignore attitude correction |
1104 | // if Gyro_I_Factor == 0 , for example at Heading Hold, ignore attitude correction |
1105 | if(!Gyro_I_Factor) |
1105 | if(!Gyro_I_Factor) |
1106 | { |
1106 | { |
1107 | AttitudeCorrectionRoll = 0; |
1107 | AttitudeCorrectionRoll = 0; |
1108 | AttitudeCorrectionPitch = 0; |
1108 | AttitudeCorrectionNick = 0; |
1109 | } |
1109 | } |
1110 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1110 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1111 | MeanIntegralPitch_old = MeanIntegralPitch; |
1111 | MeanIntegralNick_old = MeanIntegralNick; |
1112 | MeanIntegralRoll_old = MeanIntegralRoll; |
1112 | MeanIntegralRoll_old = MeanIntegralRoll; |
1113 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1113 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1114 | // reset variables used for averaging |
1114 | // reset variables used for averaging |
1115 | IntegralAccPitch = 0; |
1115 | IntegralAccNick = 0; |
1116 | IntegralAccRoll = 0; |
1116 | IntegralAccRoll = 0; |
1117 | MeanIntegralPitch = 0; |
1117 | MeanIntegralNick = 0; |
1118 | MeanIntegralRoll = 0; |
1118 | MeanIntegralRoll = 0; |
1119 | MeasurementCounter = 0; |
1119 | MeasurementCounter = 0; |
Line 1167... | Line 1167... | ||
1167 | MM3_Heading(); |
1167 | MM3_Heading(); |
1168 | } |
1168 | } |
1169 | #endif |
1169 | #endif |
Line 1170... | Line 1170... | ||
1170 | 1170 | ||
1171 | // get maximum attitude angle |
1171 | // get maximum attitude angle |
1172 | w = abs(IntegralPitch/512); |
1172 | w = abs(IntegralNick/512); |
1173 | v = abs(IntegralRoll /512); |
1173 | v = abs(IntegralRoll /512); |
1174 | if(v > w) w = v; |
1174 | if(v > w) w = v; |
1175 | // update compass course |
1175 | // update compass course |
1176 | if (w < 25 && UpdateCompassCourse && !BadCompassHeading) |
1176 | if (w < 25 && UpdateCompassCourse && !BadCompassHeading) |
Line 1193... | Line 1193... | ||
1193 | BadCompassHeading--; |
1193 | BadCompassHeading--; |
1194 | } |
1194 | } |
1195 | else |
1195 | else |
1196 | { // |
1196 | { // |
1197 | YawGyroDrift += error; |
1197 | YawGyroDrift += error; |
1198 | v = 64 + (MaxStickPitch + MaxStickRoll) / 8; |
1198 | v = 64 + (MaxStickNick + MaxStickRoll) / 8; |
1199 | // calc course deviation |
1199 | // calc course deviation |
1200 | r = ((540 + (YawGyroHeading / YAW_GYRO_DEG_FACTOR) - CompassCourse) % 360) - 180; |
1200 | r = ((540 + (YawGyroHeading / YAW_GYRO_DEG_FACTOR) - CompassCourse) % 360) - 180; |
1201 | v = (r * w) / v; // align to compass course |
1201 | v = (r * w) / v; // align to compass course |
1202 | // limit yaw rate |
1202 | // limit yaw rate |
1203 | w = 3 * FCParam.CompassYawEffect; |
1203 | w = 3 * FCParam.CompassYawEffect; |
Line 1225... | Line 1225... | ||
1225 | if(EmergencyLanding) GPS_Main(230); // enables Comming Home |
1225 | if(EmergencyLanding) GPS_Main(230); // enables Comming Home |
1226 | else GPS_Main(Poti3); // behavior controlled by Poti3 |
1226 | else GPS_Main(Poti3); // behavior controlled by Poti3 |
1227 | } |
1227 | } |
1228 | else |
1228 | else |
1229 | { |
1229 | { |
1230 | GPS_Pitch = 0; |
1230 | GPS_Nick = 0; |
1231 | GPS_Roll = 0; |
1231 | GPS_Roll = 0; |
1232 | } |
1232 | } |
1233 | #endif |
1233 | #endif |
Line 1234... | Line 1234... | ||
1234 | 1234 | ||
1235 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1235 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1236 | // Debugwerte zuordnen |
1236 | // Debugwerte zuordnen |
1237 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1237 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1238 | if(!TimerDebugOut--) |
1238 | if(!TimerDebugOut--) |
1239 | { |
1239 | { |
1240 | TimerDebugOut = 24; // update debug outputs every 25*2ms = 50 ms (20Hz) |
1240 | TimerDebugOut = 24; // update debug outputs every 25*2ms = 50 ms (20Hz) |
1241 | DebugOut.Analog[0] = IntegralPitch / ParamSet.GyroAccFactor; |
1241 | DebugOut.Analog[0] = IntegralNick / ParamSet.GyroAccFactor; |
1242 | DebugOut.Analog[1] = IntegralRoll / ParamSet.GyroAccFactor; |
1242 | DebugOut.Analog[1] = IntegralRoll / ParamSet.GyroAccFactor; |
1243 | DebugOut.Analog[2] = Mean_AccPitch; |
1243 | DebugOut.Analog[2] = Mean_AccNick; |
1244 | DebugOut.Analog[3] = Mean_AccRoll; |
1244 | DebugOut.Analog[3] = Mean_AccRoll; |
1245 | DebugOut.Analog[4] = Reading_GyroYaw; |
1245 | DebugOut.Analog[4] = Reading_GyroYaw; |
1246 | DebugOut.Analog[5] = ReadingHeight; |
1246 | DebugOut.Analog[5] = ReadingHeight; |
1247 | DebugOut.Analog[6] = (Reading_Integral_Top / 512); |
1247 | DebugOut.Analog[6] = (Reading_Integral_Top / 512); |
Line 1253... | Line 1253... | ||
1253 | DebugOut.Analog[10] = Motor_FrontLeft; |
1253 | DebugOut.Analog[10] = Motor_FrontLeft; |
1254 | DebugOut.Analog[11] = Motor_FrontRight; |
1254 | DebugOut.Analog[11] = Motor_FrontRight; |
1255 | DebugOut.Analog[12] = Motor_RearLeft; |
1255 | DebugOut.Analog[12] = Motor_RearLeft; |
1256 | DebugOut.Analog[13] = Motor_RearRight; |
1256 | DebugOut.Analog[13] = Motor_RearRight; |
1257 | DebugOut.Analog[14] = Motor_Left; |
1257 | DebugOut.Analog[14] = Motor_Left; |
1258 | DebugOut.Analog[15] = Motor_Right; |
1258 | DebugOut.Analog[15] = Motor_Right; |
1259 | #else |
1259 | #else |
1260 | DebugOut.Analog[11] = YawGyroHeading / YAW_GYRO_DEG_FACTOR; |
1260 | DebugOut.Analog[11] = YawGyroHeading / YAW_GYRO_DEG_FACTOR; |
Line 1261... | Line 1261... | ||
1261 | 1261 | ||
1262 | DebugOut.Analog[12] = Motor_Front; |
1262 | DebugOut.Analog[12] = Motor_Front; |
1263 | DebugOut.Analog[13] = Motor_Rear; |
1263 | DebugOut.Analog[13] = Motor_Rear; |
1264 | DebugOut.Analog[14] = Motor_Left; |
1264 | DebugOut.Analog[14] = Motor_Left; |
1265 | DebugOut.Analog[15] = Motor_Right; |
1265 | DebugOut.Analog[15] = Motor_Right; |
Line 1266... | Line 1266... | ||
1266 | #endif |
1266 | #endif |
Line 1267... | Line 1267... | ||
1267 | 1267 | ||
Line 1268... | Line 1268... | ||
1268 | DebugOut.Analog[16] = Mean_AccTop; |
1268 | DebugOut.Analog[16] = Mean_AccTop; |
1269 | 1269 | ||
Line 1270... | Line 1270... | ||
1270 | DebugOut.Analog[20] = ServoValue; |
1270 | DebugOut.Analog[20] = ServoValue; |
1271 | 1271 | ||
1272 | 1272 | ||
Line 1284... | Line 1284... | ||
1284 | DebugOut.Analog[22] = motor_rx[5]; |
1284 | DebugOut.Analog[22] = motor_rx[5]; |
1285 | DebugOut.Analog[23] = motor_rx[6]; |
1285 | DebugOut.Analog[23] = motor_rx[6]; |
1286 | DebugOut.Analog[24] = motor_rx[7]; |
1286 | DebugOut.Analog[24] = motor_rx[7]; |
1287 | DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7]; |
1287 | DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7]; |
Line 1288... | Line 1288... | ||
1288 | 1288 | ||
1289 | DebugOut.Analog[9] = Reading_GyroPitch; |
1289 | DebugOut.Analog[9] = Reading_GyroNick; |
1290 | DebugOut.Analog[9] = SetPointHeight; |
1290 | DebugOut.Analog[9] = SetPointHeight; |
Line 1291... | Line 1291... | ||
1291 | DebugOut.Analog[10] = Reading_IntegralGyroYaw / 128; |
1291 | DebugOut.Analog[10] = Reading_IntegralGyroYaw / 128; |
1292 | 1292 | ||
1293 | DebugOut.Analog[10] = FCParam.Gyro_I; |
1293 | DebugOut.Analog[10] = FCParam.Gyro_I; |
1294 | DebugOut.Analog[10] = ParamSet.Gyro_I; |
1294 | DebugOut.Analog[10] = ParamSet.Gyro_I; |
1295 | DebugOut.Analog[9] = CompassOffCourse; |
1295 | DebugOut.Analog[9] = CompassOffCourse; |
1296 | DebugOut.Analog[10] = ThrustMixFraction; |
1296 | DebugOut.Analog[10] = GasMixFraction; |
1297 | DebugOut.Analog[3] = HeightD * 32; |
1297 | DebugOut.Analog[3] = HeightD * 32; |
1298 | DebugOut.Analog[4] = HeightControlThrust; |
1298 | DebugOut.Analog[4] = HeightControlGas; |
Line 1299... | Line 1299... | ||
1299 | */ |
1299 | */ |
1300 | } |
1300 | } |
1301 | 1301 | ||
Line 1302... | Line 1302... | ||
1302 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1302 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1303 | // calculate control feedback from angle (gyro integral) and agular velocity (gyro signal) |
1303 | // calculate control feedback from angle (gyro integral) and agular velocity (gyro signal) |
1304 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1304 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1305 | 1305 | ||
1306 | if(Looping_Pitch) Reading_GyroPitch = Reading_GyroPitch * Gyro_P_Factor; |
1306 | if(Looping_Nick) Reading_GyroNick = Reading_GyroNick * Gyro_P_Factor; |
Line 1307... | Line 1307... | ||
1307 | else Reading_GyroPitch = IntegralPitch * Gyro_I_Factor + Reading_GyroPitch * Gyro_P_Factor; |
1307 | else Reading_GyroNick = IntegralNick * Gyro_I_Factor + Reading_GyroNick * Gyro_P_Factor; |
1308 | if(Looping_Roll) Reading_GyroRoll = Reading_GyroRoll * Gyro_P_Factor; |
1308 | if(Looping_Roll) Reading_GyroRoll = Reading_GyroRoll * Gyro_P_Factor; |
Line 1309... | Line 1309... | ||
1309 | else Reading_GyroRoll = IntegralRoll * Gyro_I_Factor + Reading_GyroRoll * Gyro_P_Factor; |
1309 | else Reading_GyroRoll = IntegralRoll * Gyro_I_Factor + Reading_GyroRoll * Gyro_P_Factor; |
1310 | Reading_GyroYaw = Reading_GyroYaw * (2 * Gyro_P_Factor) + IntegralYaw * Gyro_I_Factor / 2; |
1310 | Reading_GyroYaw = Reading_GyroYaw * (2 * Gyro_P_Factor) + IntegralYaw * Gyro_I_Factor / 2; |
1311 | 1311 | ||
1312 | DebugOut.Analog[21] = Reading_GyroPitch; |
1312 | DebugOut.Analog[21] = Reading_GyroNick; |
1313 | DebugOut.Analog[22] = Reading_GyroRoll; |
1313 | DebugOut.Analog[22] = Reading_GyroRoll; |
1314 | 1314 | ||
1315 | // limit control feedback |
1315 | // limit control feedback |
1316 | #define MAX_SENSOR (4096 * STICK_GAIN) |
1316 | #define MAX_SENSOR (4096 * STICK_GAIN) |
Line 1317... | Line 1317... | ||
1317 | if(Reading_GyroPitch > MAX_SENSOR) Reading_GyroPitch = MAX_SENSOR; |
1317 | if(Reading_GyroNick > MAX_SENSOR) Reading_GyroNick = MAX_SENSOR; |
1318 | if(Reading_GyroPitch < -MAX_SENSOR) Reading_GyroPitch = -MAX_SENSOR; |
1318 | if(Reading_GyroNick < -MAX_SENSOR) Reading_GyroNick = -MAX_SENSOR; |
1319 | if(Reading_GyroRoll > MAX_SENSOR) Reading_GyroRoll = MAX_SENSOR; |
1319 | if(Reading_GyroRoll > MAX_SENSOR) Reading_GyroRoll = MAX_SENSOR; |
1320 | if(Reading_GyroRoll < -MAX_SENSOR) Reading_GyroRoll = -MAX_SENSOR; |
1320 | if(Reading_GyroRoll < -MAX_SENSOR) Reading_GyroRoll = -MAX_SENSOR; |
Line 1321... | Line 1321... | ||
1321 | if(Reading_GyroYaw > MAX_SENSOR) Reading_GyroYaw = MAX_SENSOR; |
1321 | if(Reading_GyroYaw > MAX_SENSOR) Reading_GyroYaw = MAX_SENSOR; |
Line 1322... | Line 1322... | ||
1322 | if(Reading_GyroYaw < -MAX_SENSOR) Reading_GyroYaw = -MAX_SENSOR; |
1322 | if(Reading_GyroYaw < -MAX_SENSOR) Reading_GyroYaw = -MAX_SENSOR; |
1323 | 1323 | ||
1324 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1324 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1325 | // Height Control |
1325 | // Height Control |
Line 1347... | Line 1347... | ||
1347 | SetPointHeight = ((int16_t) ExternHeightValue + (int16_t) FCParam.MaxHeight) * (int16_t)ParamSet.Height_Gain - 20; |
1347 | SetPointHeight = ((int16_t) ExternHeightValue + (int16_t) FCParam.MaxHeight) * (int16_t)ParamSet.Height_Gain - 20; |
1348 | HeightControlActive = 1; |
1348 | HeightControlActive = 1; |
1349 | } |
1349 | } |
1350 | // get current height |
1350 | // get current height |
1351 | h = ReadingHeight; |
1351 | h = ReadingHeight; |
1352 | // if current height is above the setpoint reduce thrust |
1352 | // if current height is above the setpoint reduce gas |
1353 | if((h > SetPointHeight) && HeightControlActive) |
1353 | if((h > SetPointHeight) && HeightControlActive) |
1354 | { |
1354 | { |
1355 | // ThrustMixFraction - HightDeviation * P - HeightChange * D - ACCTop * DACC |
1355 | // GasMixFraction - HightDeviation * P - HeightChange * D - ACCTop * DACC |
1356 | // height difference -> P control part |
1356 | // height difference -> P control part |
1357 | h = ((h - SetPointHeight) * (int16_t) FCParam.Height_P) / (16 / STICK_GAIN); |
1357 | h = ((h - SetPointHeight) * (int16_t) FCParam.Height_P) / (16 / STICK_GAIN); |
1358 | h = ThrustMixFraction - h; // reduce gas |
1358 | h = GasMixFraction - h; // reduce gas |
1359 | // height gradient --> D control part |
1359 | // height gradient --> D control part |
1360 | //h -= (HeightD * FCParam.Height_D) / (8 / STICK_GAIN); // D control part |
1360 | //h -= (HeightD * FCParam.Height_D) / (8 / STICK_GAIN); // D control part |
1361 | h -= (HeightD) / (8 / STICK_GAIN); // D control part |
1361 | h -= (HeightD) / (8 / STICK_GAIN); // D control part |
1362 | // acceleration sensor effect |
1362 | // acceleration sensor effect |
1363 | tmp_int = ((Reading_Integral_Top / 128) * (int32_t) FCParam.Height_ACC_Effect) / (128 / STICK_GAIN); |
1363 | tmp_int = ((Reading_Integral_Top / 128) * (int32_t) FCParam.Height_ACC_Effect) / (128 / STICK_GAIN); |
1364 | if(tmp_int > 70 * STICK_GAIN) tmp_int = 70 * STICK_GAIN; |
1364 | if(tmp_int > 70 * STICK_GAIN) tmp_int = 70 * STICK_GAIN; |
1365 | else if(tmp_int < -(70 * STICK_GAIN)) tmp_int = -(70 * STICK_GAIN); |
1365 | else if(tmp_int < -(70 * STICK_GAIN)) tmp_int = -(70 * STICK_GAIN); |
1366 | h -= tmp_int; |
1366 | h -= tmp_int; |
1367 | // update height control thrust |
1367 | // update height control gas |
1368 | HeightControlThrust = (HeightControlThrust*15 + h) / 16; |
1368 | HeightControlGas = (HeightControlGas*15 + h) / 16; |
1369 | // limit thrust reduction |
1369 | // limit gas reduction |
1370 | if(HeightControlThrust < ParamSet.Height_MinThrust * STICK_GAIN) |
1370 | if(HeightControlGas < ParamSet.Height_MinGas * STICK_GAIN) |
1371 | { |
1371 | { |
1372 | if(ThrustMixFraction >= ParamSet.Height_MinThrust * STICK_GAIN) HeightControlThrust = ParamSet.Height_MinThrust * STICK_GAIN; |
1372 | if(GasMixFraction >= ParamSet.Height_MinGas * STICK_GAIN) HeightControlGas = ParamSet.Height_MinGas * STICK_GAIN; |
1373 | // allows landing also if thrust stick is reduced below min thrust on height control |
1373 | // allows landing also if gas stick is reduced below min gas on height control |
1374 | if(ThrustMixFraction < ParamSet.Height_MinThrust * STICK_GAIN) HeightControlThrust = ThrustMixFraction; |
1374 | if(GasMixFraction < ParamSet.Height_MinGas * STICK_GAIN) HeightControlGas = GasMixFraction; |
1375 | } |
1375 | } |
1376 | // limit thrust to stick setting |
1376 | // limit gas to stick setting |
1377 | if(HeightControlThrust > ThrustMixFraction) HeightControlThrust = ThrustMixFraction; |
1377 | if(HeightControlGas > GasMixFraction) HeightControlGas = GasMixFraction; |
1378 | ThrustMixFraction = HeightControlThrust; |
1378 | GasMixFraction = HeightControlGas; |
1379 | } |
1379 | } |
1380 | } |
1380 | } |
1381 | // limit thrust to parameter setting |
1381 | // limit gas to parameter setting |
1382 | if(ThrustMixFraction > (ParamSet.Trust_Max - 20) * STICK_GAIN) ThrustMixFraction = (ParamSet.Trust_Max - 20) * STICK_GAIN; |
1382 | if(GasMixFraction > (ParamSet.Gas_Max - 20) * STICK_GAIN) GasMixFraction = (ParamSet.Gas_Max - 20) * STICK_GAIN; |
1383 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1383 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1384 | // + Mixer and PI-Controller |
1384 | // + Mixer and PI-Controller |
1385 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1385 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1386 | DebugOut.Analog[7] = ThrustMixFraction; |
1386 | DebugOut.Analog[7] = GasMixFraction; |
1387 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1387 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1388 | // Yaw-Fraction |
1388 | // Yaw-Fraction |
1389 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1389 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1390 | YawMixFraction = Reading_GyroYaw - SetPointYaw * STICK_GAIN; // yaw controller |
1390 | YawMixFraction = Reading_GyroYaw - SetPointYaw * STICK_GAIN; // yaw controller |
1391 | #define MIN_YAWTHRUST (40 * STICK_GAIN) // yaw also below this thrust value |
1391 | #define MIN_YAWGAS (40 * STICK_GAIN) // yaw also below this gas value |
1392 | // limit YawMixFraction |
1392 | // limit YawMixFraction |
1393 | if(ThrustMixFraction > MIN_YAWTHRUST) |
1393 | if(GasMixFraction > MIN_YAWGAS) |
1394 | { |
1394 | { |
1395 | if(YawMixFraction > (ThrustMixFraction / 2)) YawMixFraction = ThrustMixFraction / 2; |
1395 | if(YawMixFraction > (GasMixFraction / 2)) YawMixFraction = GasMixFraction / 2; |
1396 | if(YawMixFraction < -(ThrustMixFraction / 2)) YawMixFraction = -(ThrustMixFraction / 2); |
1396 | if(YawMixFraction < -(GasMixFraction / 2)) YawMixFraction = -(GasMixFraction / 2); |
1397 | } |
1397 | } |
1398 | else |
1398 | else |
1399 | { |
1399 | { |
1400 | if(YawMixFraction > (MIN_YAWTHRUST / 2)) YawMixFraction = MIN_YAWTHRUST / 2; |
1400 | if(YawMixFraction > (MIN_YAWGAS / 2)) YawMixFraction = MIN_YAWGAS / 2; |
1401 | if(YawMixFraction < -(MIN_YAWTHRUST / 2)) YawMixFraction = -(MIN_YAWTHRUST / 2); |
1401 | if(YawMixFraction < -(MIN_YAWGAS / 2)) YawMixFraction = -(MIN_YAWGAS / 2); |
1402 | } |
1402 | } |
1403 | tmp_int = ParamSet.Trust_Max * STICK_GAIN; |
1403 | tmp_int = ParamSet.Gas_Max * STICK_GAIN; |
1404 | if(YawMixFraction > ((tmp_int - ThrustMixFraction))) YawMixFraction = ((tmp_int - ThrustMixFraction)); |
1404 | if(YawMixFraction > ((tmp_int - GasMixFraction))) YawMixFraction = ((tmp_int - GasMixFraction)); |
1405 | if(YawMixFraction < -((tmp_int - ThrustMixFraction))) YawMixFraction = -((tmp_int - ThrustMixFraction)); |
1405 | if(YawMixFraction < -((tmp_int - GasMixFraction))) YawMixFraction = -((tmp_int - GasMixFraction)); |
Line 1406... | Line 1406... | ||
1406 | 1406 | ||
1407 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1407 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1408 | // Pitch-Axis |
1408 | // Nick-Axis |
1409 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1409 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1410 | DiffPitch = Reading_GyroPitch - StickPitch; // get difference |
1410 | DiffNick = Reading_GyroNick - StickNick; // get difference |
1411 | if(Gyro_I_Factor) SumPitch += IntegralPitch * Gyro_I_Factor - StickPitch; // I-part for attitude control |
1411 | if(Gyro_I_Factor) SumNick += IntegralNick * Gyro_I_Factor - StickNick; // I-part for attitude control |
1412 | else SumPitch += DiffPitch; // I-part for head holding |
1412 | else SumNick += DiffNick; // I-part for head holding |
1413 | if(SumPitch > (STICK_GAIN * 16000L)) SumPitch = (STICK_GAIN * 16000L); |
1413 | if(SumNick > (STICK_GAIN * 16000L)) SumNick = (STICK_GAIN * 16000L); |
1414 | if(SumPitch < -(STICK_GAIN * 16000L)) SumPitch = -(STICK_GAIN * 16000L); |
1414 | if(SumNick < -(STICK_GAIN * 16000L)) SumNick = -(STICK_GAIN * 16000L); |
Line 1415... | Line 1415... | ||
1415 | pd_result = DiffPitch + Ki * SumPitch; // PI-controller for pitch |
1415 | pd_result = DiffNick + Ki * SumNick; // PI-controller for nick |
1416 | 1416 | ||
1417 | tmp_int = (int32_t)((int32_t)FCParam.DynamicStability * (int32_t)(ThrustMixFraction + abs(YawMixFraction)/2)) / 64; |
1417 | tmp_int = (int32_t)((int32_t)FCParam.DynamicStability * (int32_t)(GasMixFraction + abs(YawMixFraction)/2)) / 64; |
Line 1418... | Line 1418... | ||
1418 | if(pd_result > tmp_int) pd_result = tmp_int; |
1418 | if(pd_result > tmp_int) pd_result = tmp_int; |
Line 1419... | Line 1419... | ||
1419 | if(pd_result < -tmp_int) pd_result = -tmp_int; |
1419 | if(pd_result < -tmp_int) pd_result = -tmp_int; |
1420 | 1420 | ||
1421 | PitchMixFraction = pd_result; |
1421 | NickMixFraction = pd_result; |
1422 | 1422 | ||
1423 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1423 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1424 | // Roll-Axis |
1424 | // Roll-Axis |
1425 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1425 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1426 | DiffRoll = Reading_GyroRoll - StickRoll; // get difference |
1426 | DiffRoll = Reading_GyroRoll - StickRoll; // get difference |
1427 | if(Gyro_I_Factor) SumRoll += IntegralRoll * Gyro_I_Factor - StickRoll; // I-part for attitude control |
1427 | if(Gyro_I_Factor) SumRoll += IntegralRoll * Gyro_I_Factor - StickRoll; // I-part for attitude control |
1428 | else SumRoll += DiffRoll; // I-part for head holding |
1428 | else SumRoll += DiffRoll; // I-part for head holding |
1429 | if(SumRoll > (STICK_GAIN * 16000L)) SumRoll = (STICK_GAIN * 16000L); |
1429 | if(SumRoll > (STICK_GAIN * 16000L)) SumRoll = (STICK_GAIN * 16000L); |
1430 | if(SumRoll < -(STICK_GAIN * 16000L)) SumRoll = -(STICK_GAIN * 16000L); |
1430 | if(SumRoll < -(STICK_GAIN * 16000L)) SumRoll = -(STICK_GAIN * 16000L); |
Line 1431... | Line 1431... | ||
1431 | pd_result = DiffRoll + Ki * SumRoll; // PI-controller for roll |
1431 | pd_result = DiffRoll + Ki * SumRoll; // PI-controller for roll |
Line 1432... | Line 1432... | ||
1432 | tmp_int = (int32_t)((int32_t)FCParam.DynamicStability * (int32_t)(ThrustMixFraction + abs(YawMixFraction)/2)) / 64; |
1432 | tmp_int = (int32_t)((int32_t)FCParam.DynamicStability * (int32_t)(GasMixFraction + abs(YawMixFraction)/2)) / 64; |
1433 | if(pd_result > tmp_int) pd_result = tmp_int; |
1433 | if(pd_result > tmp_int) pd_result = tmp_int; |
1434 | if(pd_result < -tmp_int) pd_result = -tmp_int; |
1434 | if(pd_result < -tmp_int) pd_result = -tmp_int; |
1435 | 1435 | ||
1436 | RollMixFraction = pd_result; |
1436 | RollMixFraction = pd_result; |
1437 | 1437 | ||
1438 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1438 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1439 | // Calculate Motor Mixes |
1439 | // Calculate Motor Mixes |
1440 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1440 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1441 | 1441 | ||
1442 | #ifdef HEXAKOPTER |
1442 | #ifdef HEXAKOPTER |
1443 | // Motor FrontLeft |
1443 | // Motor FrontLeft |
1444 | MotorValue = ThrustMixFraction |
1444 | MotorValue = GasMixFraction |
1445 | + PitchMixFraction |
1445 | + NickMixFraction |
Line 1446... | Line 1446... | ||
1446 | + RollMixFraction/2 |
1446 | + RollMixFraction/2 |
1447 | - YawMixFraction; // Mixer |
1447 | - YawMixFraction; // Mixer |
1448 | MotorValue /= STICK_GAIN; |
1448 | MotorValue /= STICK_GAIN; |
1449 | if (MotorValue > ParamSet.Trust_Max) MotorValue = ParamSet.Trust_Max; |
1449 | if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
1450 | else if (MotorValue < ParamSet.Trust_Min) MotorValue = ParamSet.Trust_Min; |
1450 | else if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
1451 | Motor_FrontLeft = MotorValue; |
1451 | Motor_FrontLeft = MotorValue; |
1452 | 1452 | ||
1453 | // Motor FrontRight |
1453 | // Motor FrontRight |
1454 | MotorValue = ThrustMixFraction |
1454 | MotorValue = GasMixFraction |
Line 1455... | Line 1455... | ||
1455 | + PitchMixFraction |
1455 | + NickMixFraction |
1456 | - RollMixFraction/2 |
1456 | - RollMixFraction/2 |
1457 | + YawMixFraction; // Mixer |
1457 | + YawMixFraction; // Mixer |
1458 | MotorValue /= STICK_GAIN; |
1458 | MotorValue /= STICK_GAIN; |
1459 | if (MotorValue > ParamSet.Trust_Max) MotorValue = ParamSet.Trust_Max; |
1459 | if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
1460 | else if (MotorValue < ParamSet.Trust_Min) MotorValue = ParamSet.Trust_Min; |
1460 | else if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
1461 | Motor_FrontRight = MotorValue; |
1461 | Motor_FrontRight = MotorValue; |
1462 | 1462 | ||
1463 | // Motor RearLeft |
1463 | // Motor RearLeft |
Line 1464... | Line 1464... | ||
1464 | MotorValue = ThrustMixFraction |
1464 | MotorValue = GasMixFraction |
1465 | - PitchMixFraction |
1465 | - NickMixFraction |
1466 | + RollMixFraction/2 |
1466 | + RollMixFraction/2 |
1467 | - YawMixFraction; // Mixer |
1467 | - YawMixFraction; // Mixer |
1468 | MotorValue /= STICK_GAIN; |
1468 | MotorValue /= STICK_GAIN; |
1469 | if (MotorValue > ParamSet.Trust_Max) MotorValue = ParamSet.Trust_Max; |
1469 | if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
1470 | else if (MotorValue < ParamSet.Trust_Min) MotorValue = ParamSet.Trust_Min; |
1470 | else if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
1471 | Motor_RearLeft = MotorValue; |
1471 | Motor_RearLeft = MotorValue; |
1472 | 1472 | ||
1473 | // Motor RearRight |
1473 | // Motor RearRight |
1474 | MotorValue = ThrustMixFraction |
1474 | MotorValue = GasMixFraction |
1475 | - PitchMixFraction |
1475 | - NickMixFraction |
1476 | - RollMixFraction/2 |
1476 | - RollMixFraction/2 |
1477 | + YawMixFraction; // Mixer |
1477 | + YawMixFraction; // Mixer |
1478 | MotorValue /= STICK_GAIN; |
1478 | MotorValue /= STICK_GAIN; |
1479 | if (MotorValue > ParamSet.Trust_Max) MotorValue = ParamSet.Trust_Max; |
1479 | if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
1480 | else if (MotorValue < ParamSet.Trust_Min) MotorValue = ParamSet.Trust_Min; |
1480 | else if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
1481 | Motor_RearRight= MotorValue; |
1481 | Motor_RearRight= MotorValue; |
Line 1482... | Line 1482... | ||
1482 | 1482 | ||
1483 | // Motor Left |
1483 | // Motor Left |
1484 | MotorValue = ThrustMixFraction |
1484 | MotorValue = GasMixFraction |
1485 | + RollMixFraction |
1485 | + RollMixFraction |
1486 | + YawMixFraction; // Mixer |
1486 | + YawMixFraction; // Mixer |
1487 | MotorValue /= STICK_GAIN; |
1487 | MotorValue /= STICK_GAIN; |
1488 | if (MotorValue > ParamSet.Trust_Max) MotorValue = ParamSet.Trust_Max; |
1488 | if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
1489 | else if (MotorValue < ParamSet.Trust_Min) MotorValue = ParamSet.Trust_Min; |
1489 | else if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
Line 1490... | Line 1490... | ||
1490 | Motor_Left = MotorValue; |
1490 | Motor_Left = MotorValue; |
Line 1491... | Line 1491... | ||
1491 | 1491 | ||
1492 | // Motor Right |
1492 | // Motor Right |
1493 | MotorValue = ThrustMixFraction |
1493 | MotorValue = GasMixFraction |
1494 | - RollMixFraction |
- | |
1495 | - YawMixFraction; // Mixer |
1494 | - RollMixFraction |
1496 | MotorValue /= STICK_GAIN; |
1495 | - YawMixFraction; // Mixer |
1497 | if (MotorValue > ParamSet.Trust_Max) MotorValue = ParamSet.Trust_Max; |
1496 | MotorValue /= STICK_GAIN; |
Line 1498... | Line 1497... | ||
1498 | else if (MotorValue < ParamSet.Trust_Min) MotorValue = ParamSet.Trust_Min; |
1497 | if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
1499 | Motor_Right = MotorValue; |
1498 | else if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
1500 | 1499 | Motor_Right = MotorValue; |
|
1501 | #else |
- | |
1502 | 1500 | ||
1503 | // Motor Front |
1501 | #else |
1504 | MotorValue = ThrustMixFraction + PitchMixFraction + YawMixFraction; // Mixer |
1502 | |
Line 1505... | Line 1503... | ||
1505 | MotorValue /= STICK_GAIN; |
1503 | // Motor Front |
1506 | if ((MotorValue < 0)) MotorValue = 0; |
1504 | MotorValue = GasMixFraction + NickMixFraction + YawMixFraction; // Mixer |
1507 | else if(MotorValue > ParamSet.Trust_Max) MotorValue = ParamSet.Trust_Max; |
1505 | MotorValue /= STICK_GAIN; |
1508 | if (MotorValue < ParamSet.Trust_Min) MotorValue = ParamSet.Trust_Min; |
- | |
1509 | Motor_Front = MotorValue; |
1506 | if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
1510 | 1507 | else if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
|
1511 | // Motor Rear |
1508 | Motor_Front = MotorValue; |
Line -... | Line 1509... | ||
- | 1509 | ||
1512 | MotorValue = ThrustMixFraction - PitchMixFraction + YawMixFraction; // Mixer |
1510 | // Motor Rear |
1513 | MotorValue /= STICK_GAIN; |
1511 | MotorValue = GasMixFraction - NickMixFraction + YawMixFraction; // Mixer |
1514 | if ((MotorValue < 0)) MotorValue = 0; |
1512 | MotorValue /= STICK_GAIN; |
1515 | else if(MotorValue > ParamSet.Trust_Max) MotorValue = ParamSet.Trust_Max; |
- | |
1516 | if (MotorValue < ParamSet.Trust_Min) MotorValue = ParamSet.Trust_Min; |
1513 | if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
1517 | Motor_Rear = MotorValue; |
1514 | else if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
1518 | 1515 | Motor_Rear = MotorValue; |
|
1519 | 1516 | ||
1520 | // Motor Left |
1517 |