Exemplo n.º 1
0
        // sma is only used for the initial guess but it is the responsibility of the caller
        public void flightangle5constraint(double rT, double vT, double inc, double gamma, double LAN, double sma, bool omitCoast, bool targetInc, bool targetLAN)
        {
            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 LAN, don't reset
            if (LAN != old_LAN && !targetLAN)
            {
                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.FLIGHTANGLE5)
            {
                doupdate = true;
            }

            if (p == null || doupdate)
            {
                if (p != null)
                {
                    p.KillThread();
                }

                Debug.Log("[MechJeb] MechJebModuleGuidanceController: setting up flightangle5constraint, rT: " + rT + " vT:" + vT + " inc:" + inc + " gamma:" + gamma + " LAN:" + LAN + " sma: " + sma);
                PontryaginLaunch solver = NewPontryaginForLaunch(inc, sma);
                solver.omitCoast = omitCoast;
                solver.flightangle5constraint(rT, vT, gamma * UtilMath.Deg2Rad, inc * UtilMath.Deg2Rad, LAN * UtilMath.Deg2Rad);
                p = solver;
            }

            old_rT    = rT;
            old_vT    = vT;
            old_inc   = inc;
            old_gamma = gamma;
            old_LAN   = LAN;
        }
Exemplo n.º 2
0
        public void keplerian4constraintArgPfree(double sma, double ecc, double inc, double LAN, bool omitCoast, bool targetInc, bool targetLAN)
        {
            if (status == PVGStatus.ENABLED)
            {
                return;
            }

            bool doupdate = false;

            if (sma != old_sma || ecc != old_ecc)
            {
                doupdate = true;
            }

            // if we are tracking a target LAN, don't reset
            if (LAN != old_LAN && !targetLAN)
            {
                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.KEPLER4)
            {
                doupdate = true;
            }

            if (p == null || doupdate)
            {
                if (p != null)
                {
                    p.KillThread();
                }

                Debug.Log("[MechJeb] MechJebModuleGuidanceController: setting up keplerian4constraintArgPfree");
                PontryaginLaunch solver = NewPontryaginForLaunch(inc, sma);
                solver.omitCoast = omitCoast;
                solver.keplerian4constraintArgPfree(sma, ecc, inc * UtilMath.Deg2Rad, LAN * UtilMath.Deg2Rad);
                p = solver;
            }

            old_sma = sma;
            old_ecc = ecc;
            old_inc = inc;
            old_LAN = LAN;
        }
Exemplo n.º 3
0
        public void keplerian5constraint(double sma, double ecc, double inc, double LAN, double ArgP, bool omitCoast, bool currentInc)
        {
            if (status == PVGStatus.ENABLED)
            {
                return;
            }

            bool doupdate = false;

            if (sma != old_sma || ecc != old_ecc || inc != old_inc || LAN != old_LAN || ArgP != old_ArgP)
            {
                doupdate = true;
            }

            // avoid slight drift in the current inclination from resetting guidance constantly
            if (inc != old_inc && !currentInc)
            {
                doupdate = true;
            }

            if (p != null && p.bctype != BCType.KEPLER5)
            {
                doupdate = true;
            }

            if (p == null || doupdate)
            {
                if (p != null)
                {
                    p.KillThread();
                }

                Debug.Log("[MechJeb] MechJebModuleGuidanceController: setting up keplerian5constraint");
                PontryaginLaunch solver = NewPontryaginForLaunch(inc, sma);
                solver.omitCoast = omitCoast;
                solver.keplerian5constraint(sma, ecc, inc * UtilMath.Deg2Rad, LAN * UtilMath.Deg2Rad, ArgP * UtilMath.Deg2Rad);
                p = solver;
            }

            old_sma  = sma;
            old_ecc  = ecc;
            old_inc  = inc;
            old_LAN  = LAN;
            old_ArgP = ArgP;
        }
Exemplo n.º 4
0
        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;
        }
