Skip to content

Commit

Permalink
add time selector to two-impulse transfer
Browse files Browse the repository at this point in the history
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
  • Loading branch information
lamont-granquist committed Oct 10, 2023
1 parent c411cd8 commit 82b714e
Showing 1 changed file with 18 additions and 43 deletions.
61 changes: 18 additions & 43 deletions MechJeb2/Maneuver/OperationTransfer.cs
Expand Up @@ -62,12 +62,8 @@ public override void DoParametersGUI(Orbit o, double universalTime, MechJebModul
if (Rendezvous)
GuiUtils.SimpleTextBox(Localizer.Format("#MechJeb_Hohm_Label1"), LagTime, "sec"); //fractional target period offset

/*
if (!Coplanar)
{
_timeSelector.DoChooseTimeGUI();
}
*/
_timeSelector.DoChooseTimeGUI();

}

protected override List<ManeuverParameters> MakeNodesImpl(Orbit o, double universalTime, MechJebModuleTargetController target)
Expand All @@ -78,6 +74,21 @@ protected override List<ManeuverParameters> MakeNodesImpl(Orbit o, double univer
if (o.referenceBody != target.TargetOrbit.referenceBody)
throw new OperationException(Localizer.Format("#MechJeb_Hohm_Exception2")); //target for bi-impulsive transfer must be in the same sphere of influence.

bool anExists = o.AscendingNodeExists(target.TargetOrbit);
bool dnExists = o.DescendingNodeExists(target.TargetOrbit);

switch (_timeSelector.TimeReference)
{
case TimeReference.REL_ASCENDING when !anExists:
throw new OperationException(Localizer.Format("#MechJeb_Hohm_Exception3")); //ascending node with target doesn't exist.
case TimeReference.REL_DESCENDING when !dnExists:
throw new OperationException(Localizer.Format("#MechJeb_Hohm_Exception4")); //descending node with target doesn't exist.
case TimeReference.REL_NEAREST_AD when !(anExists || dnExists):
throw new OperationException(Localizer.Format("#MechJeb_Hohm_Exception5")); //neither ascending nor descending node with target exists.
}

double ut = _timeSelector.ComputeManeuverTime(o, universalTime, target);

if (target.Target is CelestialBody && Capture && PlanCapture)
ErrorMessage = "Insertion burn to a celestial with an SOI is not supported by this maneuver. A Transfer-to-Moon maneuver needs to be written to properly support this case.";

Expand All @@ -86,43 +97,7 @@ protected override List<ManeuverParameters> MakeNodesImpl(Orbit o, double univer
double lagTime = Rendezvous ? LagTime.val : 0;

(Vector3d dV1, double ut1, Vector3d dV2, double ut2) =
OrbitalManeuverCalculator.DeltaVAndTimeForHohmannTransfer(o, targetOrbit, universalTime, lagTime, Coplanar, Rendezvous, Capture);

/*
else
{
if (_timeSelector.TimeReference == TimeReference.COMPUTED)
{
dV = OrbitalManeuverCalculator.DeltaVAndTimeForBiImpulsiveAnnealed(o, targetOrbit, universalTime, out ut,
intercept_only: InterceptOnly);
}
else
{
bool anExists = o.AscendingNodeExists(target.TargetOrbit);
bool dnExists = o.DescendingNodeExists(target.TargetOrbit);
if (_timeSelector.TimeReference == TimeReference.REL_ASCENDING && !anExists)
{
throw new OperationException(Localizer.Format("#MechJeb_Hohm_Exception3")); //ascending node with target doesn't exist.
}
if (_timeSelector.TimeReference == TimeReference.REL_DESCENDING && !dnExists)
{
throw new OperationException(Localizer.Format("#MechJeb_Hohm_Exception4")); //descending node with target doesn't exist.
}
if (_timeSelector.TimeReference == TimeReference.REL_NEAREST_AD && !(anExists || dnExists))
{
throw new OperationException(
Localizer.Format("#MechJeb_Hohm_Exception5")); //neither ascending nor descending node with target exists.
}
ut = _timeSelector.ComputeManeuverTime(o, universalTime, target);
dV = OrbitalManeuverCalculator.DeltaVAndTimeForBiImpulsiveAnnealed(o, targetOrbit, ut, out ut, intercept_only: InterceptOnly,
fixed_ut: true);
}
}
*/
OrbitalManeuverCalculator.DeltaVAndTimeForHohmannTransfer(o, targetOrbit, ut, lagTime, Coplanar, Rendezvous, Capture);

if (Capture && PlanCapture)
return new List<ManeuverParameters> { new ManeuverParameters(dV1, ut1), new ManeuverParameters(dV2, ut2) };
Expand Down

0 comments on commit 82b714e

Please sign in to comment.