Skip to content

Commit

Permalink
Simplify RCS ullage
Browse files Browse the repository at this point in the history
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 <lamont@scriptkiddie.org>
  • Loading branch information
lamont-granquist committed Nov 8, 2023
1 parent 0af2ef4 commit f06acb0
Showing 1 changed file with 12 additions and 37 deletions.
49 changes: 12 additions & 37 deletions MechJeb2/MechJebModuleThrustController.cs
Expand Up @@ -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)]
Expand Down Expand Up @@ -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;
Expand Down 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 @@ -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;
Expand Down

0 comments on commit f06acb0

Please sign in to comment.