T: 020 8133 8760 // M: 07810 253893 // E: info@eclipseaudioservices.co.uk

The arduino based helicopter autopilot

The Arduino Helicopter Autopilot is reaching it's first hardware release. Pre-order now by contacting me with your details.
The brand new HeliShield prototype
The brand new HeliShield prototype

This article started around September 08, and charts the development of the hardware for the autopilot. Lots of photos are at the bottom of the page.

I recently purchased an Arduino from LadyAda, and started to learn the language. Having worked though the tutorials on her site I started looking at more and more complex code.

I coded an alarm clock, which successfully woke me up for a couple of mornings, 3 minutes before my normal alarm clock.

I then started thinking about what could be triggered after a specified delay, which lead me to the Nikon remote control/intervalometer. I've taken several long sequences of photos which I intend to turn into timelapse video.

I found sample code for reading the Wii nunchuck sensors, and tried it out to much success. This is about where Processing became involved. I wrote a basic readout for the accelerometer displaying a 3d cube, rotating with the reading from the accelerometers in the nunchuck.

I discovered a project someone was working on using the Wii nunchuck and arduino to stabilise a radio control helicopter.

I decided to try for myself, but using other sensors. I bought a Sparkfun development Gyro and a 3axis accelerometer, and set to coding the rest.

Another source of inspiration was this video of Lockheed Martin's MKV.

Video Player thanks to Flowplayer.
Download as FLV format video.

The project that inspired me to try was implementing stabilisation of the head of the helicopter, whilst using the existing control system too. I was aiming a little higher, with the arduino taking on the role of speed controller for the motors and controlling the servos, while reading the sensors and RC control signals.

Using the SPI bus, I quickly got the Accelerometer up and running with the demo code from sparkfun.

I borrowed code for reading the RC signals from the Ardupilot project.

The accelerometers don't provide any useful information for rotation of the helicopter (about the Z axis) but can provide a noisy approximation of pitch and roll.

The gyro provides only rotational information about the Z axis, so bridges the gap to give a fairly good approximation of the movement of the important axes of motion.

I found out about Kalman filters, and some example code, which I adapted for my purposes.

This code provides a stabilised value for both pitch and roll, and takes info from the accels to futher improve the quality of the readings from the gyro.

By filtering the accel and gyro together, the bias from the gyro can be lost in the filters, tilt proves less of an issue for the gyro and clean accurate signals can be achieved with little work.

I wrote a sketch in processing to decode the serial output from the arduino, which was sending all the output data from the sensors. I quickly constructed a basic display, plotting the XY angles computed, and the resulting output servo signals on an invisible Cartesian plot, this illustrates the point quite nicely...

As the tilt increases, the output to the servos reacts in the opposite direction. Hopefully this will result in the helicopter stabilising.

The radio control input affects the output too, but only by a relatively small amount, ie. auto correction mixed 60-40 with incoming human control. This theoretically means human control of the helicopter will be very smooth requiring minimum skill to operate.

Mixing all the signals to create the desired outputs is handled by averaging the various outputs into one signal per output function.

The test airframe is a Piccolo Eco 2, which was purchased on ebay for £7! After replacing all the broken bits I had a helicopter with no electronics. Exactly what I was after...

Having got a stabilised and filtered reading for Yaw, X and Y angles I felt it was time to try making it fly.

The initial obstacle to flying was lack of 2x motor controllers, however a couple of burly transistors (TIP41C - just because I had some spare,) two resistors and two diodes was sufficient to get both motors running, speed control being handled using PWM from the arduino.

Unfortunately, at this point I discovered a significant drawback to having a large breadboard for developing, and a very small heli.

Time for a helicopter-diet. At this point I decided to develop the Helishield - a small pcb which mounts straight on top of the arduino, carrying the headers for all the connections, the sensors and the motor controllers.

Using the GEDA suite of programs, I created a layout for the Helishield, headers for the Accelerometer, gyro, servo connections, RC receiver, power and motors, two small motor controllers, and so on. It all fits on a board about 50mm2.

I have checked alignment with all the sockets, now all I'm waiting for is the PCB which is on order, and some spare time to etch and drill the pcb.

I have some ideas about making a whole system, on one board, using SMT throughout, then the whole thing could be sub 3 grams! (at a rough guess!)

I am working on getting a serial control API too, I think it would be very interesting (in this case possibly interesting == dangerous) to be able to fly the heli from a processing sketch.

The RC control reading code needs work... I wish to make the system as robust as possible, and at present all hell breaks loose if I turn off the transmitter, and occasionally it generates a random value, this is probably a timer overflow, or variable overflow. But to all intents and purposes, a functioning RC stabiliser.

I'd like to look at the possibility of capturing the whole RC signal using just one pin. The data sent over RC has to be sent serially, therefore, at some point in the receiver, all the values will be sent together on one line. I read something about doing that somewhere once upon a time. It would probably reduce the workload of the chip, as all 4/5/6 channels could be collected at once, on one pin. Freeing input/output pins and reducing code are both priorities for me at this stage.

Once I have the PCB made the heli will fly (to a lesser or greater extent) almost immediately. I am confident that it will get off the ground without my 500 gram development board attached! Once it takes off, it /should/ be a matter of adjusting ratios of control output relative to sensor input.

When all of the above is complete and I have stable-ish flight, I will turn my attention to the gyro, because at present I am using the analog output from the gyro, while it is able to provide an SPI interface, meaning the code to read the accelerometer could also read the gyro, freeing up more code space. This bit will probably require quite some work.

The serial API will have the ability to adjust the flight controls, and will take a similar approach to the RC control. I plan to continue to improve the processing sensor readout, and begin adding some form of human interaction with the heli.

Some time in the new year I hope to invest in a Collective Pitch helicopter, this will open up doors for HeliShield v2.

I think the Piccolo has taught me a lot about helicopters, and it's never got further than skidding about on my desk so far.

I think that with the Piccolo, there will be little point in having any sensor input controlling the main rotor speed, as the torque available would probably not be immediate enough to be useful, whereas with a collective pitch heli, Z axis acceleration could slightly influence the main rotor pitch to achieve really smooth hovering, even in turbulence. I will test this feature with both types of helicopter though, it would be nice if it worked with the Piccolo too, but I have a feeling that the tail rotor would be working quite hard to keep everything straight.

Maybe I should investigate recording flight data, and plotting it somehow, then compare the results from different helicopters.

-------

Today I set about printing the masks for the PCB and etching a few test boards (having finally found a box of film suitable for the big laser printer).

The first masks I printed were good, but faint. A trial exposure for 6 minutes (under the UV) resulted in most of the resist being developed.

I set the printer to the best settings I could, and the next mask was much better. The first board I made (with a 5 minute exposure) was a great match to the mask, but the fine tracks were broken in places, and the pads were too small. Some of the pads lifted from the board during the drilling and I decided at that point that a slight redesign was needed. I have now increased the size of the pads, moved the gyro and accelerometer slightly towards the center of the board. I also removed the need for the two vias by re-routing a couple of tracks through newly found gaps. PCB layout software has a strange ability to make tiny spaces seem huge!

-------

I have made printed the new masks and made some test PCBs. The process timings are now known and repeatable, so there will be boards available to order from now on.

I will look into having the whole fabrication process done elsewhere, to allow for silk screen and other niceties, like solder masking - a must for boards with copper fill combined with hand soldering.

The board carries two motor controllers, power and radio connections, 4x servo outputs (2 share pins with the motor controllers - either use the motor controllers, or the 2 extra servos, not both), a serial header, and sockets to fit a gyro and accelerometer.

I chose to fit sensors onto headers so the sensors are available for other uses. I am looking into building a complete system on one board with the Atmel micro, Accel, Gyro etc all fitted. It would probably be entirely SMT too, for the weight savings. Let me know if you have any ideas you'd like to see incorporated into the design.

---------

I have partially populated the Helishield prototype with the parts for the motor controllers, pins to connect onto the arduino, servo headers etc.

Minor alterations have been made to the design to aid assembly,and to improve the position of the sensors. Both sensors are now roughly central.

A couple of tracks which were just too close for comfort have been tweaked too.

I'm awaiting delivery of the sockets for the gyro and accel, there seems to be a shortage. For the photo, I just plugged the header on the sensors into the holes on the PCB.

--------

I have been working on the serial control code for some time now and I have just succeeded in getting reliable control of the values in the flight algorithms from my processing sketch.

I have been offered a broken xBox 360, the dvd drive has failed, I looked up the use of the controllers using Linux, and have compiled and install the kernel module. I will have to see whether it works once I actually have it to work on. I also intend to replace the dvd drive and reflash the chip on the drive in order to boot live cds on the console. I will then try to set up the 360 as a flight control station - it seems to be plenty capable of the task.

I have also set up the library for Processing needed to read values from the controller (or other joysticks), although I can't test this until I have the controller.

I will have a system together very soon that should be light enough to fly, I will be testing all aspects of the control, and tuning the flight algorithms to stabilise the flight as much as possible.

--------------

Over the Christmas break, this project was on the front page of Sparkfun Electronics, causing a massive boost to traffic.

I've now answered questions from Bangladesh, Spain, Brazil, Russia and more...

Filling in the time between eating and sleeping, I was coding. I have written a test sketch for the Arduino with the intent of capturing all the incoming RC data in one pass, on one pin. The idea being to free up space for more (both in code and physical input/output)

Radio Control systems use PPM to code together a chain of pulses with the duration of each cycle being the value of a control, followed by a framing pause to enable the system keeping in sync.

I will test this as soon as I can get to my RC rx with the oscilloscope and find the PCM signal.

I intend to use this advance in code to further reduce the need for hardware other than the Helishield, I plan to design a complete on board solution soon.

--------------

The serial API is now fully functional too, I can smoothly control the XY movement of the rotor, and control Throttle and yaw, all from a processing sketch (and potentially anything else that can output serial - yes, even your mobile phone...)

----------

I have successfully coded a system for reading the PCM data of the radio control signal (and hence all the channels available, entirely on one input pin.

The code times the the length of the cycles of incoming pulses, when the framing pulse is found a loop starts which records the start and finish times of each cycle, then the difference between these times is the RC control values.

No matter how many channels of radio you have, thee is only one period of waiting involved with reading the signal, so overall efficiency of the code is better than waiting for a signal on each pin of the RX.

---------------

The collective pitch version is coming on fast, the code is nearly complete, and the helicopter is in transit to me. I will soon have all the equipment needed to flight test both the collective pitch and the Piccolo style helicopters.

Alongside the new PCB for the Arduino Duemillanove to control a CP heli, I will be releasing a system entirely on one PCB for weight and space saving reasons, and also because I'd like to keep the helicopter built up permanently.

Major Update - 22/05/2009

Here's a long needed update about the whole project!

The HeliShield is working and the design is now human friendly too. PCBs will be available shortly, email me if you'd like to buy one and I'll take your details and let you know when they're ready.

There will be a few ways in which you can buy the boards, bare single sided boards will be available in the next week without silkscreen. This option is not for the faint of heart, there are four leadless packages to solder on. The first PCBs sell for £15 each and will be supplied with documentation. The features on this board are as follows:

Radio baseband signal is captured on one pin.

Servo output headers for all channels

3 axis accelerometer

Single axis gyro for yaw

Dual axis gyro for roll and pitch

3 axis magnetometer for heading hold and dead-reckoning

Lots of smoothing caps

Draws power for everything directly from the speed controller

Serial header for connection to a wireless serial modem

Socket for IR rangefinder to enable gentle landings

A bit further in the future a double sided shield will be available, with silkscreen and the same spec as above. This will be the same footprint as the arduino.

Using the stock duemilanove with this board is testing it a bit, it runs stably doing all the inertial measurement, radio, serial comms bi-directionally and so on but there is very little room to expand either hardware or software. If you intend to just use a standard duemilanove I would suggest leaving out the magnetometer.

Having played with a Mega the other day, I've decided to stop the development around the Sanguino and move to the mega chip for the all-in-one system. This is on the drawing board at the moment, I will push for getting a test one done very soon, my current prototype is very hard to fit to a 450. The all in one system will be narrow enough to fit into the bodywork of a 450 size heli.

The mega is an Atmega 1280 chip, it's in a 100pin TQFP package, so it's very small and tightly spaced. I hope this will shrink the whole assembly significantly. It comes with several other bonuses, like 53gpio pins, 4 UARTS so GPS, wireless serial comms, and more can all be wired directly to this chip. There's also 128kb of flash memory for code, which doubles the sanguino's 64kb, making even more room for expansion. I see the design incorporating multiple rangefinders and a stabilised camera platform.

The code I've been developing on the sanguino will be easy to port to the 1280 as it already makes use of the two UARTS on the 644P chip. GPS parsing code works and there's already an improved serial comms approach working. I will do my best to port this code back to the code for the Duemilanove.

See the artificial horizon page for more info.

To view or download the code please click here.

Please click here to ask a question, send your praises/insults to me!

Copyright (c) Ed Simmons

Associated Photos:
Very fine traces and pads on this board. The four leadless packages have been soldered on. The newest version of the Artificial horizon without video running A recent version of artificial horizon with video Special Kalman Magic The CCPM Helicopter The tail assembly on the CCPM heli The readout displayed by a very early Processing sketch A complete(ish) looking HeliShield Six completed prototype boards Six completed prototype boards The early stages of drilling Four prototype boards nearly etched The first drilled test PCB with the Accel and Gyro plugged into the PCB Here is the testing helicopter, sitting on breadboard where the accelerometer and gyro are wired to the arduino Testing the alignment of the sensor headers - this one fits! The prototype motor controller v2 The complete system minus speed controller (and helicopter!) Accelerometer - 3 axis, 2g+-, SPI communication Gyro - 150 degrees/sec, analog and SPI communication (Currently only making use of the analog output) An arduino!
Click on pictures for full size version!