MikeWalker


Hive Mind Framework

The flight control software is based on a home grown message and threading framework named Hive Mind. Hive Mind follows a publish-subscribe messaging pattern and is thread safe by design as long as the framework is followed.
Three basic types of objects exist in Hive Mind:

Blocks: Are the main work horses of Hive Mind. Each block is a thread that contains a set of instructions run in a loop. At the end of each loop iteration the thread is locked by a mutex and waits to be unlocked by the Hive. Each block has a data space saved as an incoming message queue. Blocks all register for a certain subset of messages in the system, similar to signing up for a mailing list.

Messages: Messages are a simple data transportation framework for Blocks to communicate with each other. Messages contain a header with information such as:
  • Message Identifier
  • Endianness
  • Data Size
  • Sender Id
Furthermore all messages have a data field of the length specified in the header.

Hive Mind
The Hive: This object acts as a message broker between all of the different blocks in the system. Whenever a block publishes a message it writes it to The Hive's incoming message queue. On its next wake-up the Hive looks at every message, in order, and distributes it to Blocks which are registered for that message identifier. Once all messages are distributed the Hive unlocks any blocks which it has sent a message.

The above figure shows how a message travels in Hive Mind.

Ground Station

The drone is controlled via a ground station GUI. The GUI is coded using Qt and Qwt . Qt provides an easy framework for GUI programming and form driven design. Qwt is a Qt extension that adds easy to use dials and plots, both of which were useful.


Board

Software Layout

With a useable framework established a set of Blocks had to be picked that appropriately. The blocks running for the quad-copter are:

I2C Interface: There are three devices on the I2C interface, however they only require one thread because they all share a common I2C Bus. The I2C Interface wakes up on an interrupt at approximately 100 Hz and reads the IMU (accelerometer/gyro) and Magnetometer. When the I2C Interface receives a blade rate command it communicates it to the PWM generator governing the motors.

GPS Serial Interface: The GPS interface acts on the Rapberry Pi TTYAMA0 serial port and wakes up at 10 Hz to read messages from the GPS receiver and convert them into position data.

Radio Serial Interface: The Radio serial interfaces acts on the Raspberry Pi TTYUSB0 serial port and wakes up at 100 Hz to read data from the radio. It also wakes up whenever it receives a telemetry message from the rest of the quad-copter and writes it to the radio transmit line.

Software Layout
Navigator: The Navigator block takes the raw sensor inputs (acceleration, angular velocity, magnetic field, and GPS position) and combines them all in an Extended Kalman Filter. This provides the best estimated state (position, velocity and attitude) of the quad-copter as an output.

Guidance: The Guidance block accepts the navigation state of the quad-copter and flight commands as inputs. Guidance than uses this to calculate the required acceleration required to fly the path specified by the Flight Manager. For more on the math behind this see the algorithm section.

Autopilot: The Autopilot accepts guidance acceleration commands and the quad-copter state as inputs. The Autopilot then calculates the required blade rates to achieve these commands. For more on the math behind this see the algorithm section.

Flight Manager: The flight manager is the on board decision engine which interfaces with the ground station. It accepts input commands from the radio and outputs different types of commands to the guidance algorithm.


Rasbpian Settings

The operating system being used to run the drone is called Raspbian . It is a port of Debian Linux for the Raspberry Pi. Getting the I2C and serial interfaces set up properly is quite simple, but only if you know what to do!

Luckily the google comes to the rescue in this scenario, the following examples/instructions/tools helped me get started:
I wrote my own software to interface with the I2C, Serial and GPIO interfaces. However, there are open-source options available should you not want to be so rigorous.