Esempio n. 1
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
            });
        }
        private void updateReentryBurn()
        {
            var vesselVelocity           = VesselController.getVelocity();
            var vesselVelocityNormalized = vesselVelocity;

            vesselVelocityNormalized.Normalize();
            var gravityAtTarget = VesselController.getGravityAtPoint(Target);

            gravityAtTarget.Normalize();
            var targetRelative           = Target - landingPrediction.Position;
            var targetRelativeNormalized = targetRelative;

            targetRelativeNormalized.Normalize();
            var correction = clamp(correctionsPID.Calculate(Vector3.Zero, targetRelative * 0.010f), -1.0, 1.0);

            var desiredDirection = -vesselVelocityNormalized - correction * 0.3f;

            desiredDirection.Normalize();
            VesselDirectionController.setTargetDirection(desiredDirection);
            VesselController.setThrottle(1.0f);

            Console.WriteLine("[Reentry burn] Prediction mismatch {0}", targetRelative.Length());
        }