Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
        void ImplementState_ThrottleMax()
        {
            if (CommonStateLogic_Throttle())
            {
                return;
            }

            if (StateChanged && KspVars.CurrentThrottle != 1.0f)
            {
                KspCommands.SetThrottle(1.0f);
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
0
        void ImplementState_ThrottleZero()
        {
            if (KspVars.CurrentThrottle != 0)
            {
                KspCommands.SetThrottle(0);
                ResetCurrentState();
                return;
            }

            if (AreStabilizationSettingsAchieved(Settings.ThrottleZeroRestSettings))
            {
                NextState = LogicState.Done;
            }
        }
Exemplo n.º 5
0
        void CommonStateLogic_Aim(LogicState aimStabilizationState)
        {
            if (StateChanged && Settings.EnableManeuverHold)
            {
                KspCommands.EnableAutoPilotManeuverHold();
            }

            if (KspVars.NextManeuverOffAngle <= MaxAimErrorAngle)
            {
                NextState = aimStabilizationState;
            }

            CommonStateLogic_SkipAhead();
        }
Exemplo n.º 6
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();
     }
 }
Exemplo n.º 7
0
        void CommonStateLogic_WarpStart(double burnStartMarginSeconds, LogicState warpWaitState, LogicState skippedWarpState)
        {
            // don't prevent first attempt to warp per entry into this state
            if (StateChanged)
            {
                LastWarpRetryLateUpdateCount = null;
            }

            if (KspVars.CurrentWarpStatus == KspVars.WarpStatus.Fast)
            {
                // just wait until the warp ends if already warping
                NextState = warpWaitState;
                return;
            }

            var timeTilStart = KspVars.TimeToNextManeuverBurnStartUT;

            // skip warp entirely if we're already within the burn start margin
            if (timeTilStart <= burnStartMarginSeconds)
            {
                LogUtility.Log($"Skipping ahead to {skippedWarpState}...");
                NextState = skippedWarpState;
            }
            else
            {
                // otherwise, start the warp, but don't retry during the same state unless sufficient updates have passed
                // (prevents spamming with "already warping" messages)
                if (!LastWarpRetryLateUpdateCount.HasValue || LateUpdateCountInState - LastWarpRetryLateUpdateCount.Value >= Settings.MinWarpRetryLateUpdateDelay)
                {
                    KspCommands.TimeWarpToUT(KspVars.CurrentUT + timeTilStart - burnStartMarginSeconds);
                    LastWarpRetryLateUpdateCount = LateUpdateCountInState;
                }

                // transition to wait state if actually warping
                if (KspVars.CurrentWarpStatus == KspVars.WarpStatus.Fast)
                {
                    NextState = warpWaitState;
                }
            }
        }
Exemplo n.º 8
0
        void ImplementState_Done()
        {
            if (FullAutoPilot && MasterSwitch.IsRepeatEnabled)
            {
                KspCommands.DeleteNextManeuverNode();

                if (KspVars.IsManeuverPlanned)
                {
                    LogUtility.Log("Next maneuver...");
                    NextState = LogicState.NextManeuver;
                }
                else
                {
                    LogUtility.Log("No further maneuvers planned.");
                    NextState = LogicState.Idle;
                }
            }
            else
            {
                LogUtility.Log("Disengaging auto-throttle for manual resolution.");
                NextState = LogicState.Idle;
            }
        }