Video coming soon!
I started playing Kerbal Space Program several years ago, and it immediately captivated me. There is something undeniably special about this game which has gained a huge cult following in a few short years. It taught me a lot about space, and it has had a huge influence on my own goals and aspirations.
For a while I've seen some people online making their own Kerbal Consoles. Here are a few awesome examples:
- https://www.instructables.com/Kerbal-Controller-the-Basics/
- https://www.reddit.com/r/KerbalControllers/comments/uuqe58/introducing_untitled_space_craft_a_customizable/
The idea behind these projects is to create a physical console which can be used to pilot aircraft and spacecraft in the game. Many are inspired by the aesthetics of the kinds of consoles you would see in NASA Mission Control. Each console is made to ones own preferences, but most feature joysticks to control roll, pitch, & yaw, a throttle, and lots of buttons or switches to activate different parts such as landing gear or lights. Additionally, many consoles display information from the game as well such as altitude or velocity.
I have never had much of a background in electronics or programming, but I always wanted to make a project like this. Once I had the opportunity to make an electronics project as part of ENGI 301 - Practical Engineering Engineering at Rice University, I figured this would be perfect. It's a challenging project, but something I am very interested in.
I started by doing my research and finding lots of examples. My biggest mistake in the whole project was not doing this more thoroughly - I could have saved a lot of time if I started with the right programs. I don't know how to create Mods, so I was dependent on an open source project which had already developed one. It turns out that there are a lot of these!
The first one I went with was KSPSerialIO: https://www.instructables.com/KerbalController-a-Custom-Control-Panel-for-Rocket/. I spend a week or so trying to get this to work on an arduino. I downloaded the mod, but I just couldn't get anything to work right. I looked at the documentation over and over again to make sure I wasn't missing anything. Then I finally saw it. "Made compatible for Mac". Nothing about Windows. Whoops - back to square one. If you use a Mac and want to use an Arduino, this is probably still worth checking out, though it seems that it may not have been updated in a while.
Next I tried one called Kerbal Simpit: https://forum.kerbalspaceprogram.com/index.php?/topic/204852-112x-simpit-revamped-simpit-20/ This one actually works on Windows, and has an active community! This is where I put most of my time working on the project. I plugged in my arduino and actually got it to work! There is great documentation for this, as well as some example arduino codes. Here is a picture of using a basic button to trigger the Launch Abort System in the game.
Now that I knew the mod and Arduino library worked, all I needed to do was get it working on my PocketBeagle! I had the scripts for the arduino library, so I just needed to translate everything to python. Easy!
4 weeks later I was struggling. I had translated a lot of the library into python, but it was still riddled with errors and refused to connect to the game. I learned that c++ and python both handle data in very different ways, and turning one into the other just doesn't work out. With only a day left to complete the project, I made a difficult decision and started over with a new Mod. Back to square one.
After more digging, I finally came across kRPC. https://github.com/krpc/krpc This system actually has a python library! All I had to do was import it in my program and call the correct functions. I think it took so long to find because kRPC is most commonly used to write programs in python to make predetermined paths, rather than build controllers. For example, you could use it to write a program that automatically lands a rocket like a Falcon 9 booster, using data from the game about drag, remaining fuel, vehicle altitude and velocity, etc etc.
I installed the mod, installed the python library, and it only took 4 lines of code to connect! It took a bit of trouble shooting with the server in the game, but eventually I got my program to read out the name of the rocket on the launchpad! I wired up my switch and got it to launch!
I only had time to implement a few core features to get a rocket off of the ground, but I plan on finishing it as soon as I have time. There is lots I want to do with this. I also need to clean up the wiring and make a nice looking box for all of the components - what I have now is just a prototype.
The code works using the kRPC functions. After everything is initialized and a connection with the game is established, it cycles between sending and collecting data. Currently the collecting functions are disabled, as the refresh rate on the LCD display is too slow - something I'll fix later. It checks through the states of all of the buttons and switches and potentiometers and updates the controls for each one. This repeats until the connection is lost.
To initiate it a connection, the server needs to be started in the game. See the kRPC documentation page for more details on this. Next, a rocket needs to be on the launch pad for the program to connect. After this is all ready in game, the python script is started using sudo./run. It should connect automatically - once it does it will read out the name of the vessel. Don't worry about all of the error messages - these will be fixed later. Anything that is not yet wired up has its code commented out. A full list of the pins to be used is found on configure_pins.sh.
Comments