Back to all work
PROJECT / ksp-autopilot

Autonomous rockets 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. Two scripts do the work: one launches a vessel to a permanent, stable orbit; the other flies a booster back to a soft upright landing near the pad while the upper stage reaches orbit on the same flight. Verified in-game across 25 autonomous flights. A hobby project, not a product.

Python kRPC guidance & control PID / vis-viva no computer vision sensor-only

What it does

02 scripts
01 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 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.

Flight footage

second run / 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.

The constraint

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

Datasheet

classical guidance
Interface
kRPC over TCP, RPC and telemetry streams
Guidance
vis-viva 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 in-game booster recovered upright and intact