mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Encoder/Counter Fixes
This fixes all encoder variants with the getRate and getPeriod methods. The clock speed in the HAL was updated, as was the scaling factors for setting the stall periods. A default of .5 seconds is now set for the max period. Additionally, a long standing bug was fixed with Java 2x encoders. Changed tests to take into account the increased default timeout on encoders Change-Id: I8b54c07ea467154be94d7ae7e9ada1775933dee4
This commit is contained in:
@@ -86,6 +86,8 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
m_upSource = null;
|
||||
m_downSource = null;
|
||||
|
||||
setMaxPeriod(.5);
|
||||
|
||||
UsageReporting.report(tResourceType.kResourceType_Counter, m_index,
|
||||
mode.value);
|
||||
}
|
||||
@@ -166,12 +168,16 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
if (encodingType == null)
|
||||
throw new NullPointerException("Encoding type given was null");
|
||||
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
if (encodingType == EncodingType.k1X) {
|
||||
setUpSourceEdge(true, false);
|
||||
CounterJNI.setCounterAverageSize(m_counter, 1, status.asIntBuffer());
|
||||
} else {
|
||||
setUpSourceEdge(true, true);
|
||||
CounterJNI.setCounterAverageSize(m_counter, 2, status.asIntBuffer());
|
||||
}
|
||||
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
setDownSourceEdge(inverted, true);
|
||||
}
|
||||
|
||||
@@ -374,7 +380,7 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.setCounterDownSourceEdge(m_counter, (byte) (risingEdge ? 1
|
||||
: 0), (byte) (fallingEdge ? 0 : 1), status.asIntBuffer());
|
||||
: 0), (byte) (fallingEdge ? 1 : 0), status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
|
||||
@@ -94,6 +94,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
m_index = index.asIntBuffer().get(0);
|
||||
m_counter = null;
|
||||
setMaxPeriod(.5);
|
||||
break;
|
||||
case EncodingType.k2X_val:
|
||||
case EncodingType.k1X_val:
|
||||
@@ -464,7 +465,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
public double getPeriod() {
|
||||
double measuredPeriod;
|
||||
if (m_counter != null) {
|
||||
measuredPeriod = m_counter.getPeriod();
|
||||
measuredPeriod = m_counter.getPeriod() / decodingScaleFactor();
|
||||
} else {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
@@ -472,7 +473,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
measuredPeriod = EncoderJNI.getEncoderPeriod(m_encoder, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
return measuredPeriod / decodingScaleFactor();
|
||||
return measuredPeriod;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user