I have written a tutorial on how to program your own AutoPilot/Flight Controller from scratch using an arduino/ArduPilot/RaspberryPi. The tutorial will walk you through everything from reading the RC radio and controlling the motors through to how the PIDs are stacked on top of each other to get stable flight. Information on how to do this is quite hard to find on the Internet, so I hope this article will make the world of flight controllers more accessible and encourage more people to contribute to ArduCopter.
You can find the full article here:
and a video of the code from the article in action (you can download the code and try it on your APM - it'll behave like a KK board):
Note: the code actually flies better than the video demonstrates - my PID settings weren't optimally tuned!