public bool update() { var landingPrediction = Forecast.predictLandPosition(); var brakeAltitudePrediction = Forecast.predictImmediateRetrogradeBurnStopAltitude(); var targetRelative = Target - landingPrediction.Position; var targetRelativeNormalized = targetRelative; targetRelativeNormalized.Normalize(); float minimalCorrectiveThrottle = 0.0f; var desiredDirection = targetRelativeNormalized; desiredDirection.Normalize(); VesselDirectionController.setTargetDirection(desiredDirection); minimalCorrectiveThrottle = (float)VesselDirectionController.getOnTargetPercentage() * Math.Min(1.0f, (float)Math.Pow(targetRelative.Length() * 0.0008f, 2.0f)) * 0.1f; VesselDirectionController.update(); Console.WriteLine("Prediction mismatch {0}", targetRelative.Length()); if ((targetRelative.Length() < 1000.0 && lastMissDistance < targetRelative.Length()) || targetRelative.Length() < 10.0) { VesselController.setThrottle(0.0); return(true); } lastMissDistance = targetRelative.Length(); VesselController.setThrottle(minimalCorrectiveThrottle); return(false); }
public bool update() { landingPrediction = Forecast.predictLandPosition(); brakeAltitudePrediction = Forecast.predictImmediateRetrogradeBurnStopAltitude(); var altitude = VesselController.getAltitude(); var velocity = VesselController.getVelocity().Length(); if (currentStage == Stage.Landing && altitude <= 20.0 && velocity < 2.0f) { currentStage = Stage.Landed; } if (currentStage == Stage.Landing) { updateLandingBurn(); } if (currentStage == Stage.Landed) { updateLanded(); } VesselDirectionController.update(); return(false); }
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); }
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); }
public bool update() { landingPrediction = Forecast.predictLandPosition(); brakingLandingPrediction = Forecast.predictLandPositionWithBraking(); brakeAltitudePrediction = Forecast.predictImmediateRetrogradeBurnStopAltitude(); var altitude = VesselController.getAltitude(); var velocity = VesselController.getVelocity().Length(); var targetRelative = Target - landingPrediction.Position; double missDistance = targetRelative.Length(); if (currentStage == Stage.HighAltitudeCorrections && missDistance < 500) { currentStage = Stage.BallisticDescend; } else if (currentStage == Stage.BallisticDescend && (altitude < 25000 || velocity > 1000)) { VesselController.setThrustPercentage(1.0f); currentStage = Stage.ReentryBurn; } else if (currentStage == Stage.ReentryBurn && velocity < 550) { VesselController.setThrustPercentage(0.5f); currentStage = Stage.BallisticDescend2; } else if (currentStage == Stage.BallisticDescend2 && brakeAltitudePrediction <= 500.0) { currentStage = Stage.LandingBurn; } else if (currentStage == Stage.LandingBurn && altitude <= 20.0 && velocity < 2.0f) { currentStage = Stage.Landed; } if (currentStage == Stage.HighAltitudeCorrections) { updateHighAltitudeCorrections(); } if (currentStage == Stage.BallisticDescend) { updateBallisticDescend(); } if (currentStage == Stage.BallisticDescend2) { updateBallisticDescend2(); } if (currentStage == Stage.ReentryBurn) { updateReentryBurn(); } if (currentStage == Stage.LandingBurn) { updateLandingBurn(); } if (currentStage == Stage.Landed) { updateLanded(); } 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); }
public bool update() { VesselDirectionController.update(); return(VesselController.getAltitude() >= Altitude); }