From f06acb0d603cb3126f21811c2471a6a92c428148 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Tue, 7 Nov 2023 20:40:26 -0800 Subject: [PATCH] Simplify RCS ullage Always apply RCS ullage if we're less than verystable. Don't kill the engine if the last command was to apply throttle. In my head, this means that if we drop below verystable during spoolup we should apply some RCS, without having logic that will accidentally kill the engine and waste an ignition if ullage drops before spoolup is done. Signed-off-by: Lamont Granquist --- MechJeb2/MechJebModuleThrustController.cs | 49 ++++++----------------- 1 file changed, 12 insertions(+), 37 deletions(-) diff --git a/MechJeb2/MechJebModuleThrustController.cs b/MechJeb2/MechJebModuleThrustController.cs index 23f3ac75..8f5ef55f 100644 --- a/MechJeb2/MechJebModuleThrustController.cs +++ b/MechJeb2/MechJebModuleThrustController.cs @@ -68,7 +68,7 @@ public void LimitToPreventOverheatsInfoItem() [ToggleInfoItem("#MechJeb_SmoothThrottle", InfoItem.Category.Thrust)] //Smooth throttle [Persistent(pass = (int)Pass.GLOBAL)] - public bool SmoothThrottle = false; + public bool SmoothThrottle; [UsedImplicitly] [Persistent(pass = (int)Pass.GLOBAL)] @@ -113,7 +113,7 @@ public void AutoRCsUllageInfoItem() [ToggleInfoItem("#MechJeb_ManageAirIntakes", InfoItem.Category.Thrust)] //Manage air intakes [Persistent(pass = (int)Pass.GLOBAL)] - public bool ManageIntakes = false; + public bool ManageIntakes; [Persistent(pass = (int)Pass.GLOBAL)] public bool LimitAcceleration; @@ -225,8 +225,6 @@ public enum LimitMode private bool _tmodeChanged; - private double _ullageUntil; - private PIDController _pid; public float LastThrottle; @@ -878,48 +876,25 @@ private void ProcessUllage(FlightCtrlState s) if (!AutoRCSUllaging || s.mainThrottle <= 0F || ThrottleLimit <= 0F) return; - bool isStable = VesselState.lowestUllage == VesselState.UllageState.VeryStable; - if (!isStable) - { - _ullageUntil = VesselState.time + 0.15; - } - - if (VesselState.time >= _ullageUntil) + if (!Vessel.hasEnabledRCSModules()) return; - // Continue ullaging until at least one engine has spooled up enough to produce >1% of it's rated thrust - if (isStable && VesselState.enginesWrappers.Where(e => e.engine.requestedThrottle > 0.01) - .All(e => e.engine.currentThrottle < 0.01)) - { - _ullageUntil = VesselState.time + 0.15; - } + if (VesselState.lowestUllage == VesselState.UllageState.VeryStable) + return; - Debug.Log("MechJeb RCS auto-ullaging: found state below very stable: " + VesselState.lowestUllage); - if (Vessel.hasEnabledRCSModules()) - { - if (!Vessel.ActionGroups[KSPActionGroup.RCS]) - { - Debug.Log("MechJeb RCS auto-ullaging: enabling RCS action group for automatic ullaging"); - Vessel.ActionGroups.SetGroup(KSPActionGroup.RCS, true); - } + // limit the throttle only if we aren't already burning (don't waste ignitions) + if (LastThrottle <= 0) + SetTempLimit(0.0F, LimitMode.AUTO_RCS_ULLAGE); - Debug.Log("MechJeb RCS auto-ullaging: firing RCS to stabilize ulllage"); - if (!isStable) - { - SetTempLimit(0.0F, LimitMode.UNSTABLE_IGNITION); - } + if (!Vessel.ActionGroups[KSPActionGroup.RCS]) + Vessel.ActionGroups.SetGroup(KSPActionGroup.RCS, true); - s.Z = -1.0F; - } - else - { - Debug.Log("MechJeb RCS auto-ullaging: vessel has no enabled/staged RCS modules"); - } + s.Z = -1.0F; } private DifferentialThrottleStatus ComputeDifferentialThrottle(Vector3d torque) { - //var stopwatch = new Stopwatch(); + //var stopwatch = new Stopwatch(); //stopwatch.Start(); float mainThrottle = Vessel.ctrlState.mainThrottle;