Delta-v calculator Kerbal Space Program

Tanmay Choudhary
Geek Culture
Published in
3 min readJul 31, 2021

--

https://www.kerbalspaceprogram.com/game/kerbal-space-program/

Hey there! Let’s do a fun project today. I am a big fan of the game Kerbal Space Program so I decided to make a python program that gives you the delta-v levels for a specific destination instead of referring to the maps repeatedly. So let’s get started!

The delta-v maps

https://www.deviantart.com/s13g3/art/Kerbal-Space-Program-Delta-v-map-Lights-out-626904855

Maps like these can tell you how much delta-v is it going to take. However, when you are building your vessel, I sometimes find it cumbersome to add all the values. So I decided to make a python version of this. For now we will only consider the delta-v required from Kerbin to other planets.

The code

Because we might want add other planets in another version of the code, I am going to make a class called Kerbin. I’ll use pandas to to store the values from the map.

class Kerbin:
dfNormal = pd.DataFrame({
"Mun": [3400, 860, 310, 580],
"Minmus": [3400, 1270, 160, 180],
"Eeloo": [3400, 3420, 1370, 620],
"Moho": [3400, 4230, 2410, 870],
"Eve": [3400, 1470, 1410, 8000],
"Duna": [3400, 1090, 610, 1450],
"Dres": [3400, 2570, 1290, 430],
"Jool": [3400, 2200, 2970, 14000]
}, index=["Kerbin Orbit", "Intercept", "Low Orbit", "Land"])

I decided to make some small functions for the future such as these:

def to_orbit(self):
return 3400
def to_keostationary_orbit(self):
return self.to_orbit + 1115

The last method will be “destination”. I decided to take the name of the destination, the stage, and the mode. The mode will decide if the delta-v levels will be cumulative or not. For that we must make the cumulative dataframe.

def __init__(self):
self.dfCumulative = self.dfNormal.copy()
for i in range(1, len(self.dfCumulative.index)):
self.dfCumulative.iloc[i] += self.dfCumulative.iloc[i-1]

This will make a copy of the original dataframe and then add the values of the previous row to the current row. So the value at “Low Orbit” should give the total delta-v required to go to low orbit of that body.

Now Let’s finish making the destination method:

def destination(self, name, stage, mode):
if mode == "normal":
print("Delta-v levels")
print(self.dfNormal[name]["Kerbin Orbit": stage])
if mode == "cumulative":
print("Cumulative delta-v levels")
print(self.dfCumulative[name]["Kerbin Orbit": stage])

This will give the delta-v values from the starting point to that stage for that particular body. In time more features will be added to make this a much more advanced program.

Test

This is the file structure I have:

- bodies
-kerbin.py
- main.py

The above code will go in kerbin.py and to test it let’s write some code in main.py. Let’s start by importing it:

from bodies.kerbin import Kerbinstart = Kerbin()

Now I’ll try to get the cumulative delta-v values for low orbit to jool.

start.destination("Jool", "Low Orbit", "cumulative")

This gives me the output:

Cumulative delta-v levels
Kerbin Orbit 3400
Intercept 5600
Low Orbit 8570
Name: Jool, dtype: int64

This looks good. Let’s find the delta-v to land on Duna.

start.destination("Duna", "Land", "cumulative")

Output:

Cumulative delta-v levels
Kerbin Orbit 3400
Intercept 4490
Low Orbit 5100
Land 6550
Name: Duna, dtype: int64

As you can see things are working fine.

So that’s it for this blog. I have uploaded the code on github and I’ll update it for more bodies but the basic code will remain the same. You can add features of your own and make it more to your liking. You can even add this to your system path so that you don’t need to open python every time you want to run it. If you liked this blog, follow me here. I write on topics such as programming and space so if you are interested in that, go check out my other blogs.

Thanks for reading!

--

--

Tanmay Choudhary
Geek Culture

Space exploration, AI and Flutter enthusiast. Aspiring aerospace engineer.