public void TargetPeInsertMatchInc(double PeA, double ApA, double inc, bool omitCoast) { if (status == PVGStatus.ENABLED) { return; } bool doupdate = false; double v0m, r0m, sma; ConvertToRadVel(PeA, ApA, out r0m, out v0m, out sma); if (r0m != old_r0m || v0m != old_v0m || inc != old_inc) { //Debug.Log("old settings changed"); doupdate = true; } if (p == null || doupdate) { if (p != null) { //Debug.Log("killing a thread if its there to kill"); p.KillThread(); } //Debug.Log("mainbody.Radius = " + mainBody.Radius); //Debug.Log("mainbody.gravParameter = " + mainBody.gravParameter); lambdaDot = Vector3d.zero; double desiredHeading = OrbitalManeuverCalculator.HeadingForInclination(inc, vesselState.latitude); Vector3d desiredHeadingVector = Math.Sin(desiredHeading * UtilMath.Deg2Rad) * vesselState.east + Math.Cos(desiredHeading * UtilMath.Deg2Rad) * vesselState.north; Vector3d desiredThrustVector = Math.Cos(45 * UtilMath.Deg2Rad) * desiredHeadingVector + Math.Sin(45 * UtilMath.Deg2Rad) * vesselState.up; /* 45 pitch guess */ lambda = desiredThrustVector; PontryaginLaunch solver = new PontryaginLaunch(core: core, mu: mainBody.gravParameter, r0: vesselState.orbitalPosition, v0: vesselState.orbitalVelocity, pv0: lambda.normalized, pr0: Vector3d.zero, dV: v0m); solver.omitCoast = omitCoast; solver.flightangle4constraint(r0m, v0m, 0, inc * UtilMath.Deg2Rad); p = solver; } old_v0m = v0m; old_r0m = r0m; old_inc = inc; }
// sma is only used for the initial guess but it is the responsibility of the caller public void flightangle4constraint(double rT, double vT, double inc, double gamma, double sma, bool omitCoast, bool targetInc) { if (status == PVGStatus.ENABLED) { return; } bool doupdate = false; if (rT != old_rT || vT != old_vT || gamma != old_gamma) { doupdate = true; } // if we are tracking a target inc, don't reset if (inc != old_inc && !targetInc) { doupdate = true; } if (p != null && p.bctype != BCType.FLIGHTANGLE4) { doupdate = true; } if (p == null || doupdate) { if (p != null) { p.KillThread(); } Debug.Log("[MechJeb] MechJebModuleGuidanceController: setting up flightangle4constraint, rT: " + rT + " vT:" + vT + " inc:" + inc + " gamma:" + gamma); PontryaginLaunch solver = NewPontryaginForLaunch(inc, sma); solver.omitCoast = omitCoast; solver.flightangle4constraint(rT, vT, gamma * UtilMath.Deg2Rad, inc * UtilMath.Deg2Rad); p = solver; } old_rT = rT; old_vT = vT; old_inc = inc; old_gamma = gamma; }
// sma is only used for the initial guess but it is the responsibility of the caller public void flightangle4constraint(double rT, double vT, double inc, double gamma, double sma, bool omitCoast, bool currentInc) { if (status == PVGStatus.ENABLED) { return; } bool doupdate = false; if (rT != old_rT || vT != old_vT || gamma != old_gamma) { doupdate = true; } // avoid slight drift in the current inclination from resetting guidance constantly if (inc != old_inc && !currentInc) { doupdate = true; } if (p == null || doupdate) { if (p != null) { p.KillThread(); } Debug.Log("[MechJeb] MechJebModuleGuidanceController: setting up flightangle4constraint, rT: " + rT + " vT:" + vT + " inc:" + inc + " gamma:" + gamma); PontryaginLaunch solver = NewPontryaginForLaunch(inc, sma); solver.omitCoast = omitCoast; solver.flightangle4constraint(rT, vT, gamma * UtilMath.Deg2Rad, inc * UtilMath.Deg2Rad); p = solver; } old_rT = rT; old_vT = vT; old_inc = inc; old_gamma = gamma; }