Today I've been coding a bit on my KSP Control Center project. It's so far just 11 buttons, three SPI-controlled LED-displays and an analouge gauge, but it's getting closer to something more "real" every day.

It's for playing Kerbal Space Program, one of my favourite games. Heres a video of me showing of some of the new displays.

The three position switch in the video is for going between surface, target and orbital velocity. The code's on my github for anyone interested.

I store all my photos on my Fileserver. I am using an android application called Foldersync to sync all my photos as soon as I connect to my homes wifi.
This means I've got a huge folder filled with photos that rarely gets sorted properly.
This is about to change, I've created a script which can find which date the photo was taken and move it to the corresponding folder. It's a fairly simple program, it uses Identify along with awk and friends to figure out the date. I will most likely rewrite it in some other language in the future since this script is a bit barebones.
This script runs as a cronjob each night.

#!/usr/bin/env bash
/usr/local/bin/ /export/Mnt/Photos/sort /export/Mnt/Photos/. &> /root/sortphoto.log

I still need to figure out how to make my camera autoupload photos to that folder though.

I'm redoing my whole blog-thing(again) because logging in to the server, firing up vim and writing HTML is too much of a hassle. Jekyll seems cool and I don't know ruby, so why not? This is the post-recieve-hook I'm using

#!/usr/bin/env bash

    git clone $GIT_REPO $TMP_GIT_CLONE
    jekyll build --source $TMP_GIT_CLONE --destination $TMP_WWW
    cp -r $TMP_WWW $PUBLIC_WWW
    rm -Rf $TMP_WWW
    rm -Rf $TMP_GIT_CLONE

At first it didn't work and I couldn't figure out why... this is like the easiest script in the world, right? Spelling is not my thing today, although I'm usually quite good at it. post-recieve != post-receive(I even misspelled it when I wrote it just now).

My minisumo for Robot SM is getting close to done. Here's a nice little GIF-image showing the assembly process of Perfected Titan.

. All the code can be found at my Gitweb.
I've also filmed a short video of Perfected Titan which you can see below. I'll probably add another video when I've "optimized" the target finding code a bit. It's a finite state machine which reads the front sensors and decides on state from that.
It has got seven states and seven "behaviours".
One thing I did differently with the code on this robot is that I did a function for setting the "heading" of the robot as opposed to setting individual motorspeeds. This gives you some interesting "effects" for free. For example; the "search"-behaviour is this;
set_heading(FULL_SPEED,(ad_value[0] - ad_value[1])*2);
Set_heading works by taking speed and then using the second argument, heading, to calculate individual motorspeeds. In this particular case it works great because if ad_value[1] is larger than ad_value[0] heading will be negative, and the robot will weer to the left, if it's positive it'll weer to the right.

