Reduced Yaw Drift / Fast Gyro Sampling with the UDB / MatrixPilot from Pete Hollands .
[Note: Apologies for the low sound volume in this video. Please turn your volume up.]
This is a demonstration of the reduced Yaw Drift which is possible when sampling the gyros at 30,000 times / second (Thanks to William Premerlani for this R&D and code). Using QGroundControl and the MatrixPilot MAvlink implementation, I show a real time graph of the resulting negligble yaw drift in the UDB IMU.
In the demo I do refer to the accelerometers quite a bit. I should really have been focussing on the gyros. It is the high sampling of the gyros, and the integration of the resulting data which leads to the low yaw drift. So please ignore my comments about the accelerometers.
Demonstration uses Revision 790 of MatrixPilot_mavlink branch at this address
code.google.com/p/gentlenav/
Comments
I have not tried interpolation myself yet, so I do not know it the gain (if any) is worth the overhead. But if you consider what a gyro signal represent, I think interpolation makes sense. The way I see it, a gyro outputs an analog signal (with a theoretically infinite resolution) that represents rotation of an object. And since the object has mass we have rotation inertia. Meaning that if we look closely enough, the signal will always change gradually. And it is this gradual change (that the ADC is not capable of sampling), that I think interpolation can approximate.
You are correct, Bill. The formula assumes that the magnitude of the incoming signals in the transition band are no larger than zero dB - in other words, that there are no resonant peaks. From what you are saying, this assumption appears to be violated.
- Roy
Hi Roy,
Basically, you have it right.
However, the formula that you cite must make some assumptions about the magnitudes of the signals that we are trying to block, otherwise I would expect to see that in the formula, but it does not make any mention of the magnitude of the high frequency noise.
The problem is, the signal from vibration can be so very large, that even a properly designed anti-aliasing filter does not take it out, so it winds up aliasing into the signal.
One of the UDB users has recently reported that by using 32,000 samples per second, he was able to solve a vibration problem he was having with a glow-engine powered aircraft.
Finally, to your question about the anti-aliasing filter in the UDB, off hand I can only give you an approximate answer. I am in the process of reorganizing my notes and papers on the UDB, and I cannot find my notes on the analog anti-aliasing filters. My recollection is that it has two first order low pass filters. There is a first order low pass filter internal to the Invensense gyros, with a cutoff frequency of 100 Hz. There is also an RC filter between the gyros and the A/D. However, SparkFun accidentally swapped the R and the C, so the C sits right on the output pin of the gyro, so there is an RC filter with the R equal to the output resistance of the gyro. The capacitor is 0.1 microfards, my guess is the cutoff frequency is rather high, probably between 1000 Hz and 2000 Hz.
So, the gyros in the UDB have internal first order low pass filters with 100 Hz cutoff, and external low pass filters with about 1500 Hz cutoff.
Best regards,
Bill
I am using interrupts and running the ADC as quickly as it can.
I am intrigued by your interpolation idea, but I'm struggling with its benefits from a theoretical point of view. I think the benefits of oversampling are that it: 1) reduces aliasing errors, 2) statistically increases the effective number of bits (ENOB) in terms of ADC resolution, and 3) makes it easier to design digital filters due to the additional headroom in the frequency domain. The first item definitely does not apply for interpolation, and the third one unquestionably does. The second one I'm not sure about. It would seem that if your anti-aliasing filter is designed properly, that you could have good fidelity results with a linear scheme (as Bill suggested). After all, the signal should be band-limited and shouldn't be changing too rapidly between samples (perhaps a non-linear interpolation could provide better results? Isn't the "ideal" interpolator a "sinc" function?).
But, if you're just going to downsample/decimate anyway, I don't know if there's any benefit. It will also take time to compute the interpolation (which will only increase for more complicated algorithms), which may cut into your throughput.
Perhaps a DSP expert could shed some light on this?
Thanks
Roy
@Bill
Oops - it appears I've run into a character limit! Here's the rest:
Can you tell me the cutoff frequency and the order of the UAV Dev board's antialiasing filter? Is it just a simple RC filter (first order)?
Thanks, as always for your wonderful work and for being willing to discuss it with us.
Roy
Let me see if I understand what you're saying. The integral feedback terms of DCM should eventually converge to the gyro bias (in my experience, the bias is not constant but varies slowly. Let's assume the bias is constant for this conversation). This is why DCM subtracts the I term (but not the P term) from the sensor readings to determine the best estimate of angular velocity. This bias is an actual voltage, so it is there regardless of the ADC sample rate. When you say "residual offsets", I think you mean the difference between the converged I term and the sensor readings (perhaps averaged or filtered to eliminate noise)? You don't mean that the I term itself is converging toward zero, do you? So the oversampling works by allowing the system to determine the gyro bias more accurately, thus reducing the error or drift. (But not eliminating it, since the bias is not constant, as I said earlier). Does that sound right?
I think I have a way to determine the point of diminishing returns. You want a system such that the anti-aliasing filter reduces the magnitude of any signal that is beyond the Nyquist frequency (half the sampling frequency) to less than the (effective) LSB of your ADC. According to the Industrial Electronics Handbook, from CRC Press, pages 111 - 114 (can be found on Google Books), the formula for this is
M >= 3 N / (10 log(R/2))
Where:
M = number of filter poles
N = number of ADC bits (or effective bits obtained via oversampling)
R = ratio of sampling frequency to filter cutoff frequency (Fs = R Fc)
log = base 10 logarithm
(If aliasing in the transition band is allowed (but no aliasing in the pass band), then the formula is:
M >= 3 N / (10 log(R-1))
This assumes no resonant peaks in the transition band, so you'd have to adjust this formula to account for those. Can you tell me the cutoff frequency and the order of the UAV Dev board's anti-al
Hi Roy,
At some point, you will run into diminishing returns as you raise the sampling rate. Limiting factors include other sources of error in the calculations, the time required for the sample and hold to settle, and CPU loading. In the case of MatrixPilot running on the UAV Devboard, we are using 16 bit integer arithmetic for most calculations, so that really is the main limiting factor.
In the case of the UAVDevboard running MatrixPilot, CPU loading is not an issue. At 32,000 samples per second, the CPU loading attributable to sampling was only 1%.
Here is how I selected 32,000 samples per second:
What I have in mind is quad and heli applications. Some members of the UDB team have measured heli vibrations in the 5,000 to 10,000 Hz range, so I wanted to go higher than that.
I tried various sampling rates from 1000 to 32000 Hz, and found that resolution and residual drift continued to improve as I raised the sampling rate.
One thing I looked at was the residual gyro offsets. The UDB has a 10 bit A/D converter, and most arithmetic is done with 16 bit integers. Raising the sampling rate increases the number of effective bits. At around 32,000 samples per second, I was seeing approximately 15 bits resolution, as evidenced by residual gyro offsets on the order of a single bit in 16 bits. So I decided to stop there.
The way I measured the residual offsets was by looking at the values of the integral terms in the PI drift controller. Once the PI controller achieves lock, the value of the integrator represents the residual gyro drift. I could see the residual drift dropping as I raised the sampling rate. When it approached zero, that was far enough.
Best regards,
Bill
Bill P, Pete, et al, I understand the benefits of oversampling, and why higher rates are better than lower ones. However, at some point you have to run into diminishing returns or processor limitations. So is 30KHz the limit of your CPU? Would 15KHz be almost as good? Would 60KHz be noticeably better? Is the main benefit obtained by sampling some multiple of the sensor resonance? Thanks again for advancing the DIY UAV state of the art.
@ Nathan - let us know how it turns out. The issue with the some AVRs and arduinos on which they are based is that they only have a single ADC hardware unit. So if you have multiple sensors, you have to divide the rate by the number of sensors, hence my 2KHz result.
- Roy
Nathan,
Yes, I am subtracting the offset after the integration. The way it is implemented, the raw samples are simply summed and averaged all of the time. During power up, the offsets are computed from the "integrate and dump" values.
Best regards,
Bill