diff --git a/MechJeb2/MechJebModuleNodeExecutor.cs b/MechJeb2/MechJebModuleNodeExecutor.cs index 5466633e..b5d94868 100644 --- a/MechJeb2/MechJebModuleNodeExecutor.cs +++ b/MechJeb2/MechJebModuleNodeExecutor.cs @@ -88,8 +88,8 @@ public void Abort() Core.Warp.MinimumWarp(); Core.Thrust.ThrustOff(); Users.Clear(); - _dvLeft = 0; - State = States.IDLE; + _dvLeft = 0; + State = States.IDLE; } protected override void OnModuleEnabled() @@ -119,15 +119,11 @@ public enum States { WARPALIGN, LEAD, BURN, IDLE } private double _ignitionUT; private static bool _isLoadedPrincipia => VesselState.isLoadedPrincipia; private bool _hasNodes => Vessel.patchedConicSolver.maneuverNodes.Count > 0; - private double _ullageUntil; public override void Drive(FlightCtrlState s) => DoRCS(s); private void DoRCS(FlightCtrlState s) { - // seconds to continue to apply RCS after ullage has settled to VeryStable - const double MIN_RCS_TIME = 0.50; - if (State == States.BURN && RCSOnly) { Vessel.ActionGroups.SetGroup(KSPActionGroup.RCS, true); @@ -141,12 +137,6 @@ private void DoRCS(FlightCtrlState s) if (!Core.Thrust.AutoRCSUllaging) return; - if (VesselState.lowestUllage >= 1.0 && VesselState.time > _ullageUntil) - return; - - if (VesselState.lowestUllage < 1.0) - _ullageUntil = VesselState.time + MIN_RCS_TIME; - if (!Vessel.hasEnabledRCSModules()) return; diff --git a/MechJeb2/MechJebModuleThrustController.cs b/MechJeb2/MechJebModuleThrustController.cs index c73a118b..b4688da3 100644 --- a/MechJeb2/MechJebModuleThrustController.cs +++ b/MechJeb2/MechJebModuleThrustController.cs @@ -225,8 +225,6 @@ public enum LimitMode private bool _tmodeChanged; - private double _ullageUntil; - private PIDController _pid; public float LastThrottle; @@ -875,26 +873,22 @@ private static void MaxThrust(double[] x, ref double func, double[] grad, object /// private void ProcessUllage(FlightCtrlState s) { - // seconds to continue to apply RCS after ullage has settled to VeryStable - const double MIN_RCS_TIME = 0.50; - // seconds after VeryStable to wait before applying throttle - const double IGNITION_DELAY = 0.10; - if (!AutoRCSUllaging || s.mainThrottle <= 0F || ThrottleLimit <= 0F) return; if (!Vessel.hasEnabledRCSModules()) return; - if (VesselState.lowestUllage >= 1.0 && VesselState.time > _ullageUntil) - return; + bool stableUllage = VesselState.lowestUllage >= 1.0; - if (VesselState.lowestUllage < 1.0) - _ullageUntil = VesselState.time + MIN_RCS_TIME; + // ullage may dramatically drop below stable (by as much as to 0.76 in a single tick) so + // we cannot "detect" low ullage and compensate, but must apply RCS until thrust has come + // up sufficiently. + if (stableUllage && VesselState.thrustCurrent > VesselState.rcsThrustAvailable.Up ) + return; // limit the throttle only if we aren't already burning (don't waste ignitions) - // also apply RCS for IGNITION_DELAY seconds above VeryStable point. - if (LastThrottle <= 0 && _ullageUntil - VesselState.time < MIN_RCS_TIME - IGNITION_DELAY) + if (LastThrottle <= 0 && !stableUllage) SetTempLimit(0.0F, LimitMode.AUTO_RCS_ULLAGE); if (!Vessel.ActionGroups[KSPActionGroup.RCS])