Page 1 of 3 123 LastLast
Results 1 to 10 of 27

Thread: My homebuild controller for KSP (Picture heavy)

  1. #1

    My homebuild controller for KSP (Picture heavy)

    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

    However, it turned out that forum member zitronen had made a plugin for interfacing with an Arduino board: http://forum.kerbalspaceprogram.com/...l-%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:


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

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


    The layout of the wiring for the arduino is as below:

    This is the solder points on the gamepad:

    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:


    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:


    Assembly like this:

    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.





    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:
    Code:
      int planet[5][2] = { {66,3000}, {293,7000}, {1874,10000}, {100,5000}, {99,4000}};
      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);
        }      
      }
    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:
    Code:
     //-----------Descent warning--------------Note: VVI is negative downwards, hence abs()-------
      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);
        }  
      }
    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/...nel-simpit-WIP

    Further inspiration was found in Mulbins thread on custom controllers:
    http://forum.kerbalspaceprogram.com/...499#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.

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

  3. #3
    Spacecraft Engineer moeggz's Avatar
    Join Date
    Mar 2014
    Location
    Hudson Valley Area
    Posts
    111
    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 ) 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 lol
    PSA at KSP Read as Cave Johnson: A reminder that helmets shouldn’t be removed for any purpose on EVA, however tempting. Yes that includes snacks. Good news, new space helmets will feed snacks to you like a baby, rocket noises for the spoon included. We are on our third maker of only 3 companies. So unless you want Jeb’s "helmets" which are taped on fishbowls leave your helmets attached. Thank- Oh, apparently funerals are cheaper than the fancy space hats, so disregard this. Thanks, Kave out.

  4. #4
    Quote Originally Posted by moeggz View Post
    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 ) 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 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.

  5. #5
    Banned
    Join Date
    May 2013
    Location
    Araras, São Paulo - Brazil.
    Posts
    1,263
    Hm...I would only change some controls to be more plane like. Like a huge throttle lever for instance.

  6. #6
    @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.

  7. #7
    Modkippy Christmas! Rainbowtrout's Avatar
    Join Date
    Apr 2013
    Location
    United Kingdom
    Twitter
    @lewisandatrout
    Posts
    857
    Blog Entries
    10
    Nice! Now all you need is a rocket to go with it!
    I would like realism. But, I want a fun game.

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

  9. #9

  10. #10
    The analog gauges and sliders are absolutely lovely, and the whole concept is a winner.

    Just image how the controls and panels on Mercury/Apollo crafts looked like ...

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •