|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Gyro reset() troubles
We were testing out some autonomous code over the weekend which utilized the gyro for turning. We were noticing that about 50% of the time our code didn't seem to be working. After placing in some debug print statements (see below) we confirmed the source of the problem.
The value printed before and after the reset are quite often the same non-zero number. About 50% of the time. This is quite repeatable on our hardware. I've tried multiple gyro sensors with similar results. Code:
public void resetGyro() {
double before = getGyroAngle();
gyro.reset();
System.out.println("Gyro Before: " + before + " After: " + getGyroAngle());
}
I was wondering if any one else was experiencing this behavior. It looks like the gyro.reset() call ultimately just boils down to the following: Code:
NiFpga.writeU32(m_DeviceHandle, kReset_Addresses[m_SystemIndex], 1, status); We have a workaround, but knowing others are seeing this problem would at least restore sanity to my world. |
|
#2
|
|||
|
|||
|
Re: Gyro reset() troubles
My understanding of the gyro is that a reset is not instantaneous. It takes a bit of time for the gryo to zero itself and during this time it is best not to move. If you changed your code to the following, you might be more likely to see a value closer to zero:
Code:
public void resetGyro() {
double before = getGyroAngle();
gyro.reset();
Timer.delay(2.0);
System.out.println("Gyro Before: " + before + " After: " + getGyroAngle());
}
Hope that helps, Paul |
|
#3
|
||||||
|
||||||
|
Re: Gyro reset() troubles
Quote:
We also never reset the gyro except at the beginning of autonomous, and track everything relative to the starting angle. It ends up being much more accurate if you ever want to come back to the starting angle. |
|
#4
|
||||
|
||||
|
Re: Gyro reset() troubles
Yea I was wondering if the gyro zeroed after the reset() was called myself, our command code was running after the code I listed above. This code was also printing out the current gyro angle. In the innumerable times I executed code, I never witnessed the current angle to suddenly jump to zero (what you would expect to happen if it were time related).
We are latching in our current heading at the beginning of commands as a workaround. There still seems to be a bug though. Would anyone mind instrumenting their code and seeing if the problem is present on your hardware as well? All of my crios are tied up at the moment. Last edited by otherguy : 12-02-2014 at 23:53. Reason: fixed autocorrect errs |
|
#5
|
||||
|
||||
|
Re: Gyro reset() troubles
The reset() method is a bit goofy. It does some type of calibration with the cRIO when you call it, which can take up to a second to complete, or sometimes happens instantly.
The reset method not only sets the current angle to zero, but recalibrates and adjusts some unknown thing in the FPGA by writing some random value to it's memory. To avoid this, I don't ever call their reset method, but instead add my own that will subtract the angle that was measured at the time of the reset from the current angle. This just zeros the angle rather than doing some weird calibration sequence. |
|
#6
|
|||
|
|||
|
Re: Gyro reset() troubles
As Joe pointed out, the reset() method only zeros the accumulator as you can see in this code from the Gyro class:
Code:
public void reset() {
if (m_analog != null) {
m_analog.resetAccumulator();
}
}
Let us know if that helps. |
|
#7
|
||||
|
||||
|
Re: Gyro reset() troubles
Quote:
I don't think this is time related. And I've never had to wait for the reset method to zero the gyro in the past. We've used this method extensively in the past and have never had a problem with it previously. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|