Rev 935 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 935 | Rev 936 | ||
---|---|---|---|
Line 72... | Line 72... | ||
72 | #include "mk3mag.h" |
72 | #include "mk3mag.h" |
73 | #include "gps.h" |
73 | #include "gps.h" |
74 | #endif |
74 | #endif |
75 | #include "led.h" |
75 | #include "led.h" |
Line 76... | Line -... | ||
76 | - | ||
77 | volatile uint16_t I2CTimeout = 100; |
76 | |
78 | // gyro readings |
77 | // gyro readings |
79 | volatile int16_t Reading_GyroNick, Reading_GyroRoll, Reading_GyroYaw; |
78 | int16_t Reading_GyroNick, Reading_GyroRoll, Reading_GyroYaw; |
80 | // gyro neutral readings |
79 | // gyro neutral readings |
81 | volatile int16_t AdNeutralNick = 0, AdNeutralRoll = 0, AdNeutralYaw = 0; |
80 | int16_t AdNeutralNick = 0, AdNeutralRoll = 0, AdNeutralYaw = 0; |
82 | volatile int16_t StartNeutralRoll = 0, StartNeutralNick = 0; |
81 | int16_t StartNeutralRoll = 0, StartNeutralNick = 0; |
83 | // mean accelerations |
82 | // mean accelerations |
Line 84... | Line 83... | ||
84 | volatile int16_t Mean_AccNick, Mean_AccRoll, Mean_AccTop; |
83 | int16_t Mean_AccNick, Mean_AccRoll, Mean_AccTop; |
85 | 84 | ||
86 | // neutral acceleration readings |
85 | // neutral acceleration readings |
Line 87... | Line 86... | ||
87 | volatile int16_t NeutralAccX=0, NeutralAccY=0; |
86 | volatile int16_t NeutralAccX=0, NeutralAccY=0; |
88 | volatile float NeutralAccZ = 0; |
87 | volatile float NeutralAccZ = 0; |
89 | 88 | ||
90 | // attitude gyro integrals |
89 | // attitude gyro integrals |
91 | volatile int32_t IntegralNick = 0,IntegralNick2 = 0; |
90 | int32_t IntegralNick = 0,IntegralNick2 = 0; |
92 | volatile int32_t IntegralRoll = 0,IntegralRoll2 = 0; |
91 | int32_t IntegralRoll = 0,IntegralRoll2 = 0; |
93 | volatile int32_t IntegralYaw = 0; |
92 | int32_t IntegralYaw = 0; |
94 | volatile int32_t Reading_IntegralGyroNick = 0, Reading_IntegralGyroNick2 = 0; |
93 | int32_t Reading_IntegralGyroNick = 0, Reading_IntegralGyroNick2 = 0; |
95 | volatile int32_t Reading_IntegralGyroRoll = 0, Reading_IntegralGyroRoll2 = 0; |
94 | int32_t Reading_IntegralGyroRoll = 0, Reading_IntegralGyroRoll2 = 0; |
Line 96... | Line 95... | ||
96 | volatile int32_t Reading_IntegralGyroYaw = 0; |
95 | int32_t Reading_IntegralGyroYaw = 0; |
97 | volatile int32_t MeanIntegralNick; |
96 | int32_t MeanIntegralNick; |
98 | volatile int32_t MeanIntegralRoll; |
97 | int32_t MeanIntegralRoll; |
Line 99... | Line 98... | ||
99 | 98 | ||
100 | // attitude acceleration integrals |
99 | // attitude acceleration integrals |
101 | volatile int32_t IntegralAccNick = 0, IntegralAccRoll = 0; |
100 | int32_t IntegralAccNick = 0, IntegralAccRoll = 0; |
Line 113... | Line 112... | ||
113 | 112 | ||
Line 114... | Line 113... | ||
114 | 113 | ||
115 | int16_t NaviAccNick = 0, NaviAccRoll = 0, NaviCntAcc = 0; |
- | |
116 | - | ||
117 | 114 | int16_t NaviAccNick = 0, NaviAccRoll = 0, NaviCntAcc = 0; |
|
- | 115 | ||
Line 118... | Line 116... | ||
118 | // flags |
116 | |
Line 119... | Line 117... | ||
119 | uint8_t MotorsOn = 0; |
117 | // MK flags |
120 | uint8_t EmergencyLanding = 0; |
118 | uint16_t Model_Is_Flying = 0; |
Line 121... | Line 119... | ||
121 | uint16_t Model_Is_Flying = 0; |
119 | volatile uint8_t MKFlags = 0; |
Line 122... | Line 120... | ||
122 | 120 | ||
Line 123... | Line 121... | ||
123 | int32_t TurnOver180Nick = 250000L, TurnOver180Roll = 250000L; |
121 | int32_t TurnOver180Nick = 250000L, TurnOver180Roll = 250000L; |
124 | 122 | ||
Line 162... | Line 160... | ||
162 | /************************************************************************/ |
160 | /************************************************************************/ |
163 | void Beep(uint8_t numbeeps) |
161 | void Beep(uint8_t numbeeps) |
164 | { |
162 | { |
165 | while(numbeeps--) |
163 | while(numbeeps--) |
166 | { |
164 | { |
167 | if(MotorsOn) return; //auf keinen Fall im Flug! |
165 | if(MKFlags & MKFLAG_MOTOR_RUN) return; //auf keinen Fall bei laufenden Motoren! |
168 | BeepTime = 100; // 0.1 second |
166 | BeepTime = 100; // 0.1 second |
169 | Delay_ms(250); // blocks 250 ms as pause to next beep, |
167 | Delay_ms(250); // blocks 250 ms as pause to next beep, |
170 | // this will block the flight control loop, |
168 | // this will block the flight control loop, |
171 | // therefore do not use this funktion if motors are running |
169 | // therefore do not use this funktion if motors are running |
172 | } |
170 | } |
Line 215... | Line 213... | ||
215 | Reading_IntegralGyroRoll2 = 0; |
213 | Reading_IntegralGyroRoll2 = 0; |
216 | Reading_IntegralGyroYaw = 0; |
214 | Reading_IntegralGyroYaw = 0; |
217 | Reading_GyroNick = 0; |
215 | Reading_GyroNick = 0; |
218 | Reading_GyroRoll = 0; |
216 | Reading_GyroRoll = 0; |
219 | Reading_GyroYaw = 0; |
217 | Reading_GyroYaw = 0; |
- | 218 | Delay_ms_Mess(100); |
|
220 | StartAirPressure = AirPressure; |
219 | StartAirPressure = AirPressure; |
221 | HeightD = 0; |
220 | HeightD = 0; |
222 | Reading_Integral_Top = 0; |
221 | Reading_Integral_Top = 0; |
223 | CompassCourse = CompassHeading; |
222 | CompassCourse = CompassHeading; |
224 | BeepTime = 50; |
223 | BeepTime = 50; |
Line 227... | Line 226... | ||
227 | ExternHeightValue = 0; |
226 | ExternHeightValue = 0; |
228 | GPS_Nick = 0; |
227 | GPS_Nick = 0; |
229 | GPS_Roll = 0; |
228 | GPS_Roll = 0; |
230 | YawGyroHeading = CompassHeading * YAW_GYRO_DEG_FACTOR; |
229 | YawGyroHeading = CompassHeading * YAW_GYRO_DEG_FACTOR; |
231 | YawGyroDrift = 0; |
230 | YawGyroDrift = 0; |
- | 231 | MKFlags |= MKFLAG_CALIBRATE; |
|
232 | } |
232 | } |
Line 233... | Line 233... | ||
233 | 233 | ||
234 | /************************************************************************/ |
234 | /************************************************************************/ |
235 | /* Averaging Measurement Readings */ |
235 | /* Averaging Measurement Readings */ |
Line 354... | Line 354... | ||
354 | /************************************************************************/ |
354 | /************************************************************************/ |
355 | /* Averaging Measurement Readings for Calibration */ |
355 | /* Averaging Measurement Readings for Calibration */ |
356 | /************************************************************************/ |
356 | /************************************************************************/ |
357 | void CalibMean(void) |
357 | void CalibMean(void) |
358 | { |
358 | { |
- | 359 | if(BoardRelease >= 13) SearchGyroOffset(); |
|
359 | // stop ADC to avoid changing values during calculation |
360 | // stop ADC to avoid changing values during calculation |
360 | ADC_Disable(); |
361 | ADC_Disable(); |
Line 361... | Line 362... | ||
361 | 362 | ||
362 | Reading_GyroNick = AdValueGyrNick; |
363 | Reading_GyroNick = AdValueGyrNick; |
Line 377... | Line 378... | ||
377 | /************************************************************************/ |
378 | /************************************************************************/ |
378 | /* Transmit Motor Data via I2C */ |
379 | /* Transmit Motor Data via I2C */ |
379 | /************************************************************************/ |
380 | /************************************************************************/ |
380 | void SendMotorData(void) |
381 | void SendMotorData(void) |
381 | { |
382 | { |
382 | if(MOTOR_OFF || !MotorsOn) |
383 | if(!(MKFlags & MKFLAG_MOTOR_RUN)) |
383 | { |
384 | { |
384 | Motor_Rear = 0; |
385 | Motor_Rear = 0; |
385 | Motor_Front = 0; |
386 | Motor_Front = 0; |
386 | Motor_Right = 0; |
387 | Motor_Right = 0; |
387 | Motor_Left = 0; |
388 | Motor_Left = 0; |
388 | if(MotorTest[0]) Motor_Front = MotorTest[0]; |
389 | if(MotorTest[0]) Motor_Front = MotorTest[0]; |
389 | if(MotorTest[1]) Motor_Rear = MotorTest[1]; |
390 | if(MotorTest[1]) Motor_Rear = MotorTest[1]; |
390 | if(MotorTest[2]) Motor_Left = MotorTest[2]; |
391 | if(MotorTest[2]) Motor_Left = MotorTest[2]; |
391 | if(MotorTest[3]) Motor_Right = MotorTest[3]; |
392 | if(MotorTest[3]) Motor_Right = MotorTest[3]; |
- | 393 | MKFlags &= ~(MKFLAG_FLY|MKFLAG_START); // clear flag FLY and START if motors are off |
|
392 | } |
394 | } |
393 | - | ||
394 | DebugOut.Analog[12] = Motor_Front; |
395 | DebugOut.Analog[12] = Motor_Front; |
395 | DebugOut.Analog[13] = Motor_Rear; |
396 | DebugOut.Analog[13] = Motor_Rear; |
396 | DebugOut.Analog[14] = Motor_Left; |
397 | DebugOut.Analog[14] = Motor_Left; |
397 | DebugOut.Analog[15] = Motor_Right; |
398 | DebugOut.Analog[15] = Motor_Right; |
Line 398... | Line 399... | ||
398 | 399 | ||
399 | //Start I2C Interrupt Mode |
400 | //Start I2C Interrupt Mode |
400 | twi_state = 0; |
- | |
401 | motor = 0; |
401 | twi_state = TWI_STATE_MOTOR_TX; |
402 | I2C_Start(); |
402 | I2C_Start(); |
Line 411... | Line 411... | ||
411 | { |
411 | { |
412 | if(RC_Quality > 160) // do the mapping of RC-Potis only if the rc-signal is ok |
412 | if(RC_Quality > 160) // do the mapping of RC-Potis only if the rc-signal is ok |
413 | // else the last updated values are used |
413 | // else the last updated values are used |
414 | { |
414 | { |
415 | //update poti values by rc-signals |
415 | //update poti values by rc-signals |
416 | #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;} |
416 | #define CHK_POTI_MM(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;} |
- | 417 | #define CHK_POTI(b,a) { 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;} |
|
417 | CHK_POTI(FCParam.MaxHeight,ParamSet.MaxHeight,0,255); |
418 | CHK_POTI(FCParam.MaxHeight,ParamSet.MaxHeight); |
418 | CHK_POTI(FCParam.Height_D,ParamSet.Height_D,0,100); |
419 | CHK_POTI_MM(FCParam.Height_D,ParamSet.Height_D,0,100); |
419 | CHK_POTI(FCParam.Height_P,ParamSet.Height_P,0,100); |
420 | CHK_POTI_MM(FCParam.Height_P,ParamSet.Height_P,0,100); |
420 | CHK_POTI(FCParam.Height_ACC_Effect,ParamSet.Height_ACC_Effect,0,255); |
421 | CHK_POTI(FCParam.Height_ACC_Effect,ParamSet.Height_ACC_Effect); |
421 | CHK_POTI(FCParam.CompassYawEffect,ParamSet.CompassYawEffect,0,255); |
422 | CHK_POTI(FCParam.CompassYawEffect,ParamSet.CompassYawEffect); |
422 | CHK_POTI(FCParam.Gyro_P,ParamSet.Gyro_P,10,255); |
423 | CHK_POTI_MM(FCParam.Gyro_P,ParamSet.Gyro_P,10,255); |
423 | CHK_POTI(FCParam.Gyro_I,ParamSet.Gyro_I,0,255); |
424 | CHK_POTI(FCParam.Gyro_I,ParamSet.Gyro_I); |
424 | CHK_POTI(FCParam.I_Factor,ParamSet.I_Factor,0,255); |
425 | CHK_POTI(FCParam.I_Factor,ParamSet.I_Factor); |
425 | CHK_POTI(FCParam.UserParam1,ParamSet.UserParam1,0,255); |
426 | CHK_POTI(FCParam.UserParam1,ParamSet.UserParam1); |
426 | CHK_POTI(FCParam.UserParam2,ParamSet.UserParam2,0,255); |
427 | CHK_POTI(FCParam.UserParam2,ParamSet.UserParam2); |
427 | CHK_POTI(FCParam.UserParam3,ParamSet.UserParam3,0,255); |
428 | CHK_POTI(FCParam.UserParam3,ParamSet.UserParam3); |
428 | CHK_POTI(FCParam.UserParam4,ParamSet.UserParam4,0,255); |
429 | CHK_POTI(FCParam.UserParam4,ParamSet.UserParam4); |
429 | CHK_POTI(FCParam.UserParam5,ParamSet.UserParam5,0,255); |
430 | CHK_POTI(FCParam.UserParam5,ParamSet.UserParam5); |
430 | CHK_POTI(FCParam.UserParam6,ParamSet.UserParam6,0,255); |
431 | CHK_POTI(FCParam.UserParam6,ParamSet.UserParam6); |
431 | CHK_POTI(FCParam.UserParam7,ParamSet.UserParam7,0,255); |
432 | CHK_POTI(FCParam.UserParam7,ParamSet.UserParam7); |
432 | CHK_POTI(FCParam.UserParam8,ParamSet.UserParam8,0,255); |
433 | CHK_POTI(FCParam.UserParam8,ParamSet.UserParam8); |
433 | CHK_POTI(FCParam.ServoNickControl,ParamSet.ServoNickControl,0,255); |
434 | CHK_POTI(FCParam.ServoNickControl,ParamSet.ServoNickControl); |
434 | CHK_POTI(FCParam.LoopGasLimit,ParamSet.LoopGasLimit,0,255); |
435 | CHK_POTI(FCParam.LoopGasLimit,ParamSet.LoopGasLimit); |
435 | CHK_POTI(FCParam.Yaw_PosFeedback,ParamSet.Yaw_PosFeedback,0,255); |
436 | CHK_POTI(FCParam.Yaw_PosFeedback,ParamSet.Yaw_PosFeedback); |
436 | CHK_POTI(FCParam.Yaw_NegFeedback,ParamSet.Yaw_NegFeedback,0,255); |
437 | CHK_POTI(FCParam.Yaw_NegFeedback,ParamSet.Yaw_NegFeedback); |
437 | CHK_POTI(FCParam.DynamicStability,ParamSet.DynamicStability,0,255); |
438 | CHK_POTI(FCParam.DynamicStability,ParamSet.DynamicStability); |
- | 439 | CHK_POTI_MM(FCParam.J16Timing,ParamSet.J16Timing,1,255); |
|
- | 440 | CHK_POTI_MM(FCParam.J17Timing,ParamSet.J17Timing,1,255); |
|
- | 441 | CHK_POTI(FCParam.NaviGpsModeControl,ParamSet.NaviGpsModeControl); |
|
- | 442 | CHK_POTI(FCParam.NaviGpsGain,ParamSet.NaviGpsGain); |
|
- | 443 | CHK_POTI(FCParam.NaviGpsP,ParamSet.NaviGpsP); |
|
- | 444 | CHK_POTI(FCParam.NaviGpsI,ParamSet.NaviGpsI); |
|
- | 445 | CHK_POTI(FCParam.NaviGpsD,ParamSet.NaviGpsD); |
|
- | 446 | CHK_POTI(FCParam.NaviGpsACC,ParamSet.NaviGpsACC); |
|
- | 447 | CHK_POTI(FCParam.ExternalControl,ParamSet.ExternalControl); |
|
438 | Ki = (float) FCParam.I_Factor * FACTOR_I; |
448 | Ki = (float) FCParam.I_Factor * FACTOR_I; |
439 | } |
449 | } |
440 | } |
450 | } |
Line 499... | Line 509... | ||
499 | } |
509 | } |
500 | } |
510 | } |
501 | if(RcLostTimer) RcLostTimer--; // decremtent timer after rc sigal lost |
511 | if(RcLostTimer) RcLostTimer--; // decremtent timer after rc sigal lost |
502 | else // rc lost countdown finished |
512 | else // rc lost countdown finished |
503 | { |
513 | { |
504 | MotorsOn = 0; // stop all motors |
- | |
505 | EmergencyLanding = 0; // emergency landing is over |
514 | MKFlags &= ~(MKFLAG_MOTOR_RUN|MKFLAG_EMERGENCY_LANDING); // clear motor run flag that stop the motors in SendMotorData() |
506 | } |
515 | } |
507 | ROT_ON; // set red led |
516 | RED_ON; // set red led |
508 | if(Model_Is_Flying > 1000) // wahrscheinlich in der Luft --> langsam absenken |
517 | if(Model_Is_Flying > 1000) // wahrscheinlich in der Luft --> langsam absenken |
509 | { |
518 | { |
510 | GasMixFraction = ParamSet.EmergencyGas; // set emergency gas |
519 | GasMixFraction = ParamSet.EmergencyGas; // set emergency gas |
511 | EmergencyLanding = 1; // enable emergency landing |
520 | MKFlags |= (MKFLAG_EMERGENCY_LANDING); // ser flag fpr emergency landing |
512 | // set neutral rc inputs |
521 | // set neutral rc inputs |
513 | PPM_diff[ParamSet.ChannelAssignment[CH_NICK]] = 0; |
522 | PPM_diff[ParamSet.ChannelAssignment[CH_NICK]] = 0; |
514 | PPM_diff[ParamSet.ChannelAssignment[CH_ROLL]] = 0; |
523 | PPM_diff[ParamSet.ChannelAssignment[CH_ROLL]] = 0; |
515 | PPM_diff[ParamSet.ChannelAssignment[CH_YAW]] = 0; |
524 | PPM_diff[ParamSet.ChannelAssignment[CH_YAW]] = 0; |
516 | PPM_in[ParamSet.ChannelAssignment[CH_NICK]] = 0; |
525 | PPM_in[ParamSet.ChannelAssignment[CH_NICK]] = 0; |
517 | PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] = 0; |
526 | PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] = 0; |
518 | PPM_in[ParamSet.ChannelAssignment[CH_YAW]] = 0; |
527 | PPM_in[ParamSet.ChannelAssignment[CH_YAW]] = 0; |
519 | } |
528 | } |
520 | else MotorsOn = 0; // switch of all motors |
529 | else MKFlags &= ~(MKFLAG_MOTOR_RUN); // clear motor run flag that stop the motors in SendMotorData() |
521 | } // eof RC_Quality < 120 |
530 | } // eof RC_Quality < 120 |
522 | else |
531 | else |
523 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
532 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
524 | // RC-signal is good |
533 | // RC-signal is good |
525 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
534 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
526 | if(RC_Quality > 140) |
535 | if(RC_Quality > 140) |
527 | { |
536 | { |
528 | EmergencyLanding = 0; // switch off emergency landing if RC-signal is okay |
537 | MKFlags &= ~(MKFLAG_EMERGENCY_LANDING); // clear flag for emergency landing |
529 | // reset emergency timer |
538 | // reset emergency timer |
530 | RcLostTimer = ParamSet.EmergencyGasDuration * 50; |
539 | RcLostTimer = ParamSet.EmergencyGasDuration * 50; |
531 | if(GasMixFraction > 40) |
540 | if(GasMixFraction > 40 && (MKFlags & MKFLAG_MOTOR_RUN) ) |
532 | { |
541 | { |
533 | if(Model_Is_Flying < 0xFFFF) Model_Is_Flying++; |
542 | if(Model_Is_Flying < 0xFFFF) Model_Is_Flying++; |
534 | } |
543 | } |
535 | if(Model_Is_Flying < 256) |
544 | if(Model_Is_Flying < 256) |
536 | { |
545 | { |
537 | SumNick = 0; |
546 | SumNick = 0; |
538 | SumRoll = 0; |
547 | SumRoll = 0; |
539 | StickYaw = 0; |
548 | StickYaw = 0; |
540 | if(Model_Is_Flying == 250) UpdateCompassCourse = 1; |
549 | if(Model_Is_Flying == 250) |
- | 550 | { |
|
- | 551 | UpdateCompassCourse = 1; |
|
- | 552 | Reading_IntegralGyroYaw = 0; |
|
- | 553 | SetPointYaw = 0; |
|
- | 554 | } |
|
541 | } |
555 | } |
- | 556 | else MKFlags |= (MKFLAG_FLY); // set fly flag |
|
Line 542... | Line 557... | ||
542 | 557 | ||
543 | if(Poti1 < PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110 && Poti1) Poti1--; |
558 | if(Poti1 < PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110 && Poti1) Poti1--; |
544 | if(Poti2 < PPM_in[ParamSet.ChannelAssignment[CH_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[ParamSet.ChannelAssignment[CH_POTI2]] + 110 && Poti2) Poti2--; |
559 | if(Poti2 < PPM_in[ParamSet.ChannelAssignment[CH_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[ParamSet.ChannelAssignment[CH_POTI2]] + 110 && Poti2) Poti2--; |
545 | if(Poti3 < PPM_in[ParamSet.ChannelAssignment[CH_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[ParamSet.ChannelAssignment[CH_POTI3]] + 110 && Poti3) Poti3--; |
560 | if(Poti3 < PPM_in[ParamSet.ChannelAssignment[CH_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[ParamSet.ChannelAssignment[CH_POTI3]] + 110 && Poti3) Poti3--; |
Line 559... | Line 574... | ||
559 | if(Poti6 < 0) Poti6 = 0; else if(Poti6 > 255) Poti6 = 255; |
574 | if(Poti6 < 0) Poti6 = 0; else if(Poti6 > 255) Poti6 = 255; |
560 | if(Poti7 < 0) Poti7 = 0; else if(Poti7 > 255) Poti7 = 255; |
575 | if(Poti7 < 0) Poti7 = 0; else if(Poti7 > 255) Poti7 = 255; |
561 | if(Poti8 < 0) Poti8 = 0; else if(Poti8 > 255) Poti8 = 255; |
576 | if(Poti8 < 0) Poti8 = 0; else if(Poti8 > 255) Poti8 = 255; |
Line 562... | Line 577... | ||
562 | 577 | ||
563 | // if motors are off and the gas stick is in the upper position |
578 | // if motors are off and the gas stick is in the upper position |
564 | if((PPM_in[ParamSet.ChannelAssignment[CH_GAS]] > 80) && MotorsOn == 0) |
579 | if((PPM_in[ParamSet.ChannelAssignment[CH_GAS]] > 80) && !(MKFlags & MKFLAG_MOTOR_RUN) ) |
565 | { |
580 | { |
566 | // and if the yaw stick is in the leftmost position |
581 | // and if the yaw stick is in the leftmost position |
567 | if(PPM_in[ParamSet.ChannelAssignment[CH_YAW]] > 75) |
582 | if(PPM_in[ParamSet.ChannelAssignment[CH_YAW]] > 75) |
568 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
583 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Line 679... | Line 694... | ||
679 | { |
694 | { |
680 | if(++delay_startmotors > 200) // not immediately (wait 200 loops = 200 * 2ms = 0.4 s) |
695 | if(++delay_startmotors > 200) // not immediately (wait 200 loops = 200 * 2ms = 0.4 s) |
681 | { |
696 | { |
682 | delay_startmotors = 200; // do not repeat if once executed |
697 | delay_startmotors = 200; // do not repeat if once executed |
683 | Model_Is_Flying = 1; |
698 | Model_Is_Flying = 1; |
684 | MotorsOn = 1; |
699 | MKFlags |= (MKFLAG_MOTOR_RUN|MKFLAG_START); // set flag RUN and START |
685 | SetPointYaw = 0; |
700 | SetPointYaw = 0; |
686 | Reading_IntegralGyroYaw = 0; |
701 | Reading_IntegralGyroYaw = 0; |
687 | Reading_IntegralGyroNick = 0; |
702 | Reading_IntegralGyroNick = 0; |
688 | Reading_IntegralGyroRoll = 0; |
703 | Reading_IntegralGyroRoll = 0; |
689 | Reading_IntegralGyroNick2 = IntegralNick; |
704 | Reading_IntegralGyroNick2 = IntegralNick; |
690 | Reading_IntegralGyroRoll2 = IntegralRoll; |
705 | Reading_IntegralGyroRoll2 = IntegralRoll; |
691 | SumNick = 0; |
706 | SumNick = 0; |
692 | SumRoll = 0; |
707 | SumRoll = 0; |
693 | #if defined (USE_KILLAGREG) || defined (USE_MK3MAG) |
- | |
694 | if(ParamSet.GlobalConfig & CFG_GPS_ACTIVE) |
- | |
695 | { |
- | |
696 | GPS_SetHomePosition(); |
- | |
697 | } |
- | |
698 | #endif |
- | |
699 | } |
708 | } |
700 | } |
709 | } |
701 | else delay_startmotors = 0; // reset delay timer if sticks are not in this position |
710 | else delay_startmotors = 0; // reset delay timer if sticks are not in this position |
702 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
711 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
703 | // and yaw stick is leftmost --> stop motors |
712 | // and yaw stick is leftmost --> stop motors |
Line 706... | Line 715... | ||
706 | { |
715 | { |
707 | if(++delay_stopmotors > 200) // not immediately (wait 200 loops = 200 * 2ms = 0.4 s) |
716 | if(++delay_stopmotors > 200) // not immediately (wait 200 loops = 200 * 2ms = 0.4 s) |
708 | { |
717 | { |
709 | delay_stopmotors = 200; // do not repeat if once executed |
718 | delay_stopmotors = 200; // do not repeat if once executed |
710 | Model_Is_Flying = 0; |
719 | Model_Is_Flying = 0; |
711 | MotorsOn = 0; |
- | |
712 | #if defined (USE_KILLAGREG) || defined (USE_MK3MAG) |
- | |
713 | if(ParamSet.GlobalConfig & CFG_GPS_ACTIVE) |
- | |
714 | { |
- | |
715 | GPS_ClearHomePosition(); |
720 | MKFlags &= ~(MKFLAG_MOTOR_RUN); |
716 | } |
- | |
717 | #endif |
- | |
718 | } |
721 | } |
719 | } |
722 | } |
720 | else delay_stopmotors = 0; // reset delay timer if sticks are not in this position |
723 | else delay_stopmotors = 0; // reset delay timer if sticks are not in this position |
721 | } |
724 | } |
722 | // remapping of paameters only if the signal rc-sigbnal conditions are good |
725 | // remapping of paameters only if the signal rc-sigbnal conditions are good |
723 | } // eof RC_Quality > 150 |
726 | } // eof RC_Quality > 150 |
724 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
727 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
725 | // new values from RC |
728 | // new values from RC |
726 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
729 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
727 | if(!NewPpmData-- || EmergencyLanding) // NewData = 0 means new data from RC |
730 | if(!NewPpmData-- || (MKFlags & MKFLAG_EMERGENCY_LANDING) ) // NewData = 0 means new data from RC |
728 | { |
731 | { |
729 | int tmp_int; |
732 | int tmp_int; |
730 | ParameterMapping(); // remapping params (online poti replacement) |
733 | ParameterMapping(); // remapping params (online poti replacement) |
731 | // calculate Stick inputs by rc channels (P) and changing of rc channels (D) |
734 | // calculate Stick inputs by rc channels (P) and changing of rc channels (D) |
732 | StickNick = (StickNick * 3 + PPM_in[ParamSet.ChannelAssignment[CH_NICK]] * ParamSet.Stick_P) / 4; |
735 | StickNick = (StickNick * 3 + PPM_in[ParamSet.ChannelAssignment[CH_NICK]] * ParamSet.Stick_P) / 4; |
Line 747... | Line 750... | ||
747 | 750 | ||
748 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
751 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
749 | // Digital Control via DubWise |
752 | // Digital Control via DubWise |
Line 750... | Line 753... | ||
750 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
753 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
751 | 754 | ||
752 | #define KEY_VALUE (FCParam.UserParam8 * 4) // step width |
755 | #define KEY_VALUE (FCParam.ExternalControl * 4) // step width |
753 | if(DubWiseKeys[1]) BeepTime = 10; |
756 | if(DubWiseKeys[1]) BeepTime = 10; |
754 | if(DubWiseKeys[1] & DUB_KEY_UP) tmp_int = KEY_VALUE; |
757 | if(DubWiseKeys[1] & DUB_KEY_UP) tmp_int = KEY_VALUE; |
755 | else if(DubWiseKeys[1] & DUB_KEY_DOWN) tmp_int = -KEY_VALUE; |
758 | else if(DubWiseKeys[1] & DUB_KEY_DOWN) tmp_int = -KEY_VALUE; |
Line 763... | Line 766... | ||
763 | if(DubWiseKeys[0] & 8) ExternStickYaw = 50;else |
766 | if(DubWiseKeys[0] & 8) ExternStickYaw = 50;else |
764 | if(DubWiseKeys[0] & 4) ExternStickYaw =-50;else ExternStickYaw = 0; |
767 | if(DubWiseKeys[0] & 4) ExternStickYaw =-50;else ExternStickYaw = 0; |
765 | if(DubWiseKeys[0] & 2) ExternHeightValue++; |
768 | if(DubWiseKeys[0] & 2) ExternHeightValue++; |
766 | if(DubWiseKeys[0] & 16) ExternHeightValue--; |
769 | if(DubWiseKeys[0] & 16) ExternHeightValue--; |
Line 767... | Line 770... | ||
767 | 770 | ||
768 | StickNick += (STICK_GAIN * ExternStickNick) / 8; |
771 | StickNick += (STICK_GAIN * ExternStickNick) / 8; |
769 | StickRoll += (STICK_GAIN * ExternStickRoll) / 8; |
772 | StickRoll += (STICK_GAIN * ExternStickRoll) / 8; |
Line 770... | Line 773... | ||
770 | StickYaw += (STICK_GAIN * ExternStickYaw); |
773 | StickYaw += (STICK_GAIN * ExternStickYaw); |
771 | 774 | ||
772 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
775 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Line 773... | Line 776... | ||
773 | //+ Analog control via serial communication |
776 | //+ Analog control via serial communication |
774 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
777 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
775 | 778 | ||
776 | if(ExternControl.Config & 0x01 && FCParam.UserParam8 > 128) |
779 | if(ExternControl.Config & 0x01 && FCParam.ExternalControl > 128) |
777 | { |
780 | { |
778 | StickNick += (int16_t) ExternControl.Nick * (int16_t) ParamSet.Stick_P; |
781 | StickNick += (int16_t) ExternControl.Nick * (int16_t) ParamSet.Stick_P; |
Line 790... | Line 793... | ||
790 | if(Gyro_I_Factor < 0) Gyro_I_Factor = 0; |
793 | if(Gyro_I_Factor < 0) Gyro_I_Factor = 0; |
Line 791... | Line 794... | ||
791 | 794 | ||
Line 792... | Line 795... | ||
792 | 795 | ||
- | 796 | // update max stick positions for nick and roll |
|
- | 797 | ||
- | 798 | if(abs(StickNick / STICK_GAIN) > MaxStickNick) |
|
- | 799 | { |
|
793 | // update max stick positions for nick and roll |
800 | MaxStickNick = abs(StickNick)/STICK_GAIN; |
794 | 801 | if(MaxStickNick > 100) MaxStickNick = 100; |
|
- | 802 | } |
|
- | 803 | else MaxStickNick--; |
|
- | 804 | if(abs(StickRoll / STICK_GAIN) > MaxStickRoll) |
|
- | 805 | { |
|
795 | if(abs(StickNick / STICK_GAIN) > MaxStickNick) MaxStickNick = abs(StickNick)/STICK_GAIN; |
806 | MaxStickRoll = abs(StickRoll)/STICK_GAIN; |
Line 796... | Line 807... | ||
796 | else MaxStickNick--; |
807 | if(MaxStickRoll > 100) MaxStickRoll = 100; |
797 | if(abs(StickRoll / STICK_GAIN) > MaxStickRoll) MaxStickRoll = abs(StickRoll)/STICK_GAIN; |
808 | } |
798 | else MaxStickRoll--; |
809 | else MaxStickRoll--; |
Line 843... | Line 854... | ||
843 | if(Looping_Roll || Looping_Nick) |
854 | if(Looping_Roll || Looping_Nick) |
844 | { |
855 | { |
845 | if(GasMixFraction > ParamSet.LoopGasLimit) GasMixFraction = ParamSet.LoopGasLimit; |
856 | if(GasMixFraction > ParamSet.LoopGasLimit) GasMixFraction = ParamSet.LoopGasLimit; |
846 | } |
857 | } |
Line 847... | Line -... | ||
847 | - | ||
848 | - | ||
849 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
850 | //+ LED Control on J16/J17 |
- | |
851 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
852 | LED1_Time = FCParam.UserParam7; |
- | |
853 | LED2_Time = FCParam.UserParam8; |
- | |
854 | LED_Update(); |
- | |
855 | 858 | ||
856 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
859 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
857 | // in case of emergency landing |
860 | // in case of emergency landing |
858 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
861 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
859 | // set all inputs to save values |
862 | // set all inputs to save values |
860 | if(EmergencyLanding) |
863 | if(MKFlags & MKFLAG_EMERGENCY_LANDING) |
861 | { |
864 | { |
862 | StickYaw = 0; |
865 | StickYaw = 0; |
863 | StickNick = 0; |
866 | StickNick = 0; |
864 | StickRoll = 0; |
867 | StickRoll = 0; |
Line 905... | Line 908... | ||
905 | tmp_long = (int32_t)(IntegralNick / ParamSet.GyroAccFactor - (int32_t)Mean_AccNick); |
908 | tmp_long = (int32_t)(IntegralNick / ParamSet.GyroAccFactor - (int32_t)Mean_AccNick); |
906 | tmp_long /= 16; |
909 | tmp_long /= 16; |
907 | tmp_long2 = (int32_t)(IntegralRoll / ParamSet.GyroAccFactor - (int32_t)Mean_AccRoll); |
910 | tmp_long2 = (int32_t)(IntegralRoll / ParamSet.GyroAccFactor - (int32_t)Mean_AccRoll); |
908 | tmp_long2 /= 16; |
911 | tmp_long2 /= 16; |
Line 909... | Line 912... | ||
909 | 912 | ||
910 | if((MaxStickNick > 32) || (MaxStickRoll > 32)) // reduce effect during stick commands |
913 | if((MaxStickNick > 64) || (MaxStickRoll > 64)) // reduce effect during stick commands |
911 | { |
914 | { |
912 | tmp_long /= 3; |
915 | tmp_long /= 3; |
913 | tmp_long2 /= 3; |
916 | tmp_long2 /= 3; |
914 | } |
917 | } |
Line 957... | Line 960... | ||
957 | // Calculate deviation of the averaged gyro integral and the averaged acceleration integral |
960 | // Calculate deviation of the averaged gyro integral and the averaged acceleration integral |
958 | IntegralErrorRoll = (int32_t)(MeanIntegralRoll - (int32_t)IntegralAccRoll); |
961 | IntegralErrorRoll = (int32_t)(MeanIntegralRoll - (int32_t)IntegralAccRoll); |
959 | CorrectionRoll = IntegralErrorRoll / ParamSet.GyroAccTrim; |
962 | CorrectionRoll = IntegralErrorRoll / ParamSet.GyroAccTrim; |
960 | AttitudeCorrectionRoll = CorrectionRoll / BALANCE_NUMBER; |
963 | AttitudeCorrectionRoll = CorrectionRoll / BALANCE_NUMBER; |
Line 961... | Line 964... | ||
961 | 964 | ||
962 | if((MaxStickNick > 32) || (MaxStickRoll > 32) || (abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]) > 25)) |
965 | if((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]) > 25)) |
963 | { |
966 | { |
964 | AttitudeCorrectionNick /= 2; |
967 | AttitudeCorrectionNick /= 2; |
965 | AttitudeCorrectionRoll /= 2; |
968 | AttitudeCorrectionRoll /= 2; |
Line 1024... | Line 1027... | ||
1024 | else last_n_n = 0; |
1027 | else last_n_n = 0; |
1025 | } |
1028 | } |
1026 | else |
1029 | else |
1027 | { |
1030 | { |
1028 | cnt = 0; |
1031 | cnt = 0; |
1029 | BadCompassHeading = 500; |
1032 | BadCompassHeading = 1000; |
1030 | } |
1033 | } |
1031 | if(cnt > ParamSet.DriftComp) cnt = ParamSet.DriftComp; |
1034 | if(cnt > ParamSet.DriftComp) cnt = ParamSet.DriftComp; |
1032 | // correct Gyro Offsets |
1035 | // correct Gyro Offsets |
1033 | if(IntegralErrorNick > ERROR_LIMIT) AdNeutralNick += cnt; |
1036 | if(IntegralErrorNick > ERROR_LIMIT) AdNeutralNick += cnt; |
1034 | if(IntegralErrorNick < -ERROR_LIMIT) AdNeutralNick -= cnt; |
1037 | if(IntegralErrorNick < -ERROR_LIMIT) AdNeutralNick -= cnt; |
Line 1064... | Line 1067... | ||
1064 | else last_r_n = 0; |
1067 | else last_r_n = 0; |
1065 | } |
1068 | } |
1066 | else |
1069 | else |
1067 | { |
1070 | { |
1068 | cnt = 0; |
1071 | cnt = 0; |
1069 | BadCompassHeading = 500; |
1072 | BadCompassHeading = 1000; |
1070 | } |
1073 | } |
1071 | // correct Gyro Offsets |
1074 | // correct Gyro Offsets |
1072 | if(cnt > ParamSet.DriftComp) cnt = ParamSet.DriftComp; |
1075 | if(cnt > ParamSet.DriftComp) cnt = ParamSet.DriftComp; |
1073 | if(IntegralErrorRoll > ERROR_LIMIT) AdNeutralRoll += cnt; |
1076 | if(IntegralErrorRoll > ERROR_LIMIT) AdNeutralRoll += cnt; |
1074 | if(IntegralErrorRoll < -ERROR_LIMIT) AdNeutralRoll -= cnt; |
1077 | if(IntegralErrorRoll < -ERROR_LIMIT) AdNeutralRoll -= cnt; |
Line 1107... | Line 1110... | ||
1107 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1110 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1108 | // Yawing |
1111 | // Yawing |
1109 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1112 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1110 | if(abs(StickYaw) > 15 ) // yaw stick is activated |
1113 | if(abs(StickYaw) > 15 ) // yaw stick is activated |
1111 | { |
1114 | { |
- | 1115 | BadCompassHeading = 1000; |
|
1112 | if(!(ParamSet.GlobalConfig & CFG_COMPASS_FIX)) |
1116 | if(!(ParamSet.GlobalConfig & CFG_COMPASS_FIX)) |
1113 | { |
1117 | { |
1114 | UpdateCompassCourse = 1; |
1118 | UpdateCompassCourse = 1; |
1115 | CompassCourse = YawGyroHeading; |
- | |
1116 | BadCompassHeading = 250; |
- | |
1117 | } |
1119 | } |
1118 | } |
1120 | } |
1119 | // exponential stick sensitivity in yawring rate |
1121 | // exponential stick sensitivity in yawring rate |
1120 | tmp_int = (int32_t) ParamSet.Yaw_P * ((int32_t)StickYaw * abs(StickYaw)) / 512L; // expo y = ax + bx² |
1122 | tmp_int = (int32_t) ParamSet.Yaw_P * ((int32_t)StickYaw * abs(StickYaw)) / 512L; // expo y = ax + bx² |
1121 | tmp_int += (ParamSet.Yaw_P * StickYaw) / 4; |
1123 | tmp_int += (ParamSet.Yaw_P * StickYaw) / 4; |
Line 1132... | Line 1134... | ||
1132 | // compass code is used if Compass option is selected |
1134 | // compass code is used if Compass option is selected |
1133 | if((ParamSet.GlobalConfig & CFG_COMPASS_ACTIVE)) |
1135 | if((ParamSet.GlobalConfig & CFG_COMPASS_ACTIVE)) |
1134 | { |
1136 | { |
1135 | int16_t w, v, r,correction, error; |
1137 | int16_t w, v, r,correction, error; |
Line 1136... | Line 1138... | ||
1136 | 1138 | ||
1137 | if(CompassCalState && MotorsOn == 0 ) |
1139 | if(CompassCalState && !(MKFlags & MKFLAG_MOTOR_RUN) ) |
1138 | { |
1140 | { |
1139 | SetCompassCalState(); |
1141 | SetCompassCalState(); |
1140 | #ifdef USE_KILLAGREG |
1142 | #ifdef USE_KILLAGREG |
1141 | MM3_Calibrate(); |
1143 | MM3_Calibrate(); |
Line 1151... | Line 1153... | ||
1151 | MM3_Heading(); |
1153 | MM3_Heading(); |
1152 | } |
1154 | } |
1153 | #endif |
1155 | #endif |
Line 1154... | Line 1156... | ||
1154 | 1156 | ||
1155 | // get maximum attitude angle |
1157 | // get maximum attitude angle |
1156 | w = abs(IntegralNick/512); |
1158 | w = abs(IntegralNick / 512); |
1157 | v = abs(IntegralRoll /512); |
1159 | v = abs(IntegralRoll / 512); |
1158 | if(v > w) w = v; |
- | |
1159 | // update compass course |
- | |
1160 | if (w < 25 && UpdateCompassCourse && !BadCompassHeading) |
- | |
1161 | { |
1160 | if(v > w) w = v; |
1162 | BeepTime = 200; |
- | |
1163 | CompassCourse = YawGyroHeading / YAW_GYRO_DEG_FACTOR; |
- | |
1164 | UpdateCompassCourse = 0; |
- | |
1165 | } |
1161 | correction = w / 8 + 1; |
1166 | // calculate the deviation of the yaw gyro heading and the compass heading |
1162 | // calculate the deviation of the yaw gyro heading and the compass heading |
1167 | if (CompassHeading < 0) error = 0; // disable yaw drift compensation if compass heading is undefined |
1163 | if (CompassHeading < 0) error = 0; // disable yaw drift compensation if compass heading is undefined |
- | 1164 | else error = ((540 + CompassHeading - (YawGyroHeading / YAW_GYRO_DEG_FACTOR)) % 360) - 180; |
|
- | 1165 | ||
- | 1166 | if(!BadCompassHeading && w < 25) |
|
- | 1167 | { |
|
- | 1168 | YawGyroDrift += error; |
|
- | 1169 | if(UpdateCompassCourse) |
|
1168 | else error = ((540 + CompassHeading - (YawGyroHeading / YAW_GYRO_DEG_FACTOR)) % 360) - 180; |
1170 | { |
- | 1171 | BeepTime = 200; |
|
- | 1172 | CompassCourse = (YawGyroHeading / YAW_GYRO_DEG_FACTOR); |
|
- | 1173 | UpdateCompassCourse = 0; |
|
- | 1174 | } |
|
1169 | correction = w / 8 + 1; |
1175 | } |
1170 | YawGyroHeading += (error * 8) / correction; |
1176 | YawGyroHeading += (error * 8) / correction; |
1171 | w = (w * FCParam.CompassYawEffect) / 64; |
1177 | w = (w * FCParam.CompassYawEffect) / 32; |
1172 | w = FCParam.CompassYawEffect - w; |
1178 | w = FCParam.CompassYawEffect - w; |
1173 | if(w > 0) |
1179 | if(w >= 0) |
1174 | { |
1180 | { |
1175 | if(BadCompassHeading) |
- | |
1176 | { // wait a while |
- | |
1177 | BadCompassHeading--; |
1181 | if(!BadCompassHeading) |
1178 | } |
- | |
1179 | else |
- | |
1180 | { // |
- | |
1181 | YawGyroDrift += error; |
1182 | { |
1182 | v = 64 + (MaxStickNick + MaxStickRoll) / 8; |
1183 | v = 64 + (MaxStickNick + MaxStickRoll) / 8; |
1183 | // calc course deviation |
1184 | // calc course deviation |
1184 | r = ((540 + (YawGyroHeading / YAW_GYRO_DEG_FACTOR) - CompassCourse) % 360) - 180; |
1185 | r = ((540 + (YawGyroHeading / YAW_GYRO_DEG_FACTOR) - CompassCourse) % 360) - 180; |
1185 | v = (r * w) / v; // align to compass course |
1186 | v = (r * w) / v; // align to compass course |
1186 | // limit yaw rate |
1187 | // limit yaw rate |
1187 | w = 3 * FCParam.CompassYawEffect; |
1188 | w = 3 * FCParam.CompassYawEffect; |
1188 | if (v > w) v = w; |
1189 | if (v > w) v = w; |
1189 | else if (v < -w) v = -w; |
1190 | else if (v < -w) v = -w; |
1190 | Reading_IntegralGyroYaw += v; |
1191 | Reading_IntegralGyroYaw += v; |
- | 1192 | } |
|
- | 1193 | else |
|
- | 1194 | { // wait a while |
|
- | 1195 | BadCompassHeading--; |
|
1191 | } |
1196 | } |
1192 | } |
1197 | } |
1193 | else |
1198 | else |
1194 | { // ignore compass at extreme attitudes for a while |
1199 | { // ignore compass at extreme attitudes for a while |
1195 | BadCompassHeading = 250; |
1200 | BadCompassHeading = 500; |
1196 | } |
1201 | } |
1197 | } |
1202 | } |
Line 1198... | Line 1203... | ||
1198 | } |
1203 | } |
1199 | 1204 | ||
1200 | #if defined (USE_KILLAGREG) || defined (USE_MK3MAG) |
1205 | #if defined (USE_KILLAGREG) || defined (USE_MK3MAG) |
1201 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1206 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1202 | // GPS |
1207 | // GPS |
1203 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1208 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1204 | if(ParamSet.GlobalConfig & CFG_GPS_ACTIVE) |
- | |
1205 | { |
- | |
1206 | GPS_I_Factor = FCParam.UserParam2; |
1209 | if(ParamSet.GlobalConfig & CFG_GPS_ACTIVE) |
1207 | GPS_P_Factor = FCParam.UserParam5; |
1210 | { |
1208 | GPS_D_Factor = FCParam.UserParam6; |
- | |
1209 | if(EmergencyLanding) GPS_Main(230); // enables Comming Home |
1211 | GPS_Main(); |
1210 | else GPS_Main(Poti3); // behavior controlled by Poti3 |
1212 | MKFlags &= ~(MKFLAG_CALIBRATE | MKFLAG_START); |
1211 | } |
1213 | } |
1212 | else |
1214 | else |
1213 | { |
1215 | { |
Line 1231... | Line 1233... | ||
1231 | DebugOut.Analog[6] = (Reading_Integral_Top / 512); |
1233 | DebugOut.Analog[6] = (Reading_Integral_Top / 512); |
1232 | DebugOut.Analog[8] = CompassHeading; |
1234 | DebugOut.Analog[8] = CompassHeading; |
1233 | DebugOut.Analog[9] = UBat; |
1235 | DebugOut.Analog[9] = UBat; |
1234 | DebugOut.Analog[10] = RC_Quality; |
1236 | DebugOut.Analog[10] = RC_Quality; |
1235 | DebugOut.Analog[11] = YawGyroHeading / YAW_GYRO_DEG_FACTOR; |
1237 | DebugOut.Analog[11] = YawGyroHeading / YAW_GYRO_DEG_FACTOR; |
1236 | DebugOut.Analog[16] = Mean_AccTop; |
1238 | //DebugOut.Analog[16] = Mean_AccTop; |
Line 1237... | Line 1239... | ||
1237 | 1239 | ||
Line 1295... | Line 1297... | ||
1295 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1297 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Line 1296... | Line 1298... | ||
1296 | 1298 | ||
Line 1297... | Line 1299... | ||
1297 | GasMixFraction *= STICK_GAIN; |
1299 | GasMixFraction *= STICK_GAIN; |
1298 | 1300 | ||
1299 | // If height control is activated and no emergency landing is active |
1301 | // If height control is activated and no emergency landing is active |
1300 | if((ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL) && (!EmergencyLanding) ) |
1302 | if((ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL) && !(MKFlags & MKFLAG_EMERGENCY_LANDING) ) |
1301 | { |
1303 | { |
1302 | int tmp_int; |
1304 | int tmp_int; |
1303 | // if height control is activated by an rc channel |
1305 | // if height control is activated by an rc channel |
Line 1388... | Line 1390... | ||
1388 | 1390 | ||
1389 | // Motor Front |
1391 | // Motor Front |
1390 | MotorValue = GasMixFraction + pd_result + YawMixFraction; // Mixer |
1392 | MotorValue = GasMixFraction + pd_result + YawMixFraction; // Mixer |
1391 | MotorValue /= STICK_GAIN; |
1393 | MotorValue /= STICK_GAIN; |
1392 | if ((MotorValue < 0)) MotorValue = 0; |
1394 | if ((MotorValue < 0)) MotorValue = 0; |
1393 | else if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
1395 | else if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
1394 | if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
1396 | if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
Line 1395... | Line 1397... | ||
1395 | Motor_Front = MotorValue; |
1397 | Motor_Front = MotorValue; |
1396 | 1398 | ||
1397 | // Motor Rear |
1399 | // Motor Rear |
1398 | MotorValue = GasMixFraction - pd_result + YawMixFraction; // Mixer |
1400 | MotorValue = GasMixFraction - pd_result + YawMixFraction; // Mixer |
1399 | MotorValue /= STICK_GAIN; |
1401 | MotorValue /= STICK_GAIN; |
1400 | if ((MotorValue < 0)) MotorValue = 0; |
1402 | if ((MotorValue < 0)) MotorValue = 0; |
1401 | else if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
1403 | else if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
1402 | if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
1404 | if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
1403 | Motor_Rear = MotorValue; |
1405 | Motor_Rear = MotorValue; |
1404 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1406 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1405 | // Roll-Axis |
1407 | // Roll-Axis |
Line 1417... | Line 1419... | ||
1417 | // Motor Left |
1419 | // Motor Left |
1418 | MotorValue = GasMixFraction + pd_result - YawMixFraction; // Mixer |
1420 | MotorValue = GasMixFraction + pd_result - YawMixFraction; // Mixer |
1419 | MotorValue /= STICK_GAIN; |
1421 | MotorValue /= STICK_GAIN; |
1420 | if ((MotorValue < 0)) MotorValue = 0; |
1422 | if ((MotorValue < 0)) MotorValue = 0; |
1421 | else if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
1423 | else if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
1422 | if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
1424 | if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
1423 | Motor_Left = MotorValue; |
1425 | Motor_Left = MotorValue; |
Line 1424... | Line 1426... | ||
1424 | 1426 | ||
1425 | // Motor Right |
1427 | // Motor Right |
1426 | MotorValue = GasMixFraction - pd_result - YawMixFraction; // Mixer |
1428 | MotorValue = GasMixFraction - pd_result - YawMixFraction; // Mixer |
1427 | MotorValue /= STICK_GAIN; |
1429 | MotorValue /= STICK_GAIN; |
1428 | if ((MotorValue < 0)) MotorValue = 0; |
1430 | if ((MotorValue < 0)) MotorValue = 0; |
1429 | else if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
1431 | else if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
1430 | if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
1432 | if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
1431 | Motor_Right = MotorValue; |
1433 | Motor_Right = MotorValue; |