2015-11-21

K-42 Part 6: Iterations and reiterations

This post is a repost of a blog entry from 12th November 2015 on Kerbal Space Program forum (soon to be defunct).

The K-42 project have been on the back burner for a while due to a near rage quit.

I had the whole thing up and running and all seemed well until I actually started playing the game. I experienced crashes all the time and couldn't quite figure out what caused them. Every time I tried to fly a mission, the game crashed after around 2-10 minutes of play time.

I tried to remove all mods except KSPserialIO, it still crashed. I thought it might be due to sending control packets asyncronously so I limited the send rate to be the same as the receive rate. It became a tiny bit more stable. I removed the control packets totally and implemented the whole thing as two joystick controls with 20 buttons each and only used KSPserialIO to get output from the game. Still crashing. I decreased update frequency and transmision speed and thought problem solved, but noooo, crashes came less frequent but seemed to be proportional to the total amount of packets sent by the mod.

So, as it is never too late to give up, i decided to make a tactical retreat and forget about KSPserialIO.

Next choice was Telemachus. Looked nice but I would need to build a demon that read json data and translated it into a serial byte stream. I started to look for information about using web sockets and json when I discovered a mod that could make my life much easier, kRPC.

Why parse json when you can use a Python lib to read parameters from KSP by simple functions and variables? That was exactly what kRPC was about. All I had to do was to install kRPC, a Python interpreter, a serial communication library and ... learn Python.

Four days into the process I have a working daemon transferring data from KSP to my command panel.

All there is left to do now is to test if it is stable. Please wish me luck.

K-42 Part 5: The Master Control Program

This post is a repost of a blog entry from 26th September 2015 on Kerbal Space Program forum (soon to be defunct).

I've finally mangled the bugs out of the basic software for the Kommodore-42 master control unit. There is still no real functionality in the guidance computer, but it looks like the rest works as planned. As all this has been a learning project, the code is a bit ugly and could use a cleanup in a few places. I will also have to try to optimize the memory use as I have only 2.5 kB EEPROM left.

In order to make it play well with Kerbal I've had to use all the tricks available in that litte Atmega 32u4. I use the serial emulation and the keyboard emulation for the switches. In order to get the joysticks to work well with SAS I had to add joystick emulation as well as sending joystick commands over the KSPserialIO mod caused SAS to cease working until it was turned off and on again.

There is still room for a lot of expansion as I still have 2 action groups, 17 key combinations, 29 joystick buttons, 3 rotational joystick axes and 119 I2C adresses left for future use. The future is full of possibilities but now I'm going to play the game for a few weeks.

Source Code:
https://drive.google.com/open?id=0B5...TdvNkNWYnY2ZDQ

P.S. I also added two LEDs to the Engine and chute module that serves as indicators when it is safe to deply the chutes. I will add a picture, description and the new source code some other day as it's getting really late while I'm writing this.

P.P.S. I've decided that all source code and design of my control panel is licensed with the WTFPL version 2 as quoted below:
            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
                    Version 2, December 2004

 Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>

 Everyone is permitted to copy and distribute verbatim or modified
 copies of this license document, and changing it is allowed as long
 as the name is changed.

            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  0. You just DO WHAT THE FUCK YOU WANT TO.

K-42 The hardware, part 4: Alarm module and Guidance Computer

This post is a repost of a blog entry from 26th September 2015 on Kerbal Space Program forum (soon to be defunct).


The Alarm Module 
The alarm module took a little time to complete as it was the only module able to receive commands from the master over I2C. There's a command to light up alarms, to blink them and to set off the master alarm. It is also able to generate simple sounds other than the master alarm signal but those are limited to periodic beeps with a single frequency. I've used the beep to indicate radar altitude when in landing mode which make it easier to estimate distance to ground while monitoring vertical speed.
If the master does not poll the state of the alarm module often enough the computer alarm lights up and if the delay is more than 15 seconds it sounds the master alarm.
Source code: 
https://drive.google.com/open?id=0B5...HpIS0x6REItVVE

 

The Guidance Computer

The guidance computer is made up of two modules, one input module and one display module. They contain very little processing ability and are in all respects just IO units.

The input module contains a home brewed matrix keyboard and four switches. The switches are read over I2C as for all other modules but the keyboard sends ASCII over the serial TX line to the master.

The display module is simply a serial terminal that can parse simple commands embedded in the string sent to it. All commands starts and ends with a single backslash as it is not possible to print a backslash on the display anyway and I couldn't think of a reason to print the Yen sign that has substituted it.

The most common commands (those I've actually used) are as follows:

  • "\W\" - Wipe (clear) all displays.
  • "\w\" - Wipe current display only.
  • "\Dn\" - Select deisplay where n is the display number, 0-2.
  • "\Cxx:yy\" - Set cursor to character position xx on line yy on current display.
  • "\B\" - Display cursor as a blinking block.
  • "\b\" - Hide cursor.
Source code:
https://drive.google.com/open?id=0B5...Gw3WUJHZThyY00