EN
← Back to all work
PROJECT / ksp-autopilot

Automated rocket landing in Kerbal Space Program

Python autopilot scripts that fly rockets in Kerbal Space Program without human input, driving the game live over the kRPC mod: telemetry streams out, control commands stream in, over TCP. One script launches a vessel into a permanent, stable orbit. The second includes the first and also returns the booster to a soft upright landing near the pad while the upper stage reaches orbit. Verified in-game across 25 autonomous flights. It is currently a personal project rather than a public product.

Python kRPC PID / vis-viva

Scripts

02 scripts
01 Launch to orbit

Launch to a permanent orbit

launch_to_orbit.py flies the active vessel through a gravity-turn ascent and circularizes at apoapsis into a stable orbit that will not decay, 70 to 80 km by default. It handles single-stage and two-stage rockets: a two-stage craft stages automatically, dropping the first stage once its fuel runs out and finishing the orbit on the second.

Target altitude, gravity-turn end, the first-stage fuel reserve, and an optional physics time-warp to run the ascent faster are all tunable from the command line.

02 Launch and recover

Launch and fly the booster back

launch_and_recover.py runs a Falcon-9-style profile on a two-stage rocket: launch, then separate the first stage once it burns down to a set fuel limit (30% by default). From there both stages are flown at once in a single control loop: the booster turns around, burns back toward the pad, deploys airbrakes on descent, and brakes to a soft upright touchdown, while the second stage carries on to orbit.

Best run to date: the booster landed undamaged, 0.3° off vertical, descending at 2.85 m/s at touchdown, with the upper stage in a stable 70.5 × 84 km orbit on the same flight.

Full flight footage

second script / full mission
REC launch_and_recover.py end to end: launch, stage separation, and the booster flying itself back to a powered vertical landing, with an inset of the second stage reaching orbit at the same moment.

Constraints

sensor-only

Sensor-only flight

The autopilot reads only what a real flight computer could, then derives the rest itself: orbital elements, time to apoapsis, the landing burn, and a drag-aware prediction of where the booster will fall, the way real avionics would.

Used: onboard sensing

  • position & velocity (GPS / INS)
  • altitude & radar altitude
  • vertical speed & speed
  • mass, thrust, remaining fuel
  • attitude
  • an onboard atmosphere / drag model

Not used: game metadata

  • map-view apoapsis / periapsis
  • the game's predicted impact point
  • maneuver-node Δv
  • anything a real booster could not sense

Components

classical guidance
Interface
kRPC over TCP, RPC and telemetry streams
Guidance
vis-viva equation gravity-turn pitch program, suicide-burn solver
Control
PID loops slew-rate-limited attitude on reaction wheels (no gimbal)
Sensing
Onboard state only position, velocity, mass, thrust, fuel, attitude, radar altitude, in-house drag model
Mods
kRPC plus Physics Range Extender (keeps both stages simulated apart)
Tests
93 pytest tests over the pure-math guidance layer
Status
Verified across >25 flights booster returns upright and intact