public override List <ManeuverParameters> MakeNodesImpl(Orbit o, double UT, MechJebModuleTargetController target) { if (!target.NormalTargetExists) { throw new OperationException(Localizer.Format("#MechJeb_approach_Exception1"));//must select a target for the course correction. } Orbit correctionPatch = o; while (correctionPatch != null) { if (correctionPatch.referenceBody == target.TargetOrbit.referenceBody) { o = correctionPatch; UT = correctionPatch.StartUT; break; } correctionPatch = target.core.vessel.GetNextPatch(correctionPatch); } if (correctionPatch == null || correctionPatch.referenceBody != target.TargetOrbit.referenceBody) { throw new OperationException(Localizer.Format("#MechJeb_approach_Exception2"));//"target for course correction must be in the same sphere of influence" } if (o.NextClosestApproachTime(target.TargetOrbit, UT) < UT + 1 || o.NextClosestApproachDistance(target.TargetOrbit, UT) > target.TargetOrbit.semiMajorAxis * 0.2) { errorMessage = Localizer.Format("#MechJeb_Approach_errormsg");//Warning: orbit before course correction doesn't seem to approach target very closely. Planned course correction may be extreme. Recommend plotting an approximate intercept orbit and then plotting a course correction. } CelestialBody targetBody = target.Target as CelestialBody; Vector3d dV = targetBody != null? OrbitalManeuverCalculator.DeltaVAndTimeForCheapestCourseCorrection(o, UT, target.TargetOrbit, targetBody, targetBody.Radius + courseCorrectFinalPeA, out UT) : OrbitalManeuverCalculator.DeltaVAndTimeForCheapestCourseCorrection(o, UT, target.TargetOrbit, interceptDistance, out UT); List <ManeuverParameters> NodeList = new List <ManeuverParameters>(); NodeList.Add(new ManeuverParameters(dV, UT)); return(NodeList); }
void MakeNodeForOperation(Orbit o, double UT) { Vector3d dV = Vector3d.zero; double bodyRadius = o.referenceBody.Radius; switch (operation) { case Operation.CIRCULARIZE: dV = OrbitalManeuverCalculator.DeltaVToCircularize(o, UT); break; case Operation.ELLIPTICIZE: dV = OrbitalManeuverCalculator.DeltaVToEllipticize(o, UT, newPeA + bodyRadius, newApA + bodyRadius); break; case Operation.PERIAPSIS: dV = OrbitalManeuverCalculator.DeltaVToChangePeriapsis(o, UT, newPeA + bodyRadius); break; case Operation.APOAPSIS: dV = OrbitalManeuverCalculator.DeltaVToChangeApoapsis(o, UT, newApA + bodyRadius); break; case Operation.INCLINATION: dV = OrbitalManeuverCalculator.DeltaVToChangeInclination(o, UT, newInc); break; case Operation.PLANE: if (timeReference == TimeReference.REL_ASCENDING) { dV = OrbitalManeuverCalculator.DeltaVAndTimeToMatchPlanesAscending(o, core.target.Orbit, UT, out UT); } else { dV = OrbitalManeuverCalculator.DeltaVAndTimeToMatchPlanesDescending(o, core.target.Orbit, UT, out UT); } break; case Operation.TRANSFER: dV = OrbitalManeuverCalculator.DeltaVAndTimeForHohmannTransfer(o, core.target.Orbit, UT, out UT); break; case Operation.MOON_RETURN: dV = OrbitalManeuverCalculator.DeltaVAndTimeForMoonReturnEjection(o, UT, o.referenceBody.referenceBody.Radius + moonReturnAltitude, out UT); break; case Operation.COURSE_CORRECTION: CelestialBody targetBody = core.target.Target as CelestialBody; if (targetBody != null) { dV = OrbitalManeuverCalculator.DeltaVAndTimeForCheapestCourseCorrection(o, UT, core.target.Orbit, targetBody, targetBody.Radius + courseCorrectFinalPeA, out UT); } else { dV = OrbitalManeuverCalculator.DeltaVAndTimeForCheapestCourseCorrection(o, UT, core.target.Orbit, out UT); } break; case Operation.INTERPLANETARY_TRANSFER: dV = OrbitalManeuverCalculator.DeltaVAndTimeForInterplanetaryTransferEjection(o, UT, core.target.Orbit, true, out UT); break; case Operation.LAMBERT: dV = OrbitalManeuverCalculator.DeltaVToInterceptAtTime(o, UT, core.target.Orbit, UT + interceptInterval); break; case Operation.KILL_RELVEL: dV = OrbitalManeuverCalculator.DeltaVToMatchVelocities(o, UT, core.target.Orbit); break; } vessel.PlaceManeuverNode(o, dV, UT); }
void MakeNodeForOperation(Orbit o, double UT, Operation op, double newPeA, double newApA, double newInc, double courseCorrectFinalPeA, double moonReturnAltitude, double interceptInterval) { Vector3d dV = Vector3d.zero; double bodyRadius = o.referenceBody.Radius; // print(newPeA + " - " + this.newPeA + "\n" + // newApA + " - " + this.newApA + "\n" + // newInc + " - " + this.newInc + "\n" + // courseCorrectFinalPeA + " - " + this.courseCorrectFinalPeA + "\n" + // moonReturnAltitude + " - " + this.moonReturnAltitude + "\n" + // interceptInterval + " - " + this.interceptInterval); switch (op) { case Operation.CIRCULARIZE: dV = OrbitalManeuverCalculator.DeltaVToCircularize(o, UT); break; case Operation.ELLIPTICIZE: dV = OrbitalManeuverCalculator.DeltaVToEllipticize(o, UT, newPeA + bodyRadius, newApA + bodyRadius); break; case Operation.PERIAPSIS: dV = OrbitalManeuverCalculator.DeltaVToChangePeriapsis(o, UT, newPeA + bodyRadius); break; case Operation.APOAPSIS: dV = OrbitalManeuverCalculator.DeltaVToChangeApoapsis(o, UT, newApA + bodyRadius); break; case Operation.INCLINATION: dV = OrbitalManeuverCalculator.DeltaVToChangeInclination(o, UT, newInc); break; case Operation.PLANE: if (timeReference == TimeReference.REL_ASCENDING) { dV = OrbitalManeuverCalculator.DeltaVAndTimeToMatchPlanesAscending(o, core.target.TargetOrbit, UT, out UT); } else { dV = OrbitalManeuverCalculator.DeltaVAndTimeToMatchPlanesDescending(o, core.target.TargetOrbit, UT, out UT); } break; case Operation.TRANSFER: dV = OrbitalManeuverCalculator.DeltaVAndTimeForHohmannTransfer(o, core.target.TargetOrbit, UT, out UT); break; case Operation.MOON_RETURN: dV = OrbitalManeuverCalculator.DeltaVAndTimeForMoonReturnEjection(o, UT, o.referenceBody.referenceBody.Radius + moonReturnAltitude, out UT); break; case Operation.COURSE_CORRECTION: CelestialBody targetBody = core.target.Target as CelestialBody; if (targetBody != null) { dV = OrbitalManeuverCalculator.DeltaVAndTimeForCheapestCourseCorrection(o, UT, core.target.TargetOrbit, targetBody, targetBody.Radius + courseCorrectFinalPeA, out UT); } else { dV = OrbitalManeuverCalculator.DeltaVAndTimeForCheapestCourseCorrection(o, UT, core.target.TargetOrbit, interceptDistance, out UT); } break; case Operation.INTERPLANETARY_TRANSFER: dV = OrbitalManeuverCalculator.DeltaVAndTimeForInterplanetaryTransferEjection(o, UT, core.target.TargetOrbit, true, out UT); break; case Operation.LAMBERT: dV = OrbitalManeuverCalculator.DeltaVToInterceptAtTime(o, UT, core.target.TargetOrbit, UT + interceptInterval); break; case Operation.KILL_RELVEL: dV = OrbitalManeuverCalculator.DeltaVToMatchVelocities(o, UT, core.target.TargetOrbit); break; case Operation.RESONANT_ORBIT: dV = OrbitalManeuverCalculator.DeltaVToResonantOrbit(o, UT, (double)resonanceNumerator.val / resonanceDenominator.val); break; case Operation.SEMI_MAJOR: dV = OrbitalManeuverCalculator.DeltaVForSemiMajorAxis(o, UT, newSMA); break; case Operation.LAN: dV = OrbitalManeuverCalculator.DeltaVToShiftLAN(o, UT, core.target.targetLongitude); break; } vessel.PlaceManeuverNode(o, dV, UT); }