Go Down

Topic: Arduino Helicopter Autopilot (Read 10 times) previous topic - next topic

Ed Simmons


Firstly, the code I borrowed some of the kalman filtering was based on the Wii nunchuck, but this code uses the Sparkfun accel and gyros.

I'm constantly omptimising the code, and yes delay is bad, I never use pulse in.

I am interested in looking at some of the other hardware timers, but for the moment I'm concentrating on getting the hardware smaller and well integrated into the helicopter. I have a collective pitch version too now, there are two platforms to build.

Cheers for all the support!


Jan 07, 2009, 12:58 pm Last Edit: Jan 07, 2009, 12:59 pm by mem Reason: 1
But i suggest to use external interrupts with a hardware timer to count the pulses... Without wasting CPU power, the secret is never use pulseIn

Hi jordi,

The most recent ardupilot code I could find does use pulseIn, have you posted a version of the code that uses the timer?

Ed Simmons

Hi all,

Once again, thanks for all your input and interest.

The code is now online and both Collective pitch and fixed pitch development code-bases are available.

The serial API has been implemented with control input from the processing sketch.

Come and get it from www.eclipseaudioservices.co.uk/extras/helicopter.html

Have fun!


Jan 22, 2009, 01:45 pm Last Edit: Jan 22, 2009, 01:47 pm by mem Reason: 1
Hi Ed, interesting writup - I would love to see the helicopter in flight - have you posted a video?

BTW,  I see that your RC signal decode and servo output code  are both done in the foreground. This eats into the number of sensor readings you can process. You may want to consider using code that does the decoding and servo driving in background using  the ATmega168 hardware timers to do the work.

The RC decoder is here : http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1228137503
it uses pin 8 as input and has failsafe that can be set to last good signal or any preset

The servo driver code is here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1230479947/13

PM me if you would like help integrating the code into your app.

Ed Simmons

Hi mem,

I'd like to work on integrating these, I've looked at both libraries in an effort to understand the timer functions etc. I'd be interested in trying to now that I've got my tax return out of the way.

The servo outputs seem to have the biggest impact on performance, it would be great to get that going in the background. I also like the idea of the preset values on signal loss, given that there is mixing between RC and Serial control it would not be good to include noise from the RC when flying on the serial 'line'.

I've upped the sensor count too, I now have the code ready for 6 degrees of freedom, but there's a few little issues to iron out.

There will be some video soon, but the hardware needs some more work before I risk actually flying properly. It's dangerous enough on a tether! (For a little while, it was over-reacting to movements)



Joe C

This is fantastic! Keep us posted

Ed Simmons

Hi all, Mem in particular, you might be interested to know that I've adopted your libraries.

The servodecode and servotimer2 libraries work very nicely.

As I expected, they're a lot less heavy on the processor. I have to say I enjoyed the process of implementing these features myself, it certainly taught me a lot in the process, but implementing this in hardware is the way forwards.

The refresh rate has practically doubled, and I've honed my control system further, there is no noticable change in performance between signal present and failsafe states (my first encounter with servodecode had some unexpected results - I am so glad I've been working without the speed controller connected!!)

Do you know of the reason for the spurious state changes between failsafe and ready when the RC transmitter is turned off? I'm guessing that it's because of noise on the input which lies within the timing range we're interested in.

I've put in a counter and only allow the signal to pass once 10 consecutive cycles are OK.


Ed Simmons

Gah - a continuation of the previous post...

I've also spotted that because I'm disregarding the failsafe state readings, the function of the failsafe set positions is lost.

Although, this may not be a problem, I'd like to look into ways of making the library's failsafe response more certain, it's prone to letting through 1 or 2 sets of spurious readings in between a whole load of failsafe positions.

Getting there, flight testing will re-commence soon.


Jan 22, 2009, 10:27 pm Last Edit: Jan 22, 2009, 10:31 pm by mem Reason: 1
Well done!

Yes, if there is noise on the input that is within the valid signal timing range it can turn the failsafe off. A fix for this would be to modify the failsafe code to wait for some larger number of consecutive value frames before coming out of failsafe.  Also, I would like to do a check to detect if the timings on consecutive frames is random (and therefore probably noise). This is on my todo list but its pretty far down so feel free to add this if you want to.

edit: I was composing this when you sent your previous post


Great Project!

This thread has made me almost buy a RC heli too many times. ;)
I was into the fuel RC 4x4 some 7 years ago, and I find myself missing it when reading this post. I remember I actually wanted a helicopter, but I was 13yr and the age restriction was set at 14. :(

Would you recommand a el or fuel heli? [I have a lot of space, both indoors and outdoors, and I also have some/little experience starting twostroke engines (? do not remember their name, but those engines that helis and planes uses)] Also; I also want a 4channel heli or more.

Sorry for being slightly off topic, but I love the whole idea of radicontrolled complex machinery 8-)


Recommending the ideal heli power source is a bit like recommending the ideal programming language - it depends on what you want to do.

I prefer electric - its clean, low hassle, and I can fly indoors in a large enough space. The battery technology available today has virtually eliminated the traditional power to weight advantages of gas/nitro fueled engines.

There are many other choices you need to make - size, rotor mechanics, kit or built, type of electronics etc.

There is lots of information on the web of the pros and cons of each - www.rcgroups.com is a good source for detailed info.

If there is a radio control flying club near you - drop in on and ask the people there - having someone local experienced in the kind of heli that you have can make learning much easier.

Have fun!

Ed Simmons

I'd second what Mem was saying, electric helis seem to be the way forwards especially for the development of something like this, I personally quite enjoy being able to sit indoors working on the code with the helicopter attached to the computer for debugging.

Nitro engines vibrate more, giving more grief to the sensors (more noise) and potentially can harm the electronics in other ways too (fuel contaminations etc etc)

Brushless motors and LIpoly batteries yield a similar performance to nitro engines these days anyhow. Having two or more available means you can cycle the batteries between use and charging.

The code works equally well with either, but it may be advisable to make some small adjustments to how the throttle pulse is calculated in order to maintain a smooth idle.

Oh - and did I mention that you can fly this system over a wireless serial link from Processing, or anything else you fancy coding to output the right control data...


What is a typical max load for a beginners el heli with 55-60cm main rotor?

This has inspired me to add another project on my TODO

Ed Simmons

Umm - my 450 Trex has a max flying weight of about 900 grams. The heli itself without the batteries is about  600 grams.

If you are using a CCPM (collective pitch) heli, look at the CPHeli code on my site, if you are thinking of using a fixed pitch heli, look at the Piccolo code.


I'm so glad to hear people are liking this project - any productive ideas that you have, please let me know and I'll see what I can do to integrate them.

I've ditched the autonomous procedures for now, I'll be looking into it again soon. But to be perfectly honest, autonomy is easy in comparison to making it stable in the first place.

Best of luck!!


Jan 24, 2009, 12:35 am Last Edit: Jan 24, 2009, 12:39 am by aercam Reason: 1
Hi Ed and MEM,

Ed, I downloaded your code and tried to run it. Although it compiled fine and runs, the servo movements are very jerky. The servos do move proportionally, but they are not smooth at all. There are three very prominent steps as you move the transmitter sticks. The Yaw servo will not move and I had to change the input pin from pin2(what the code specifies) to pin8(what ServoDecode uses). Do you have any idea why the movements are so jerky?

Another thing. How can you specify 5 timers? I thought Arduino only had three.

I am very interested in your mixing of the channel pulsewidths for use in my Tri Copter.


Go Up