Rev 707 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 707 | Rev 711 | ||
---|---|---|---|
Line 67... | Line 67... | ||
67 | #include "mm3.h" |
67 | #include "mm3.h" |
Line 68... | Line 68... | ||
68 | 68 | ||
69 | 69 | ||
70 | volatile unsigned int I2CTimeout = 100; |
70 | volatile unsigned int I2CTimeout = 100; |
71 | // gyro readings |
71 | // gyro readings |
72 | volatile int16_t ReadingPitch, ReadingRoll, ReadingYaw; |
72 | volatile int16_t Reading_GyroPitch, Reading_GyroRoll, Reading_GyroYaw; |
73 | // gyro neutral readings |
73 | // gyro neutral readings |
74 | volatile int16_t AdNeutralPitch = 0, AdNeutralRoll = 0, AdNeutralYaw = 0; |
74 | volatile int16_t AdNeutralPitch = 0, AdNeutralRoll = 0, AdNeutralYaw = 0; |
75 | volatile int16_t StartNeutralRoll = 0, StartNeutralPitch = 0; |
75 | volatile int16_t StartNeutralRoll = 0, StartNeutralPitch = 0; |
Line 82... | Line 82... | ||
82 | 82 | ||
83 | // attitude gyro integrals |
83 | // attitude gyro integrals |
84 | volatile int32_t IntegralPitch = 0,IntegralPitch2 = 0; |
84 | volatile int32_t IntegralPitch = 0,IntegralPitch2 = 0; |
85 | volatile int32_t IntegralRoll = 0,IntegralRoll2 = 0; |
85 | volatile int32_t IntegralRoll = 0,IntegralRoll2 = 0; |
86 | volatile int32_t IntegralYaw = 0; |
86 | volatile int32_t IntegralYaw = 0; |
87 | volatile int32_t Reading_IntegralPitch = 0, Reading_IntegralPitch2 = 0; |
87 | volatile int32_t Reading_IntegralGyroPitch = 0, Reading_IntegralGyroPitch2 = 0; |
88 | volatile int32_t Reading_IntegralRoll = 0, Reading_IntegralRoll2 = 0; |
88 | volatile int32_t Reading_IntegralGyroRoll = 0, Reading_IntegralGyroRoll2 = 0; |
89 | volatile int32_t Reading_IntegralYaw = 0, Reading_IntegralYaw2 = 0; |
89 | volatile int32_t Reading_IntegralGyroYaw = 0, Reading_IntegralGyroYaw2 = 0; |
90 | volatile int32_t MeanIntegralPitch, MeanIntegralPitch2; |
90 | volatile int32_t MeanIntegralPitch; |
Line 91... | Line 91... | ||
91 | volatile int32_t MeanIntegralRoll, MeanIntegralRoll2; |
91 | volatile int32_t MeanIntegralRoll; |
92 | 92 | ||
93 | // attitude acceleration integrals |
93 | // attitude acceleration integrals |
Line 94... | Line 94... | ||
94 | volatile int32_t IntegralAccPitch = 0,IntegralAccRoll = 0,IntegralAccZ = 0; |
94 | volatile int32_t IntegralAccPitch = 0, IntegralAccRoll = 0, IntegralAccZ = 0; |
95 | volatile int32_t Reading_Integral_Top = 0; |
95 | volatile int32_t Reading_Integral_Top = 0; |
96 | 96 | ||
Line 114... | Line 114... | ||
114 | // setpoints for motors |
114 | // setpoints for motors |
115 | volatile uint8_t Motor_Front, Motor_Rear, Motor_Right, Motor_Left; |
115 | volatile uint8_t Motor_Front, Motor_Rear, Motor_Right, Motor_Left; |
Line 116... | Line 116... | ||
116 | 116 | ||
117 | // stick values derived by rc channels readings |
117 | // stick values derived by rc channels readings |
- | 118 | int16_t StickPitch = 0, StickRoll = 0, StickYaw = 0, StickThrust = 0; |
|
118 | int16_t StickPitch = 0, StickRoll = 0, StickYaw = 0, StickThrust = 0; |
119 | int16_t MaxStickPitch = 0, MaxStickRoll = 0, MaxStickYaw = 0; |
119 | // stick values derived by uart inputs |
120 | // stick values derived by uart inputs |
Line 120... | Line -... | ||
120 | int16_t ExternStickPitch = 0, ExternStickRoll = 0, ExternStickYaw = 0, ExternHightValue = -20; |
- | |
- | 121 | int16_t ExternStickPitch = 0, ExternStickRoll = 0, ExternStickYaw = 0, ExternHightValue = -20; |
|
Line 121... | Line 122... | ||
121 | 122 | ||
122 | int MaxStickPitch = 0, MaxStickRoll = 0; |
123 | |
Line 186... | Line 187... | ||
186 | { |
187 | { |
187 | NeutralAccX = (int16_t)GetParamWord(PID_ACC_PITCH); |
188 | NeutralAccX = (int16_t)GetParamWord(PID_ACC_PITCH); |
188 | NeutralAccY = (int16_t)GetParamWord(PID_ACC_ROLL); |
189 | NeutralAccY = (int16_t)GetParamWord(PID_ACC_ROLL); |
189 | NeutralAccZ = (int16_t)GetParamWord(PID_ACC_Z); |
190 | NeutralAccZ = (int16_t)GetParamWord(PID_ACC_Z); |
190 | } |
191 | } |
191 | Reading_IntegralPitch = 0; |
192 | Reading_IntegralGyroPitch = 0; |
192 | Reading_IntegralPitch2 = 0; |
193 | Reading_IntegralGyroPitch2 = 0; |
193 | Reading_IntegralRoll = 0; |
194 | Reading_IntegralGyroRoll = 0; |
194 | Reading_IntegralRoll2 = 0; |
195 | Reading_IntegralGyroRoll2 = 0; |
195 | Reading_IntegralYaw = 0; |
196 | Reading_IntegralGyroYaw = 0; |
196 | ReadingPitch = 0; |
197 | Reading_GyroPitch = 0; |
197 | ReadingRoll = 0; |
198 | Reading_GyroRoll = 0; |
198 | ReadingYaw = 0; |
199 | Reading_GyroYaw = 0; |
199 | StartAirPressure = AirPressure; |
200 | StartAirPressure = AirPressure; |
200 | HightD = 0; |
201 | HightD = 0; |
201 | Reading_Integral_Top = 0; |
202 | Reading_Integral_Top = 0; |
202 | CompassCourse = CompassHeading; |
203 | CompassCourse = CompassHeading; |
203 | GPS_Neutral(); |
204 | GPS_Neutral(); |
Line 212... | Line 213... | ||
212 | /************************************************************************/ |
213 | /************************************************************************/ |
213 | void Mean(void) |
214 | void Mean(void) |
214 | { |
215 | { |
215 | static int32_t tmpl,tmpl2; |
216 | static int32_t tmpl,tmpl2; |
Line 216... | Line 217... | ||
216 | 217 | ||
217 | // Get offset corrected gyro readings |
218 | // Get offset corrected gyro readings (~ to angular velocity) |
218 | ReadingYaw = AdNeutralYaw - AdValueGyrYaw; |
219 | Reading_GyroYaw = AdNeutralYaw - AdValueGyrYaw; |
219 | ReadingRoll = AdValueGyrRoll - AdNeutralRoll; |
220 | Reading_GyroRoll = AdValueGyrRoll - AdNeutralRoll; |
Line 220... | Line 221... | ||
220 | ReadingPitch = AdValueGyrPitch - AdNeutralPitch; |
221 | Reading_GyroPitch = AdValueGyrPitch - AdNeutralPitch; |
221 | 222 | ||
Line 222... | Line 223... | ||
222 | DebugOut.Analog[26] = ReadingPitch; |
223 | DebugOut.Analog[26] = Reading_GyroPitch; |
- | 224 | DebugOut.Analog[28] = Reading_GyroRoll; |
|
223 | DebugOut.Analog[28] = ReadingRoll; |
225 | |
224 | 226 | // Acceleration Sensor |
|
225 | // Acceleration Sensor |
227 | // sliding average sensor readings |
Line -... | Line 228... | ||
- | 228 | Mean_AccPitch = ((int32_t)Mean_AccPitch * 1 + ((ACC_AMPLIFY * (int32_t)AdValueAccPitch))) / 2L; |
|
226 | Mean_AccPitch = ((int32_t)Mean_AccPitch * 1 + ((ACC_AMPLIFY * (int32_t)AdValueAccPitch))) / 2L; |
229 | Mean_AccRoll = ((int32_t)Mean_AccRoll * 1 + ((ACC_AMPLIFY * (int32_t)AdValueAccRoll))) / 2L; |
227 | Mean_AccRoll = ((int32_t)Mean_AccRoll * 1 + ((ACC_AMPLIFY * (int32_t)AdValueAccRoll))) / 2L; |
230 | Mean_AccTop = ((int32_t)Mean_AccTop * 1 + ((int32_t)AdValueAccTop)) / 2L; |
228 | Mean_AccTop = ((int32_t)Mean_AccTop * 1 + ((int32_t)AdValueAccTop)) / 2L; |
231 | |
Line 229... | Line 232... | ||
229 | 232 | // sum sensor readings for later averaging |
|
- | 233 | IntegralAccPitch += ACC_AMPLIFY * AdValueAccPitch; |
|
230 | IntegralAccPitch += ACC_AMPLIFY * AdValueAccPitch; |
234 | IntegralAccRoll += ACC_AMPLIFY * AdValueAccRoll; |
231 | IntegralAccRoll += ACC_AMPLIFY * AdValueAccRoll; |
235 | IntegralAccZ += Current_AccZ - NeutralAccZ; |
232 | IntegralAccZ += Current_AccZ - NeutralAccZ; |
- | |
233 | 236 | ||
234 | // Yaw |
237 | // Yaw |
235 | Reading_IntegralYaw += ReadingYaw; |
238 | // calculate yaw gyro intergral (~ to rotation angle) |
236 | Reading_IntegralYaw2 += ReadingYaw; |
239 | Reading_IntegralGyroYaw += Reading_GyroYaw; |
237 | 240 | Reading_IntegralGyroYaw2 += Reading_GyroYaw; |
|
238 | // Coupling fraction |
241 | // Coupling fraction |
239 | if(!Looping_Pitch && !Looping_Roll && (ParamSet.GlobalConfig & CFG_AXIS_COUPLING_ACTIVE)) |
242 | if(!Looping_Pitch && !Looping_Roll && (ParamSet.GlobalConfig & CFG_AXIS_COUPLING_ACTIVE)) |
240 | { |
243 | { |
241 | tmpl = Reading_IntegralPitch / 4096L; |
244 | tmpl = Reading_IntegralGyroPitch / 4096L; |
242 | tmpl *= ReadingYaw; |
245 | tmpl *= Reading_GyroYaw; |
243 | tmpl *= FCParam.Yaw_PosFeedback; //125 |
246 | tmpl *= FCParam.Yaw_PosFeedback; //125 |
244 | tmpl /= 2048L; |
247 | tmpl /= 2048L; |
245 | tmpl2 = Reading_IntegralRoll / 4096L; |
248 | tmpl2 = Reading_IntegralGyroRoll / 4096L; |
- | 249 | tmpl2 *= Reading_GyroYaw; |
|
246 | tmpl2 *= ReadingYaw; |
250 | tmpl2 *= FCParam.Yaw_PosFeedback; |
247 | tmpl2 *= FCParam.Yaw_PosFeedback; |
251 | tmpl2 /= 2048L; |
248 | tmpl2 /= 2048L; |
252 | } |
249 | } |
253 | else tmpl = tmpl2 = 0; |
250 | else tmpl = tmpl2 = 0; |
254 | |
251 | // Roll |
255 | // Roll |
252 | ReadingRoll += tmpl; |
256 | Reading_GyroRoll += tmpl; |
253 | ReadingRoll += (tmpl2 * FCParam.Yaw_NegFeedback) / 512L; //109 |
257 | Reading_GyroRoll += (tmpl2 * FCParam.Yaw_NegFeedback) / 512L; //109 |
254 | Reading_IntegralRoll2 += ReadingRoll; |
258 | Reading_IntegralGyroRoll2 += Reading_GyroRoll; |
255 | Reading_IntegralRoll += ReadingRoll - AttitudeCorrectionRoll; |
259 | Reading_IntegralGyroRoll += Reading_GyroRoll - AttitudeCorrectionRoll; |
256 | if(Reading_IntegralRoll > TurnOver180Roll) |
260 | if(Reading_IntegralGyroRoll > TurnOver180Roll) |
257 | { |
261 | { |
258 | Reading_IntegralRoll = -(TurnOver180Roll - 10000L); |
262 | Reading_IntegralGyroRoll = -(TurnOver180Roll - 10000L); |
259 | Reading_IntegralRoll2 = Reading_IntegralRoll; |
263 | Reading_IntegralGyroRoll2 = Reading_IntegralGyroRoll; |
260 | } |
264 | } |
261 | if(Reading_IntegralRoll < -TurnOver180Roll) |
265 | if(Reading_IntegralGyroRoll < -TurnOver180Roll) |
262 | { |
266 | { |
263 | Reading_IntegralRoll = (TurnOver180Roll - 10000L); |
267 | Reading_IntegralGyroRoll = (TurnOver180Roll - 10000L); |
264 | Reading_IntegralRoll2 = Reading_IntegralRoll; |
268 | Reading_IntegralGyroRoll2 = Reading_IntegralGyroRoll; |
265 | } |
269 | } |
266 | if(AdValueGyrRoll < 15) ReadingRoll = -1000; |
270 | if(AdValueGyrRoll < 15) Reading_GyroRoll = -1000; |
267 | if(AdValueGyrRoll < 7) ReadingRoll = -2000; |
271 | if(AdValueGyrRoll < 7) Reading_GyroRoll = -2000; |
268 | if(BoardRelease == 10) |
272 | if(BoardRelease == 10) |
269 | { |
273 | { |
270 | if(AdValueGyrRoll > 1010) ReadingRoll = +1000; |
274 | if(AdValueGyrRoll > 1010) Reading_GyroRoll = +1000; |
271 | if(AdValueGyrRoll > 1017) ReadingRoll = +2000; |
275 | if(AdValueGyrRoll > 1017) Reading_GyroRoll = +2000; |
272 | } |
276 | } |
273 | else |
277 | else |
274 | { |
278 | { |
275 | if(AdValueGyrRoll > 2020) ReadingRoll = +1000; |
279 | if(AdValueGyrRoll > 2020) Reading_GyroRoll = +1000; |
276 | if(AdValueGyrRoll > 2034) ReadingRoll = +2000; |
280 | if(AdValueGyrRoll > 2034) Reading_GyroRoll = +2000; |
277 | } |
281 | } |
278 | // Pitch |
282 | // Pitch |
279 | ReadingPitch -= tmpl2; |
283 | Reading_GyroPitch -= tmpl2; |
280 | ReadingPitch -= (tmpl*FCParam.Yaw_NegFeedback) / 512L; |
284 | Reading_GyroPitch -= (tmpl*FCParam.Yaw_NegFeedback) / 512L; |
281 | Reading_IntegralPitch2 += ReadingPitch; |
285 | Reading_IntegralGyroPitch2 += Reading_GyroPitch; |
282 | Reading_IntegralPitch += ReadingPitch - AttitudeCorrectionPitch; |
286 | Reading_IntegralGyroPitch += Reading_GyroPitch - AttitudeCorrectionPitch; |
283 | if(Reading_IntegralPitch > TurnOver180Pitch) |
287 | if(Reading_IntegralGyroPitch > TurnOver180Pitch) |
284 | { |
288 | { |
285 | Reading_IntegralPitch = -(TurnOver180Pitch - 10000L); |
289 | Reading_IntegralGyroPitch = -(TurnOver180Pitch - 10000L); |
286 | Reading_IntegralPitch2 = Reading_IntegralPitch; |
290 | Reading_IntegralGyroPitch2 = Reading_IntegralGyroPitch; |
287 | } |
291 | } |
288 | if(Reading_IntegralPitch < -TurnOver180Pitch) |
292 | if(Reading_IntegralGyroPitch < -TurnOver180Pitch) |
289 | { |
293 | { |
290 | Reading_IntegralPitch = (TurnOver180Pitch - 10000L); |
294 | Reading_IntegralGyroPitch = (TurnOver180Pitch - 10000L); |
291 | Reading_IntegralPitch2 = Reading_IntegralPitch; |
295 | Reading_IntegralGyroPitch2 = Reading_IntegralGyroPitch; |
292 | } |
296 | } |
293 | if(AdValueGyrPitch < 15) ReadingPitch = -1000; |
297 | if(AdValueGyrPitch < 15) Reading_GyroPitch = -1000; |
294 | if(AdValueGyrPitch < 7) ReadingPitch = -2000; |
298 | if(AdValueGyrPitch < 7) Reading_GyroPitch = -2000; |
295 | if(BoardRelease == 10) |
299 | if(BoardRelease == 10) |
296 | { |
300 | { |
297 | if(AdValueGyrPitch > 1010) ReadingPitch = +1000; |
301 | if(AdValueGyrPitch > 1010) Reading_GyroPitch = +1000; |
298 | if(AdValueGyrPitch > 1017) ReadingPitch = +2000; |
302 | if(AdValueGyrPitch > 1017) Reading_GyroPitch = +2000; |
299 | } |
303 | } |
Line 300... | Line 304... | ||
300 | else |
304 | else |
301 | { |
305 | { |
Line 302... | Line 306... | ||
302 | if(AdValueGyrPitch > 2020) ReadingPitch = +1000; |
306 | if(AdValueGyrPitch > 2020) Reading_GyroPitch = +1000; |
303 | if(AdValueGyrPitch > 2034) ReadingPitch = +2000; |
307 | if(AdValueGyrPitch > 2034) Reading_GyroPitch = +2000; |
304 | } |
308 | } |
305 | 309 | ||
306 | // start ADC |
310 | // start ADC |
Line 307... | Line 311... | ||
307 | ADC_Enable(); |
311 | ADC_Enable(); |
308 | 312 | ||
309 | IntegralYaw = Reading_IntegralYaw; |
313 | IntegralYaw = Reading_IntegralGyroYaw; |
310 | IntegralPitch = Reading_IntegralPitch; |
314 | IntegralPitch = Reading_IntegralGyroPitch; |
311 | IntegralRoll = Reading_IntegralRoll; |
315 | IntegralRoll = Reading_IntegralGyroRoll; |
312 | IntegralPitch2 = Reading_IntegralPitch2; |
316 | IntegralPitch2 = Reading_IntegralGyroPitch2; |
313 | IntegralRoll2 = Reading_IntegralRoll2; |
317 | IntegralRoll2 = Reading_IntegralGyroRoll2; |
314 | 318 | ||
315 | if(ParamSet.GlobalConfig & CFG_ROTARY_RATE_LIMITER && !Looping_Pitch && !Looping_Roll) |
319 | if((ParamSet.GlobalConfig & CFG_ROTARY_RATE_LIMITER) && !Looping_Pitch && !Looping_Roll) |
316 | { |
320 | { |
317 | if(ReadingPitch > 200) ReadingPitch += 4 * (ReadingPitch - 200); |
321 | if(Reading_GyroPitch > 200) Reading_GyroPitch += 4 * (Reading_GyroPitch - 200); |
318 | else if(ReadingPitch < -200) ReadingPitch += 4 * (ReadingPitch + 200); |
322 | else if(Reading_GyroPitch < -200) Reading_GyroPitch += 4 * (Reading_GyroPitch + 200); |
319 | if(ReadingRoll > 200) ReadingRoll += 4 * (ReadingRoll - 200); |
323 | if(Reading_GyroRoll > 200) Reading_GyroRoll += 4 * (Reading_GyroRoll - 200); |
Line 337... | Line 341... | ||
337 | void CalibMean(void) |
341 | void CalibMean(void) |
338 | { |
342 | { |
339 | // stop ADC to avoid changing values during calculation |
343 | // stop ADC to avoid changing values during calculation |
340 | ADC_Disable(); |
344 | ADC_Disable(); |
Line 341... | Line 345... | ||
341 | 345 | ||
342 | ReadingPitch = AdValueGyrPitch; |
346 | Reading_GyroPitch = AdValueGyrPitch; |
343 | ReadingRoll = AdValueGyrRoll; |
347 | Reading_GyroRoll = AdValueGyrRoll; |
Line 344... | Line 348... | ||
344 | ReadingYaw = AdValueGyrYaw; |
348 | Reading_GyroYaw = AdValueGyrYaw; |
345 | 349 | ||
346 | Mean_AccPitch = ACC_AMPLIFY * (int32_t)AdValueAccPitch; |
350 | Mean_AccPitch = ACC_AMPLIFY * (int32_t)AdValueAccPitch; |
347 | Mean_AccRoll = ACC_AMPLIFY * (int32_t)AdValueAccRoll; |
351 | Mean_AccRoll = ACC_AMPLIFY * (int32_t)AdValueAccRoll; |
348 | Mean_AccTop = (int32_t)AdValueAccTop; |
352 | Mean_AccTop = (int32_t)AdValueAccTop; |
349 | // start ADC |
353 | // start ADC |
350 | ADC_Enable(); |
354 | ADC_Enable(); |
351 | //update poti values by rc-signals (why not +127?) |
355 | //update poti values by rc-signals (why not +127?) |
352 | if(Poti1 < PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110 && Poti1) Poti1--; |
356 | if(Poti1 < PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110 && Poti1) Poti1--; |
Line 397... | Line 401... | ||
397 | /* Maps the parameter to poti values */ |
401 | /* Maps the parameter to poti values */ |
398 | /************************************************************************/ |
402 | /************************************************************************/ |
399 | void ParameterMapping(void) |
403 | void ParameterMapping(void) |
400 | { |
404 | { |
Line 401... | Line 405... | ||
401 | 405 | ||
402 | #define CHK_POTI(b,a,min,max) { if(a > 250) { if(a == 251) b = Poti1; else if(a == 252) b = Poti2; else if(a == 253) b = Poti3; else if(a == 254) b = Poti4;} else b = a; if(b <= min) b = min; else if(b >= max) b = max;} |
406 | #define CHK_POTI(b,a,min,max) { if(a > 250) { if(a == 251) b = Poti1; else if(a == 252) b = Poti2; else if(a == 253) b = Poti3; else if(a == 254) b = Poti4;} else b = a; if(b <= min) b = min; else if(b >= max) b = max;} |
403 | CHK_POTI(FCParam.MaxHight,ParamSet.MaxHight,0,255); |
407 | CHK_POTI(FCParam.MaxHight,ParamSet.MaxHight,0,255); |
404 | CHK_POTI(FCParam.AirPressure_D,ParamSet.AirPressure_D,0,100); |
408 | CHK_POTI(FCParam.Hight_D,ParamSet.Hight_D,0,100); |
405 | CHK_POTI(FCParam.Hight_P,ParamSet.Hight_P,0,100); |
409 | CHK_POTI(FCParam.Hight_P,ParamSet.Hight_P,0,100); |
406 | CHK_POTI(FCParam.Hight_ACC_Effect,ParamSet.Hight_ACC_Effect,0,255); |
410 | CHK_POTI(FCParam.Hight_ACC_Effect,ParamSet.Hight_ACC_Effect,0,255); |
407 | CHK_POTI(FCParam.CompassYawEffect,ParamSet.CompassYawEffect,0,255); |
411 | CHK_POTI(FCParam.CompassYawEffect,ParamSet.CompassYawEffect,0,255); |
408 | CHK_POTI(FCParam.Gyro_P,ParamSet.Gyro_P,10,255); |
412 | CHK_POTI(FCParam.Gyro_P,ParamSet.Gyro_P,10,255); |
409 | CHK_POTI(FCParam.Gyro_I,ParamSet.Gyro_I,0,255); |
413 | CHK_POTI(FCParam.Gyro_I,ParamSet.Gyro_I,0,255); |
410 | CHK_POTI(FCParam.I_Factor,ParamSet.I_Factor,0,255); |
414 | CHK_POTI(FCParam.I_Factor,ParamSet.I_Factor,0,255); |
411 | CHK_POTI(FCParam.UserParam1,ParamSet.UserParam1,0,255); |
415 | CHK_POTI(FCParam.UserParam1,ParamSet.UserParam1,0,255); |
412 | CHK_POTI(FCParam.UserParam2,ParamSet.UserParam2,0,255); |
416 | CHK_POTI(FCParam.UserParam2,ParamSet.UserParam2,0,255); |
413 | CHK_POTI(FCParam.UserParam3,ParamSet.UserParam3,0,255); |
417 | CHK_POTI(FCParam.UserParam3,ParamSet.UserParam3,0,255); |
414 | CHK_POTI(FCParam.UserParam4,ParamSet.UserParam4,0,255); |
418 | CHK_POTI(FCParam.UserParam4,ParamSet.UserParam4,0,255); |
415 | CHK_POTI(FCParam.UserParam5,ParamSet.UserParam5,0,255); |
419 | CHK_POTI(FCParam.UserParam5,ParamSet.UserParam5,0,255); |
416 | CHK_POTI(FCParam.UserParam6,ParamSet.UserParam6,0,255); |
420 | CHK_POTI(FCParam.UserParam6,ParamSet.UserParam6,0,255); |
417 | CHK_POTI(FCParam.UserParam7,ParamSet.UserParam7,0,255); |
421 | CHK_POTI(FCParam.UserParam7,ParamSet.UserParam7,0,255); |
418 | CHK_POTI(FCParam.UserParam8,ParamSet.UserParam8,0,255); |
422 | CHK_POTI(FCParam.UserParam8,ParamSet.UserParam8,0,255); |
419 | CHK_POTI(FCParam.ServoPitchControl,ParamSet.ServoPitchControl,0,255); |
423 | CHK_POTI(FCParam.ServoPitchControl,ParamSet.ServoPitchControl,0,255); |
420 | CHK_POTI(FCParam.LoopThrustLimit,ParamSet.LoopThrustLimit,0,255); |
424 | CHK_POTI(FCParam.LoopThrustLimit,ParamSet.LoopThrustLimit,0,255); |
421 | CHK_POTI(FCParam.Yaw_PosFeedback,ParamSet.Yaw_PosFeedback,0,255); |
425 | CHK_POTI(FCParam.Yaw_PosFeedback,ParamSet.Yaw_PosFeedback,0,255); |
422 | CHK_POTI(FCParam.Yaw_NegFeedback,ParamSet.Yaw_NegFeedback,0,255); |
426 | CHK_POTI(FCParam.Yaw_NegFeedback,ParamSet.Yaw_NegFeedback,0,255); |
Line 423... | Line 427... | ||
423 | CHK_POTI(FCParam.DynamicStability,ParamSet.DynamicStability,0,255); |
427 | CHK_POTI(FCParam.DynamicStability,ParamSet.DynamicStability,0,255); |
424 | 428 | ||
Line 425... | Line 429... | ||
425 | Ki = (float) FCParam.I_Factor * FACTOR_I; |
429 | Ki = (float) FCParam.I_Factor * FACTOR_I; |
426 | } |
430 | } |
427 | 431 | ||
428 | 432 | ||
429 | /************************************************************************/ |
433 | /************************************************************************/ |
430 | /* MotorControl */ |
434 | /* MotorControl */ |
431 | /************************************************************************/ |
435 | /************************************************************************/ |
432 | void MotorRegler(void) |
436 | void MotorRegler(void) |
433 | { |
437 | { |
434 | int16_t MotorValue, pd_ergebnis, h, tmp_int; |
438 | int16_t MotorValue, pd_result, h, tmp_int; |
435 | int16_t YawMixingFraction, ThrustMixingFraction; |
439 | int16_t YawMixFraction, ThrustMixFraction; |
436 | static int32_t SumPitch = 0, SumRoll = 0; |
440 | static int32_t SumPitch = 0, SumRoll = 0; |
437 | static int32_t SetPointYaw = 0, tmp_long, tmp_long2; |
441 | static int32_t SetPointYaw = 0; |
438 | static int32_t IntegralErrorPitch = 0; |
442 | static int32_t IntegralErrorPitch = 0; |
439 | static int32_t IntegralErrorRoll = 0; |
443 | static int32_t IntegralErrorRoll = 0; |
440 | static uint16_t RcLostTimer; |
444 | static uint16_t RcLostTimer; |
441 | static uint8_t delay_neutral = 0, delay_startmotors = 0, delay_stopmotors = 0; |
445 | static uint8_t delay_neutral = 0, delay_startmotors = 0, delay_stopmotors = 0; |
442 | static uint16_t Modell_Is_Flying = 0; |
446 | static uint16_t Modell_Is_Flying = 0; |
443 | static uint8_t EmergencyLanding = 0; |
447 | static uint8_t EmergencyLanding = 0; |
444 | static uint8_t HightControlActive = 0; |
448 | static uint8_t HightControlActive = 0; |
Line 445... | Line 449... | ||
445 | static int16_t hoehenregler = 0; |
449 | static int16_t HightControlThrust = 0; |
Line 446... | Line 450... | ||
446 | static int8_t TimerDebugOut = 0; |
450 | static int8_t TimerDebugOut = 0; |
447 | static int8_t StoreNewCompassCourse = 0; |
451 | static int8_t StoreNewCompassCourse = 0; |
448 | static int32_t CorrectionPitch, CorrectionRoll; |
452 | static int32_t CorrectionPitch, CorrectionRoll; |
449 | 453 | ||
450 | Mean(); |
454 | Mean(); |
451 | 455 | ||
452 | GRN_ON; |
456 | GRN_ON; |
453 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
457 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
454 | // determine thrust value |
458 | // determine thrust value |
455 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
459 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
456 | ThrustMixingFraction = StickThrust; |
460 | ThrustMixFraction = StickThrust; |
Line 480... | Line 484... | ||
480 | EmergencyLanding = 0; // emergency landing is over |
484 | EmergencyLanding = 0; // emergency landing is over |
481 | } |
485 | } |
482 | ROT_ON; // set red led |
486 | ROT_ON; // set red led |
483 | if(Modell_Is_Flying > 2000) // wahrscheinlich in der Luft --> langsam absenken |
487 | if(Modell_Is_Flying > 2000) // wahrscheinlich in der Luft --> langsam absenken |
484 | { |
488 | { |
485 | ThrustMixingFraction = ParamSet.EmergencyThrust; // set emergency thrust |
489 | ThrustMixFraction = ParamSet.EmergencyThrust; // set emergency thrust |
486 | EmergencyLanding = 1; // enable emergency landing |
490 | EmergencyLanding = 1; // enable emergency landing |
487 | // set neutral rc inputs |
491 | // set neutral rc inputs |
488 | PPM_diff[ParamSet.ChannelAssignment[CH_PITCH]] = 0; |
492 | PPM_diff[ParamSet.ChannelAssignment[CH_PITCH]] = 0; |
489 | PPM_diff[ParamSet.ChannelAssignment[CH_ROLL]] = 0; |
493 | PPM_diff[ParamSet.ChannelAssignment[CH_ROLL]] = 0; |
490 | PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] = 0; |
494 | PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] = 0; |
Line 500... | Line 504... | ||
500 | if(SenderOkay > 140) |
504 | if(SenderOkay > 140) |
501 | { |
505 | { |
502 | EmergencyLanding = 0; // switch off emergency landing if RC-signal is okay |
506 | EmergencyLanding = 0; // switch off emergency landing if RC-signal is okay |
503 | // reset emergency timer |
507 | // reset emergency timer |
504 | RcLostTimer = ParamSet.EmergencyThrustDuration * 50; |
508 | RcLostTimer = ParamSet.EmergencyThrustDuration * 50; |
505 | if(ThrustMixingFraction > 40) |
509 | if(ThrustMixFraction > 40) |
506 | { |
510 | { |
507 | if(Modell_Is_Flying < 0xFFFF) Modell_Is_Flying++; |
511 | if(Modell_Is_Flying < 0xFFFF) Modell_Is_Flying++; |
508 | } |
512 | } |
509 | if((Modell_Is_Flying < 200) || (ThrustMixingFraction < 40)) |
513 | if((Modell_Is_Flying < 200) || (ThrustMixFraction < 40)) |
510 | { |
514 | { |
511 | SumPitch = 0; |
515 | SumPitch = 0; |
512 | SumRoll = 0; |
516 | SumRoll = 0; |
513 | Reading_IntegralYaw = 0; |
517 | Reading_IntegralGyroYaw = 0; |
514 | Reading_IntegralYaw2 = 0; |
518 | Reading_IntegralGyroYaw2 = 0; |
515 | } |
519 | } |
516 | // if motors are off and the thrust stick is in the upper position |
520 | // if motors are off and the thrust stick is in the upper position |
517 | if((PPM_in[ParamSet.ChannelAssignment[CH_THRUST]] > 80) && MotorsOn == 0) |
521 | if((PPM_in[ParamSet.ChannelAssignment[CH_THRUST]] > 80) && MotorsOn == 0) |
518 | { |
522 | { |
519 | // and if the yaw stick is in the leftmost position |
523 | // and if the yaw stick is in the leftmost position |
Line 592... | Line 596... | ||
592 | { |
596 | { |
593 | delay_startmotors = 200; // do not repeat if once executed |
597 | delay_startmotors = 200; // do not repeat if once executed |
594 | Modell_Is_Flying = 1; |
598 | Modell_Is_Flying = 1; |
595 | MotorsOn = 1; |
599 | MotorsOn = 1; |
596 | SetPointYaw = 0; |
600 | SetPointYaw = 0; |
597 | Reading_IntegralYaw = 0; |
601 | Reading_IntegralGyroYaw = 0; |
598 | Reading_IntegralYaw2 = 0; |
602 | Reading_IntegralGyroYaw2 = 0; |
599 | Reading_IntegralPitch = 0; |
603 | Reading_IntegralGyroPitch = 0; |
600 | Reading_IntegralRoll = 0; |
604 | Reading_IntegralGyroRoll = 0; |
601 | Reading_IntegralPitch2 = IntegralPitch; |
605 | Reading_IntegralGyroPitch2 = IntegralPitch; |
602 | Reading_IntegralRoll2 = IntegralRoll; |
606 | Reading_IntegralGyroRoll2 = IntegralRoll; |
603 | SumPitch = 0; |
607 | SumPitch = 0; |
604 | SumRoll = 0; |
608 | SumRoll = 0; |
605 | } |
609 | } |
606 | } |
610 | } |
607 | else delay_startmotors = 0; // reset delay timer if sticks are not in this position |
611 | else delay_startmotors = 0; // reset delay timer if sticks are not in this position |
Line 637... | Line 641... | ||
637 | 641 | ||
638 | // direct mapping of yaw and thrust |
642 | // direct mapping of yaw and thrust |
639 | StickYaw = -PPM_in[ParamSet.ChannelAssignment[CH_YAW]]; |
643 | StickYaw = -PPM_in[ParamSet.ChannelAssignment[CH_YAW]]; |
Line 640... | Line 644... | ||
640 | StickThrust = PPM_in[ParamSet.ChannelAssignment[CH_THRUST]] + 120;// shift to positive numbers |
644 | StickThrust = PPM_in[ParamSet.ChannelAssignment[CH_THRUST]] + 120;// shift to positive numbers |
641 | 645 | ||
642 | // update max stick positions for pitch and roll |
646 | // update max stick positions for pitch, roll and yaw |
643 | if(abs(PPM_in[ParamSet.ChannelAssignment[CH_PITCH]]) > MaxStickPitch) |
647 | if(abs(PPM_in[ParamSet.ChannelAssignment[CH_PITCH]]) > MaxStickPitch) |
644 | MaxStickPitch = abs(PPM_in[ParamSet.ChannelAssignment[CH_PITCH]]); |
648 | MaxStickPitch = abs(PPM_in[ParamSet.ChannelAssignment[CH_PITCH]]); |
645 | else MaxStickPitch--; |
649 | else MaxStickPitch--; |
646 | if(abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]) > MaxStickRoll) |
650 | if(abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]) > MaxStickRoll) |
- | 651 | MaxStickRoll = abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]); |
|
- | 652 | else MaxStickRoll--; |
|
- | 653 | if(abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]) > MaxStickYaw) |
|
Line 647... | Line 654... | ||
647 | MaxStickRoll = abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]); |
654 | MaxStickYaw = abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]); |
Line 648... | Line 655... | ||
648 | else MaxStickRoll--; |
655 | else MaxStickYaw--; |
649 | 656 | ||
Line 737... | Line 744... | ||
737 | 744 | ||
738 | 745 | ||
739 | if(Looping_Roll) BeepTime = 100; |
746 | if(Looping_Roll) BeepTime = 100; |
740 | if(Looping_Roll || Looping_Pitch) |
747 | if(Looping_Roll || Looping_Pitch) |
741 | { |
748 | { |
Line 742... | Line 749... | ||
742 | if(ThrustMixingFraction > ParamSet.LoopThrustLimit) ThrustMixingFraction = ParamSet.LoopThrustLimit; |
749 | if(ThrustMixFraction > ParamSet.LoopThrustLimit) ThrustMixFraction = ParamSet.LoopThrustLimit; |
743 | } |
750 | } |
744 | 751 | ||
Line 755... | Line 762... | ||
755 | Gyro_I_Factor = 0.003; |
762 | Gyro_I_Factor = 0.003; |
756 | Looping_Roll = 0; |
763 | Looping_Roll = 0; |
757 | Looping_Pitch = 0; |
764 | Looping_Pitch = 0; |
758 | MaxStickPitch = 0; |
765 | MaxStickPitch = 0; |
759 | MaxStickRoll = 0; |
766 | MaxStickRoll = 0; |
- | 767 | MaxStickYaw = 0; |
|
760 | } |
768 | } |
Line 761... | Line 769... | ||
761 | 769 | ||
762 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
770 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
763 | // Trim Gyro-Integrals to ACC-Signals |
771 | // Trim Gyro-Integrals to ACC-Signals |
Line 764... | Line 772... | ||
764 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
772 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
765 | - | ||
- | 773 | ||
766 | #define ABGLEICH_ANZAHL 256L |
774 | #define BALANCE_NUMBER 256L |
767 | 775 | // sum for averaging |
|
768 | MeanIntegralPitch += IntegralPitch; // sum for averaging |
- | |
769 | MeanIntegralRoll += IntegralRoll; |
- | |
Line 770... | Line 776... | ||
770 | MeanIntegralPitch2 += IntegralPitch2; |
776 | MeanIntegralPitch += IntegralPitch; |
771 | MeanIntegralRoll2 += IntegralRoll2; |
777 | MeanIntegralRoll += IntegralRoll; |
- | 778 | ||
- | 779 | if(Looping_Pitch || Looping_Roll) // if looping in any direction |
|
- | 780 | { |
|
772 | 781 | // reset averaging for acc and gyro integral as well as gyro integral acc correction |
|
773 | if(Looping_Pitch || Looping_Roll) // if looping in any direction |
782 | MeasurementCounter = 0; |
- | 783 | ||
- | 784 | IntegralAccPitch = 0; |
|
774 | { |
785 | IntegralAccRoll = 0; |
775 | IntegralAccPitch = 0; |
786 | IntegralAccZ = 0; |
776 | IntegralAccRoll = 0; |
- | |
777 | MeanIntegralPitch = 0; |
- | |
- | 787 | ||
778 | MeanIntegralRoll = 0; |
788 | MeanIntegralPitch = 0; |
779 | MeanIntegralPitch2 = 0; |
789 | MeanIntegralRoll = 0; |
780 | MeanIntegralRoll2 = 0; |
- | |
- | 790 | ||
781 | Reading_IntegralPitch2 = Reading_IntegralPitch; |
791 | Reading_IntegralGyroPitch2 = Reading_IntegralGyroPitch; |
782 | Reading_IntegralRoll2 = Reading_IntegralRoll; |
792 | Reading_IntegralGyroRoll2 = Reading_IntegralGyroRoll; |
783 | ZaehlMessungen = 0; |
793 | |
Line 784... | Line 794... | ||
784 | AttitudeCorrectionPitch = 0; |
794 | AttitudeCorrectionPitch = 0; |
785 | AttitudeCorrectionRoll = 0; |
795 | AttitudeCorrectionRoll = 0; |
786 | } |
796 | } |
787 | 797 | ||
788 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
798 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
789 | if(!Looping_Pitch && !Looping_Roll) // if not lopping in any direction |
799 | if(!Looping_Pitch && !Looping_Roll) // if not lopping in any direction |
790 | { |
800 | { |
- | 801 | int32_t tmp_long, tmp_long2; |
|
791 | int32_t tmp_long, tmp_long2; |
802 | // determine the deviation of gyro integral from averaged acceleration sensor |
- | 803 | tmp_long = (int32_t)(IntegralPitch / ParamSet.GyroAccFaktor - (int32_t)Mean_AccPitch); |
|
792 | tmp_long = (int32_t)(IntegralPitch / ParamSet.GyroAccFaktor - (int32_t)Mean_AccPitch); |
804 | tmp_long /= 16; |
793 | tmp_long2 = (int32_t)(IntegralRoll / ParamSet.GyroAccFaktor - (int32_t)Mean_AccRoll); |
805 | tmp_long2 = (int32_t)(IntegralRoll / ParamSet.GyroAccFaktor - (int32_t)Mean_AccRoll); |
794 | tmp_long /= 16; |
806 | tmp_long2 /= 16; |
795 | tmp_long2 /= 16; |
807 | |
796 | if((MaxStickPitch > 15) || (MaxStickRoll > 15)) |
808 | if((MaxStickPitch > 15) || (MaxStickRoll > 15)) |
797 | { |
809 | { |
798 | tmp_long /= 3; |
810 | tmp_long /= 3; |
799 | tmp_long2 /= 3; |
811 | tmp_long2 /= 3; |
800 | } |
812 | } |
801 | if(abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]) > 25) |
813 | if(MaxStickYaw > 25) |
Line 802... | Line 814... | ||
802 | { |
814 | { |
- | 815 | tmp_long /= 3; |
|
803 | tmp_long /= 3; |
816 | tmp_long2 /= 3; |
804 | tmp_long2 /= 3; |
817 | } |
805 | } |
818 | |
806 | 819 | #define BALANCE 32 |
|
807 | #define BALANCE 32 |
- | |
- | 820 | // limit correction |
|
808 | if(tmp_long > BALANCE) tmp_long = BALANCE; |
821 | if(tmp_long > BALANCE) tmp_long = BALANCE; |
809 | if(tmp_long < -BALANCE) tmp_long =-BALANCE; |
822 | if(tmp_long < -BALANCE) tmp_long =-BALANCE; |
810 | if(tmp_long2 > BALANCE) tmp_long2 = BALANCE; |
823 | if(tmp_long2 > BALANCE) tmp_long2 = BALANCE; |
811 | if(tmp_long2 <-BALANCE) tmp_long2 =-BALANCE; |
824 | if(tmp_long2 <-BALANCE) tmp_long2 =-BALANCE; |
- | 825 | // correct current readings |
|
- | 826 | Reading_IntegralGyroPitch -= tmp_long; |
|
- | 827 | Reading_IntegralGyroRoll -= tmp_long2; |
|
- | 828 | } |
|
- | 829 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 830 | // MeasurementCounter is incremented in the isr of analog.c |
|
- | 831 | if(MeasurementCounter >= BALANCE_NUMBER) // averaging number has reached |
|
- | 832 | { |
|
- | 833 | static int cnt = 0; |
|
- | 834 | static char last_n_p, last_n_n, last_r_p, last_r_n; |
|
- | 835 | static long MeanIntegralPitch_old, MeanIntegralRoll_old; |
|
- | 836 | ||
- | 837 | // if not lopping in any direction (this should be alwais the case, |
|
- | 838 | // because the Measurement counter is reset to 0 if looping in any direction is active.) |
|
- | 839 | if(!Looping_Pitch && !Looping_Roll) |
|
- | 840 | { |
|
- | 841 | // Calculate mean value of the gyro integrals |
|
- | 842 | MeanIntegralPitch /= BALANCE_NUMBER; |
|
- | 843 | MeanIntegralRoll /= BALANCE_NUMBER; |
|
- | 844 | ||
- | 845 | // Calculate mean of the acceleration values |
|
- | 846 | IntegralAccPitch = (ParamSet.GyroAccFaktor * IntegralAccPitch) / BALANCE_NUMBER; |
|
- | 847 | IntegralAccRoll = (ParamSet.GyroAccFaktor * IntegralAccRoll ) / BALANCE_NUMBER; |
|
- | 848 | IntegralAccZ = IntegralAccZ / BALANCE_NUMBER; |
|
- | 849 | ||
- | 850 | // Pitch ++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 851 | // Calculate deviation of the averaged gyro integral and the averaged acceleration integral |
|
- | 852 | IntegralErrorPitch = (int32_t)(MeanIntegralPitch - (int32_t)IntegralAccPitch); |
|
- | 853 | CorrectionPitch = IntegralErrorPitch / ParamSet.GyroAccTrim; |
|
- | 854 | AttitudeCorrectionPitch = CorrectionPitch / BALANCE_NUMBER; |
|
Line 812... | Line 855... | ||
812 | 855 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
|
813 | Reading_IntegralPitch -= tmp_long; |
856 | // Calculate deviation of the averaged gyro integral and the averaged acceleration integral |
814 | Reading_IntegralRoll -= tmp_long2; |
857 | IntegralErrorRoll = (int32_t)(MeanIntegralRoll - (int32_t)IntegralAccRoll); |
815 | } |
- | |
816 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
817 | 858 | CorrectionRoll = IntegralErrorRoll / ParamSet.GyroAccTrim; |
|
818 | if(ZaehlMessungen >= ABGLEICH_ANZAHL) |
859 | AttitudeCorrectionRoll = CorrectionRoll / BALANCE_NUMBER; |
819 | { |
- | |
820 | static int cnt = 0; |
- | |
821 | static char last_n_p,last_n_n,last_r_p,last_r_n; |
- | |
822 | static long MeanIntegralPitch_old,MeanIntegralRoll_old; |
- | |
823 | if(!Looping_Pitch && !Looping_Roll) |
- | |
824 | { |
- | |
825 | MeanIntegralPitch /= ABGLEICH_ANZAHL; |
- | |
826 | MeanIntegralRoll /= ABGLEICH_ANZAHL; |
- | |
827 | IntegralAccPitch = (ParamSet.GyroAccFaktor * IntegralAccPitch) / ABGLEICH_ANZAHL; |
- | |
828 | IntegralAccRoll = (ParamSet.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL; |
- | |
829 | IntegralAccZ = IntegralAccZ / ABGLEICH_ANZAHL; |
- | |
830 | #define MAX_I 0//(Poti2/10) |
- | |
Line -... | Line 860... | ||
- | 860 | ||
- | 861 | if((MaxStickPitch > 15) || (MaxStickRoll > 15) || (MaxStickYaw > 25)) |
|
- | 862 | { |
|
- | 863 | AttitudeCorrectionPitch /= 2; |
|
- | 864 | AttitudeCorrectionRoll /= 2; |
|
- | 865 | } |
|
- | 866 | ||
- | 867 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 868 | // Gyro-Drift ermitteln |
|
- | 869 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 870 | // deviation of gyro pitch integral (IntegralPitch is corrected by averaged acc sensor) |
|
- | 871 | IntegralErrorPitch = IntegralPitch2 - IntegralPitch; |
|
- | 872 | Reading_IntegralGyroPitch2 -= IntegralErrorPitch; |
|
- | 873 | // deviation of gyro pitch integral (IntegralPitch is corrected by averaged acc sensor) |
|
- | 874 | IntegralErrorRoll = IntegralRoll2 - IntegralRoll; |
|
- | 875 | Reading_IntegralGyroRoll2 -= IntegralErrorRoll; |
|
- | 876 | ||
- | 877 | ||
- | 878 | DebugOut.Analog[17] = IntegralAccPitch / 26; |
|
- | 879 | DebugOut.Analog[18] = IntegralAccRoll / 26; |
|
- | 880 | DebugOut.Analog[19] = IntegralErrorPitch;// / 26; |
|
- | 881 | DebugOut.Analog[20] = IntegralErrorRoll;// / 26; |
|
- | 882 | DebugOut.Analog[21] = MeanIntegralPitch / 26; |
|
- | 883 | DebugOut.Analog[22] = MeanIntegralRoll / 26; |
|
- | 884 | //DebugOut.Analog[28] = CorrectionPitch; |
|
- | 885 | DebugOut.Analog[29] = CorrectionRoll; |
|
- | 886 | DebugOut.Analog[30] = AttitudeCorrectionRoll * 10; |
|
- | 887 | ||
- | 888 | #define ERROR_LIMIT (BALANCE_NUMBER * 4) |
|
- | 889 | #define ERROR_LIMIT2 (BALANCE_NUMBER * 16) |
|
- | 890 | #define MOVEMENT_LIMIT 20000 |
|
- | 891 | // Pitch +++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 892 | cnt = 1;// + labs(IntegralErrorPitch) / 4096; |
|
- | 893 | CorrectionPitch = 0; |
|
- | 894 | if(labs(MeanIntegralPitch_old - MeanIntegralPitch) < MOVEMENT_LIMIT) |
|
- | 895 | { |
|
- | 896 | if(IntegralErrorPitch > ERROR_LIMIT2) |
|
- | 897 | { |
|
- | 898 | if(last_n_p) |
|
- | 899 | { |
|
- | 900 | cnt += labs(IntegralErrorPitch) / ERROR_LIMIT2; |
|
- | 901 | CorrectionPitch = IntegralErrorPitch / 8; |
|
- | 902 | if(CorrectionPitch > 5000) CorrectionPitch = 5000; |
|
- | 903 | AttitudeCorrectionPitch += CorrectionPitch / BALANCE_NUMBER; |
|
- | 904 | } |
|
- | 905 | else last_n_p = 1; |
|
- | 906 | } |
|
- | 907 | else last_n_p = 0; |
|
831 | // Pitch ++++++++++++++++++++++++++++++++++++++++++++++++ |
908 | if(IntegralErrorPitch < -ERROR_LIMIT2) |
- | 909 | { |
|
- | 910 | if(last_n_n) |
|
- | 911 | { |
|
- | 912 | cnt += labs(IntegralErrorPitch) / ERROR_LIMIT2; |
|
- | 913 | CorrectionPitch = IntegralErrorPitch / 8; |
|
- | 914 | if(CorrectionPitch < -5000) CorrectionPitch = -5000; |
|
- | 915 | AttitudeCorrectionPitch += CorrectionPitch / BALANCE_NUMBER; |
|
- | 916 | } |
|
- | 917 | else last_n_n = 1; |
|
- | 918 | } |
|
- | 919 | else last_n_n = 0; |
|
- | 920 | } |
|
- | 921 | else cnt = 0; |
|
- | 922 | if(cnt > ParamSet.DriftComp) cnt = ParamSet.DriftComp; |
|
- | 923 | // correct Gyro Offsets |
|
- | 924 | if(IntegralErrorPitch > ERROR_LIMIT) AdNeutralPitch += cnt; |
|
- | 925 | if(IntegralErrorPitch < -ERROR_LIMIT) AdNeutralPitch -= cnt; |
|
- | 926 | ||
- | 927 | // Roll +++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 928 | cnt = 1;// + labs(IntegralErrorPitch) / 4096; |
|
- | 929 | CorrectionRoll = 0; |
|
- | 930 | if(labs(MeanIntegralRoll_old - MeanIntegralRoll) < MOVEMENT_LIMIT) |
|
- | 931 | { |
|
- | 932 | if(IntegralErrorRoll > ERROR_LIMIT2) |
|
- | 933 | { |
|
- | 934 | if(last_r_p) |
|
- | 935 | { |
|
- | 936 | cnt += labs(IntegralErrorRoll) / ERROR_LIMIT2; |
|
- | 937 | CorrectionRoll = IntegralErrorRoll / 8; |
|
- | 938 | if(CorrectionRoll > 5000) CorrectionRoll = 5000; |
|
- | 939 | AttitudeCorrectionRoll += CorrectionRoll / BALANCE_NUMBER; |
|
- | 940 | } |
|
- | 941 | else last_r_p = 1; |
|
- | 942 | } |
|
- | 943 | else last_r_p = 0; |
|
832 | IntegralErrorPitch = (long)(MeanIntegralPitch - (long)IntegralAccPitch); |
944 | if(IntegralErrorRoll < -ERROR_LIMIT2) |
- | 945 | { |
|
- | 946 | if(last_r_n) |
|
- | 947 | { |
|
- | 948 | cnt += labs(IntegralErrorRoll) / ERROR_LIMIT2; |
|
- | 949 | CorrectionRoll = IntegralErrorRoll / 8; |
|
- | 950 | if(CorrectionRoll < -5000) CorrectionRoll = -5000; |
|
- | 951 | AttitudeCorrectionRoll += CorrectionRoll / BALANCE_NUMBER; |
|
- | 952 | } |
|
- | 953 | else last_r_n = 1; |
|
- | 954 | } |
|
- | 955 | else last_r_n = 0; |
|
- | 956 | } |
|
- | 957 | else cnt = 0; |
|
- | 958 | // correct Gyro Offsets |
|
- | 959 | if(cnt > ParamSet.DriftComp) cnt = ParamSet.DriftComp; |
|
- | 960 | if(IntegralErrorRoll > ERROR_LIMIT) AdNeutralRoll += cnt; |
|
- | 961 | if(IntegralErrorRoll < -ERROR_LIMIT) AdNeutralRoll -= cnt; |
|
- | 962 | ||
- | 963 | DebugOut.Analog[27] = CorrectionRoll; |
|
- | 964 | DebugOut.Analog[23] = AdNeutralPitch;//10*(AdNeutralPitch - StartNeutralPitch); |
|
- | 965 | DebugOut.Analog[24] = 10*(AdNeutralRoll - StartNeutralRoll); |
|
- | 966 | } |
|
- | 967 | else // looping is active |
|
- | 968 | { |
|
- | 969 | AttitudeCorrectionRoll = 0; |
|
- | 970 | AttitudeCorrectionPitch = 0; |
|
- | 971 | } |
|
- | 972 | ||
- | 973 | // if Gyro_I_Faktor == 0 , for example at Heading Hold, ignore attitude correction |
|
- | 974 | if(!Gyro_I_Factor) |
|
- | 975 | { |
|
- | 976 | AttitudeCorrectionRoll = 0; |
|
- | 977 | AttitudeCorrectionPitch = 0; |
|
- | 978 | } |
|
- | 979 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 980 | MeanIntegralPitch_old = MeanIntegralPitch; |
|
- | 981 | MeanIntegralRoll_old = MeanIntegralRoll; |
|
- | 982 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 983 | // reset variables used for averaging |
|
Line 833... | Line -... | ||
833 | CorrectionPitch = IntegralErrorPitch / ParamSet.GyroAccTrim; |
- | |
834 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
835 | IntegralErrorRoll = (long)(MeanIntegralRoll - (long)IntegralAccRoll); |
- | |
836 | CorrectionRoll = IntegralErrorRoll / ParamSet.GyroAccTrim; |
- | |
837 | - | ||
Line 838... | Line 984... | ||
838 | AttitudeCorrectionPitch = CorrectionPitch / ABGLEICH_ANZAHL; |
984 | IntegralAccPitch = 0; |
839 | AttitudeCorrectionRoll = CorrectionRoll / ABGLEICH_ANZAHL; |
985 | IntegralAccRoll = 0; |
840 | 986 | IntegralAccZ = 0; |
|
841 | if((MaxStickPitch > 15) || (MaxStickRoll > 15) || (abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]) > 25)) |
- | |
842 | { |
- | |
843 | AttitudeCorrectionPitch /= 2; |
- | |
844 | AttitudeCorrectionPitch /= 2; |
- | |
845 | } |
- | |
846 | - | ||
847 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
848 | // Gyro-Drift ermitteln |
- | |
849 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
850 | MeanIntegralPitch2 /= ABGLEICH_ANZAHL; |
- | |
851 | MeanIntegralRoll2 /= ABGLEICH_ANZAHL; |
- | |
852 | tmp_long = IntegralPitch2 - IntegralPitch; |
- | |
853 | tmp_long2 = IntegralRoll2 - IntegralRoll; |
- | |
854 | //DebugOut.Analog[25] = MeanIntegralRoll2 / 26; |
- | |
855 | - | ||
856 | IntegralErrorPitch = tmp_long; |
- | |
857 | IntegralErrorRoll = tmp_long2; |
- | |
858 | Reading_IntegralPitch2 -= IntegralErrorPitch; |
- | |
859 | Reading_IntegralRoll2 -= IntegralErrorRoll; |
- | |
860 | 987 | MeanIntegralPitch = 0; |
|
861 | // IntegralErrorPitch = (IntegralErrorPitch * 1 + tmp_long) / 2; |
- | |
862 | // IntegralErrorRoll = (IntegralErrorRoll * 1 + tmp_long2) / 2; |
- | |
863 | - | ||
864 | - | ||
865 | DebugOut.Analog[17] = IntegralAccPitch / 26; |
- | |
866 | DebugOut.Analog[18] = IntegralAccRoll / 26; |
- | |
867 | DebugOut.Analog[19] = IntegralErrorPitch;// / 26; |
- | |
868 | DebugOut.Analog[20] = IntegralErrorRoll;// / 26; |
- | |
869 | DebugOut.Analog[21] = MeanIntegralPitch / 26; |
- | |
870 | DebugOut.Analog[22] = MeanIntegralRoll / 26; |
- | |
871 | //DebugOut.Analog[28] = CorrectionPitch; |
- | |
872 | DebugOut.Analog[29] = CorrectionRoll; |
- | |
873 | DebugOut.Analog[30] = AttitudeCorrectionRoll * 10; |
- | |
874 | - | ||
875 | #define FEHLER_LIMIT (ABGLEICH_ANZAHL * 4) |
- | |
876 | #define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16) |
- | |
877 | #define BEWEGUNGS_LIMIT 20000 |
- | |
878 | // Pitch +++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
879 | cnt = 1;// + labs(IntegralErrorPitch) / 4096; |
- | |
880 | if(labs(MeanIntegralPitch_old - MeanIntegralPitch) < BEWEGUNGS_LIMIT) |
- | |
881 | { |
- | |
882 | if(IntegralErrorPitch > FEHLER_LIMIT2) |
- | |
883 | { |
- | |
884 | if(last_n_p) |
- | |
885 | { |
- | |
886 | cnt += labs(IntegralErrorPitch) / FEHLER_LIMIT2; |
- | |
887 | CorrectionPitch = IntegralErrorPitch / 8; |
- | |
888 | if(CorrectionPitch > 5000) CorrectionPitch = 5000; |
- | |
889 | AttitudeCorrectionPitch += CorrectionPitch / ABGLEICH_ANZAHL; |
- | |
890 | } |
- | |
891 | else last_n_p = 1; |
- | |
892 | } else last_n_p = 0; |
- | |
893 | if(IntegralErrorPitch < -FEHLER_LIMIT2) |
- | |
894 | { |
- | |
895 | if(last_n_n) |
- | |
896 | { |
- | |
897 | cnt += labs(IntegralErrorPitch) / FEHLER_LIMIT2; |
- | |
898 | CorrectionPitch = IntegralErrorPitch / 8; |
- | |
899 | if(CorrectionPitch < -5000) CorrectionPitch = -5000; |
- | |
900 | AttitudeCorrectionPitch += CorrectionPitch / ABGLEICH_ANZAHL; |
- | |
901 | } |
- | |
902 | else last_n_n = 1; |
- | |
903 | } else last_n_n = 0; |
- | |
904 | } else cnt = 0; |
- | |
905 | if(cnt > ParamSet.DriftComp) cnt = ParamSet.DriftComp; |
- | |
906 | if(IntegralErrorPitch > FEHLER_LIMIT) AdNeutralPitch += cnt; |
- | |
907 | if(IntegralErrorPitch < -FEHLER_LIMIT) AdNeutralPitch -= cnt; |
- | |
908 | - | ||
909 | // Roll +++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
910 | cnt = 1;// + labs(IntegralErrorPitch) / 4096; |
- | |
911 | - | ||
912 | CorrectionRoll = 0; |
- | |
913 | if(labs(MeanIntegralRoll_old - MeanIntegralRoll) < BEWEGUNGS_LIMIT) |
- | |
914 | { |
- | |
915 | if(IntegralErrorRoll > FEHLER_LIMIT2) |
- | |
916 | { |
- | |
917 | if(last_r_p) |
- | |
918 | { |
- | |
919 | cnt += labs(IntegralErrorRoll) / FEHLER_LIMIT2; |
- | |
920 | CorrectionRoll = IntegralErrorRoll / 8; |
- | |
921 | if(CorrectionRoll > 5000) CorrectionRoll = 5000; |
- | |
922 | AttitudeCorrectionRoll += CorrectionRoll / ABGLEICH_ANZAHL; |
- | |
923 | } |
- | |
924 | else last_r_p = 1; |
- | |
925 | } else last_r_p = 0; |
- | |
926 | if(IntegralErrorRoll < -FEHLER_LIMIT2) |
- | |
927 | { |
- | |
928 | if(last_r_n) |
- | |
929 | { |
- | |
930 | cnt += labs(IntegralErrorRoll) / FEHLER_LIMIT2; |
- | |
931 | CorrectionRoll = IntegralErrorRoll / 8; |
- | |
932 | if(CorrectionRoll < -5000) CorrectionRoll = -5000; |
- | |
933 | AttitudeCorrectionRoll += CorrectionRoll / ABGLEICH_ANZAHL; |
988 | MeanIntegralRoll = 0; |
934 | } |
- | |
935 | else last_r_n = 1; |
989 | MeasurementCounter = 0; |
936 | } else last_r_n = 0; |
- | |
937 | } else |
- | |
938 | { |
- | |
939 | cnt = 0; |
- | |
940 | } |
- | |
941 | - | ||
942 | if(cnt > ParamSet.DriftComp) cnt = ParamSet.DriftComp; |
- | |
943 | if(IntegralErrorRoll > FEHLER_LIMIT) AdNeutralRoll += cnt; |
- | |
944 | if(IntegralErrorRoll < -FEHLER_LIMIT) AdNeutralRoll -= cnt; |
990 | } // end of averaging |
945 | DebugOut.Analog[27] = CorrectionRoll; |
- | |
946 | DebugOut.Analog[23] = AdNeutralPitch;//10*(AdNeutralPitch - StartNeutralPitch); |
- | |
947 | DebugOut.Analog[24] = 10*(AdNeutralRoll - StartNeutralRoll); |
- | |
948 | } |
- | |
949 | else |
- | |
950 | { |
- | |
951 | AttitudeCorrectionRoll = 0; |
- | |
952 | AttitudeCorrectionPitch = 0; |
- | |
953 | } |
- | |
954 | - | ||
955 | if(!Gyro_I_Factor) { AttitudeCorrectionRoll = 0; AttitudeCorrectionPitch = 0;} // z.B. bei HH |
- | |
956 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
957 | MeanIntegralPitch_old = MeanIntegralPitch; |
- | |
958 | MeanIntegralRoll_old = MeanIntegralRoll; |
- | |
959 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
960 | IntegralAccPitch = 0; |
991 | |
961 | IntegralAccRoll = 0; |
- | |
962 | IntegralAccZ = 0; |
- | |
963 | MeanIntegralPitch = 0; |
- | |
964 | MeanIntegralRoll = 0; |
- | |
965 | MeanIntegralPitch2 = 0; |
- | |
966 | MeanIntegralRoll2 = 0; |
- | |
967 | ZaehlMessungen = 0; |
- | |
968 | } |
- | |
969 | //DebugOut.Analog[31] = StickRoll / (26*Gyro_I_Factor); |
992 | |
970 | 993 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
971 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
994 | // Yawing |
972 | // Gieren |
995 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | 996 | if(MaxStickYaw > 20) // yaw stick is activated |
|
973 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
997 | { // if not fixed compass course is set update compass course |
974 | if(abs(StickYaw) > 20) // war 35 |
998 | if(!(ParamSet.GlobalConfig & CFG_COMPASS_FIX)) StoreNewCompassCourse = 1; |
Line 975... | Line 999... | ||
975 | { |
999 | } |
976 | if(!(ParamSet.GlobalConfig & CFG_COMPASS_FIX)) StoreNewCompassCourse = 1; |
1000 | // exponential stick sensitivity in yawring rate |
977 | } |
1001 | tmp_int = (int32_t) ParamSet.Yaw_P * ((int32_t)StickYaw * abs(StickYaw)) / 512L; // expo y = ax + bx² |
978 | tmp_int = (long) ParamSet.Yaw_P * ((long)StickYaw * abs(StickYaw)) / 512L; // expo y = ax + bx² |
1002 | tmp_int += (ParamSet.Yaw_P * StickYaw) / 4; |
979 | tmp_int += (ParamSet.Yaw_P * StickYaw) / 4; |
1003 | SetPointYaw = tmp_int; |
980 | SetPointYaw = tmp_int; |
1004 | Reading_IntegralGyroYaw -= tmp_int; |
981 | Reading_IntegralYaw -= tmp_int; |
1005 | // limit the effect |
Line 982... | Line 1006... | ||
982 | if(Reading_IntegralYaw > 50000) Reading_IntegralYaw = 50000; // begrenzen |
1006 | if(Reading_IntegralGyroYaw > 50000) Reading_IntegralGyroYaw = 50000; |
983 | if(Reading_IntegralYaw <-50000) Reading_IntegralYaw =-50000; |
1007 | if(Reading_IntegralGyroYaw <-50000) Reading_IntegralGyroYaw =-50000; |
984 | 1008 | ||
985 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1009 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
986 | // Kompass |
- | |
987 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
988 | if(ParamSet.GlobalConfig & CFG_COMPASS_ACTIVE) |
- | |
989 | { |
- | |
990 | int w,v; |
- | |
991 | static uint8_t updCompass = 0; |
- | |
992 | - | ||
993 | if (!updCompass--) // Aufruf mit ~10 Hz |
- | |
994 | { |
1010 | // Compass |
995 | CompassHeading = MM3_heading(); // get current compass reading |
- | |
996 | CompassOffCourse = ((540 + CompassHeading - CompassCourse) % 360) - 180; |
- | |
997 | updCompass = 50; |
- | |
998 | } |
1011 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
999 | - | ||
1000 | w = abs(IntegralPitch /512); // mit zunehmender Neigung den Einfluss drosseln |
- | |
1001 | v = abs(IntegralRoll /512); |
1012 | if(ParamSet.GlobalConfig & CFG_COMPASS_ACTIVE) |
1002 | if(v > w) w = v; // grösste Neigung ermitteln |
- | |
1003 | if(w < 35 && StoreNewCompassCourse) |
- | |
1004 | { |
- | |
Line -... | Line 1013... | ||
- | 1013 | { |
|
- | 1014 | int16_t w,v; |
|
- | 1015 | static uint8_t updCompass = 0; |
|
- | 1016 | ||
- | 1017 | if (!updCompass--) |
|
- | 1018 | { |
|
- | 1019 | updCompass = 49; // update only at 2ms*50 = 100ms (10Hz) |
|
- | 1020 | // get current compass heading (angule between MK head and magnetic north) |
|
- | 1021 | CompassHeading = MM3_heading(); |
|
- | 1022 | // calculate OffCourse (angular deviation from heading to course) |
|
- | 1023 | CompassOffCourse = ((540 + CompassHeading - CompassCourse) % 360) - 180; |
|
- | 1024 | ||
- | 1025 | } |
|
- | 1026 | ||
- | 1027 | // reduce compass effect with increasing declination |
|
- | 1028 | w = abs(IntegralPitch / 512); |
|
- | 1029 | v = abs(IntegralRoll / 512); |
|
- | 1030 | if(v > w) w = v; // get maximum declination |
|
- | 1031 | // if declination is small enough update compass course if neccessary |
|
1005 | CompassCourse = CompassHeading; |
1032 | if(w < 35 && StoreNewCompassCourse) |
1006 | StoreNewCompassCourse = 0; |
1033 | { |
1007 | } |
1034 | CompassCourse = CompassHeading; |
1008 | w = (w * FCParam.CompassYawEffect) / 64; // auf die Wirkung normieren |
1035 | StoreNewCompassCourse = 0; |
1009 | w = FCParam.CompassYawEffect - w; // Wirkung ggf drosseln |
1036 | } |
1010 | if(w > 0) |
1037 | w = (w * FCParam.CompassYawEffect) / 64; // scale to parameter |
1011 | { |
1038 | w = FCParam.CompassYawEffect - w; // reduce commpass effect with increasing declination |
1012 | Reading_IntegralYaw -= (CompassOffCourse * w) / 32; // nach Kompass ausrichten |
1039 | if(w > 0) // if there is any compass effect (avoid negative compass feedback) |
1013 | } |
1040 | { |
1014 | } |
1041 | Reading_IntegralGyroYaw -= (CompassOffCourse * w) / 32; |
1015 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1042 | } |
1016 | 1043 | } |
|
1017 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1044 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1018 | // Debugwerte zuordnen |
1045 | // Debugwerte zuordnen |
1019 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1046 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1020 | if(!TimerDebugOut--) |
1047 | if(!TimerDebugOut--) |
1021 | { |
1048 | { |
1022 | TimerDebugOut = 24; |
1049 | TimerDebugOut = 24; // update debug outputs every 25*2ms = 50 ms (20Hz) |
1023 | DebugOut.Analog[0] = IntegralPitch / ParamSet.GyroAccFaktor; |
1050 | DebugOut.Analog[0] = IntegralPitch / ParamSet.GyroAccFaktor; |
1024 | DebugOut.Analog[1] = IntegralRoll / ParamSet.GyroAccFaktor; |
1051 | DebugOut.Analog[1] = IntegralRoll / ParamSet.GyroAccFaktor; |
1025 | DebugOut.Analog[2] = Mean_AccPitch; |
1052 | DebugOut.Analog[2] = Mean_AccPitch; |
1026 | DebugOut.Analog[3] = Mean_AccRoll; |
1053 | DebugOut.Analog[3] = Mean_AccRoll; |
1027 | DebugOut.Analog[4] = ReadingYaw; |
1054 | DebugOut.Analog[4] = Reading_GyroYaw; |
1028 | DebugOut.Analog[5] = ReadingHight; |
1055 | DebugOut.Analog[5] = ReadingHight; |
1029 | DebugOut.Analog[6] = (Reading_Integral_Top / 512); |
1056 | DebugOut.Analog[6] = (Reading_Integral_Top / 512); |
1030 | DebugOut.Analog[8] = CompassHeading; |
1057 | DebugOut.Analog[8] = CompassHeading; |
1031 | DebugOut.Analog[9] = UBat; |
1058 | DebugOut.Analog[9] = UBat; |
1032 | DebugOut.Analog[10] = SenderOkay; |
1059 | DebugOut.Analog[10] = SenderOkay; |
1033 | DebugOut.Analog[16] = Mean_AccTop; |
1060 | DebugOut.Analog[16] = Mean_AccTop; |
1034 | 1061 | ||
1035 | /* DebugOut.Analog[16] = motor_rx[0]; |
1062 | /* DebugOut.Analog[16] = motor_rx[0]; |
1036 | DebugOut.Analog[17] = motor_rx[1]; |
1063 | DebugOut.Analog[17] = motor_rx[1]; |
1037 | DebugOut.Analog[18] = motor_rx[2]; |
1064 | DebugOut.Analog[18] = motor_rx[2]; |
1038 | DebugOut.Analog[19] = motor_rx[3]; |
1065 | DebugOut.Analog[19] = motor_rx[3]; |
1039 | DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3]; |
1066 | DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3]; |
1040 | DebugOut.Analog[20] /= 14; |
1067 | DebugOut.Analog[20] /= 14; |
1041 | DebugOut.Analog[21] = motor_rx[4]; |
1068 | DebugOut.Analog[21] = motor_rx[4]; |
1042 | DebugOut.Analog[22] = motor_rx[5]; |
1069 | DebugOut.Analog[22] = motor_rx[5]; |
1043 | DebugOut.Analog[23] = motor_rx[6]; |
1070 | DebugOut.Analog[23] = motor_rx[6]; |
1044 | DebugOut.Analog[24] = motor_rx[7]; |
1071 | DebugOut.Analog[24] = motor_rx[7]; |
1045 | DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7]; |
- | |
1046 | */ |
- | |
1047 | // DebugOut.Analog[9] = ReadingPitch; |
- | |
1048 | // DebugOut.Analog[9] = SetPointHight; |
- | |
1049 | // DebugOut.Analog[10] = Reading_IntegralYaw / 128; |
- | |
1050 | // DebugOut.Analog[11] = CompassCourse; |
- | |
1051 | // DebugOut.Analog[10] = FCParam.Gyro_I; |
- | |
1052 | // DebugOut.Analog[10] = ParamSet.Gyro_I; |
- | |
1053 | // DebugOut.Analog[9] = CompassOffCourse; |
- | |
1054 | // DebugOut.Analog[10] = ThrustMixingFraction; |
- | |
1055 | // DebugOut.Analog[3] = HightD * 32; |
- | |
1056 | // DebugOut.Analog[4] = hoehenregler; |
- | |
1057 | } |
- | |
1058 | - | ||
1059 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1060 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
- | |
1061 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1062 | //DebugOut.Analog[26] = ReadingPitch; |
- | |
1063 | //DebugOut.Analog[28] = ReadingRoll; |
- | |
1064 | - | ||
1065 | if(Looping_Pitch) ReadingPitch = ReadingPitch * Gyro_P_Factor; |
- | |
1066 | else ReadingPitch = IntegralPitch * Gyro_I_Factor + ReadingPitch * Gyro_P_Factor; |
- | |
1067 | if(Looping_Roll) ReadingRoll = ReadingRoll * Gyro_P_Factor; |
- | |
1068 | else ReadingRoll = IntegralRoll * Gyro_I_Factor + ReadingRoll * Gyro_P_Factor; |
- | |
1069 | ReadingYaw = ReadingYaw * (2 * Gyro_P_Factor) + IntegralYaw * Gyro_I_Factor / 2; |
- | |
1070 | - | ||
1071 | DebugOut.Analog[25] = IntegralRoll * Gyro_I_Factor; |
- | |
1072 | DebugOut.Analog[31] = StickRoll;// / (26*Gyro_I_Factor); |
- | |
1073 | DebugOut.Analog[28] = ReadingRoll; |
- | |
1074 | - | ||
1075 | // Maximalwerte abfangen |
- | |
1076 | #define MAX_SENSOR 2048 |
- | |
1077 | if(ReadingPitch > MAX_SENSOR) ReadingPitch = MAX_SENSOR; |
- | |
1078 | if(ReadingPitch < -MAX_SENSOR) ReadingPitch = -MAX_SENSOR; |
- | |
1079 | if(ReadingRoll > MAX_SENSOR) ReadingRoll = MAX_SENSOR; |
- | |
1080 | if(ReadingRoll < -MAX_SENSOR) ReadingRoll = -MAX_SENSOR; |
- | |
1081 | if(ReadingYaw > MAX_SENSOR) ReadingYaw = MAX_SENSOR; |
- | |
1082 | if(ReadingYaw < -MAX_SENSOR) ReadingYaw = -MAX_SENSOR; |
- | |
1083 | - | ||
1084 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1085 | // Höhenregelung |
- | |
1086 | // Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht |
- | |
1087 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1088 | //OCR0B = 180 - (Poti1 + 120) / 4; |
- | |
1089 | //DruckOffsetSetting = OCR0B; |
- | |
1090 | if((ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL)) // Höhenregelung |
- | |
1091 | { |
- | |
1092 | int tmp_int; |
1072 | DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7]; |
1093 | if(ParamSet.GlobalConfig & CFG_HEIGHT_SWITCH) // Regler wird über Schalter gesteuert |
- | |
1094 | { |
- | |
1095 | if(FCParam.MaxHight < 50) |
1073 | |
Line 1096... | Line -... | ||
1096 | { |
- | |
1097 | SetPointHight = ReadingHight - 20; // FCParam.MaxHight ist der PPM-Wert des Schalters |
- | |
1098 | HightControlActive = 0; |
- | |
1099 | } |
- | |
1100 | else |
- | |
1101 | HightControlActive = 1; |
- | |
1102 | } |
- | |
1103 | else |
- | |
1104 | { |
- | |
1105 | SetPointHight = ((int) ExternHightValue + (int) FCParam.MaxHight) * (int)ParamSet.Hight_Gain - 20; |
- | |
1106 | HightControlActive = 1; |
- | |
1107 | } |
- | |
1108 | - | ||
1109 | if(EmergencyLanding) SetPointHight = 0; |
- | |
1110 | h = ReadingHight; |
- | |
1111 | if((h > SetPointHight) && HightControlActive) // zu hoch --> drosseln |
- | |
1112 | { h = ((h - SetPointHight) * (int) FCParam.Hight_P) / 16; // Differenz bestimmen --> P-Anteil |
- | |
1113 | h = ThrustMixingFraction - h; // vom Gas abziehen |
- | |
1114 | h -= (HightD * FCParam.AirPressure_D)/8; // D-Anteil |
- | |
1115 | tmp_int = ((Reading_Integral_Top / 512) * (signed long) FCParam.Hight_ACC_Effect) / 32; |
- | |
1116 | if(tmp_int > 50) tmp_int = 50; |
- | |
1117 | else if(tmp_int < -50) tmp_int = -50; |
1074 | DebugOut.Analog[9] = Reading_GyroPitch; |
1118 | h -= tmp_int; |
1075 | DebugOut.Analog[9] = SetPointHight; |
1119 | hoehenregler = (hoehenregler*15 + h) / 16; |
1076 | DebugOut.Analog[10] = Reading_IntegralGyroYaw / 128; |
- | 1077 | DebugOut.Analog[11] = CompassCourse; |
|
- | 1078 | DebugOut.Analog[10] = FCParam.Gyro_I; |
|
- | 1079 | DebugOut.Analog[10] = ParamSet.Gyro_I; |
|
- | 1080 | DebugOut.Analog[9] = CompassOffCourse; |
|
- | 1081 | DebugOut.Analog[10] = ThrustMixFraction; |
|
- | 1082 | DebugOut.Analog[3] = HightD * 32; |
|
- | 1083 | DebugOut.Analog[4] = HightControlThrust; |
|
- | 1084 | */ |
|
- | 1085 | } |
|
1120 | if(hoehenregler < ParamSet.Hight_MinThrust) // nicht unter MIN |
1086 | |
- | 1087 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1088 | // calculate control feedback from angle (gyro integral) and agular velocity (gyro signal) |
|
- | 1089 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1090 | ||
- | 1091 | if(Looping_Pitch) Reading_GyroPitch = Reading_GyroPitch * Gyro_P_Factor; |
|
- | 1092 | else Reading_GyroPitch = IntegralPitch * Gyro_I_Factor + Reading_GyroPitch * Gyro_P_Factor; |
|
- | 1093 | if(Looping_Roll) Reading_GyroRoll = Reading_GyroRoll * Gyro_P_Factor; |
|
- | 1094 | else Reading_GyroRoll = IntegralRoll * Gyro_I_Factor + Reading_GyroRoll * Gyro_P_Factor; |
|
- | 1095 | Reading_GyroYaw = Reading_GyroYaw * (2 * Gyro_P_Factor) + IntegralYaw * Gyro_I_Factor / 2; |
|
- | 1096 | ||
1121 | { |
1097 | DebugOut.Analog[25] = IntegralRoll * Gyro_I_Factor; |
1122 | if(ThrustMixingFraction >= ParamSet.Hight_MinThrust) hoehenregler = ParamSet.Hight_MinThrust; |
1098 | DebugOut.Analog[31] = StickRoll;// / (26*Gyro_I_Factor); |
- | 1099 | DebugOut.Analog[28] = Reading_GyroRoll; |
|
1123 | if(ThrustMixingFraction < ParamSet.Hight_MinThrust) hoehenregler = ThrustMixingFraction; |
1100 | |
- | 1101 | // limit control feedback |
|
- | 1102 | #define MAX_SENSOR 2048 |
|
- | 1103 | if(Reading_GyroPitch > MAX_SENSOR) Reading_GyroPitch = MAX_SENSOR; |
|
1124 | } |
1104 | if(Reading_GyroPitch < -MAX_SENSOR) Reading_GyroPitch = -MAX_SENSOR; |
- | 1105 | if(Reading_GyroRoll > MAX_SENSOR) Reading_GyroRoll = MAX_SENSOR; |
|
- | 1106 | if(Reading_GyroRoll < -MAX_SENSOR) Reading_GyroRoll = -MAX_SENSOR; |
|
- | 1107 | if(Reading_GyroYaw > MAX_SENSOR) Reading_GyroYaw = MAX_SENSOR; |
|
- | 1108 | if(Reading_GyroYaw < -MAX_SENSOR) Reading_GyroYaw = -MAX_SENSOR; |
|
- | 1109 | ||
1125 | if(hoehenregler > ThrustMixingFraction) hoehenregler = ThrustMixingFraction; // nicht mehr als Gas |
1110 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | 1111 | // Hight Control |
|
- | 1112 | // The higth control algorithm reduces the thrust but does not increas the thrust. |
|
- | 1113 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1114 | // If hight control is activated and no emergency landing is activre |
|
- | 1115 | if((ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL) && (!EmergencyLanding) ) |
|
- | 1116 | { |
|
- | 1117 | int tmp_int; |
|
1126 | ThrustMixingFraction = hoehenregler; |
1118 | // if hight control is activated by an rc channel |
- | 1119 | if(ParamSet.GlobalConfig & CFG_HEIGHT_SWITCH) |
|
- | 1120 | { // check if parameter is less than activation threshold |
|
- | 1121 | if(FCParam.MaxHight < 50) |
|
- | 1122 | { |
|
- | 1123 | SetPointHight = ReadingHight - 20; // update SetPoint with current reading |
|
1127 | } |
1124 | HightControlActive = 0; // disable hight control |
- | 1125 | } |
|
- | 1126 | else HightControlActive = 1; // enable hight control |
|
- | 1127 | } |
|
- | 1128 | else // no switchable hight control |
|
- | 1129 | { |
|
- | 1130 | SetPointHight = ((int16_t) ExternHightValue + (int16_t) FCParam.MaxHight) * (int16_t)ParamSet.Hight_Gain - 20; |
|
- | 1131 | HightControlActive = 1; |
|
- | 1132 | } |
|
- | 1133 | // get current hight |
|
- | 1134 | h = ReadingHight; |
|
- | 1135 | // if current hight is above the setpoint reduce thrust |
|
- | 1136 | if((h > SetPointHight) && HightControlActive) |
|
- | 1137 | { |
|
- | 1138 | // hight difference -> P control part |
|
- | 1139 | h = ((h - SetPointHight) * (int16_t) FCParam.Hight_P) / 16; |
|
1128 | } |
1140 | h = ThrustMixFraction - h; // reduce gas |
- | 1141 | // higth gradient --> D control part |
|
1129 | if(ThrustMixingFraction > ParamSet.Trust_Max - 20) ThrustMixingFraction = ParamSet.Trust_Max - 20; |
1142 | h -= (HightD * FCParam.Hight_D) / 8; // D control part |
- | 1143 | // acceleration sensor effect |
|
- | 1144 | tmp_int = ((Reading_Integral_Top / 512) * (int32_t) FCParam.Hight_ACC_Effect) / 32; |
|
1130 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1145 | if(tmp_int > 50) tmp_int = 50; |
- | 1146 | if(tmp_int < -50) tmp_int = -50; |
|
- | 1147 | h -= tmp_int; |
|
- | 1148 | // update hight control thrust |
|
- | 1149 | HightControlThrust = (HightControlThrust*15 + h) / 16; |
|
1131 | // + Mischer und PI-Regler |
1150 | // limit thrust reduction |
- | 1151 | if(HightControlThrust < ParamSet.Hight_MinThrust) |
|
- | 1152 | { |
|
- | 1153 | if(ThrustMixFraction >= ParamSet.Hight_MinThrust) HightControlThrust = ParamSet.Hight_MinThrust; |
|
- | 1154 | // allows landing also if thrust stick is reduced below min thrust on hight control |
|
- | 1155 | if(ThrustMixFraction < ParamSet.Hight_MinThrust) HightControlThrust = ThrustMixFraction; |
|
- | 1156 | } |
|
- | 1157 | // limit thrust to stick setting |
|
- | 1158 | if(HightControlThrust > ThrustMixFraction) HightControlThrust = ThrustMixFraction; |
|
Line -... | Line 1159... | ||
- | 1159 | ThrustMixFraction = HightControlThrust; |
|
- | 1160 | } |
|
- | 1161 | } |
|
- | 1162 | // limit thrust to parameter setting |
|
- | 1163 | if(ThrustMixFraction > ParamSet.Trust_Max - 20) ThrustMixFraction = ParamSet.Trust_Max - 20; |
|
1132 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1164 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1133 | DebugOut.Analog[7] = ThrustMixingFraction; |
1165 | // + Mixer and PI-Controller |
1134 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1166 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1135 | // Gier-Anteil |
1167 | DebugOut.Analog[7] = ThrustMixFraction; |
1136 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1168 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1137 | #define MUL_G 1.0 |
1169 | // Yaw-Fraction |
1138 | YawMixingFraction = ReadingYaw - SetPointYaw; // Regler für Gier |
1170 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1139 | // YawMixingFraction = 0; |
1171 | YawMixFraction = Reading_GyroYaw - SetPointYaw; // yaw controller |
1140 | 1172 | ||
1141 | if(YawMixingFraction > (ThrustMixingFraction / 2)) YawMixingFraction = ThrustMixingFraction / 2; |
1173 | // limit YawMixFraction |
1142 | if(YawMixingFraction < -(ThrustMixingFraction / 2)) YawMixingFraction = -(ThrustMixingFraction / 2); |
- | |
1143 | if(YawMixingFraction > ((ParamSet.Trust_Max - ThrustMixingFraction))) YawMixingFraction = ((ParamSet.Trust_Max - ThrustMixingFraction)); |
- | |
1144 | if(YawMixingFraction < -((ParamSet.Trust_Max - ThrustMixingFraction))) YawMixingFraction = -((ParamSet.Trust_Max - ThrustMixingFraction)); |
- | |
1145 | - | ||
Line -... | Line 1174... | ||
- | 1174 | if(YawMixFraction > (ThrustMixFraction / 2)) YawMixFraction = ThrustMixFraction / 2; |
|
- | 1175 | if(YawMixFraction < -(ThrustMixFraction / 2)) YawMixFraction = -(ThrustMixFraction / 2); |
|
- | 1176 | if(YawMixFraction > ((ParamSet.Trust_Max - ThrustMixFraction))) YawMixFraction = ((ParamSet.Trust_Max - ThrustMixFraction)); |
|
- | 1177 | if(YawMixFraction < -((ParamSet.Trust_Max - ThrustMixFraction))) YawMixFraction = -((ParamSet.Trust_Max - ThrustMixFraction)); |
|
- | 1178 | if(ThrustMixFraction < 20) YawMixFraction = 0; |
|
1146 | if(ThrustMixingFraction < 20) YawMixingFraction = 0; |
1179 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1147 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1180 | // Pitch-Axis |
1148 | // Pitch-Achse |
1181 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1149 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1182 | DiffPitch = Reading_GyroPitch - (StickPitch - GPS_Pitch); // get difference |
1150 | DiffPitch = ReadingPitch - (StickPitch - GPS_Pitch); // Differenz bestimmen |
1183 | if(Gyro_I_Factor) SumPitch += IntegralPitch * Gyro_I_Factor - (StickPitch - GPS_Pitch); // I-part for attitude control |
- | 1184 | else SumPitch += DiffPitch; // I-part for head holding |
|
1151 | if(Gyro_I_Factor) SumPitch += IntegralPitch * Gyro_I_Factor - (StickPitch - GPS_Pitch); // I-Anteil bei Winkelregelung |
1185 | if(SumPitch > 16000) SumPitch = 16000; |
1152 | else SumPitch += DiffPitch; // I-Anteil bei HH |
1186 | if(SumPitch < -16000) SumPitch = -16000; |
1153 | if(SumPitch > 16000) SumPitch = 16000; |
1187 | pd_result = DiffPitch + Ki * SumPitch; // PI-controller for pitch |
1154 | if(SumPitch < -16000) SumPitch = -16000; |
1188 | |
1155 | pd_ergebnis = DiffPitch + Ki * SumPitch; // PI-Regler für Pitch |
1189 | tmp_int = (int32_t)((int32_t)FCParam.DynamicStability * (int32_t)(ThrustMixFraction + abs(YawMixFraction)/2)) / 64; |
1156 | // Motor Vorn |
1190 | if(pd_result > tmp_int) pd_result = tmp_int; |
1157 | tmp_int = (long)((long)FCParam.DynamicStability * (long)(ThrustMixingFraction + abs(YawMixingFraction)/2)) / 64; |
1191 | if(pd_result < -tmp_int) pd_result = -tmp_int; |
1158 | if(pd_ergebnis > tmp_int) pd_ergebnis = tmp_int; |
1192 | |
1159 | if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int; |
1193 | // Motor Front |
1160 | 1194 | MotorValue = ThrustMixFraction + pd_result + YawMixFraction; // Mixer |
|
1161 | MotorValue = ThrustMixingFraction + pd_ergebnis + YawMixingFraction; // Mischer |
1195 | if ((MotorValue < 0)) MotorValue = 0; |
1162 | if ((MotorValue < 0)) MotorValue = 0; |
1196 | else if(MotorValue > ParamSet.Trust_Max) MotorValue = ParamSet.Trust_Max; |
1163 | else if(MotorValue > ParamSet.Trust_Max) MotorValue = ParamSet.Trust_Max; |
1197 | if (MotorValue < ParamSet.Trust_Min) MotorValue = ParamSet.Trust_Min; |
1164 | if (MotorValue < ParamSet.Trust_Min) MotorValue = ParamSet.Trust_Min; |
1198 | Motor_Front = MotorValue; |
1165 | Motor_Front = MotorValue; |
1199 | |
1166 | // Motor Heck |
1200 | // Motor Rear |
1167 | MotorValue = ThrustMixingFraction - pd_ergebnis + YawMixingFraction; |
1201 | MotorValue = ThrustMixFraction - pd_result + YawMixFraction; // Mixer |
1168 | if ((MotorValue < 0)) MotorValue = 0; |
1202 | if ((MotorValue < 0)) MotorValue = 0; |
1169 | else if(MotorValue > ParamSet.Trust_Max) MotorValue = ParamSet.Trust_Max; |
- | |
1170 | if (MotorValue < ParamSet.Trust_Min) MotorValue = ParamSet.Trust_Min; |
- | |
1171 | Motor_Rear = MotorValue; |
- | |
Line -... | Line 1203... | ||
- | 1203 | else if(MotorValue > ParamSet.Trust_Max) MotorValue = ParamSet.Trust_Max; |
|
- | 1204 | if (MotorValue < ParamSet.Trust_Min) MotorValue = ParamSet.Trust_Min; |
|
1172 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1205 | Motor_Rear = MotorValue; |
1173 | // Roll-Achse |
1206 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1174 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1207 | // Roll-Axis |
1175 | DiffRoll = ReadingRoll - (StickRoll - GPS_Roll); // Differenz bestimmen |
1208 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1176 | if(Gyro_I_Factor) SumRoll += IntegralRoll * Gyro_I_Factor - (StickRoll - GPS_Roll);// I-Anteil bei Winkelregelung |
- | |
1177 | else SumRoll += DiffRoll; // I-Anteil bei HH |
- | |
Line -... | Line 1209... | ||
- | 1209 | DiffRoll = Reading_GyroRoll - (StickRoll - GPS_Roll); // get difference |
|
- | 1210 | if(Gyro_I_Factor) SumRoll += IntegralRoll * Gyro_I_Factor - (StickRoll - GPS_Roll); // I-part for attitude control |
|
1178 | if(SumRoll > 16000) SumRoll = 16000; |
1211 | else SumRoll += DiffRoll; // I-part for head holding |
1179 | if(SumRoll < -16000) SumRoll = -16000; |
1212 | if(SumRoll > 16000) SumRoll = 16000; |
1180 | pd_ergebnis = DiffRoll + Ki * SumRoll; // PI-Regler für Roll |
1213 | if(SumRoll < -16000) SumRoll = -16000; |
1181 | tmp_int = (long)((long)FCParam.DynamicStability * (long)(ThrustMixingFraction + abs(YawMixingFraction)/2)) / 64; |
1214 | pd_result = DiffRoll + Ki * SumRoll; // PI-controller for roll |
1182 | if(pd_ergebnis > tmp_int) pd_ergebnis = tmp_int; |
- | |
1183 | if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int; |
1215 | tmp_int = (int32_t)((int32_t)FCParam.DynamicStability * (int32_t)(ThrustMixFraction + abs(YawMixFraction)/2)) / 64; |