void set_heading(int16_t speed, uint16_t difference) {

        // Set heading, left = speed + diff, right = speed - diff

        int left = speed + difference;

        left = constrain(255,-255,left);

        int right = speed - difference;

        right = constrain(255,-255,right);



The constrain() is a function that keeps a value between x, y. Nothing fancy. Set_motors() just sets motorspeed on a -255 to 255 scale, where 255 is full speed forward and -255 is full reverse.
Another interesting part of the code is the ADC-reading code. It doesn't do any Kalman filtering or anything, but it constantly reads the ADC-values in an interrupt, roughly 125kHz. It works like this

// ad_value is an array that contains all the ad values

volatile uint16_t ad_value[NR_AD_CHANNEL];

// Local values

volatile unsigned char ad_count=0;

void init_adc(void) {

        //5V AREF

        ADMUX |= (1<<REFS0);

        //AD enable, AD interrupt enable and clk/128 prescaling

        ADCSRA |= (<<ADEN) | (1<<ADIE) | (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0);


        // Prepares first ad channel

        ADMUX &= 0b11110000;

        // Disable digital on the ADC-pins

        DIDR0 = 0x01;

        //Starts the first conversion

        ADCSRA |= (1<<ADSC);








        // Select ADC channel with safety mask

        ADMUX = (ADMUX & 0b11110000) | ad_count;


        ADCSRA |= (1<<ADSC);


Neat huh?

The PCB of version 2 of Perfect Titan is finished, the new robot is named Perfected Titan, since I fixed some placement issues on the PCB this time over. I also added a protection diode and "proper" connectors for LEDs. I have one pin left actually, didn't end up using three Sharp-sensors as I had originally planned, don't know where to put the third one to be honest. I'm considering putting 10 cm sensor in the back for it, haven't decided yet. Here's the schematic:


Click for a larger version

And the pcb layout PCB

Click for a larger version

The chassi is almost finished, there will be some build log pictures up later. I've started doing some small work on the code and realised I need a finite state machine. All computer programs is in some way a finite state machine, but using it as a design from the start is very well suited for robotics. I looked around quite a bit for something to draw the state machine up in. The best alternative I found was Qfsm. I encourage you to try it out, a really nice piece of software. Aur-package will be avaliable, later.

It's a bit late, but here's a film of my robot, Perfect Titan, at Stockholm Robot championship 2012, I'll do a proper write up about it later when I've finished my current build.

It's powered by two FingerTech Gold Spark 63:1 motors with FingerTech Cobra wheels. They're a fantastic combo, my next build; Perfected Titan(since it's sort of like v2.0 of Perfect titan) will have the 50:1 Gold Spark motors and Cobra wheels. Crazy grip in those wheels. Here's a picture of Perfect Titan:

The big blob in the front is a bunch of sinkers made for fishing I bought for cheap at Överskottsbolaget held together with shrink tube and tape.

I've more and more started using plain C on my Arduino, because timers etc. One big caveat I encountered was writing a good Makefile.
Therefore I'll share my own makefile with you.

My current notetaking and information system consists of assorted postit-notes in my jackets pockets and textfiles with names like "hej", "file123" and "notes_lol". This is (for obvious reasons) not a very good system. So I've decided to set up a personal wiki. I first tried Zim which seemed quite good but didn't suit my needs very well.
I've decided on DokuWiki as the wiki engine and Lightttpd as the webserver.
The first thing we need to do is installing both the packages, this is done with the command

$ sudo pacman -Syu dokuwiki lighttpd php-cgi

After this is done we need to configure lighttpd.
Add these lines to fastcgi.conf

server.modules += ( "mod_fastcgi" )

#server.indexfiles += ( "index.php" ) #this is deprecated

index-file.names += ( "index.php" )

fastcgi.server = (

    ".php" => (

      "localhost" => ( 

        "bin-path" => "/usr/bin/php-cgi",

        "socket" => "/run/lighttpd/php-fastcgi.sock",

        "max-procs" => 4, # default value

        "bin-environment" => (

          "PHP_FCGI_CHILDREN" => "1", # default value


        "broken-scriptfilename" => "enable"



And then in lighttpd.conf add this line:

include "conf.d/fastcgi.conf"

You also need to set open_basedir to include your dokuwiki-install-folder. After that, you should have nice wiki running at http://localhost:80

I've had this video uploaded for about a week, just forgot to write about it here.

Some mini-sumo matches to get you warmed up before Stockholm Robot Championship 2012. I hope to see a lot of people there. I'm going to participate in minisumo, linefollowing and possibly the "Folkrace", we'll see if I find the time.

Always wanted to have that cool IDE-feature of automatic comments in your newly created source-files but can't stop using vim as your IDE? Now you can have both!
First; create a file named c_template that you put somewhere(I put mine in ~/.vim/templates) that contains the following



 * File Name :

 * Purpose :

 * Creation Date :

 * Last Modified :

 * Created By :




Then, in your ~/.vimrc insert the following somewhere

" To automatically put a comment in a new c-file

autocmd bufnewfile *.c so /home/yourusernamehere/.vim/templates/c_header.txt

autocmd bufnewfile *.c exe "1," . 8 . "g/File Name :.*/s//File Name : " .expand("%")

autocmd bufnewfile *.c exe "1," . 8 . "g/Creation Date :.*/s//Creation Date : " .strftime("%d-%m-%Y")

autocmd Bufwritepre,filewritepre *.c execute "normal ma"

autocmd Bufwritepre,filewritepre *.c exe "1," . 10 . "g/Last Modified :.*/s/Last Modified :.*/Last Modified : " .strftime("%c")

autocmd bufwritepost,filewritepost *.c execute "normal `a"

Now, open a new file called test.c, neat huh? Write some text in it, save it and reopen. Now the Last-Modified : should be right as well, it's like magic!