Skip to content

Commit

Permalink
Run optimizer during final countdown
Browse files Browse the repository at this point in the history
When doing launch to plane run the optimizer before T=0 secs

Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
  • Loading branch information
lamont-granquist committed Jan 17, 2024
1 parent fa685a5 commit dde57e9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
11 changes: 0 additions & 11 deletions MechJeb2/MechJebModuleAscentBaseAutopilot.cs
Expand Up @@ -112,7 +112,6 @@ public override void OnFixedUpdate()
{
if (Enabled && VesselState.thrustAvailable < 10E-4) // only stage if we have no engines active
StageManager.ActivateNextStage();
TimedLaunchHook(); // let ascentPath modules do stuff edge triggered on launch starting
TimedLaunch = false;
}
else
Expand Down Expand Up @@ -214,11 +213,6 @@ private void DriveAscent()
Debug.Log("Awaiting Liftoff");
Status = Localizer.Format("#MechJeb_Ascent_status6"); //"Awaiting liftoff"

if (TMinus > AscentSettings.WarpCountDown)
Core.Guidance.Enabled = false;
else
Core.Guidance.AssertStart(false);

Core.Attitude.SetAxisControl(false, false, false);
return;
}
Expand Down Expand Up @@ -289,11 +283,6 @@ private void DriveCircularizationBurn()

protected abstract bool DriveAscent2();

protected virtual void TimedLaunchHook()
{
// triggered when timed launches start the actual launch
}

//data used by ThrottleToRaiseApoapsis
private float _raiseApoapsisLastThrottle;
private double _raiseApoapsisLastApR;
Expand Down
25 changes: 19 additions & 6 deletions MechJeb2/MechJebModuleAscentPVGAutopilot.cs
@@ -1,6 +1,7 @@
extern alias JetBrainsAnnotations;
using System;
using KSP.Localization;
using UnityEngine;

/*
* Optimized launches for RSS/RO
Expand Down Expand Up @@ -32,6 +33,24 @@ protected override void OnModuleDisabled()
Core.Glueball.Users.Remove(this);
}

public override void Drive(FlightCtrlState s)
{
if (TimedLaunch)
{
if (TMinus <= AscentSettings.WarpCountDown)
{
SetTarget();
Core.Guidance.AssertStart(false);
}
}
else
{
SetTarget();
Core.Guidance.AssertStart();
}
base.Drive(s);
}

private enum AscentMode
{
VERTICAL_ASCENT,
Expand All @@ -43,14 +62,8 @@ private enum AscentMode

private AscentMode _mode;

protected override void TimedLaunchHook() =>
// timedLaunch kills the optimizer so re-enable it here
Core.Guidance.Enabled = true;

protected override bool DriveAscent2()
{
SetTarget();
Core.Guidance.AssertStart();
switch (_mode)
{
case AscentMode.VERTICAL_ASCENT:
Expand Down
5 changes: 4 additions & 1 deletion MechJeb2/MechJebModuleGuidanceController.cs
Expand Up @@ -75,7 +75,10 @@ protected override void OnModuleDisabled()
private bool _allowExecution;

// we wait until we get a signal to allow execution to start
public void AssertStart(bool allowExecution = true) => _allowExecution = allowExecution;
public void AssertStart(bool allowExecution = true)
{
_allowExecution = allowExecution;
}

public override void OnFixedUpdate()
{
Expand Down

0 comments on commit dde57e9

Please sign in to comment.