Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Clamp {
- PARAMETER value.
- PARAMETER lower.
- PARAMETER upper.
- return Max(lower, Min(upper, value)).
- }
- function GetOrbitalSpeed {
- PARAMETER altitude.
- PARAMETER apo.
- PARAMETER peri.
- local a to Body:Radius + (apo + peri)/2.
- return Sqrt(Body:Mu(2/(Body:Radius + altitude) - 1/a)).
- }
- function GetLaunchAzimuthInertial {
- PARAMETER targetInclination.
- PARAMETER launchLatitude.
- return Arcsin(Clamp(Cos(targetInclination)/Cos(launchLatitude), -1, 1)).
- }
- function GetLaunchAzimuthRotating {
- PARAMETER targetInclination.
- PARAMETER launchLatitude.
- PARAMETER targetAltitude.
- local azimuth_inertial to GetLaunchAzimuthInertial(targetInclination, launchLatitude).
- local v_equatorial to 2*Constant():Pi*Body:Radius / Body:RotationPeriod.
- local v_orbit to Sqrt(Body:Mu / (Body:Radius + targetAltitude)).
- local v_xrot to v_orbit * sin(azimuth_inertial) - v_equatorial * cos(launchLatitude).
- local v_yrot to v_orbit * cos(azimuth_inertial).
- return Arctan(v_xrot/v_yrot).
- }
- // Declare parameters and consants.
- PARAMETER targetAltitude.
- PARAMETER targetInclination.
- set launchLatitude to Ship:Latitude.
- set launchAzimuth to GetLaunchAzimuthRotating(targetInclination, Ship:Latitude, targetAltitude).
- // Link control inputs to their respective buffers.
- set throttleBuf to 0.
- lock THROTTLE to Clamp(throttleBuf, 0, 1).
- set directionBuf to 90.
- set pitchBuf to 90.
- lock STEERING to heading(directionBuf, pitchBuf):Vector.
- set runmode to 1.
- until (runmode = 0) {
- // Liftoff
- if (runmode = 1) {
- SAS off.
- RCS off.
- LIGHTS on.
- set throttleBuf to 1.
- set directionBuf to 90.
- set pitchBuf to 90.
- stage.
- set runmode to 2.
- }
- // Vertical Ascent
- else if (runmode = 2) {
- if (Ship:Altitude > 2000) {
- set runmode to 3.
- }
- }
- // Gravity Turn
- else if (runmode = 3) {
- set pitchBuf to 90 * (1 - ALT:RADAR / targetAltitude).
- set directionBuf to launchAzimuth.
- if (Ship:Obt:Apoapsis > 0.95*targetAltitude) {
- set runmode to 4.
- }
- }
- // Deceleration
- else if (runmode = 4) {
- set throttleBuf to 1 - (Ship:Apoapsis - 0.95*targetAltitude)/(0.05*targetAltitude).
- if (Ship:Altitude > 70000) {
- set runmode to 5.
- }
- }
- // Coasting
- else if (runmode = 5) {
- set throttleBuf to 0.
- }
- // Illegal Runmode
- else {
- set runmode to 0.
- }
- clearscreen.
- print "r: " at (44, 1).
- print runmode at (48, 1).
- print "Direction: " + directionBuf at (5,5).
- print "Pitch: " + pitchBuf at (5,6).
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement