Beispiel #1
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 #2
0
        public LandingPrediction predictLandPosition()
        {
            VesselController.updateBodyPosition();
            var   currentPosition = VesselController.getPosition();
            var   currentVelocity = VesselController.getVelocity();
            float stepsize        = 0.01f;
            float time            = 0.0f;

            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 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);
        }
        private void updateHighAltitudeCorrections()
        {
            var targetRelative           = Target - landingPrediction.Position;
            var targetRelativeNormalized = targetRelative;

            targetRelativeNormalized.Normalize();

            var overShootTarget = Target + targetRelativeNormalized * 1000.0f;

            targetRelativeNormalized = overShootTarget - landingPrediction.Position;
            targetRelativeNormalized.Normalize();

            var desiredDirection = targetRelativeNormalized;// * Math.Min(1.0f, targetRelative.Length() * 0.01f);

            desiredDirection.Normalize();
            VesselDirectionController.setTargetDirection(desiredDirection);
            var   vesselVelocity            = VesselController.getVelocity();
            float minimalCorrectiveThrottle = (float)VesselDirectionController.getOnTargetPercentage() *
                                              Math.Min(1.0f, targetRelative.Length() * 0.0001f) * 1.0f;// * Math.Min(1.0f, vesselVelocity.Length() * 0.005f);

            VesselController.setThrottle(minimalCorrectiveThrottle);
            Console.WriteLine("[High altitude pinpoint] Prediction mismatch {0}", targetRelative.Length());

            /*
             * var vesselVelocity = VesselController.getVelocity();
             * var vesselVelocityNormalized = vesselVelocity;
             * vesselVelocityNormalized.Normalize();
             * VesselDirectionController.setTargetDirection(-vesselVelocityNormalized);*/
        }
        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);
        }