public bool update()
        {
            var vesselVelocity = VesselController.getVelocity();

            var downDirection = VesselController.getGravity();

            downDirection.Normalize();

            var velocity = Vector3.Dot(vesselVelocity, -downDirection);

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

            var pidCalculatedThrottle = LandingSpeedPID.Calculate(TargetVelocity, velocity);

            Console.WriteLine("PID Result : {0}", pidCalculatedThrottle);

            double hoverPercentage = predictThrustPercentageForAcceleration(VesselController.getGravity().Length()) * 2.0 - 1.0;

            pidCalculatedThrottle -= hoverPercentage;

            VesselController.setThrottle(clamp(pidCalculatedThrottle, -1.0, 1.0) * 0.5 + 0.5);

            return(false);
        }
Beispiel #2
0
        private void updateLandingBurn()
        {
            var vesselVelocity           = VesselController.getVelocity();
            var vesselVelocityNormalized = vesselVelocity;

            vesselVelocityNormalized.Normalize();

            VesselDirectionController.setTargetDirection(-vesselVelocityNormalized);

            double hoverPercentage = predictThrustPercentageForAcceleration(VesselController.getGravity().Length());
            double val             = vesselVelocity.Length() - (5.0f + VesselController.getAltitude() * 0.09f);// - landingSpeedPID.Calculate(17.0f, vesselVelocity.Length());

            if (brakeAltitudePrediction <= 0.0)
            {
                val = 1.0;
            }
            // if (vesselVelocity.Length() > VesselController.getAltitude() * 0.2f + 5.0) val = 1.0;
            VesselController.setThrottle(clamp(val, 0.0, 1.0));

            if (VesselController.getAltitude() < 500)
            {
                VesselController.setLandingGearState(true);
            }

            Console.WriteLine("[Landing burn] Brake prediction {0}", brakeAltitudePrediction);
        }
Beispiel #3
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);
        }
        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);
        }
        private void updateLandingBurn()
        {
            var targetRelative           = Target - landingPrediction.Position;
            var targetRelativeNormalized = targetRelative;

            targetRelativeNormalized.Normalize();

            var downDirection = VesselController.getGravity();

            downDirection.Normalize();
            var vesselVelocity           = VesselController.getVelocity();
            var vesselVelocityNormalized = vesselVelocity;

            vesselVelocityNormalized.Normalize();


            var altitude       = VesselController.getAltitude();
            var targetAltitude = VesselController.getAltitudeAtPoint(Target);

            altitude -= targetAltitude;

            float tiltMultiplier     = 0.38f;
            float relativeMultiplier = 0.0125f;

            if (altitude < 7000)
            {
                tiltMultiplier     = 0.18f;
                relativeMultiplier = 0.0225f;
            }
            if (altitude < 5000)
            {
                tiltMultiplier     = 0.08f;
                relativeMultiplier = 0.0825f;
            }
            if (altitude < 2500)
            {
                tiltMultiplier = 0.0f;
            }

            var desiredDirection = -vesselVelocityNormalized + targetRelativeNormalized * tiltMultiplier * Math.Min(1.0f, targetRelative.Length() * relativeMultiplier);

            if (vesselVelocity.Length() < 15.0)
            {
                bool upsidedown = Vector3.Dot(downDirection, vesselVelocityNormalized) < 0.0;
                desiredDirection = -(upsidedown ? downDirection : vesselVelocityNormalized);// + targetRelativeNormalized * 0.10f * Math.Min(1.0f, targetRelative.Length() * 0.0225f);
            }

            VesselDirectionController.setTargetDirection(desiredDirection);

            var velocity = Vector3.Dot(vesselVelocity, -downDirection);

            var pidCalculatedThrottle = landingSpeedPID.Calculate(-altitude * 0.06f - 5.0f, velocity);
            //Console.WriteLine("PID Result : {0}", pidCalculatedThrottle);

            double hoverPercentage = predictThrustPercentageForAcceleration(VesselController.getGravity().Length()) * 2.0 - 1.0;

            pidCalculatedThrottle -= hoverPercentage;

            VesselController.setThrottle(clamp(pidCalculatedThrottle, -1.0, 1.0) * 0.5 + 0.5);

            if (VesselController.getAltitude() < 500)
            {
                VesselController.setLandingGearState(true);
            }

            Console.WriteLine("[Landing burn] Prediction mismatch {0} Brake prediction {1}", targetRelative.Length(), brakeAltitudePrediction);
        }
        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);
        }