Jump to content

WIP - Custom Hardware Control Panel


KK4TEE

Recommended Posts

nEyCCoMh.jpg

I've been working on this for a couple of months and finally got to the point where it is almost useable, so I thought I'd share. It started as a desire to have a real "Launch" button to press to send off my space ships in Kerbal Space Program, but as evolved into much more.

I've built an Arduino based control board that can receive information from KSP and display it on analog gauges, as well as read button presses and toggle switches and press keyboard keys to activate things like staging or SAS.

This is my first Arduino Project, first Python project, first time soldering, and first KSP modding attempt. It has been, and continues to be, an enormous amount of fun!

The hardest part of this project was figuring out how to get flight information from KSP out to an Arduino over a serial connection. At first I tried to write a plugin for KSP that would print values to a serial port directly, but I quickly became overwhelmed and decided to try another approach.

I then tried to find a way to use information from Telemachus, but I couldn't figure out how to parse the server to get individual bits of flight data instead of a graph. I'm fairly sure it can be done, but I'm new at all of this and couldn't figure it out yet.

I ended up finding a mod (Flight Recorder) that would save flight information to a CSV file every 200ms. I then wrote a Python program to parse the CSV file, create a dictionary using the headers (Mission time, altitude, Geeforce, etc) and then read the last line of the file for the values to add to the dictionary keys. It then formats it as a string and prints the values to the serial port with a newline character at the end.

Sadly Flight Recorder doesn't (yet) record resource usage, so I had to experiment using kOS to log that information to a separate CSV file. This actually works great for a few minutes, but I don't think kOS was really meant to write to a file 5 times per second. It seems to develop a memory leak and crashes the game fairly quickly.

Reading toggle switch states and keypad buttons into KSP was actually fairly easy. I used an Arduino Micro setup as a USB HID Keyboard to press a pre-programed key based on which toggle switch was flipped. When I press the yellow "Stage" button the arduino sends a "Space" character from the keyboard. When I press the blue SAS button it presses "t" as a keyboard.

The tablet computer (or any device with a web browser) is able to view a simple HTML page generated by the python program. The python program calls a set of functions that print HTML headers to a file, then print the dictionary that stores the most recent flight information, then print the trailing HTML. I got the idea of doing it this way from one of the other mods that was like Flight Recorder (but sadly I can't remember what it was called). Basically the table formatting doesn't change, so you just print the HTML code in between each call to print a piece of flight data. The resulting HTML file is then served via an Apache webserver that I have on my computer, which can be accessed by any other computer on the LAN (or internet, if you setup port forwarding). My code for this doesn't work very well yet, which is why I ended up using a lot of place holders so far. I'm still learning how to prevent extra "\" characters from showing up, as well as odd spacings, among other things. Once it is useable I'll add it to the github page.

Here is a part list of most of the things I needed for the project, not including tools:

The pelican case and waterproof connectors were probably the most expensive bits.

1x Pelican 1200 Case

1x Arduino Micro (for reading the button states)

1x Arduino Mega (for driving all of the displays)

5x Colored LED Angel Eye buttons from spark fun (product 11966)

2x Power Symbol LED button from eBay

Various LEDs and resistors that I got from kits on Amazon and Radioshack

1x "4x5 keys metal panel" keypad from eBay/China. It has removable caps so you can print your own labels ("Map View" for example)

2x 12 position rotary switch "Amico Split Shaft" from Amazon, with knob. These weren't as useful as I had anticipated. I wanted to use them to set individual time warp levels (1x, 5x, 10x, etc) but I don't know how to pass that into KSP.

8x 5v Voltmeter from sparkfun. These were more cube shaped than I anticipated, but work fairly well and feature swappable backgrounds so I can label them "Liquid Fuel" or "Electric Charge" instead of "Volts".

5x Eight digit 7 segment display with serial interface (kit). I'll use these to output Altitude, Periapsis, Apoapsis, Current Velocity, and Radar Altimeter or MET. The serial interface is used to save pins on the Arduino.

5x Covered Toggle Switch w/ LED (Missile Cover) from Sparkfun. Smaller than expected, but they do allow you to toggle the LED separately from the switch.

1x "On/Off Key Switch with 2 Round Keys" from Amazon. The one from Sparkfun looked kind of cheap, so I bought a larger higher current one from Amazon.

2x SB400 Solderable breadboard from Amazon. I only used one, but I ordered a second just in case I messed up.

-- Various USB cable adapters.

4x 1/8"x12"x12" Polycarbonate sheets from Amazon to act as the mounting surface.

LM2587 DC/DC Booster Converter Voltage Regulator from Amazon. This converts 5v USB power to 9v for the LEDs buttons and future desk lamp.

5x TIP120 Transistor from Amazon to switch the 9V supply for LEDs. The idea is so that when a ship runs low on Electric Charge the Arduino will quickly flicker the LEDs to simulate low power. It also lets me dim all of the various displays/LEDs depending on how bright I want them to be.

1x 4x20 Character LCD w/ Serial interface from eBay. This will display anything that I don't feel like having a dedicated display for.

1x Waterproof USB connector from usbfirewire.com. The first one had a defect with the cap, but their customer service was very good and they sent a replacement via next day air.

1x CAT6 Waterproof connector from Amazon.

1x Box of military surplus gauges from eBay. I ended up getting some cool ones including the ones pictured in the album and one multi gauge labeled a "Bat-o-Meter". It turned out to be used for testing batteries, not seeing how close you are to Gotham City.

Imugur Link with more pics: http://imgur.com/a/iF0sT

Reddit Link w/ some discussion: http://www.reddit.com/r/KerbalSpaceProgram/comments/1s1hn6/my_custom_ksp_control_board/

I've put my code up on github under a GPLv3 license in case anyone is interested in doing a similar project for themselves.

https://github.com/KK4TEE/Control-Panel

If anyone knows of a plugin for KSP that can print serial output, please let me know! My eventual goal is to get a KSP plugin in C# that can send data out a serial port directly, but I have a lot to learn still before I can code that myself. Thanks, and enjoy!

Link to comment
Share on other sites

You can access individual data values from Telemachus using the appropriate URL; an example is given below.


http://[B]127.0.0.1:8085[/B]/telemachus/datalink?alt=[B]v.altitude[/B]&pd=[B]v.dynamicPressure[/B]

This will return a JSON formatted string with the requested values.

Link to comment
Share on other sites

2x 12 position rotary switch "Amico Split Shaft" from Amazon, with knob. These weren't as useful as I had anticipated. I wanted to use them to set individual time warp levels (1x, 5x, 10x, etc) but I don't know how to pass that into KSP.

Very nice work!

If I understand correctly, these rotary switches work by powering each individual terminal/pin on the back according to the chosen setting. The power is supplied to the pole, which passes it on to said pin.

You could differentiate output to the Arduino by soldering a resistor of different resistance to each pin. By using an analog input on the Arduino, you can figure out which way the switch is turned. After that you can work with the assumption that you start at warp 0x. Each time you switch up one level, the Arduino passes ">" to KSP, and each time you switch down one level, KSP recieves "<".

Edit: One problem I see is when you are not allowed to use a higher warp by KSP due to altitude. There is no way I know of to relay that back to the Arduino, although I see that you posted a possible solution on Reddit by turning warp to 0 and back to the desired level each time the switch changes position. That way you will get the highest possible warp level every time you set it to that level or higher.

Edited by Camacha
Link to comment
Share on other sites

2x 12 position rotary switch "Amico Split Shaft" from Amazon, with knob. These weren't as useful as I had anticipated. I wanted to use them to set individual time warp levels (1x, 5x, 10x, etc) but I don't know how to pass that into KSP.

I think this is similar to what you want to do. This is a tutorial for interfacing a rotary encoder to a Trinket Arduino to create a volume knob

http://learn.adafruit.com/trinket-usb-volume-knob?view=all

The example has it emitting text strings for "volume up" or "volume down" through the serial port. Like Camacha says, you can replace that with ">" or "<"

This is an example of reading a set of momentary-contact switches with a single Arduino analog input pin by using different resistors on each button

http://tronixstuff.com/2011/01/11/tutorial-using-analog-input-for-multiple-buttons/

This is similar to what Camacha was talking about with resistors on a rotary switch.

Edited by nyrath
Link to comment
Share on other sites

nyrath and Camacha: Thanks for the tips for interfacing the 12 position knob. I tried my hand at soldering the first one in a resistor chain to use an analog pin and almost butchered it, but it now seems to be working alright. I'll try adding the time-warp controls to my program when I switch the data feed from Flight Recorder to Telemachus. The example code in the links was very helpful.

Moach: That's a nice battlestation you've got! Among other things I like the way you have the Logitech and throttle control setup for easy access on the left. I'm looking forward to adding a SpaceNavigator to my setup once KSP supports it, and I'm hoping it will work with Star Citizen as well.

I'll try to make a video of the setup in action once I get the gauges working a little more reliably. I need to solder in some resistors or install a voltage regulator for the gauges because the raw USB power seems to fluctuate depending on if the backlights are on or not. If the lights are on the gauges droop down about 10%, throwing the readings off. I'm planing on putting a 5v regulator after my 9v up-converter so that I get a very stable 5v for gauges and Arduino in addition to 9V for the lights. Hopefully I'll be able to work on that some this weekend.

Link to comment
Share on other sites

Thanks Rich. That should help me out a lot. I'm looking forward to learning about JSON strings now.

You are using Python, correct? If so, there is a Python library that can parse JSON strings for you.

JSON parser documentation

http://docs.python.org/2/library/json.html

Example

http://stackoverflow.com/questions/8220748/parsing-json-python

Link to comment
Share on other sites

  • 1 month later...

Wow, this is fantastic.

I'm currently building a custom switch panel for KSP using on/off toggle switches which will be run through a pulse generator board (off the shelf, specifically for flight sim building http://www.desktopaviator.com/Products/Model_2120/index.htm) but once this first panel is completed I was considering buying an Arduino for gauges... I will have to download your code! Would it be ok to get some hints from you when I finally get to this stage?

I'll post up my control panel in a new thread as I build it soon... just waiting on a delivery of switches to start construction!

Also I was wondering what type of switch you are using... are you using single state switches that stay locked in the "on" position as I plan to? If so have you found a way to convert the constant "on" signal to a button press with Arduino? If not I'll stick with the pulse generator which achieves this effect... just that Arduino is cheaper :)

Link to comment
Share on other sites

  • 3 weeks later...
This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...