Jump to content

My homebuild controller for KSP (Picture heavy)


Freshmeat

Recommended Posts

Soon after starting the wonderful adventure of Kerbal Space Program, I plugged in an old Logitech Dual Shock controller, as the keyboard was quite inadequate for fine control. A gamepad, however, does not come with a throttle, and the only separate throttle I could find was a Saitek priced at €100 :0.0:

However, it turned out that forum member zitronen had made a plugin for interfacing with an Arduino board: http://forum.kerbalspaceprogram.com/threads/66393-Hardware-Plugin-Arduino-based-physical-display-serial-port-io-tutorial-%2804-May%29. As the school where I am teaching bought some Arduino boards half a year ago, this could be a chance to finally learn to program the little buggers. If it turned out ok, I could invest in hardware myself, otherwise no harm would be done. Initial tests quickly decided that a throttle could be build in about 10 minutes, using already supplied code from zitronen. But his program hinted at several other interseting functions, so I started planning, buying, wiring, coding and learning a lot about the Arduino, eventually ending up with this:

P7014868_zps226781ca.jpg

This controller is made of an Arduino and the aforementioned Dual Shock that gave its life for the advance of all Kerbalkind. It has following functionality:

  1. Yaw/Pitch/Roll control. The Roll is the stick above left joystick. More on that later.
  2. Throttle slider with additional fine tuning slider far left, and killswitch.
  3. Translate all directions. Right joystick plus stick right hand side.
  4. RCS, SAS, Precision control, Light, Gear and Brakes controlled by switches. A led above the switch light up when function is activated.
  5. Pushbottons for Stage, Abort, Time Warp, Map mode and Camera control.
  6. Analog meters for Monopropellant, Battery (Either remaining charge or current drawn), Fuel (liquid or Xenon) and Radar Altitude (3km or 30 km max)
  7. Warning lights up upon a fast change in acceleration. This is handy as it always happens when a stage burns out. A pushbutton resets the warning.
  8. Warning lights up if either ascent or decent is going to fast or slow

    1. Ascent is measured against atmosphere terminal velocity, selectable by planet on a slider.
    2. Descent is to fast is you need more than .9 of your max acceleration to get to 0 m/s before you hit ground, or more than 7 m/s at less than 100m. Same slider as before also is used to indicate your acceleration (=(TWR-1)*g_current_body).

    3. Three additional warning lights and two pushbuttons are yet to have functions assigned.


      The layout of the wiring for the arduino is as below:
      controller_schem_zpse3b09c10.png
      This is the solder points on the gamepad:
      solderpoints_zpsc1cb6ff6.jpg
      Turns out that 3 and 5 are same, as well as 8 and 9. Also, a few buttons is missing in above table, but the principle is far more important than the actual numbers. Had I needed more buttons, I would have torn apart a keyboard from a junkyard, locally they go for around €4. Anyway, it is fairly straightforward to solder wire to the points, and then to the relevant pushbuttons. Two microswitches sit on either side of the small wooden stick that controls RCS forward/back for a digital joystick.
      My workbench:
      DSC_0004_zps3f44a78a.jpg
      Mounting is done after painting, so the board is lifted on blocks covered in cloth. I have no acces to PCB, so the resistors are soldered to nails in a chipboard. Surprisingly, it works. I am very happy I invested in ten different colors of wire, though. Note the wires soldered to the gamepad as described above.
      The onedimensional roll stick was made of a 10k potmeter, springs from a couple of ballpens and some wood:
      DSC_0007_zps334c331e.jpg
      Assembly like this:
      DSC_0016_zpsdb9e92ec.jpg
      It is a bit hard to control, I think that a better rounding of the bottom would have been good. Perfectly adequate for roll, though.
      P7014867_zps10bcd2fe.jpg
      Above label is printed on some label sheets I had lying around and cut to size, The transparent labels are made with a DYMO. The box itself is wood, the top is paneling of some kind bought cheap in a DIY shop (a miscut, got 50 cm x 150 cm for €4), spraypainted with grey primer.
      For code, I took zitronens code and modified it to my own use. As they are, they are hardly useful for anybody, but a few things to note:
      The switches are set in groups in parallel, each with a unique resistor. That makes it possible to read a value on an analogue pin and assign the relevant controls for the activated switches. In order to activate diodes, a given control is activated when the circuit to the analogue pin is broken.
      I bought my meters as very cheap (€3) analog meters 0-1 mA. The turned out to react nonlinear to a PWM pin, so I made a few readings of PWM vs meter and made a 5th order polynomial fit. Works fine. Additionally, the radar altitude is on a logarithmic scale in the code to cover precision at low altitude with higher range.
      The change in acceleration is checked by storing current acceleration every 100 ms. The program checks against the previous value, and if the difference is above 0.1 G, the warning led is turned on. I tried to make and exception if the throttle had been moved, but for some reason it does not work. Investigations pending.
      Change in battery level is done against last packet, and divided by gametime since last packet.
      The ascent warning is done in a piece of code like this:

      if (WarnSelect == true && 6*planet[planetSelect][1] > VData.Alt){ //-----------Only for low altitudes
      if (VData.Vsurf > 1.1*sqrt(912400/planet[planetSelect][0]/pow(2.718,(-VData.Alt/planet[planetSelect][1])))) {
      digitalWrite(VHLED,HIGH); //------too fast
      digitalWrite(VLLED,LOW);
      }
      else if (VData.Vsurf < 0.9*sqrt(912400/planet[planetSelect][0]/pow(2.718,(-VData.Alt/planet[planetSelect][1])))) {
      digitalWrite(VHLED,LOW); //-----too slow
      digitalWrite(VLLED,HIGH);
      }
      else {
      digitalWrite(VHLED,LOW); //-----just right
      digitalWrite(VLLED,LOW);
      }
      }
        int planet[5][2] = { {66,3000}, {293,7000}, {1874,10000}, {100,5000}, {99,4000}};

      the planet[][] array is acceleration of gravity divided by ground level pressure, and scale height ot atmosphere, by planets with atmosphere. The wiki has more information on the subject:http://wiki.kerbalspaceprogram.com/wiki/Atmosphere
      The descent code looks like this, and continues above if statement:

      else if (WarnSelect == false && 6*planet[planetSelect][1] > VData.Alt) { //----------Low altitudes only
      if (abs(VData.VVI) > 0.6*sqrt(2*maxAcc*VData.RAlt)){ // Too fast
      digitalWrite(VHLED,HIGH);
      digitalWrite(VLLED,LOW);
      }
      else if (abs(VData.VVI) < 0.4*sqrt(2*maxAcc*VData.RAlt) && VData.RAlt > 100){ // Too slow
      digitalWrite(VHLED,LOW);
      digitalWrite(VLLED,HIGH);
      }
      else if (abs(VData.VVI) > 7 && VData.RAlt <= 100) { //------- Very low altitude
      digitalWrite(VHLED,HIGH);
      digitalWrite(VLLED,LOW);
      }
      else {
      digitalWrite(VHLED,LOW); // Just right
      digitalWrite(VLLED,LOW);
      }
      }
       //-----------Descent warning--------------Note: VVI is negative downwards, hence abs()-------

      The relevant check is Galileis law of falling bodies, with some factors in front for safety. I might change the 0.6 and 0.4 to get more fuel efficient landings when I get more comfortable with the system.
      It goes without saying that I could not have done this without zitronens plugin, nor his fast response to my questions. Another great source of help was reading Mulbins posts in the same thread, as he asked the questions I needed to before I even thought about them, as well as his own kick-ass controller:
      http://forum.kerbalspaceprogram.com/threads/66742-Custom-hardware-control-switch-panel-simpit-WIP
      Further inspiration was found in Mulbins thread on custom controllers:
      http://forum.kerbalspaceprogram.com/threads/66763-Custom-hardware-simpit-repository-For-people-who-take-KSP-a-little-too-far?p=920499#post920499
      For people thinking this was an achievement, I would say it is a lot of individual components, but each component is pretty simple. The circuits should be understood by any high schooler, and the programming is dumbed down C, with plenty of examples to learn from on the Arduino homepage. So if you want to, just do it.
Link to comment
Share on other sites

Very nice, clean layout. I like the use of the analog meters. I'm toying around with the idea of doing this myself... bought an Arduino Due against my better judgement that I'm trying to learn, and now I'm trying to scavenge some parts out of the remote to one of those little helicopters. Can't get the stupid solder out of the pieces I want even with a wick and a pump. *headdesk* lol

Link to comment
Share on other sites

KSP is a game that really could benefit from a custom set up like this. And while I am only a little intimidated by the physical construction (particularly soldering; I solder and braze a lot for appliances, but for some reason those skills do not transfer to electronic work :P) I am very intimidated by the programming. The furthest I've gone was a Fahrenheit/Celsius converter that I copied line for line out of a programming for dummies book. Needles to say it scared me off. I respect the talent, I just wish I could find someone on the forum who enjoys doing this sorta thing as a hobby and would be willing to make one for a reasonable purchase price... hint hint :wink: lol

Link to comment
Share on other sites

KSP is a game that really could benefit from a custom set up like this. And while I am only a little intimidated by the physical construction (particularly soldering; I solder and braze a lot for appliances, but for some reason those skills do not transfer to electronic work :P) I am very intimidated by the programming. The furthest I've gone was a Fahrenheit/Celsius converter that I copied line for line out of a programming for dummies book. Needles to say it scared me off. I respect the talent, I just wish I could find someone on the forum who enjoys doing this sorta thing as a hobby and would be willing to make one for a reasonable purchase price... hint hint :wink: lol

Haha I already tried bribing Luis and it didn't work. I'm not even that worried about the programming part, it's not my strongsuit but I'll figure it out. This whole messing around with tiny sharp hot things and liquid metal is for the birds.

Link to comment
Share on other sites

@Moeggz: If you do a setup like mine, I can send you the code I use, if it is OK with zitronen. And a couple of small debugging pieces of code to figure out what you need to change. I go on holiday in a couple of weeks, but afterwards we can probably figure it out.

@MR4Y: I originally wanted to do a throttle, but this setup gives me finer control. If you want a throttle, you just use a rotary potmeter with a stick instead of sliders. It could be done as standalone in a couple of hours and the time it takes for paint to dry. The code would work out of the box.

Link to comment
Share on other sites

Nice! I certainly applaud anyone who takes the time to do some really nice electronics work. It's something I could do, but often don't have the patience for. I like it!

I think if I made a control panel, I'd probably hack up a keyboard and use momentary switches, soldered to specific key contacts in the keyboard. Cheaper/easier, to a point, but of course doesn't allow for any outputs on the panel (displays, meaningful lights, etc), or toggles.

Link to comment
Share on other sites

Wow, that's really incredible! I bet it flies like a dream once you get used to it! I wonder if there's a way you could set up some little vibrationy things like the ones they have in console game controllers to go off inside the board when you crash? Just for that extra bit of realism.

Link to comment
Share on other sites

Very nice, OP!

May I make a suggestion? A very Kerbal button indeed. It should be labelled "Cheese it!" and would throw throttle to max, stage everything at once, pop all chutes, extend all ladder legs and antennas, open all science projects and solar panels, and slam on any wheel brakes.

Perfect for when everything is lost to make it more lost in the most Kerbal way possible. :)

Link to comment
Share on other sites

I was just looking thru the KSP facebook post about custom controllers...For yours I had a thought. You could mount inside of it three speakers... two mid-highs (even down to a 2-3 inch size for fitment) and one larger one for bass (5-6 inch). All could be powered by one tiny 60W amp.

Once thats done it would make the noise of the rocket, and the bass speaker would very well make it vibrate to all ends, thus a more engaging interaction with it.

Come to think of it, you could skip the bass speaker and just attach a low profile Shaker to the inside and get the bass that way.

Link to comment
Share on other sites

What was your total time and money investment in this project from concept to finished product?

From original idea, a couple of months. Actual time spent construction and coding is estimated some 30 hours, starting from "What is an Arduino?". As I said, zitronens thread is extremely helpful, and I made a foot pedal board for DayZ from an old keyboard and some game switches last year, so I had some know-how.

The price tag ended rather hefty, because I had no electronics parts to start with but my soldering iron. I had to get wire, resistors, leds, everything. I did not know about cheap alternatives to the original Arduino brand (Mulbin uses a Fundino with good results). Further, I changed design a couple of times, so I have some stuff left over. That, and bying locally, ended up at a €150 price tag. If you go EBay and have a bit of equipment to start with, I reckon it would be half that. I plan to do an upper bar for controlling action groups and a couple of displays, and I think I can do that for €50, even including a clone of the Mega board.

@smalldiaphragms: There is absolutely no space left under the hood. I mounted everything on the backside of the panel for easy acces and hardware debugging, so the area in the middel is the Arduino, below the blue buttons is resistors for the swithes, above them resistors for leds, the entire right hand side is the gamepad and my joysticks.

For some reason yellow notes have problems sticking to the surface. I found out during debugging, when I tried to use it to label my switches. Snacks, however are always within reach, and the design includes enough space for a cup of coffee or glass of wine beside the setup.

Link to comment
Share on other sites

I'm making my own controller, and I was wondering how you got access to things like camera control and time warp control. Did you have to edit zitronen's plugin, or is there some way to do that already?

These where made by utilizing the controller. I am unfortunately out of bandwith for the pictures, but it showed the points where I soldered wires directly to the print. Then I just set it up directly in KSP. However, the Arduino has a keyboard libary that allows it to send a keypress to the PC. So it should be relatively easy to do directly from the arduino by sending the appropriate key stroke, e.g. sending an "m" when you want to change map view, or "." to increase time warp.

No matter what you do, you will have to modify the code zitronen wrote. It is however reasonably well laid out and very well documented.

Link to comment
Share on other sites

All your images are exceeding bandwidth and will not show. Photobucket is not very good IMHO and I would suggest imgur. There is better forum support for imgur albums and I`ve not seen`bandwidth exceeded` on any images.

Please, don't use Photobucket again. It displays the bandwidth limit exceeded instead of the picture. Use imgur instead

Saw this as I was typing, hehe.

Link to comment
Share on other sites

These where made by utilizing the controller. I am unfortunately out of bandwith for the pictures, but it showed the points where I soldered wires directly to the print. Then I just set it up directly in KSP. However, the Arduino has a keyboard libary that allows it to send a keypress to the PC. So it should be relatively easy to do directly from the arduino by sending the appropriate key stroke, e.g. sending an "m" when you want to change map view, or "." to increase time warp.

No matter what you do, you will have to modify the code zitronen wrote. It is however reasonably well laid out and very well documented.

Oh wow I didn't know that the arduino could send keystrokes! A new door of possibilities has opened! Thanks!

EDIT: Wait, will key presses work with the Arduino Uno?

Edited by jandcando
Link to comment
Share on other sites

No, you will need Arduino Leonardo or clone (like teensy 3.1) for key strokes.

Edit: It won't work by default, but it looks like people have been able to get it to work. Do a search on uno usb hid keyboard.

Edited by zitronen
Link to comment
Share on other sites

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...