# I used to be indecisive…

but now I’m not so sure…

whether I actually need a horizontal acceleration PID.  I’d considered adding the horizontal acceleration PID between the horizontal speed PID and the pitch / roll angle PIDs.  Its output would set the angle target for those PIDs, but I’ve come to the conclusion that there is a direct mathematical link between horizontal acceleration (the output from the horizontal speed PID) and the tilt angle target set for the angle PIDs

Consider we want 1g acceleration horizontally, and 1g acceleration vertically to give us horizontal acceleration – i.e. no rise or fall in flight height.  Then the power must be applied equally horizontally and vertically, meaning a 45º tilt.  Or putting it slightly clearer, the acceleration from the accelerometer is measured in g’s, so if we setup the gains of the horizontal speed PID to output in (approximate) g’s, and denote earth axis acceleration along the x and z axes as aeax and aeaz respectively then

tan(θ) = aeax / aeaz

But for horizontal flight aeaz = 1g. So

θ = atan(aeax)

This means the target acceleration from the horizontal speed PID output (i.e. target acceleration) if measured in units of g maps directly to a target angle for the pitch / roll angle PIDs which is “a good thing”TM as it’s much better than adding a noisy accelerometer PID into the system.

## 7 thoughts on “I used to be indecisive…”

• Wow! So far out of my depth that my head hurts!

1. Hi Andy,

Just a quick naive question though: For the PID tuning, it seems to be really hard, but I do this this for work a lot, and, I’ve never encountered a case where the Ziegler-Nichols method (http://en.wikipedia.org/wiki/Ziegler%E2%80%93Nichols_method) doesn’t work ; Have you thought about doing that?

My second question is about the need for levelling the quad perfectly before takeoff. As I understand it, this is to basically provide a “zero” for the orientation measurement…. Makes me wonder… I’ve seen a lot of videos with quadcopter being (literally) thrown in the air by hand and see them stabilise nicely… how do they do it?? As surely, they do not have a perfectly levelled start!

Cheers
David

• Hi David,

When I started this project just over a year ago, I knew virtually nothing about how quadcopters worked other than the basic physics, so it seems like a fascinating challenge. Even my math(s) has got very rusty in the last 20 years since I left Uni! So all of this development has been groping around in the dark – and actually that’s been part of the fun – I could have used ‘off the shelf’ code for Kalman filters, Euler angles and the Ziegler-Nichols PID tuning, but I either had never heard of them (like the Ziegler-Nichols, until today!), or I wanted to take an experimental approach and work it out by myself. The PID tuning actually isn’t hard done manually, once you know what you’re doing – it’s just that I didn’t!

As far as the “tossing the drone” launch, I don’t think my quad will ever cope with that, but it can now do a none-level take-off – you just need to calibrate your accelerometer (once, I suspect), so that it reads (0, 0, 1)g on a horizontal surface. As gravity then never shifts, the accelerometer outputs will always read (0, 0, 1)g when horizontal, regardless of take-off attitude. The problem to solve there is that the accelerometer is noisy as hell, so needs to be merged with gyro output using either Kalman or complementary filters – I’m using complementary as I understand them and they are within my math(s) capabilities!!!

Cheers,

Andy

• Well I never – just looked at the wiki on Ziegler-Nichols and the basic methodology is what I used – tuning P gain first up to ‘stable’ oscillations, dropping it just a touch (5 – 10% I think I did), and then tweaking I and D gains for long term and quick response reactions based upon the tuned P gain, plus the time difference between samples!

Gotta love reinventing the wheel!

Andy

• Yes, the Ziegler-Nichols method is in fact rather intuitive. But it’s especially useful when one need to start with ‘something’ to get going… so effectively, you need tune the P… the I and the D are calculated from Ku and Tu. Then, from there, fine tuning can/should be done.

I just found this (http://web.mit.edu/scolton/www/filter.pdf) as an alternative filtering from the typical Kalman algorithm – Hope that helps!

I’m currently revising an old RC car I found in my parent’s basement with a raspberry pi…. when I’m done with that, I might well move to building a quadcopter… sounds like a lot of fun!! 🙂

• That’s exactly the complementary filter I’m using based exactly on that article – I have it linked somewhere in my blog – it was the one I’d found clear enough for me to completely understand rather than just believe and trust in, which is how Kalman feels to me currently. So far, it’s working very well.

This site uses Akismet to reduce spam. Learn how your comment data is processed.