Jump to content

KAPCOM - Arduino+Python+Telemachus modular hardware controller


lawnmowerlatte

Recommended Posts

I don't usually post on the forums, but I've been working on my controller for a while and thought I'd share. I started about a year ago and have been working in bursts when I have time and energy, but it's finally coming together. Unlike most projects I've seen, I'm using PyKSP and Telemachus to send fly by wire and receive telemetry directly from the game rather than using keypresses or KSP Serial IO. The primary reason for this was to accomplish cross platform support since I use both Mac and Linux.

One of the things I've tried to focus on is making this as modular and reusable as possible so other DIYers can use this as a base. Included in this project is an Arduino shield which can be used on a Mega 2560 or Uno to expose GVS (Ground-Vcc-Signal) headers which can be connected up to buttons, switches, etc. without the need for a custom board for each individual project. The Arduino sketch is close to zero configuration, it acts as a dumb hardware controller reading and writing pins based on serial input. The serial input is directed by a Python program which manages the flow of information from Telemachus to Arduino. The Python script is strongly OOP and uses a configuration file to create objects to control the hardware. Anything that Telemachus can read or write is available to have buttons or switches control it. Eventually this configuration file will be generated by an interactive script to make things even easier.

It's still a work in progress. I'm currently moving from Proof of Concept to Prototype stage. This means wiring up all my buttons and switches while I'm waiting for my PCBs to arrive and then mounting everything in a bigger shoebox. I've ordered 10 in case anyone is interested.

This is my first project like this and I've been learning on the fly, so I'm really excited to see it approaching something useful. It may not look as polished as some of the other projects I've seen posted on here, but it's still very much a work in progress. I'd love some feedback on how I can better make reusing my work easier for someone without an electronics/programming background.

Javascript is disabled. View full album

KAPCOM on Hackaday

KAPCOM on GitHub

KAPCOM on imgur

Full Demonstration:

Getting Started:

Edited by lawnmowerlatte
Added more links
Link to comment
Share on other sites

Wow man. Is that all functional for KSP? WOW!

To varying degrees. The joysticks work (except for 1 axis, there's a bad trace on the protoboard) and the buttons and displays are drivable from Python, but I haven't tested it with data from Telemachus yet. I had everything working about 3 months ago, but it was all written for the Arduino and I was using too much RAM when I added all of the devices together. I ended up scrapping/rewriting it all into Python. It's actually more functional now in some ways (it's more configurable, easier to work with and debug), but still a bit rough around the edges.

Link to comment
Share on other sites

I'm actually using 602p's pyksp module (with a few minor changes; I really have to send a pull request one of these days) to do the Telemachus interaction. My code basically binds the Arduino pin to an API call and defines specific behaviors for easily dealing with buttons, indicators, joysticks, displays, etc. I'm planning on making a video once I get my PCBs delivered and assembled, hopefully this weekend.

The green 7-segments come from a seller on Tindie. However, he's out of stock of the green ones at the moment. I actually was going to buy another, but he told me he is still waiting on his order of displays.

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

I just posted a series of videos showing how to get started with your hardware controller using KAPCOM software. I cover software prerequisites, loading the Arduino sketch, connecting via serial, using the included Python modules, setting up a configuration file and finally connecting to Kerbal Space Program and launching a rocket. I hope this is helpful!

Link to comment
Share on other sites

  • 2 weeks later...

Kudos on going down a completely different route. :)

I know some python - not much - so I think it's brave to go down a path that [comparatively] has little support.

Do you have any plans / vision for the final controller layout / enclosure?

Edited by Sputnix
left out some grammar xD
Link to comment
Share on other sites

Thanks! I don't know if I'd call it brave, so much as stubborn. At the time I started working, there were no cross-platform options available other than Telemachus. I knew I wanted to support Linux and Mac primarily, so I just ran with it. Despite major overhauls of how my code worked, I never switched for another mod. In retrospect, I'm glad I went this way; it is more flexible since it can be run on a remote machine. I'm going to set mine up on a Raspberry Pi so I can play on my TV wirelessly.

I do have a plan for an enclosure, but at this stage it's just a 3D model. Eventually I'll get around to mounting it all, but it hasn't been a priority. However, my shoebox is showing signs of strain, so I think I'll be working on this sooner rather than later.

Link to comment
Share on other sites

  • 9 months later...

Hi.

Thanks for this great mod. I'm very thrilled by the capabilities and the easy configuration, but stumbled over some obstacles.

 

 

The Arduino Mega 2560 has 54 digital pins, so I thought Pin 54 has to be A0. I found it at 160. Seems odd, but who really cares?

 

Thanks again.

I have an 3.2" LCDisplay connected.

Can you give me a hint on how to display information on that.

 

I managed to get everything working until Video Part3 2:18. There you lost me.

In my little test-setup I got only one thing. A poti to throttle at Analog-0. Worked fine in Part 2, p.getAnalog(), and the Pin set as 0xA0.

In your .json file, why is the PIN set to 164. In Part 2 it was at Analog-2.

 

I tried to understand, but gave up at some point and just configured mine like this:

{
            "api": "set_throttle",
            "type": "analogIn",
            "name": "Throttle",
            "pin": 0,
            "options": {
                "format": "floatpoint",
                "deadzone": 0.05,
                "invert": "False"
            }

}

Also tried "pin": 0xA0,

...

I started ksp, put some telemachus antenna at Kerbal-Xs hull. Then weird things happened. Telemachus works fine. I get a connection to the browser, giving me all infos, etc.

But as I try starting python kapcom.py via the command-shell, at nearly every try I get this:


Traceback (most recent call last):
  File "kapcom.py", line 429, in <module>
    main()
  File "kapcom.py", line 402, in main
    k = kapcom()
  File "kapcom.py", line 144, in __init__
    j   =   json.load(file)
  File "C:\Python27\lib\json\__init__.py", line 291, in load
    **kw)
  File "C:\Python27\lib\json\__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "C:\Python27\lib\json\decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python27\lib\json\decoder.py", line 382, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded


=======[ Stats ]=======
Cycles:        0

 

Only one time, I absolutely don't know, if I had done something different it worked and I got it started...fly by wire...OK....Waiting for input. But the Poit wasn't affecting the games throttle value. Tried for about half an hour, but can't reproduce it.

 

You have any guess?

 

Benji

Edited by Benji
typed localhost, not "localhost". One problem solved
Link to comment
Share on other sites

Tried to do something about the lag and got the baud up to 250000. But still lagged.

All my input devices will be hooked up to analog inputs. But I would like to display informations on an 3.2" LCDisplay. You think I can try to comment out some code in your python-files to speed things up?

Link to comment
Share on other sites

  • 3 months later...

Hey, sorry for resurrecting this, just wanted to know if it was still an active project, whether it works with the latest KSP, etc. Also, Sorry if this is a dumb question, I haven't looked too thoroughly at the files, but how do toggle switches work with this system? Buttons are fairly self explanatory, they work just like a keypress, but is a toggle switch input any different? (Think old style, shiny silver, guarded toggle switches.)

Edited by MarcRan17
Link to comment
Share on other sites

  • 3 weeks later...
On February 18, 2016 at 3:58 PM, Benji said:

Tried to do something about the lag and got the baud up to 250000. But still lagged.

All my input devices will be hooked up to analog inputs. But I would like to display informations on an 3.2" LCDisplay. You think I can try to comment out some code in your python-files to speed things up?

Yeah, I'm sure you can, there are definitely some optimizations that could be made. If you make any changes you think would be generally good, send me a pull request on GitHub.

Link to comment
Share on other sites

On June 16, 2016 at 3:11 AM, MarcRan17 said:

Hey, sorry for resurrecting this, just wanted to know if it was still an active project, whether it works with the latest KSP, etc. Also, Sorry if this is a dumb question, I haven't looked too thoroughly at the files, but how do toggle switches work with this system? Buttons are fairly self explanatory, they work just like a keypress, but is a toggle switch input any different? (Think old style, shiny silver, guarded toggle switches.)

Sorry, I've been away from the board for a while and haven't done much work on this lately. Since this project mainly depends on Telemachus, as long as that is updated it should be okay.

A toggle switch is a type of DigitalIn button, but the format would be either "true", "false', "zero" or "one" — that way it only triggers on on or off and sends a 'True', 'False', '0' or '1'. If you need to add something new, it's in `libraries/pin.py` under `_Pin.__str__()`

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