Rev 791 | Rev 793 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 791 | Rev 792 | ||
---|---|---|---|
Line 89... | Line 89... | ||
89 | volatile int32_t IntegralPitch = 0,IntegralPitch2 = 0; |
89 | volatile int32_t IntegralPitch = 0,IntegralPitch2 = 0; |
90 | volatile int32_t IntegralRoll = 0,IntegralRoll2 = 0; |
90 | volatile int32_t IntegralRoll = 0,IntegralRoll2 = 0; |
91 | volatile int32_t IntegralYaw = 0; |
91 | volatile int32_t IntegralYaw = 0; |
92 | volatile int32_t Reading_IntegralGyroPitch = 0, Reading_IntegralGyroPitch2 = 0; |
92 | volatile int32_t Reading_IntegralGyroPitch = 0, Reading_IntegralGyroPitch2 = 0; |
93 | volatile int32_t Reading_IntegralGyroRoll = 0, Reading_IntegralGyroRoll2 = 0; |
93 | volatile int32_t Reading_IntegralGyroRoll = 0, Reading_IntegralGyroRoll2 = 0; |
94 | volatile int32_t Reading_IntegralGyroYaw = 0, Reading_IntegralGyroYaw2 = 0; |
94 | volatile int32_t Reading_IntegralGyroYaw = 0; |
95 | volatile int32_t MeanIntegralPitch; |
95 | volatile int32_t MeanIntegralPitch; |
96 | volatile int32_t MeanIntegralRoll; |
96 | volatile int32_t MeanIntegralRoll; |
Line 97... | Line 97... | ||
97 | 97 | ||
98 | // attitude acceleration integrals |
98 | // attitude acceleration integrals |
Line 240... | Line 240... | ||
240 | IntegralAccRoll += ACC_AMPLIFY * AdValueAccRoll; |
240 | IntegralAccRoll += ACC_AMPLIFY * AdValueAccRoll; |
Line 241... | Line 241... | ||
241 | 241 | ||
242 | // Yaw |
242 | // Yaw |
243 | // calculate yaw gyro intergral (~ to rotation angle) |
243 | // calculate yaw gyro intergral (~ to rotation angle) |
244 | Reading_IntegralGyroYaw += Reading_GyroYaw; |
- | |
245 | Reading_IntegralGyroYaw2 += Reading_GyroYaw; |
244 | Reading_IntegralGyroYaw += Reading_GyroYaw; |
246 | // Coupling fraction |
245 | // Coupling fraction |
247 | if(!Looping_Pitch && !Looping_Roll && (ParamSet.GlobalConfig & CFG_AXIS_COUPLING_ACTIVE)) |
246 | if(!Looping_Pitch && !Looping_Roll && (ParamSet.GlobalConfig & CFG_AXIS_COUPLING_ACTIVE)) |
248 | { |
247 | { |
249 | tmpl = Reading_IntegralGyroPitch / 4096L; |
248 | tmpl = Reading_IntegralGyroPitch / 4096L; |
Line 434... | Line 433... | ||
434 | static uint8_t delay_neutral = 0, delay_startmotors = 0, delay_stopmotors = 0; |
433 | static uint8_t delay_neutral = 0, delay_startmotors = 0, delay_stopmotors = 0; |
435 | static uint16_t Model_Is_Flying = 0; |
434 | static uint16_t Model_Is_Flying = 0; |
436 | static uint8_t HeightControlActive = 0; |
435 | static uint8_t HeightControlActive = 0; |
437 | static int16_t HeightControlThrust = 0; |
436 | static int16_t HeightControlThrust = 0; |
438 | static int8_t TimerDebugOut = 0; |
437 | static int8_t TimerDebugOut = 0; |
439 | static int8_t StoreNewCompassCourse = 0; |
438 | static uint16_t UpdateCompassCourse = 0; |
440 | static int32_t CorrectionPitch, CorrectionRoll; |
439 | static int32_t CorrectionPitch, CorrectionRoll; |
Line 441... | Line 440... | ||
441 | 440 | ||
442 | Mean(); |
441 | Mean(); |
Line 502... | Line 501... | ||
502 | if((Model_Is_Flying < 200) || (ThrustMixFraction < 40)) |
501 | if((Model_Is_Flying < 200) || (ThrustMixFraction < 40)) |
503 | { |
502 | { |
504 | SumPitch = 0; |
503 | SumPitch = 0; |
505 | SumRoll = 0; |
504 | SumRoll = 0; |
506 | Reading_IntegralGyroYaw = 0; |
505 | Reading_IntegralGyroYaw = 0; |
507 | Reading_IntegralGyroYaw2 = 0; |
- | |
508 | } |
506 | } |
Line 509... | Line 507... | ||
509 | 507 | ||
510 | if(Poti1 < PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110 && Poti1) Poti1--; |
508 | if(Poti1 < PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110 && Poti1) Poti1--; |
511 | if(Poti2 < PPM_in[ParamSet.ChannelAssignment[CH_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[ParamSet.ChannelAssignment[CH_POTI2]] + 110 && Poti2) Poti2--; |
509 | if(Poti2 < PPM_in[ParamSet.ChannelAssignment[CH_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[ParamSet.ChannelAssignment[CH_POTI2]] + 110 && Poti2) Poti2--; |
Line 574... | Line 572... | ||
574 | } |
572 | } |
575 | // and if the yaw stick is in the rightmost position |
573 | // and if the yaw stick is in the rightmost position |
576 | // save the ACC neutral setting to eeprom |
574 | // save the ACC neutral setting to eeprom |
577 | else if(PPM_in[ParamSet.ChannelAssignment[CH_YAW]] < -75) |
575 | else if(PPM_in[ParamSet.ChannelAssignment[CH_YAW]] < -75) |
578 | { |
576 | { |
579 | if(++delay_neutral > 200) // not immediately (wait 200 loops = 200 * 2ms = 0.4 s) |
577 | if(++delay_neutral > 200) // not immediately (wait 200 loops = 200 * 2ms = 0.4 s) |
580 | { |
578 | { |
581 | delay_neutral = 0; |
579 | delay_neutral = 0; |
582 | GRN_OFF; |
580 | GRN_OFF; |
583 | SetParamWord(PID_ACC_PITCH, 0xFFFF); // make value invalid |
581 | SetParamWord(PID_ACC_PITCH, 0xFFFF); // make value invalid |
584 | Model_Is_Flying = 0; |
582 | Model_Is_Flying = 0; |
585 | SetNeutral(); |
583 | SetNeutral(); |
586 | // Save ACC neutral settings to eeprom |
584 | // Save ACC neutral settings to eeprom |
587 | SetParamWord(PID_ACC_PITCH, (uint16_t)NeutralAccX); |
585 | SetParamWord(PID_ACC_PITCH, (uint16_t)NeutralAccX); |
588 | SetParamWord(PID_ACC_ROLL, (uint16_t)NeutralAccY); |
586 | SetParamWord(PID_ACC_ROLL, (uint16_t)NeutralAccY); |
589 | SetParamWord(PID_ACC_Z, (uint16_t)NeutralAccZ); |
587 | SetParamWord(PID_ACC_Z, (uint16_t)NeutralAccZ); |
590 | Beep(GetActiveParamSet()); |
588 | Beep(GetActiveParamSet()); |
591 | } |
589 | } |
592 | } |
590 | } |
593 | else delay_neutral = 0; |
591 | else delay_neutral = 0; |
594 | } |
592 | } |
595 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
593 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Line 607... | Line 605... | ||
607 | delay_startmotors = 200; // do not repeat if once executed |
605 | delay_startmotors = 200; // do not repeat if once executed |
608 | Model_Is_Flying = 1; |
606 | Model_Is_Flying = 1; |
609 | MotorsOn = 1; |
607 | MotorsOn = 1; |
610 | SetPointYaw = 0; |
608 | SetPointYaw = 0; |
611 | Reading_IntegralGyroYaw = 0; |
609 | Reading_IntegralGyroYaw = 0; |
612 | Reading_IntegralGyroYaw2 = 0; |
- | |
613 | Reading_IntegralGyroPitch = 0; |
610 | Reading_IntegralGyroPitch = 0; |
614 | Reading_IntegralGyroRoll = 0; |
611 | Reading_IntegralGyroRoll = 0; |
615 | Reading_IntegralGyroPitch2 = IntegralPitch; |
612 | Reading_IntegralGyroPitch2 = IntegralPitch; |
616 | Reading_IntegralGyroRoll2 = IntegralRoll; |
613 | Reading_IntegralGyroRoll2 = IntegralRoll; |
617 | SumPitch = 0; |
614 | SumPitch = 0; |
Line 1009... | Line 1006... | ||
1009 | 1006 | ||
1010 | 1007 | ||
1011 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1008 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1012 | // Yawing |
1009 | // Yawing |
1013 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1010 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1014 | if(abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]) > 20) // yaw stick is activated |
1011 | if(abs(StickYaw) > 20 ) // yaw stick is activated |
1015 | { // if not fixed compass course is set update compass course |
1012 | { // if not fixed compass course is set update compass course for 1s |
1016 | if(!(ParamSet.GlobalConfig & CFG_COMPASS_FIX)) StoreNewCompassCourse = 1; |
1013 | if(!(ParamSet.GlobalConfig & CFG_COMPASS_FIX)) UpdateCompassCourse = 500; |
1017 | } |
1014 | } |
1018 | // exponential stick sensitivity in yawring rate |
1015 | // exponential stick sensitivity in yawring rate |
1019 | tmp_int = (int32_t) ParamSet.Yaw_P * ((int32_t)StickYaw * abs(StickYaw)) / 512L; // expo y = ax + bx² |
1016 | tmp_int = (int32_t) ParamSet.Yaw_P * ((int32_t)StickYaw * abs(StickYaw)) / 512L; // expo y = ax + bx² |
1020 | tmp_int += (ParamSet.Yaw_P * StickYaw) / 4; |
- | |
1021 | SetPointYaw = tmp_int; |
1017 | tmp_int += (ParamSet.Yaw_P * StickYaw) / 4; |
1022 | Reading_IntegralGyroYaw -= tmp_int; |
1018 | SetPointYaw = tmp_int; |
1023 | // limit the effect |
1019 | // limit the effect |
Line 1024... | Line 1020... | ||
1024 | if(Reading_IntegralGyroYaw > 50000) Reading_IntegralGyroYaw = 50000; |
1020 | if(Reading_IntegralGyroYaw > 50000) Reading_IntegralGyroYaw = 50000; |
Line 1041... | Line 1037... | ||
1041 | CompassHeading = MM3_Heading(); |
1037 | CompassHeading = MM3_Heading(); |
1042 | #endif |
1038 | #endif |
1043 | #ifdef USE_CMPS03 |
1039 | #ifdef USE_CMPS03 |
1044 | CompassHeading = CMPS03_Heading(); |
1040 | CompassHeading = CMPS03_Heading(); |
1045 | #endif |
1041 | #endif |
1046 | - | ||
1047 | if (CompassHeading < 0) // no compass data available |
1042 | if (CompassHeading < 0) // no compass data available |
1048 | { |
1043 | { |
1049 | CompassOffCourse = 0; // disables gyro compass correction |
1044 | CompassOffCourse = 0; // disables gyro compass correction |
1050 | } |
1045 | } |
1051 | else // calculate OffCourse (angular deviation from heading to course) |
1046 | else // calculate OffCourse (angular deviation from heading to course) |
1052 | CompassOffCourse = ((540 + CompassHeading - CompassCourse) % 360) - 180; |
1047 | CompassOffCourse = ((540 + CompassHeading - CompassCourse) % 360) - 180; |
1053 | } |
1048 | } |
1054 | - | ||
1055 | // reduce compass effect with increasing declination |
1049 | // reduce compass effect with increasing declination |
1056 | w = abs(IntegralPitch / 512); |
1050 | w = abs(IntegralPitch / 512); |
1057 | v = abs(IntegralRoll / 512); |
1051 | v = abs(IntegralRoll / 512); |
1058 | if(v > w) w = v; // get maximum declination |
1052 | if(v > w) w = v; // get maximum declination |
1059 | // if declination is small enough then update compass course if neccessary |
1053 | // if declination is small enough then update compass course if neccessary |
1060 | if((w < 35) && StoreNewCompassCourse && (CompassHeading>=0) ) // 35 corresponds to a declination of ~14 deg |
1054 | if((w < 70) && UpdateCompassCourse && (CompassHeading>=0) ) // 70 corresponds to a declination of ~28 deg |
1061 | { |
1055 | { |
1062 | CompassCourse = CompassHeading; |
1056 | CompassCourse = CompassHeading; |
1063 | StoreNewCompassCourse = 0; |
1057 | CompassOffCourse = 0; // should be set immediatly because the CompassOffCourse is otherwise only refreshed if new compass heading is calulated |
1064 | } |
1058 | } |
- | 1059 | if(UpdateCompassCourse) UpdateCompassCourse--; |
|
1065 | w = (w * FCParam.CompassYawEffect) / 64; // (w=0 for 64->~25 deg, 128->~50 deg) for higher declinaions the compass drift compensation is disabled |
1060 | w = (w * FCParam.CompassYawEffect) / 64; // (w=0 for 64->~25 deg, 128->~50 deg) for higher declinaions the compass drift compensation is disabled |
1066 | w = FCParam.CompassYawEffect - w; // reduce compass effect with increasing declination |
1061 | w = FCParam.CompassYawEffect - w; // reduce compass effect with increasing declination |
1067 | if(w > 0) // if there is any compass effect (avoid negative compass feedback) |
1062 | if(w > 0) // if there is any compass effect (avoid negative compass feedback) |
1068 | { |
1063 | { |
1069 | Reading_IntegralGyroYaw += (CompassOffCourse * w) / 32; |
1064 | Reading_IntegralGyroYaw += (CompassOffCourse * w) / 32; |