KSP, kOS, and Apollo Guidance Computer

Space flight have been computer controlled and/or computer assisted since first time man ventured to space. So what does this have to do with Kerbal Space Program? Surely there are computers on Kerbin, you can see that in the various buildings on KSC, as well as inside views of the cockpits and command modules. Also the unmanned probe control units are clearly computers.

But all the examples I have mentioned are just skins, it gives a realistic texture to the components in the game, but not much more. But that changed when I discovered the mod kOS: Scriptable Autopilot System. I will in a few posts describe my project to, to some extent, implement the AGC in KSP.

The Apollo Guidance Computer, or AGC, was a curiosity by itself. Everything about it was thought through, its amount of memory was calculated out of weight and program necesity, it was made just enough user friendly for the astronauts to give it the necessary instruction, and so forth.

First we have to look at kOS language. I am not going into details of the language, just some of the basic. The language have a very simple syntax, it have a set of basic algorithmic functions covering almost all the needs for the scripts (I had to figure out some workarounds where I got stuck), some reserved words, and an integration to the game internal API.

To make it simple, your local hard drive (game directory), is your KSP program server. You can run programs from there at any time as long as you have radio link back to KSP. You then install a computer module on your ship which is your space craft local computer. You can choose to have multiple computers on a ship if you want to run multiple tasks in paralell, but remember each aditional running computer will require more electrical energy, so adding too many would require more batteries and solar panels.

A hello world in kOS would look something like this:

// hello.ks

PRINT "Hello Space!".

This will just clear the screen and print the words “Hello Space!” on the screen, nothing more. A much more useful script would be a countdown, and this will introduce a few more advanced features.

// lib/countdown.ks
// A countdown to run in start of launch procedures
// Always to be executed from 0: 
PRINT "Counting down:".
FROM {local countdown is 10.} UNTIL countdown = 0 STEP {SET countdown to countdown - 1.} DO {
    PRINT "... " + countdown.
    HUDTEXT(countdown, 1, 4, 26, RED, False).
    WAIT 1. // pauses the script here for 1 second.
HUDTEXT("0", 3, 4, 26, RED, False).

I might be referring back to this script several times, as I use it in launch scripts to get a countdown on screen.

Add a Comment

Your email address will not be published. Required fields are marked *