void update()
        {
            if (TransferTime < 0)
            {
                TrajectoryCalculator.ClosestApproach(Orbit, TargetOrbit, StartUT, VSL.Geometry.MinDistance, out AtTargetUT);
                TransferTime = AtTargetUT - StartUT;
            }
            else
            {
                AtTargetUT = StartUT + TransferTime;
            }
            var obt     = TrajectoryCalculator.NextOrbit(Orbit, AtTargetUT);
            var t_orbit = TrajectoryCalculator.NextOrbit(TargetOrbit, AtTargetUT);

            AtTargetPos      = obt.getRelativePositionAtUT(AtTargetUT);
            AtTargetVel      = obt.getOrbitalVelocityAtUT(AtTargetUT);
            TargetPos        = TrajectoryCalculator.RelativePosAtUT(obt.referenceBody, t_orbit, AtTargetUT);
            AtTargetRelPos   = AtTargetPos - TargetPos;
            DistanceToTarget = AtTargetRelPos.magnitude - VSL.Geometry.MinDistance;
            DirectHit        = DistanceToTarget < 1;
            DistanceToTarget = Utils.ClampL(DistanceToTarget, 0);
            BrakeDeltaV      = t_orbit.GetFrameVelAtUT(AtTargetUT) - obt.GetFrameVelAtUT(AtTargetUT);
            var brake_dV = (float)BrakeDeltaV.magnitude;

            BrakeDuration = VSL.Engines.TTB_Precise(brake_dV);
            BrakeFuel     = VSL.Engines.FuelNeeded(brake_dV);
            FullBrake     = GetTotalFuel() < VSL.Engines.AvailableFuelMass;
            //check if this trajectory is too close to any of celestial bodies it passes by
            KillerOrbit = TransferTime < BrakeDuration + ManeuverDuration;
            update_killer(OrigOrbit, StartUT);
            update_killer(Orbit, AtTargetUT);
//            Utils.Log("{}", this);//debug
        }
Exemple #2
0
        protected override void Update()
        {
            Vector3 dV;

            if (CFG.AP1[Autopilot1.MatchVel])
            {
                Working = true;
                dV      = CFG.Target.GetObtVelocity() - VSL.vessel.obt_velocity;
                if (!Executor.Execute(dV, MinDeltaV))
                {
                    Executor.Reset();
                }
            }
            else
            {
                var tOrb = CFG.Target.GetOrbit();
                var dist = Working? 0 :
                           TrajectoryCalculator.NearestApproach(VSL.orbit, tOrb, VSL.Physics.UT, VSL.Geometry.MinDistance + 10, out ApprUT);
                TTA = (float)(ApprUT - VSL.Physics.UT);
                switch (stage)
                {
                case Stage.Start:
                    if (dist > C.MaxApproachDistance)
                    {
                        Status(Colors.Warning.Tag("WARNING: ") +
                               "Nearest approach distance is " +
                               Colors.Selected2.Tag("<b>{0}</b>\n") +
                               Colors.Danger.Tag("<b>Push to proceed. At your own risk.</b>"),
                               Utils.formatBigValue((float)dist, "m"));
                        stage = Stage.Wait;
                        goto case Stage.Wait;
                    }
                    stage = Stage.Brake;
                    goto case Stage.Brake;

                case Stage.Wait:
                    if (!string.IsNullOrEmpty(TCAGui.StatusMessage))
                    {
                        break;
                    }
                    stage = Stage.Brake;
                    goto case Stage.Brake;

                case Stage.Brake:
                    dV = (TrajectoryCalculator.NextOrbit(tOrb, ApprUT).GetFrameVelAtUT(ApprUT) - VSL.orbit.GetFrameVelAtUT(ApprUT)).xzy;
                    if (!Executor.Execute(dV, MinDeltaV, StartCondition))
                    {
                        Reset();
                    }
                    break;
                }
            }
        }
        protected override void Update()
        {
            Vector3 dV;

            if (CFG.AP1[Autopilot1.MatchVel])
            {
                Working = true;
                dV      = CFG.Target.GetObtVelocity() - VSL.vessel.obt_velocity;
                if (!Executor.Execute(dV, GLB.THR.MinDeltaV))
                {
                    Executor.Reset();
                }
            }
            else
            {
                double ApprUT;
                var    tOrb = CFG.Target.GetOrbit();
                var    dist = TrajectoryCalculator.NearestApproach(VSL.orbit, tOrb, VSL.Physics.UT, VSL.Geometry.MinDistance + 10, out ApprUT);
                TTA = (float)(ApprUT - VSL.Physics.UT);
                switch (stage)
                {
                case Stage.Start:
                    if (dist > MVA.MaxApproachDistance)
                    {
                        Status(string.Format("<color=yellow>WARNING:</color> Nearest approach distance is <color=magenta><b>{0}</b></color>\n" +
                                             "<color=red><b>Push to proceed. At your own risk.</b></color>",
                                             Utils.formatBigValue((float)dist, "m")));
                        stage = Stage.Wait;
                        goto case Stage.Wait;
                    }
                    stage = Stage.Brake;
                    goto case Stage.Brake;

                case Stage.Wait:
                    if (!string.IsNullOrEmpty(TCAGui.StatusMessage))
                    {
                        break;
                    }
                    stage = Stage.Brake;
                    goto case Stage.Brake;

                case Stage.Brake:
                    dV = (TrajectoryCalculator.NextOrbit(tOrb, ApprUT).GetFrameVelAtUT(ApprUT) - VSL.orbit.GetFrameVelAtUT(ApprUT)).xzy;
                    if (!Executor.Execute(dV, GLB.THR.MinDeltaV, StartCondition))
                    {
                        Reset();
                    }
                    break;
                }
            }
        }