Пример #1
0
        void ImplementState_ThrottleUp()
        {
            if (CommonStateLogic_Throttle())
            {
                return;
            }

            var secondsToMax = TargetMaxThrottleUT - KspVars.CurrentUT;

            if (secondsToMax <= 0)
            {
                if (KspVars.CurrentThrottle != 1.0f)
                {
                    KspCommands.SetThrottle(1.0f);
                }
                NextState = LogicState.ThrottleMax;
            }
            else
            {
                var marginPortionFulfilled = (Settings.ThrottleUpSeconds - secondsToMax) / Settings.ThrottleUpSeconds;
                var newThrottle            = (float)((1.0f - Settings.InitialThrottleSetting) * marginPortionFulfilled + (double)Settings.InitialThrottleSetting);
                if (newThrottle > 1.0f)
                {
                    newThrottle = 1.0f;
                }
                if (newThrottle < 0.0f)
                {
                    newThrottle = 0.0f;
                }
                KspCommands.SetThrottle(newThrottle, false);
            }
        }
Пример #2
0
        void ImplementState_ThrottleMax()
        {
            if (CommonStateLogic_Throttle())
            {
                return;
            }

            if (StateChanged && KspVars.CurrentThrottle != 1.0f)
            {
                KspCommands.SetThrottle(1.0f);
            }
        }
Пример #3
0
        /// <summary>
        /// Checks if we should stop, slow down, or allow for staging.  If so, handles the appropriate throttling and state transition, and returns true.
        /// If we don't need to do any of that currently, returns false.
        /// </summary>
        bool CommonStateLogic_Throttle()
        {
            // see how much delta V remains
            var remainingDeltaV = KspVars.NextManeuverRemainingDeltaV;

            // see if we should stop
            bool remainingDeltaVIncreasing = (remainingDeltaV - LastRemainingDeltaV) > Settings.RemainingDeltaVIncreaseDetectionSafety;

            LastRemainingDeltaV = remainingDeltaV;
            bool reachedGoal = remainingDeltaV <= Settings.MaxRemainingDeltaVGoal;
            bool stop        = remainingDeltaVIncreasing || reachedGoal;

            // stop if we must
            if (stop)
            {
                LogUtility.Log($"Stop: ReachedGoal = {reachedGoal}, RemainingDeltaVIncreasing = {remainingDeltaVIncreasing}");
                LogUtility.Log($"Final Remaining DeltaV: {remainingDeltaV}");
                KspCommands.SetThrottle(0);
                NextState = LogicState.ThrottleZero;
                return(true);
            }

            // see if we should wait for staging
            if (KspVars.IsCurrentStageExhausted)
            {
                LogUtility.Log($"Stage fuel exhausted - manually stage to continue.");
                StateAfterStaging = CurrentState;
                NextState         = LogicState.Staging;
                return(true);
            }


            // otherwise slow down according to lower throttle ramp if within threshold
            var burnTimeRemainingAtCurrentThrottle = KspVars.EstimatedNextManeuverBurnTimeRemainingAtCurrentThrottle;

            if (!double.IsNaN(burnTimeRemainingAtCurrentThrottle))
            {
                for (int i = 0; i < Settings.LowerThrottleRamp.Length; i++)
                {
                    if (burnTimeRemainingAtCurrentThrottle <= Settings.LowerThrottleRamp[i].secondsRemaining &&
                        KspVars.CurrentThrottle > (Settings.LowerThrottleRamp[i].maxThrottle + Settings.ThrottleCheckSafetyMargin))
                    {
                        LogUtility.LogBurnEstimates();
                        KspCommands.SetThrottle(Settings.LowerThrottleRamp[i].maxThrottle);
                        NextState = LogicState.ThrottleDown;
                        return(true);
                    }
                }
            }

            return(false);
        }
Пример #4
0
        void ImplementState_ThrottleZero()
        {
            if (KspVars.CurrentThrottle != 0)
            {
                KspCommands.SetThrottle(0);
                ResetCurrentState();
                return;
            }

            if (AreStabilizationSettingsAchieved(Settings.ThrottleZeroRestSettings))
            {
                NextState = LogicState.Done;
            }
        }
Пример #5
0
 void ImplementState_Countdown()
 {
     if (KspVars.CurrentThrottle != 0.0)
     {
         LogUtility.Log("Throttle already engaged - regarding current setting as max.");
         NextState = LogicState.ThrottleMax;
         CommonStateLogic_Throttle();
     }
     else if (KspVars.TimeToNextManeuverBurnStartUT <= Settings.ThrottleUpSeconds * squareRootOfOneHalf)
     {
         TargetMaxThrottleUT = KspVars.NextManeuverBurnStartUT + (Settings.ThrottleUpSeconds * (1 - squareRootOfOneHalf));
         LastRemainingDeltaV = KspVars.NextManeuverRemainingDeltaV;
         KspCommands.SetThrottle(Settings.InitialThrottleSetting);
         NextState = LogicState.ThrottleUp;
         CommonStateLogic_Throttle();
     }
 }