Exemplo n.º 5
0
        public void TargetPeInsertMatchOrbitPlane(double PeA, double ApA, Orbit o, 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)
            {
                doupdate = true;
            }

            if (p == null || doupdate)
            {
                if (p != null)
                {
                    p.KillThread();
                }

                lambdaDot = Vector3d.zero;
                double   desiredHeading       = OrbitalManeuverCalculator.HeadingForInclination(o.inclination, 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;
                Vector3d pos, vel;
                o.GetOrbitalStateVectorsAtUT(vesselState.time, out pos, out vel);
                Vector3d h   = Vector3d.Cross(pos.xzy, vel.xzy);
                double   hTm = v0m * r0m; // FIXME: gamma
                solver.flightangle5constraint(r0m, v0m, 0, h.normalized * hTm);
                p = solver;
                Debug.Log("created TargetPeInsertMatchOrbitPlane solver");
            }

            old_v0m = v0m;
            old_r0m = r0m;
        }
        // sma is only used for the initial guess but it is the responsibility of the caller
        public void flightangle4constraintMAXE(double rTm, double gamma, double inc, double LAN, int numStages, double sma, bool omitCoast, bool currentInc)
        {
            if (status == PVGStatus.ENABLED)
            {
                return;
            }

            bool doupdate = false;

            if (rTm != old_rTm || gamma != old_gamma || numStages != old_numStages || LAN != old_LAN)
            {
                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)
                {
                    Log.dbg("killing a thread if its there to kill");
                    p.KillThread();
                }

                Log.info("MechJebModuleGuidanceController: setting up flightangle3constraintMAXE");
                PontryaginLaunch solver = NewPontryaginForLaunch(inc, sma);
                solver.omitCoast = omitCoast;
                solver.flightangle4constraintMAXE(rTm, gamma * UtilMath.Deg2Rad, inc * UtilMath.Deg2Rad, LAN * UtilMath.Deg2Rad, numStages);
                p = solver;
            }

            old_rTm       = rTm;
            old_gamma     = gamma;
            old_LAN       = LAN;
            old_numStages = numStages;
            old_inc       = inc;
        }
        // sma is only used for the initial guess but it is the responsibility of the caller
        public void flightangle5constraint(double rT, double vT, double inc, double gamma, double LAN, double sma, bool omitCoast, bool currentInc)
        {
            if (status == PVGStatus.ENABLED)
            {
                return;
            }

            bool doupdate = false;

            if (rT != old_rT || vT != old_vT || gamma != old_gamma || LAN != old_LAN)
            {
                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 flightangle5constraint, rT: " + rT + " vT:" + vT + " inc:" + inc + " gamma:" + gamma + " LAN:" + LAN + " sma: " + sma);
                PontryaginLaunch solver = NewPontryaginForLaunch(inc, sma);
                solver.omitCoast = omitCoast;
                solver.flightangle5constraint(rT, vT, gamma * UtilMath.Deg2Rad, inc * UtilMath.Deg2Rad, LAN * UtilMath.Deg2Rad);
                p = solver;
            }

            old_rT    = rT;
            old_vT    = vT;
            old_inc   = inc;
            old_gamma = gamma;
            old_LAN   = LAN;
        }
        public void keplerian4constraintArgPfree(double sma, double ecc, double inc, double LAN, bool omitCoast, bool currentInc)
        {
            if (status == PVGStatus.ENABLED)
            {
                return;
            }

            bool doupdate = false;

            if (sma != old_sma || ecc != old_ecc || LAN != old_LAN)
            {
                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();
                }

                Log.info("MechJebModuleGuidanceController: setting up keplerian4constraintArgPfree");
                PontryaginLaunch solver = NewPontryaginForLaunch(inc, sma);
                solver.omitCoast = omitCoast;
                solver.keplerian4constraintArgPfree(sma, ecc, inc * UtilMath.Deg2Rad, LAN * UtilMath.Deg2Rad);
                p = solver;
            }

            old_sma = sma;
            old_ecc = ecc;
            old_inc = inc;
            old_LAN = LAN;
        }
        // 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();
                }

                Log.info("MechJebModuleGuidanceController: setting up flightangle4constraint, rT: {0}; vT:{1}; inc:{2}; gamma: {3}", rT, vT, inc, 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;
        }