Skip to content

Commit

Permalink
The final RCS ullage fix
Browse files Browse the repository at this point in the history
1. the node executor will continuously apply RCS in the "lead"
   time if the vessel is aligned with the node.

2. the thrust controller will continuously apply RCS until the
   thrust of the engines exceeds the fore thrust of the RCS
   engines.

Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
  • Loading branch information
lamont-granquist committed Nov 9, 2023
1 parent bcb686a commit 50fae03
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
14 changes: 2 additions & 12 deletions MechJeb2/MechJebModuleNodeExecutor.cs
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand All @@ -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;

Expand Down
20 changes: 7 additions & 13 deletions MechJeb2/MechJebModuleThrustController.cs
Expand Up @@ -225,8 +225,6 @@ public enum LimitMode

private bool _tmodeChanged;

private double _ullageUntil;

private PIDController _pid;

public float LastThrottle;
Expand Down Expand Up @@ -875,26 +873,22 @@ private static void MaxThrust(double[] x, ref double func, double[] grad, object
/// <param name="s"></param>
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])
Expand Down

0 comments on commit 50fae03

Please sign in to comment.