Beispiel #1
0
        public bool update()
        {
            var    orbit            = Forecast.predictOrbit();
            var    apo              = orbit.Apoapsis;
            double velocityNeeded   = VesselController.calculateOrbitalVelocityAtAltitude(Altitude);
            double currentVelocity  = VesselController.getOrbitalVelocity().Length();
            double shipAcceleration = VesselController.getEnginesAcceleration();
            double timeOfManouver   = (velocityNeeded - currentVelocity) / shipAcceleration;
            float  mixer            = (float)(apo / Altitude);
            var    downDirection    = VesselController.getGravity();

            downDirection.Normalize();
            VesselDirectionController.setTargetDirection(-downDirection);

            if (currentStage == Stage.Ascend)
            {
                Console.WriteLine("[Ascend] Apoapsis {0}", apo);

                if (orbit.Apoapsis < Altitude)
                {
                    VesselController.setThrottle(VesselDirectionController.getOnTargetPercentage());
                }
                else
                {
                    VesselController.setThrottle(0.0f);
                    return(true);
                }
            }

            VesselDirectionController.update();
            return(false);
        }
Beispiel #2
0
        public LandingPrediction predictLandPositionWithBraking()
        {
            VesselController.updateBodyPosition();
            var    currentPosition       = VesselController.getPosition();
            var    currentVelocity       = VesselController.getVelocity();
            float  stepsize              = 0.01f;
            float  time                  = 0.0f;
            bool   isVelocityDecreasing  = true;
            double lastVelocityMagnitude = currentVelocity.Length();

            while (VesselController.getAltitudeAtPoint(currentPosition) > 0 && isVelocityDecreasing)
            {
                var vesselThrust       = VesselController.getEnginesAcceleration();
                var normalizedVelocity = currentVelocity;
                normalizedVelocity.Normalize();
                currentPosition += currentVelocity * stepsize;
                currentVelocity += (float)vesselThrust * -normalizedVelocity * stepsize;
                currentVelocity += -normalizedVelocity * stepsize * (float)VesselController.getDrag()
                                   * (float)calculateDynamicPressure(VesselController.getAltitudeAtPoint(currentPosition), currentVelocity.Length());
                currentVelocity      += VesselController.getGravityAtPoint(currentPosition) * stepsize;
                time                 += stepsize;
                isVelocityDecreasing  = currentVelocity.Length() < lastVelocityMagnitude;
                lastVelocityMagnitude = currentVelocity.Length();
            }
            while (VesselController.getAltitudeAtPoint(currentPosition) > 0)
            {
                var normalizedVelocity = currentVelocity;
                normalizedVelocity.Normalize();
                currentPosition += currentVelocity * stepsize;
                currentVelocity += -normalizedVelocity * stepsize * (float)VesselController.getDrag()
                                   * (float)calculateDynamicPressure(VesselController.getAltitudeAtPoint(currentPosition), currentVelocity.Length());
                currentVelocity += VesselController.getGravityAtPoint(currentPosition) * stepsize;
                time            += stepsize;
            }
            return(new LandingPrediction()
            {
                Position = currentPosition,
                Velocity = currentVelocity,
                TimeLeft = time
            });
        }
        public bool update()
        {
            var    orbit              = Forecast.predictOrbit();
            var    apo                = orbit.Apoapsis;
            double velocityNeeded     = VesselController.calculateOrbitalVelocityAtAltitude(Altitude);
            double currentVelocity    = VesselController.getOrbitalVelocity().Length();
            double shipAcceleration   = VesselController.getEnginesAcceleration();
            double timeOfManouver     = (velocityNeeded - currentVelocity) / shipAcceleration;
            var    velocityNormalized = VesselController.getVelocity();

            velocityNormalized.Normalize();
            float mixer         = (float)(apo / Altitude);
            var   downDirection = VesselController.getGravity();

            downDirection.Normalize();
            var tangential = Vector3.Transform(-downDirection, Quaternion.RotationYawPitchRoll(MathUtil.DegreesToRadians(-25.0f), 0.0f, 0.0f));
            var direction  = -downDirection * (1.0f - mixer) + tangential * (mixer);

            direction.Normalize();
            VesselDirectionController.setTargetDirection(direction);

            if (currentStage == Stage.Ascend)
            {
                Console.WriteLine("[Ascend] Apoapsis {0}", apo);

                if (orbit.Apoapsis < Altitude)
                {
                    VesselController.setThrottle(VesselDirectionController.getOnTargetPercentage());
                }
                else
                {
                    VesselController.setThrottle(0.0f);
                    return(true);
                }
            }

            VesselDirectionController.update();
            return(false);
        }
        public bool update()
        {
            var    orbit            = Forecast.predictOrbit();
            var    apo              = orbit.Apoapsis;
            double velocityNeeded   = VesselController.calculateOrbitalVelocityAtAltitude(Altitude);
            double currentVelocity  = VesselController.getOrbitalVelocity().Length();
            double shipAcceleration = VesselController.getEnginesAcceleration();
            double timeOfManouver   = (velocityNeeded - currentVelocity) / shipAcceleration;
            float  mixer            = (float)(apo / Altitude);
            var    downDirection    = VesselController.getGravity();

            downDirection.Normalize();
            var tangential = Vector3.Transform(downDirection, Quaternion.RotationYawPitchRoll(MathUtil.DegreesToRadians(90.0f), 0.0f, 0.0f));
            var direction  = -downDirection * (1.0f - mixer) + tangential * (mixer);

            if (mixer > 1.0)
            {
                float newMixer = 1.0f - (mixer - 1.0f);
                direction = downDirection * (1.0f - newMixer) + tangential * (newMixer);
            }
            VesselDirectionController.setTargetDirection(direction);

            if (currentStage == Stage.Ascend)
            {
                Console.WriteLine("[Ascend] Apoapsis {0}", apo);

                if (orbit.Apoapsis < Altitude)
                {
                    VesselController.setThrottle(VesselDirectionController.getOnTargetPercentage());
                }
                else
                {
                    VesselController.setThrottle(0.0f);
                    currentStage = Stage.WaitForCircularize;
                }
            }

            if (currentStage == Stage.WaitForCircularize)
            {
                VesselController.setThrottle(0.0f);
                Console.WriteLine("[Waiting] Time left {0}", orbit.TimeToApoapsis - timeOfManouver * 0.5);
                if (orbit.TimeToApoapsis < timeOfManouver * 0.5)
                {
                    currentStage = Stage.Circularize;
                }
            }
            if (currentStage == Stage.Circularize)
            {
                Console.WriteLine("[Circularize] Apoapsis {0} Periapsis {1} Delta V required {2}", apo, orbit.Periapsis, velocityNeeded - currentVelocity);
                double min = Math.Min(orbit.Periapsis, orbit.Apoapsis);
                if (min < Altitude)
                {
                    VesselController.setThrottle(clamp((Altitude - min) * 0.02, 0.0, 1.0));
                }
                else
                {
                    VesselController.setThrottle(0.0f);
                }
            }


            VesselDirectionController.update();
            return(false);
        }