Posts

Showing posts from April, 2017

The Fast and the Furious World (of Trigonometric Functions on ATMega328)

Image
Atan2 algorithms - speed vs accuracy Running trigonometric functions on an 8-bit AVR is inevitably going to be slow.  Floating point operations come with speed overheads and the most accurate algorithms usually come at a further timing price.  The arctangent function (atan/atan2) is ubiquitously useful, and especially so for Quadcopter's and robotics.  Briefly, an  atan2   function takes Y and X as arguments and works out which quadrant the tangent angle is in, and uses that to call a corresponding  atan   function.  I have been investigated the timings of various trigonometric functions on an ATMega328p chip running at 16 MHz, and in particular exploring 4 atan2 implementations and their trade-offs for accuracy.

Bluetooth programmer

Image
From breadboard to perfboard I have been busy bending Bluetooth modules to my will.  The typical parameters I need to control are the module name, baud rate, and whether the module is a slave or master.  To program my quadcopter over Bluetooth, I have defined a Bluetooth module as a Master, which connects automatically to the quadcopter slave module when available.  The Master module connects to the PC via an RS232 USB converter - until now this been a mass of wires living on a breadboard, but I've now finally soldered a simple circuit together to allow me to program modules more easily.

Quadcopter code structure

Image
I've been meaning to post this for a while but after soldering everything together and correcting the errors in the PCB (details blogged here: Resolving UART bus conflict and Power control ), THE THING FLIES !  In fact it flies pretty well. I thought I would record the code structure of the quadcopter. Below, psuedo-code for the quadcopter main loop, focusing on stabilisation: