Accumulators wait for the next sample after reset

Analog accumulators now wait for the amount of time a full sample
(including oversampling and averaging) lasts after
AnalogInput::ResetAccumulator() is called, so they don't return
old values after being reset.

This delay should be microseconds long and will only happen
when an accumulator is reset.

A new test is is the C++ TiltPanCameraTest that tests this behavior
with the Gyro class.

Change-Id: I1b3ffdeec187959f95c5e637a6d428c9a4bc2cf4
This commit is contained in:
Thomas Clark
2014-07-31 15:46:14 -04:00
parent 2735406bfb
commit 8fe888dbc9
3 changed files with 34 additions and 6 deletions

View File

@@ -7,6 +7,7 @@
#include "AnalogInput.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "Resource.h"
#include "Timer.h"
#include "WPIErrors.h"
#include "LiveWindow/LiveWindow.h"
@@ -284,6 +285,16 @@ void AnalogInput::ResetAccumulator()
int32_t status = 0;
resetAccumulator(m_port, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
if(!StatusIsFatal())
{
// Wait until the next sample, so the next call to GetAccumulator*()
// won't have old values.
const float sampleTime = 1.0f / GetSampleRate();
const float overSamples = 1 << GetOversampleBits();
const float averageSamples = 1 << GetAverageBits();
Wait(sampleTime * overSamples * averageSamples);
}
}
/**