Skip to content

Commit

Permalink
Changes requested by Lamont
Browse files Browse the repository at this point in the history
  • Loading branch information
Nazfib committed May 17, 2022
1 parent 41272b4 commit f2ccfdb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
6 changes: 2 additions & 4 deletions MechJeb2/MechJebLib/Maths/Functions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ public static class Functions
/// <param name="celestialLongitude">Celestial longitude of the current position of the launch site.</param>
/// <param name="LAN">Longitude of the Ascending Node of the target plane (degrees).</param>
/// <param name="inc">Inclination of the target plane (degrees).</param>
/// <param name="launchNorth">True when the returned time is until the northern launch window, false for the southern window.</param>
public static double MinimumTimeToPlane(double rotationPeriod,double latitude,double celestialLongitude,double LAN,double inc, out bool launchNorth)
public static (double time, double inclination) MinimumTimeToPlane(double rotationPeriod,double latitude,double celestialLongitude,double LAN,double inc)
{
double north = TimeToPlane(rotationPeriod,latitude,celestialLongitude,LAN,Math.Abs(inc));
double south = TimeToPlane(rotationPeriod,latitude,celestialLongitude,LAN,-Math.Abs(inc));
launchNorth = (north < south);
return Math.Min(north, south);
return north < south ? (north,Math.Abs(inc)) : (south,-Math.Abs(inc));
}


Expand Down
28 changes: 9 additions & 19 deletions MechJeb2/MechJebModuleAscentGuidance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,18 +441,15 @@ private void ShowAutoWarpGUIElements()
if (targetExists && GuiUtils.ButtonTextBox(CachedLocalizer.Instance.MechJeb_Ascent_button15,autopilot.launchLANDifference,"º",width: LAN_width)) //Launch into plane of target
{
launchingToPlane = true;
autopilot.StartCountdown(vesselState.time +
Functions.MinimumTimeToPlane(
mainBody.rotationPeriod,
vesselState.latitude,
vesselState.celestialLongitude,
core.target.TargetOrbit.LAN - autopilot.launchLANDifference,
core.target.TargetOrbit.inclination,
out bool launchingNorth
)
);
// Fix up the sign of the inclination to match the window MinimumTimeToPlane selected
desiredInclination = launchingNorth ? Math.Abs(desiredInclination) : -Math.Abs(desiredInclination);
(double timeToPlane, double inclination) = Functions.MinimumTimeToPlane(
mainBody.rotationPeriod,
vesselState.latitude,
vesselState.celestialLongitude,
core.target.TargetOrbit.LAN - autopilot.launchLANDifference,
core.target.TargetOrbit.inclination
);
autopilot.StartCountdown(vesselState.time + timeToPlane);
desiredInclination = inclination;
}

//Launch to target LAN
Expand Down Expand Up @@ -494,13 +491,6 @@ out bool launchingNorth

if (Launching)
{
if (launchingToPlane)
{
desiredInclination = MuUtils.Clamp(core.target.TargetOrbit.inclination,Math.Abs(vesselState.latitude),180 - Math.Abs(vesselState.latitude));
desiredInclination *=
Math.Sign(Vector3d.Dot(core.target.TargetOrbit.SwappedOrbitNormal(),
Vector3d.Cross(vesselState.CoM - mainBody.position,mainBody.transform.up)));
}
GUILayout.Label(launchTimer);
if (GUILayout.Button(CachedLocalizer.Instance.MechJeb_Ascent_button17))//Abort
launchingToPlane = launchingToRendezvous = launchingToMatchLAN = launchingToLAN = autopilot.timedLaunch = false;
Expand Down

0 comments on commit f2ccfdb

Please sign in to comment.