In addition to BYOAQ-BAT, I’m still flying Zoë, trying to tackle the accelerometer drift, especially in the Z axis. That problem is that with drifting Z axis accelerometer, it’s hard to get a decent vertical hover because
The basic code just calculated gravity prior to flight, and then subtracts that from acceleration readings during the flight to come up with net acceleration. But if the sensors drift during flight, the subtraction of gravity from the sensor readings will also drift, leading to sensors thinking they are hovering while they are still climbing. This morning’s test had the quad drifting to ground during the hover phase, and on the ground prematurely in the descent phase.
My current approach has been to use a complementary ‘filter’ (though it’s not really filtering) to slowly mix new readings of acceleration into the preset gravity readings. It works to some extent, but not well enough. It does suggest filtering gravity may be a suitable approach. This morning’s test had the flight climbing too high, and continuing to drift slowly upwards during hover.
What I need is a proper digital low pass filter to separate net acceleration from gravity drift. And thanks to Phil’s comment, I’ve been investigating IIR filters and found a couple of things which are both useful and critically, I understand.
- Oxford University lectures on digital signal processing – Lecture 6 – Design of Digital Filters
- York University Digital Filter Parameter Calculator
The gravity drift is slow and always in the same direction where as the acceleration is neither, so I’m thinking a very low cut-off (0.5Hz or less) DLPF will work. Currently I’m implementing a hard-coded second-order Butterworth filter with a sample rate of 71Hz (the frequency of my motion processing) and a cut off of 0.5Hz. If this is successful, I’ll add the code to actually calculate the Butterworth parameters so I can easily experiment with other filter types, cut-off frquencies and order for the filter.