Rev 1077 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1077 | Rev 1078 | ||
---|---|---|---|
Line 71... | Line 71... | ||
71 | #ifdef USE_MK3MAG |
71 | #ifdef USE_MK3MAG |
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" |
- | 76 | #include "spi.h" |
|
Line 76... | Line 77... | ||
76 | 77 | ||
77 | // gyro readings |
78 | // gyro readings |
78 | int16_t Reading_GyroNick, Reading_GyroRoll, Reading_GyroYaw; |
79 | int16_t Reading_GyroNick, Reading_GyroRoll, Reading_GyroYaw; |
79 | // gyro neutral readings |
80 | // gyro neutral readings |
Line 138... | Line 139... | ||
138 | // stick values derived by uart inputs |
139 | // stick values derived by uart inputs |
139 | int16_t ExternStickNick = 0, ExternStickRoll = 0, ExternStickYaw = 0, ExternHeightValue = -20; |
140 | int16_t ExternStickNick = 0, ExternStickRoll = 0, ExternStickYaw = 0, ExternHeightValue = -20; |
Line 140... | Line -... | ||
140 | - | ||
141 | 141 | ||
142 | 142 | ||
Line 143... | Line 143... | ||
143 | 143 | ||
Line 181... | Line 181... | ||
181 | AdNeutralNick = 0; |
181 | AdNeutralNick = 0; |
182 | AdNeutralRoll = 0; |
182 | AdNeutralRoll = 0; |
183 | AdNeutralYaw = 0; |
183 | AdNeutralYaw = 0; |
184 | FCParam.Yaw_PosFeedback = 0; |
184 | FCParam.Yaw_PosFeedback = 0; |
185 | FCParam.Yaw_NegFeedback = 0; |
185 | FCParam.Yaw_NegFeedback = 0; |
- | 186 | ExpandBaro = 0; |
|
186 | CalibMean(); |
187 | CalibMean(); |
187 | Delay_ms_Mess(100); |
188 | Delay_ms_Mess(100); |
188 | CalibMean(); |
189 | CalibMean(); |
189 | if((ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL)) // Height Control activated? |
190 | if((ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL)) // Height Control activated? |
190 | { |
191 | { |
Line 227... | Line 228... | ||
227 | GPS_Nick = 0; |
228 | GPS_Nick = 0; |
228 | GPS_Roll = 0; |
229 | GPS_Roll = 0; |
229 | YawGyroHeading = CompassHeading * YAW_GYRO_DEG_FACTOR; |
230 | YawGyroHeading = CompassHeading * YAW_GYRO_DEG_FACTOR; |
230 | YawGyroDrift = 0; |
231 | YawGyroDrift = 0; |
231 | MKFlags |= MKFLAG_CALIBRATE; |
232 | MKFlags |= MKFLAG_CALIBRATE; |
- | 233 | FromNaviCtrl_Value.Kalman_K = -1; |
|
- | 234 | FromNaviCtrl_Value.Kalman_MaxDrift = ParamSet.DriftComp * 16; |
|
- | 235 | FromNaviCtrl_Value.Kalman_MaxFusion = 32; |
|
232 | } |
236 | } |
Line 233... | Line 237... | ||
233 | 237 | ||
234 | /************************************************************************/ |
238 | /************************************************************************/ |
235 | /* Averaging Measurement Readings */ |
239 | /* Averaging Measurement Readings */ |
Line 354... | Line 358... | ||
354 | /************************************************************************/ |
358 | /************************************************************************/ |
355 | /* Averaging Measurement Readings for Calibration */ |
359 | /* Averaging Measurement Readings for Calibration */ |
356 | /************************************************************************/ |
360 | /************************************************************************/ |
357 | void CalibMean(void) |
361 | void CalibMean(void) |
358 | { |
362 | { |
359 | if(BoardRelease >= 13) SearchGyroOffset(); |
363 | if(BoardRelease == 13) SearchGyroOffset(); |
360 | // stop ADC to avoid changing values during calculation |
364 | // stop ADC to avoid changing values during calculation |
361 | ADC_Disable(); |
365 | ADC_Disable(); |
Line 362... | Line 366... | ||
362 | 366 | ||
363 | Reading_GyroNick = AdValueGyrNick; |
367 | Reading_GyroNick = AdValueGyrNick; |
Line 436... | Line 440... | ||
436 | CHK_POTI(FCParam.Yaw_PosFeedback,ParamSet.Yaw_PosFeedback); |
440 | CHK_POTI(FCParam.Yaw_PosFeedback,ParamSet.Yaw_PosFeedback); |
437 | CHK_POTI(FCParam.Yaw_NegFeedback,ParamSet.Yaw_NegFeedback); |
441 | CHK_POTI(FCParam.Yaw_NegFeedback,ParamSet.Yaw_NegFeedback); |
438 | CHK_POTI(FCParam.DynamicStability,ParamSet.DynamicStability); |
442 | CHK_POTI(FCParam.DynamicStability,ParamSet.DynamicStability); |
439 | CHK_POTI_MM(FCParam.J16Timing,ParamSet.J16Timing,1,255); |
443 | CHK_POTI_MM(FCParam.J16Timing,ParamSet.J16Timing,1,255); |
440 | CHK_POTI_MM(FCParam.J17Timing,ParamSet.J17Timing,1,255); |
444 | CHK_POTI_MM(FCParam.J17Timing,ParamSet.J17Timing,1,255); |
- | 445 | #if (defined (USE_KILLAGREG) || defined (USE_MK3MAG)) |
|
441 | CHK_POTI(FCParam.NaviGpsModeControl,ParamSet.NaviGpsModeControl); |
446 | CHK_POTI(FCParam.NaviGpsModeControl,ParamSet.NaviGpsModeControl); |
442 | CHK_POTI(FCParam.NaviGpsGain,ParamSet.NaviGpsGain); |
447 | CHK_POTI(FCParam.NaviGpsGain,ParamSet.NaviGpsGain); |
443 | CHK_POTI(FCParam.NaviGpsP,ParamSet.NaviGpsP); |
448 | CHK_POTI(FCParam.NaviGpsP,ParamSet.NaviGpsP); |
444 | CHK_POTI(FCParam.NaviGpsI,ParamSet.NaviGpsI); |
449 | CHK_POTI(FCParam.NaviGpsI,ParamSet.NaviGpsI); |
445 | CHK_POTI(FCParam.NaviGpsD,ParamSet.NaviGpsD); |
450 | CHK_POTI(FCParam.NaviGpsD,ParamSet.NaviGpsD); |
446 | CHK_POTI(FCParam.NaviGpsACC,ParamSet.NaviGpsACC); |
451 | CHK_POTI(FCParam.NaviGpsACC,ParamSet.NaviGpsACC); |
- | 452 | CHK_POTI_MM(FCParam.NaviOperatingRadius,ParamSet.NaviOperatingRadius,10, 255); |
|
- | 453 | CHK_POTI(FCParam.NaviWindCorrection,ParamSet.NaviWindCorrection); |
|
- | 454 | CHK_POTI(FCParam.NaviSpeedCompensation,NaviSpeedCompensation.NaviGpsACC); |
|
- | 455 | #endif |
|
447 | CHK_POTI(FCParam.ExternalControl,ParamSet.ExternalControl); |
456 | CHK_POTI(FCParam.ExternalControl,ParamSet.ExternalControl); |
448 | Ki = (float) FCParam.I_Factor * FACTOR_I; |
457 | Ki = (float) FCParam.I_Factor * FACTOR_I; |
449 | } |
458 | } |
450 | } |
459 | } |
Line 459... | Line 468... | ||
459 | // if nick is down trigger to next cal state |
468 | // if nick is down trigger to next cal state |
460 | if((PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < -70) && !stick) |
469 | if((PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < -70) && !stick) |
461 | { |
470 | { |
462 | stick = 1; |
471 | stick = 1; |
463 | CompassCalState++; |
472 | CompassCalState++; |
464 | if(CompassCalState < 5) Beep(CompassCalState); |
473 | if(CompassCalState < 5) Beep(CompassCalState); |
465 | else BeepTime = 1000; |
474 | else BeepTime = 1000; |
466 | } |
475 | } |
467 | } |
476 | } |
Line 630... | Line 639... | ||
630 | else |
639 | else |
631 | { |
640 | { |
632 | if(ParamSet.GlobalConfig & (CFG_COMPASS_ACTIVE|CFG_GPS_ACTIVE)) |
641 | if(ParamSet.GlobalConfig & (CFG_COMPASS_ACTIVE|CFG_GPS_ACTIVE)) |
633 | { |
642 | { |
634 | // if roll stick is centered and nick stick is down |
643 | // if roll stick is centered and nick stick is down |
635 | if (abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]) < 20 && PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < -70) |
644 | if (abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]) < 30 && PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < -70) |
636 | { |
645 | { |
637 | // nick/roll joystick |
646 | // nick/roll joystick |
638 | // _________ |
647 | // _________ |
639 | // | | |
648 | // | | |
640 | // | | |
649 | // | | |
Line 727... | Line 736... | ||
727 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
736 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
728 | // new values from RC |
737 | // new values from RC |
729 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
738 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
730 | if(!NewPpmData-- || (MKFlags & MKFLAG_EMERGENCY_LANDING) ) // NewData = 0 means new data from RC |
739 | if(!NewPpmData-- || (MKFlags & MKFLAG_EMERGENCY_LANDING) ) // NewData = 0 means new data from RC |
731 | { |
740 | { |
732 | int tmp_int; |
- | |
733 | ParameterMapping(); // remapping params (online poti replacement) |
741 | ParameterMapping(); // remapping params (online poti replacement) |
734 | // calculate Stick inputs by rc channels (P) and changing of rc channels (D) |
742 | // calculate Stick inputs by rc channels (P) and changing of rc channels (D) |
735 | StickNick = (StickNick * 3 + PPM_in[ParamSet.ChannelAssignment[CH_NICK]] * ParamSet.Stick_P) / 4; |
743 | StickNick = (StickNick * 3 + PPM_in[ParamSet.ChannelAssignment[CH_NICK]] * ParamSet.Stick_P) / 4; |
736 | StickNick += PPM_diff[ParamSet.ChannelAssignment[CH_NICK]] * ParamSet.Stick_D; |
744 | StickNick += PPM_diff[ParamSet.ChannelAssignment[CH_NICK]] * ParamSet.Stick_D; |
737 | StickNick -= (GPS_Nick); |
745 | StickNick -= (GPS_Nick); |
Line 746... | Line 754... | ||
746 | 754 | ||
747 | // update gyro control loop factors |
755 | // update gyro control loop factors |
748 | Gyro_P_Factor = ((float) FCParam.Gyro_P + 10.0) / (256.0 / STICK_GAIN); |
756 | Gyro_P_Factor = ((float) FCParam.Gyro_P + 10.0) / (256.0 / STICK_GAIN); |
Line 749... | Line -... | ||
749 | Gyro_I_Factor = ((float) FCParam.Gyro_I) / (44000 / STICK_GAIN); |
- | |
750 | - | ||
751 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
752 | // Digital Control via DubWise |
- | |
753 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
754 | - | ||
755 | #define KEY_VALUE (FCParam.ExternalControl * 4) // step width |
- | |
756 | if(DubWiseKeys[1]) BeepTime = 10; |
- | |
757 | if(DubWiseKeys[1] & DUB_KEY_UP) tmp_int = KEY_VALUE; |
- | |
758 | else if(DubWiseKeys[1] & DUB_KEY_DOWN) tmp_int = -KEY_VALUE; |
- | |
759 | else tmp_int = 0; |
- | |
760 | ExternStickNick = (ExternStickNick * 7 + tmp_int) / 8; |
- | |
761 | if(DubWiseKeys[1] & DUB_KEY_LEFT) tmp_int = KEY_VALUE; |
- | |
762 | else if(DubWiseKeys[1] & DUB_KEY_RIGHT) tmp_int = -KEY_VALUE; |
- | |
763 | else tmp_int = 0; |
- | |
764 | ExternStickRoll = (ExternStickRoll * 7 + tmp_int) / 8; |
- | |
765 | - | ||
766 | if(DubWiseKeys[0] & 8) ExternStickYaw = 50;else |
- | |
767 | if(DubWiseKeys[0] & 4) ExternStickYaw =-50;else ExternStickYaw = 0; |
- | |
768 | if(DubWiseKeys[0] & 2) ExternHeightValue++; |
- | |
769 | if(DubWiseKeys[0] & 16) ExternHeightValue--; |
- | |
770 | - | ||
771 | StickNick += (STICK_GAIN * ExternStickNick) / 8; |
- | |
Line 772... | Line 757... | ||
772 | StickRoll += (STICK_GAIN * ExternStickRoll) / 8; |
757 | Gyro_I_Factor = ((float) FCParam.Gyro_I) / (44000 / STICK_GAIN); |
773 | StickYaw += (STICK_GAIN * ExternStickYaw); |
758 | |
774 | 759 | ||
Line 810... | Line 795... | ||
810 | 795 | ||
811 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
796 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
812 | // Looping? |
797 | // Looping? |
Line 813... | Line 798... | ||
813 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
798 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
814 | 799 | ||
815 | if((PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_LEFT) Looping_Left = 1; |
800 | if((PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > ParamSet.LoopThreshold) && ParamSet.BitConfig & CFG_LOOP_LEFT) Looping_Left = 1; |
816 | else |
801 | else |
817 | { |
802 | { |
818 | if(Looping_Left) // Hysteresis |
803 | if(Looping_Left) // Hysteresis |
819 | { |
804 | { |
820 | if((PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] < (ParamSet.LoopThreshold - ParamSet.LoopHysteresis))) Looping_Left = 0; |
805 | if((PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] < (ParamSet.LoopThreshold - ParamSet.LoopHysteresis))) Looping_Left = 0; |
821 | } |
806 | } |
822 | } |
807 | } |
823 | if((PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] < -ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_RIGHT) Looping_Right = 1; |
808 | if((PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] < -ParamSet.LoopThreshold) && ParamSet.BitConfig & CFG_LOOP_RIGHT) Looping_Right = 1; |
824 | else |
809 | else |
825 | { |
810 | { |
826 | if(Looping_Right) // Hysteresis |
811 | if(Looping_Right) // Hysteresis |
827 | { |
812 | { |
828 | if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > -(ParamSet.LoopThreshold - ParamSet.LoopHysteresis)) Looping_Right = 0; |
813 | if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > -(ParamSet.LoopThreshold - ParamSet.LoopHysteresis)) Looping_Right = 0; |
Line 829... | Line 814... | ||
829 | } |
814 | } |
830 | } |
815 | } |
831 | 816 | ||
832 | if((PPM_in[ParamSet.ChannelAssignment[CH_NICK]] > ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_UP) Looping_Top = 1; |
817 | if((PPM_in[ParamSet.ChannelAssignment[CH_NICK]] > ParamSet.LoopThreshold) && ParamSet.BitConfig & CFG_LOOP_UP) Looping_Top = 1; |
833 | else |
818 | else |
834 | { |
819 | { |
835 | if(Looping_Top) // Hysteresis |
820 | if(Looping_Top) // Hysteresis |
836 | { |
821 | { |
837 | if((PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < (ParamSet.LoopThreshold - ParamSet.LoopHysteresis))) Looping_Top = 0; |
822 | if((PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < (ParamSet.LoopThreshold - ParamSet.LoopHysteresis))) Looping_Top = 0; |
838 | } |
823 | } |
839 | } |
824 | } |
840 | if((PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < -ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_DOWN) Looping_Down = 1; |
825 | if((PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < -ParamSet.LoopThreshold) && ParamSet.BitConfig & CFG_LOOP_DOWN) Looping_Down = 1; |
841 | else |
826 | else |
842 | { |
827 | { |
Line 902... | Line 887... | ||
902 | 887 | ||
903 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
888 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
904 | if(!Looping_Nick && !Looping_Roll) // if not lopping in any direction |
889 | if(!Looping_Nick && !Looping_Roll) // if not lopping in any direction |
905 | { |
890 | { |
906 | int32_t tmp_long, tmp_long2; |
- | |
907 | // determine the deviation of gyro integral from averaged acceleration sensor |
- | |
908 | tmp_long = (int32_t)(IntegralNick / ParamSet.GyroAccFactor - (int32_t)Mean_AccNick); |
- | |
909 | tmp_long /= 16; |
- | |
910 | tmp_long2 = (int32_t)(IntegralRoll / ParamSet.GyroAccFactor - (int32_t)Mean_AccRoll); |
891 | int32_t tmp_long, tmp_long2; |
911 | tmp_long2 /= 16; |
- | |
912 | - | ||
913 | if((MaxStickNick > 64) || (MaxStickRoll > 64)) // reduce effect during stick commands |
892 | if(FromNaviCtrl_Value.Kalman_K != -1) |
- | 893 | { |
|
- | 894 | // determine the deviation of gyro integral from averaged acceleration sensor |
|
- | 895 | tmp_long = (int32_t)(IntegralNick / ParamSet.GyroAccFactor - (int32_t)Mean_AccNick); |
|
- | 896 | tmp_long = (tmp_long * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
|
- | 897 | tmp_long2 = (int32_t)(IntegralRoll / ParamSet.GyroAccFactor - (int32_t)Mean_AccRoll); |
|
- | 898 | tmp_long2 = (tmp_long2 * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
|
- | 899 | ||
- | 900 | if((MaxStickNick > 64) || (MaxStickRoll > 64)) // reduce effect during stick commands |
|
- | 901 | { |
|
- | 902 | tmp_long /= 2; |
|
- | 903 | tmp_long2 /= 2; |
|
- | 904 | } |
|
- | 905 | if(abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]) > 25) // reduce further if yaw stick is active |
|
914 | { |
906 | { |
915 | tmp_long /= 3; |
907 | tmp_long /= 3; |
- | 908 | tmp_long2 /= 3; |
|
- | 909 | } |
|
- | 910 | // limit correction effect |
|
- | 911 | if(tmp_long > (int32_t)FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (int32_t)FromNaviCtrl_Value.Kalman_MaxFusion; |
|
- | 912 | if(tmp_long < -(int32_t)FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long =-(int32_t)FromNaviCtrl_Value.Kalman_MaxFusion; |
|
- | 913 | if(tmp_long2 > (int32_t)FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (int32_t)FromNaviCtrl_Value.Kalman_MaxFusion; |
|
916 | tmp_long2 /= 3; |
914 | if(tmp_long2 <-(int32_t)FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 =-(int32_t)FromNaviCtrl_Value.Kalman_MaxFusion; |
917 | } |
- | |
- | 915 | } |
|
918 | if(abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]) > 25) // reduce further if yaw stick is active |
916 | else |
- | 917 | { |
|
- | 918 | // determine the deviation of gyro integral from averaged acceleration sensor |
|
919 | { |
919 | tmp_long = (int32_t)(IntegralNick / ParamSet.GyroAccFactor - (int32_t)Mean_AccNick); |
- | 920 | tmp_long /= 16; |
|
920 | tmp_long /= 3; |
921 | tmp_long2 = (int32_t)(IntegralRoll / ParamSet.GyroAccFactor - (int32_t)Mean_AccRoll); |
921 | tmp_long2 /= 3; |
- | |
Line -... | Line 922... | ||
- | 922 | tmp_long2 /= 16; |
|
- | 923 | ||
- | 924 | if((MaxStickNick > 64) || (MaxStickRoll > 64)) // reduce effect during stick commands |
|
- | 925 | { |
|
- | 926 | tmp_long /= 3; |
|
- | 927 | tmp_long2 /= 3; |
|
- | 928 | } |
|
- | 929 | if(abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]) > 25) // reduce further if yaw stick is active |
|
- | 930 | { |
|
- | 931 | tmp_long /= 3; |
|
- | 932 | tmp_long2 /= 3; |
|
922 | } |
933 | } |
923 | 934 | ||
924 | #define BALANCE 32 |
935 | #define BALANCE 32 |
925 | // limit correction effect |
936 | // limit correction effect |
926 | if(tmp_long > BALANCE) tmp_long = BALANCE; |
937 | if(tmp_long > BALANCE) tmp_long = BALANCE; |
927 | if(tmp_long < -BALANCE) tmp_long =-BALANCE; |
938 | if(tmp_long < -BALANCE) tmp_long =-BALANCE; |
- | 939 | if(tmp_long2 > BALANCE) tmp_long2 = BALANCE; |
|
928 | if(tmp_long2 > BALANCE) tmp_long2 = BALANCE; |
940 | if(tmp_long2 <-BALANCE) tmp_long2 =-BALANCE; |
929 | if(tmp_long2 <-BALANCE) tmp_long2 =-BALANCE; |
941 | } |
930 | // correct current readings |
942 | // correct current readings |
931 | Reading_IntegralGyroNick -= tmp_long; |
943 | Reading_IntegralGyroNick -= tmp_long; |
932 | Reading_IntegralGyroRoll -= tmp_long2; |
944 | Reading_IntegralGyroRoll -= tmp_long2; |
Line 960... | Line 972... | ||
960 | // Calculate deviation of the averaged gyro integral and the averaged acceleration integral |
972 | // Calculate deviation of the averaged gyro integral and the averaged acceleration integral |
961 | IntegralErrorRoll = (int32_t)(MeanIntegralRoll - (int32_t)IntegralAccRoll); |
973 | IntegralErrorRoll = (int32_t)(MeanIntegralRoll - (int32_t)IntegralAccRoll); |
962 | CorrectionRoll = IntegralErrorRoll / ParamSet.GyroAccTrim; |
974 | CorrectionRoll = IntegralErrorRoll / ParamSet.GyroAccTrim; |
963 | AttitudeCorrectionRoll = CorrectionRoll / BALANCE_NUMBER; |
975 | AttitudeCorrectionRoll = CorrectionRoll / BALANCE_NUMBER; |
Line 964... | Line 976... | ||
964 | 976 | ||
965 | if((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]) > 25)) |
977 | if(((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]) > 25)) && (FromNaviCtrl_Value.Kalman_K == -1)) |
966 | { |
978 | { |
967 | AttitudeCorrectionNick /= 2; |
979 | AttitudeCorrectionNick /= 2; |
968 | AttitudeCorrectionRoll /= 2; |
980 | AttitudeCorrectionRoll /= 2; |
Line 979... | Line 991... | ||
979 | Reading_IntegralGyroRoll2 -= IntegralErrorRoll; |
991 | Reading_IntegralGyroRoll2 -= IntegralErrorRoll; |
Line 980... | Line 992... | ||
980 | 992 | ||
981 | if(YawGyroDrift > BALANCE_NUMBER/2) AdNeutralYaw++; |
993 | if(YawGyroDrift > BALANCE_NUMBER/2) AdNeutralYaw++; |
982 | if(YawGyroDrift < -BALANCE_NUMBER/2) AdNeutralYaw--; |
994 | if(YawGyroDrift < -BALANCE_NUMBER/2) AdNeutralYaw--; |
983 | YawGyroDrift = 0; |
- | |
984 | /* |
- | |
985 | DebugOut.Analog[17] = IntegralAccNick / 26; |
- | |
986 | DebugOut.Analog[18] = IntegralAccRoll / 26; |
- | |
987 | DebugOut.Analog[19] = IntegralErrorNick;// / 26; |
- | |
988 | DebugOut.Analog[20] = IntegralErrorRoll;// / 26; |
- | |
989 | DebugOut.Analog[21] = MeanIntegralNick / 26; |
- | |
990 | DebugOut.Analog[22] = MeanIntegralRoll / 26; |
- | |
991 | //DebugOut.Analog[28] = CorrectionNick; |
- | |
992 | DebugOut.Analog[29] = CorrectionRoll; |
- | |
993 | DebugOut.Analog[30] = AttitudeCorrectionRoll * 10; |
- | |
Line 994... | Line 995... | ||
994 | */ |
995 | YawGyroDrift = 0; |
995 | 996 | ||
996 | #define ERROR_LIMIT (BALANCE_NUMBER * 4) |
997 | #define ERROR_LIMIT (BALANCE_NUMBER * 4) |
997 | #define ERROR_LIMIT2 (BALANCE_NUMBER * 16) |
998 | #define ERROR_LIMIT2 (BALANCE_NUMBER * 16) |
998 | #define MOVEMENT_LIMIT 20000 |
999 | #define MOVEMENT_LIMIT 20000 |
999 | // Nick +++++++++++++++++++++++++++++++++++++++++++++++++ |
1000 | // Nick +++++++++++++++++++++++++++++++++++++++++++++++++ |
1000 | cnt = 1;// + labs(IntegralErrorNick) / 4096; |
1001 | cnt = 1;// + labs(IntegralErrorNick) / 4096; |
1001 | CorrectionNick = 0; |
1002 | CorrectionNick = 0; |
1002 | if(labs(MeanIntegralNick_old - MeanIntegralNick) < MOVEMENT_LIMIT) |
1003 | if((labs(MeanIntegralNick_old - MeanIntegralNick) < MOVEMENT_LIMIT) || (FromNaviCtrl_Value.Kalman_MaxDrift > 3* 16)) |
1003 | { |
1004 | { |
1004 | if(IntegralErrorNick > ERROR_LIMIT2) |
1005 | if(IntegralErrorNick > ERROR_LIMIT2) |
1005 | { |
1006 | { |
Line 1030... | Line 1031... | ||
1030 | { |
1031 | { |
1031 | cnt = 0; |
1032 | cnt = 0; |
1032 | BadCompassHeading = 1000; |
1033 | BadCompassHeading = 1000; |
1033 | } |
1034 | } |
1034 | if(cnt > ParamSet.DriftComp) cnt = ParamSet.DriftComp; |
1035 | if(cnt > ParamSet.DriftComp) cnt = ParamSet.DriftComp; |
- | 1036 | if(cnt * 16 > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift / 16; |
|
1035 | // correct Gyro Offsets |
1037 | // correct Gyro Offsets |
1036 | if(IntegralErrorNick > ERROR_LIMIT) AdNeutralNick += cnt; |
1038 | if(IntegralErrorNick > ERROR_LIMIT) AdNeutralNick += cnt; |
1037 | if(IntegralErrorNick < -ERROR_LIMIT) AdNeutralNick -= cnt; |
1039 | if(IntegralErrorNick < -ERROR_LIMIT) AdNeutralNick -= cnt; |
Line 1038... | Line 1040... | ||
1038 | 1040 | ||
1039 | // Roll +++++++++++++++++++++++++++++++++++++++++++++++++ |
1041 | // Roll +++++++++++++++++++++++++++++++++++++++++++++++++ |
1040 | cnt = 1;// + labs(IntegralErrorNick) / 4096; |
1042 | cnt = 1;// + labs(IntegralErrorNick) / 4096; |
1041 | CorrectionRoll = 0; |
1043 | CorrectionRoll = 0; |
1042 | if(labs(MeanIntegralRoll_old - MeanIntegralRoll) < MOVEMENT_LIMIT) |
1044 | if((labs(MeanIntegralRoll_old - MeanIntegralRoll) < MOVEMENT_LIMIT) || (FromNaviCtrl_Value.Kalman_MaxDrift > 3* 16)) |
1043 | { |
1045 | { |
1044 | if(IntegralErrorRoll > ERROR_LIMIT2) |
1046 | if(IntegralErrorRoll > ERROR_LIMIT2) |
1045 | { |
1047 | { |
1046 | if(last_r_p) |
1048 | if(last_r_p) |
Line 1071... | Line 1073... | ||
1071 | cnt = 0; |
1073 | cnt = 0; |
1072 | BadCompassHeading = 1000; |
1074 | BadCompassHeading = 1000; |
1073 | } |
1075 | } |
1074 | // correct Gyro Offsets |
1076 | // correct Gyro Offsets |
1075 | if(cnt > ParamSet.DriftComp) cnt = ParamSet.DriftComp; |
1077 | if(cnt > ParamSet.DriftComp) cnt = ParamSet.DriftComp; |
- | 1078 | if(cnt * 16 > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift / 16; |
|
1076 | if(IntegralErrorRoll > ERROR_LIMIT) AdNeutralRoll += cnt; |
1079 | if(IntegralErrorRoll > ERROR_LIMIT) AdNeutralRoll += cnt; |
1077 | if(IntegralErrorRoll < -ERROR_LIMIT) AdNeutralRoll -= cnt; |
1080 | if(IntegralErrorRoll < -ERROR_LIMIT) AdNeutralRoll -= cnt; |
1078 | /* |
- | |
1079 | DebugOut.Analog[27] = CorrectionRoll; |
- | |
1080 | DebugOut.Analog[23] = AdNeutralNick;//10*(AdNeutralNick - StartNeutralNick); |
- | |
1081 | DebugOut.Analog[24] = 10*(AdNeutralRoll - StartNeutralRoll); |
- | |
1082 | */ |
1081 | |
1083 | } |
1082 | } |
1084 | else // looping is active |
1083 | else // looping is active |
1085 | { |
1084 | { |
1086 | AttitudeCorrectionRoll = 0; |
1085 | AttitudeCorrectionRoll = 0; |
1087 | AttitudeCorrectionNick = 0; |
1086 | AttitudeCorrectionNick = 0; |
Line 1160... | Line 1159... | ||
1160 | if(v > w) w = v; |
1159 | if(v > w) w = v; |
1161 | correction = w / 8 + 1; |
1160 | correction = w / 8 + 1; |
1162 | // calculate the deviation of the yaw gyro heading and the compass heading |
1161 | // calculate the deviation of the yaw gyro heading and the compass heading |
1163 | if (CompassHeading < 0) error = 0; // disable yaw drift compensation if compass heading is undefined |
1162 | 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; |
1163 | else error = ((540 + CompassHeading - (YawGyroHeading / YAW_GYRO_DEG_FACTOR)) % 360) - 180; |
- | 1164 | if(UpdateCompassCourse) |
|
- | 1165 | { |
|
- | 1166 | error = 0; |
|
- | 1167 | YawGyroHeading = CompassHeading * YAW_GYRO_DEG_FACTOR; |
|
1165 | 1168 | } |
|
1166 | if(!BadCompassHeading && w < 25) |
1169 | if(!BadCompassHeading && w < 25) |
1167 | { |
1170 | { |
1168 | YawGyroDrift += error; |
1171 | YawGyroDrift += error; |
1169 | if(UpdateCompassCourse) |
1172 | if(UpdateCompassCourse) |
1170 | { |
1173 | { |
Line 1234... | Line 1237... | ||
1234 | DebugOut.Analog[8] = CompassHeading; |
1237 | DebugOut.Analog[8] = CompassHeading; |
1235 | DebugOut.Analog[9] = UBat; |
1238 | DebugOut.Analog[9] = UBat; |
1236 | DebugOut.Analog[10] = RC_Quality; |
1239 | DebugOut.Analog[10] = RC_Quality; |
1237 | DebugOut.Analog[11] = YawGyroHeading / YAW_GYRO_DEG_FACTOR; |
1240 | DebugOut.Analog[11] = YawGyroHeading / YAW_GYRO_DEG_FACTOR; |
1238 | //DebugOut.Analog[16] = Mean_AccTop; |
1241 | //DebugOut.Analog[16] = Mean_AccTop; |
1239 | - | ||
- | 1242 | DebugOut.Analog[17] = FromNaviCtrl_Value.Distance; |
|
- | 1243 | DebugOut.Analog[18] = FromNaviCtrl_Value.OsdBar; |
|
1240 | DebugOut.Analog[20] = ServoValue; |
1244 | DebugOut.Analog[20] = ServoValue; |
1241 | - | ||
1242 | - | ||
1243 | - | ||
- | 1245 | DebugOut.Analog[27] = (int16_t)FromNaviCtrl_Value.Kalman_MaxDrift; |
|
- | 1246 | DebugOut.Analog[29] = (int16_t)FromNaviCtrl_Value.Kalman_K; |
|
1244 | DebugOut.Analog[30] = GPS_Nick; |
1247 | DebugOut.Analog[30] = GPS_Nick; |
1245 | DebugOut.Analog[31] = GPS_Roll; |
1248 | DebugOut.Analog[31] = GPS_Roll; |
Line 1246... | Line -... | ||
1246 | - | ||
1247 | /* DebugOut.Analog[16] = motor_rx[0]; |
- | |
1248 | DebugOut.Analog[17] = motor_rx[1]; |
- | |
1249 | DebugOut.Analog[18] = motor_rx[2]; |
- | |
1250 | DebugOut.Analog[19] = motor_rx[3]; |
- | |
1251 | DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3]; |
- | |
1252 | DebugOut.Analog[20] /= 14; |
- | |
1253 | DebugOut.Analog[21] = motor_rx[4]; |
- | |
1254 | DebugOut.Analog[22] = motor_rx[5]; |
- | |
1255 | DebugOut.Analog[23] = motor_rx[6]; |
- | |
1256 | DebugOut.Analog[24] = motor_rx[7]; |
- | |
1257 | DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7]; |
- | |
1258 | - | ||
1259 | DebugOut.Analog[9] = Reading_GyroNick; |
- | |
1260 | DebugOut.Analog[9] = SetPointHeight; |
- | |
1261 | DebugOut.Analog[10] = Reading_IntegralGyroYaw / 128; |
- | |
1262 | - | ||
1263 | DebugOut.Analog[10] = FCParam.Gyro_I; |
- | |
1264 | DebugOut.Analog[10] = ParamSet.Gyro_I; |
- | |
1265 | DebugOut.Analog[9] = CompassOffCourse; |
- | |
1266 | DebugOut.Analog[10] = GasMixFraction; |
- | |
1267 | DebugOut.Analog[3] = HeightD * 32; |
- | |
1268 | DebugOut.Analog[4] = HeightControlGas; |
- | |
1269 | */ |
1249 | |
Line 1270... | Line 1250... | ||
1270 | } |
1250 | } |
1271 | 1251 | ||
1272 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1252 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Line 1296... | Line 1276... | ||
1296 | // The height control algorithm reduces the gas but does not increase the gas. |
1276 | // The height control algorithm reduces the gas but does not increase the gas. |
1297 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1277 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Line 1298... | Line 1278... | ||
1298 | 1278 | ||
Line 1299... | Line 1279... | ||
1299 | GasMixFraction *= STICK_GAIN; |
1279 | GasMixFraction *= STICK_GAIN; |
1300 | 1280 | ||
1301 | // If height control is activated and no emergency landing is active |
1281 | // if height control is activated and no emergency landing is active |
1302 | if((ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL) && !(MKFlags & MKFLAG_EMERGENCY_LANDING) ) |
1282 | if((ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL) && !(MKFlags & MKFLAG_EMERGENCY_LANDING) ) |
- | 1283 | { |
|
1303 | { |
1284 | int tmp_int; |
1304 | int tmp_int; |
1285 | static uint8_t delay = 100; |
1305 | // if height control is activated by an rc channel |
1286 | // if height control is activated by an rc channel |
- | 1287 | if(ParamSet.GlobalConfig & CFG_HEIGHT_SWITCH) |
|
- | 1288 | { // check if parameter is less than activation threshold |
|
- | 1289 | if( |
|
- | 1290 | ( (ParamSet.BitConfig & CFG_HEIGHT_3SWITCH) && ( (FCParam.MaxHeight > 80) && (FCParam.MaxHeight < 140) ) )|| // for 3-state switch height control is only disabled in center position |
|
- | 1291 | (!(ParamSet.BitConfig & CFG_HEIGHT_3SWITCH) && (FCParam.MaxHeight < 50) ) // for 2-State switch height control is disabled in lower position |
|
- | 1292 | ) |
|
- | 1293 | { //hight control not active |
|
- | 1294 | if(!delay--) |
|
1306 | if(ParamSet.GlobalConfig & CFG_HEIGHT_SWITCH) |
1295 | { |
- | 1296 | // measurement of air pressure close to upper limit |
|
- | 1297 | if(ReadingAirPressure > 1000) |
|
- | 1298 | { // lower offset |
|
- | 1299 | ExpandBaro -= 10; |
|
- | 1300 | OCR0A = PressureSensorOffset - ExpandBaro; |
|
- | 1301 | BeepTime = 300; |
|
- | 1302 | delay = 250; |
|
- | 1303 | } |
|
- | 1304 | // measurement of air pressure close to lower limit |
|
- | 1305 | else if(ReadingAirPressure < 100) |
|
- | 1306 | { // increase offset |
|
- | 1307 | ExpandBaro += 10; |
|
- | 1308 | OCR0A = PressureSensorOffset - ExpandBaro; |
|
- | 1309 | BeepTime = 300; |
|
- | 1310 | delay = 250; |
|
1307 | { // check if parameter is less than activation threshold |
1311 | } |
1308 | if(FCParam.MaxHeight < 50) |
1312 | else |
1309 | { |
1313 | { |
- | 1314 | SetPointHeight = ReadingHeight - 20; // update SetPoint with current reading |
|
- | 1315 | HeightControlActive = 0; // disable height control |
|
- | 1316 | delay = 1; |
|
- | 1317 | } |
|
- | 1318 | } |
|
- | 1319 | } |
|
- | 1320 | else |
|
- | 1321 | { //hight control not active |
|
1310 | SetPointHeight = ReadingHeight - 20; // update SetPoint with current reading |
1322 | HeightControlActive = 1; // enable height control |
1311 | HeightControlActive = 0; // disable height control |
- | |
1312 | } |
1323 | delay = 200; |
1313 | else HeightControlActive = 1; // enable height control |
1324 | } |
1314 | } |
1325 | } |
1315 | else // no switchable height control |
1326 | else // no switchable height control |
1316 | { |
1327 | { |