mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Gyro deadband defaults to 0
The gyro class no longer attempts to set a default deadband, but it still has an optional SetDeadband() method. The gyro integration tests were modified and still pass consistently. Change-Id: I08a97b00b98b49b0a3c63306fcc809857523af2b
This commit is contained in:
@@ -27,8 +27,7 @@ public class Gyro extends SensorBase implements PIDSource, LiveWindowSendable {
|
||||
static final int kOversampleBits = 10;
|
||||
static final int kAverageBits = 0;
|
||||
static final double kSamplesPerSecond = 50.0;
|
||||
static final double kCalibrationSampleTime = 0.01;
|
||||
static final int kNumCalibrationSamples = 500;
|
||||
static final double kCalibrationSampleTime = 5.0;
|
||||
static final double kDefaultVoltsPerDegreePerSecond = 0.007;
|
||||
private AnalogInput m_analog;
|
||||
double m_voltsPerDegreePerSecond;
|
||||
@@ -57,26 +56,12 @@ public class Gyro extends SensorBase implements PIDSource, LiveWindowSendable {
|
||||
double sampleRate = kSamplesPerSecond
|
||||
* (1 << (kAverageBits + kOversampleBits));
|
||||
AnalogInput.setGlobalSampleRate(sampleRate);
|
||||
|
||||
Timer.delay(1.0);
|
||||
|
||||
m_analog.initAccumulator();
|
||||
m_analog.resetAccumulator();
|
||||
|
||||
// Get the lowest and highest value that occur within a large number of
|
||||
// calibration samples. These are used to determine an appropriate
|
||||
// default deadband.
|
||||
int lowestSample = Integer.MAX_VALUE, highestSample = Integer.MIN_VALUE;
|
||||
for(int i = 0; i < kNumCalibrationSamples; i++) {
|
||||
int sample = m_analog.getAverageValue();
|
||||
|
||||
if(sample < lowestSample) {
|
||||
lowestSample = sample;
|
||||
} else if(sample > highestSample) {
|
||||
highestSample = sample;
|
||||
}
|
||||
|
||||
Timer.delay(kCalibrationSampleTime);
|
||||
}
|
||||
Timer.delay(kCalibrationSampleTime);
|
||||
|
||||
m_analog.getAccumulatorOutput(result);
|
||||
|
||||
@@ -85,12 +70,11 @@ public class Gyro extends SensorBase implements PIDSource, LiveWindowSendable {
|
||||
m_offset = ((double) result.value / (double) result.count)
|
||||
- m_center;
|
||||
|
||||
int deadband = Math.max(highestSample - m_center, m_center - lowestSample);
|
||||
|
||||
m_analog.setAccumulatorCenter(m_center);
|
||||
m_analog.setAccumulatorDeadband(deadband);
|
||||
m_analog.resetAccumulator();
|
||||
|
||||
setDeadband(0.0);
|
||||
|
||||
setPIDSourceParameter(PIDSourceParameter.kAngle);
|
||||
|
||||
UsageReporting.report(tResourceType.kResourceType_Gyro, m_analog.getChannel());
|
||||
@@ -209,8 +193,9 @@ public class Gyro extends SensorBase implements PIDSource, LiveWindowSendable {
|
||||
|
||||
/**
|
||||
* Set the size of the neutral zone. Any voltage from the gyro less than
|
||||
* this amount from the center is considered stationary. This is set by
|
||||
* default after calibration.
|
||||
* this amount from the center is considered stationary. Setting a
|
||||
* deadband will decrease the amount of drift when the gyro isn't rotating,
|
||||
* but will make it less accurate.
|
||||
*
|
||||
* @param volts The size of the deadband in volts
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user