Created
August 16, 2019 17:05
-
-
Save allaryin/28e62f3c2608c9d74a65d792c9076508 to your computer and use it in GitHub Desktop.
pseudocode algorithm for ship autopilot in a vacuum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ( | |
stopped_velocity = 0.5m/s | |
cruise_velocity = 75km/s | |
safe_distance = 500m | |
) | |
drift_to(dest) { | |
ship.heading = angle_to(dest) | |
ship.dampeners = off | |
accel_timer = new timer() | |
accel_timer.start() | |
// accelerate to cruising velocity | |
while (distance = ship.pos - dest) > safe_distance { | |
if (distance / accel_timer) > ship.velocity { | |
break | |
} else if ship.velocity < cruise_velocity { | |
ship.thrusters = 100% | |
} | |
} | |
// target/max velocity achieved, cut engines and spin around | |
accel_timer.stop() | |
decel_distance = ship.velocity * accel_timer | |
ship.thrusters = off | |
ship.heading = !ship.heading | |
// drift | |
while ship.pos - dest > safe_distance + decel_distance { | |
speakers.play(blue_danube) | |
} | |
// decelerate to a stop | |
ship.dampeners = on | |
while ship.velocity > stopped_velocity { | |
ship.thrusters = 100% | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment