I just discovered something else interesting about the gyro code... specifically the way the angle resolution relates to the analog input scaling.
I detected this as I was logging heading data as I was driving around and around our track.
On my system I have 4 Analog inputs, that I'm running 4 amples per update at 1600 Hz... This give me a Gyro update rate of 100 updates per second, and an ADC Range of 2048 and
In the Gyro code... for an ADXRS150 I have
Quote:
|
#define GYRO_SENSITIVITY_RAD 1396L // in units of milliradians/sec/volt
|
And finally I have
Quote:
long Get_Gyro_Angle(void)
{
// Return the calculated gyro angle to the caller.
return(((gyro_angle * GYRO_SENSITIVITY * 5L) / (ADC_RANGE * ADC_UPDATE_RATE)) * GYRO_CAL_FACTOR);
}
|
So, since I've been caught before on this one.. I calculated the value of the divisor of this expression. ADC_RANGE * ADC_UPDATE_RATE = 2048 * 100 = 204800. So I'm dividing a "Long" by this number.... I should be able to calculate the maximum result I can get...
Max Long is 2147483648 so if I divide this by 204800 I get 10485 ... Which, in theory is the maximum result I can get...
But wait, this is millirads so the maximum angle I can measue is... just over 1.6 full rotations...
Oops... Either I did my math wrong, or I have to reduce my update rate.
In fact, this does reflect what I see in my log data... after getting to 10485 mRad, the angle starts counting down again...
So I need to reduce my ADC range/rate, or reduce my measurement accuracy (like changing to tenth of a degree.)
No wonder my bot corrected in the wrong direction on evey second lap
