mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
Add methods to retreive the FPGA index for counters and encoders and return the encoding type as an integer
Change-Id: Iaa4062ec124b968b27e7c812cc754032fcb354d2 Add methods to retrieve the FPGA index for counters and encoders and return the encoding type as an integer Change-Id: If04dc291f39a9b331495d2b97a8b87d3ded71280
This commit is contained in:
@@ -67,7 +67,7 @@ public:
|
||||
bool GetDirection();
|
||||
void SetSamplesToAverage(int samplesToAverage);
|
||||
int GetSamplesToAverage();
|
||||
uint32_t GetIndex()
|
||||
uint32_t GetFPGAIndex()
|
||||
{
|
||||
return m_index;
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ public:
|
||||
// CounterBase interface
|
||||
int32_t Get();
|
||||
int32_t GetRaw();
|
||||
int32_t GetEncodingScale();
|
||||
void Reset();
|
||||
double GetPeriod();
|
||||
void SetMaxPeriod(double maxPeriod);
|
||||
@@ -63,6 +64,11 @@ public:
|
||||
void InitTable(ITable *subTable);
|
||||
ITable * GetTable();
|
||||
|
||||
int32_t GetFPGAIndex()
|
||||
{
|
||||
return m_index;
|
||||
}
|
||||
|
||||
private:
|
||||
void InitEncoder(bool _reverseDirection, EncodingType encodingType);
|
||||
double DecodingScaleFactor();
|
||||
@@ -72,9 +78,11 @@ private:
|
||||
bool m_allocatedASource; // was the A source allocated locally?
|
||||
bool m_allocatedBSource; // was the B source allocated locally?
|
||||
void* m_encoder;
|
||||
int32_t m_index; // The encoder's FPGA index.
|
||||
double m_distancePerPulse; // distance of travel for each encoder tick
|
||||
Counter *m_counter; // Counter object for 1x and 2x encoding
|
||||
EncodingType m_encodingType; // Encoding type
|
||||
int32_t m_encodingScale; // 1x, 2x, or 4x, per the encodingType
|
||||
PIDSourceParameter m_pidSource; // Encoder parameter that sources a PID controller
|
||||
|
||||
ITable *m_table;
|
||||
|
||||
@@ -23,8 +23,8 @@ void Counter::InitCounter(Mode mode)
|
||||
m_table = NULL;
|
||||
|
||||
int32_t status = 0;
|
||||
uint32_t index = 0;
|
||||
m_counter = initializeCounter(mode, &index, &status);
|
||||
m_index = 0;
|
||||
m_counter = initializeCounter(mode, &m_index, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
|
||||
m_upSource = NULL;
|
||||
@@ -34,7 +34,7 @@ void Counter::InitCounter(Mode mode)
|
||||
|
||||
SetMaxPeriod(.5);
|
||||
|
||||
HALReport(HALUsageReporting::kResourceType_Counter, index, mode);
|
||||
HALReport(HALUsageReporting::kResourceType_Counter, m_index, mode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,11 +28,12 @@ void Encoder::InitEncoder(bool reverseDirection, EncodingType encodingType)
|
||||
{
|
||||
m_table = NULL;
|
||||
m_encodingType = encodingType;
|
||||
int32_t index = 0;
|
||||
m_index = 0;
|
||||
switch (encodingType)
|
||||
{
|
||||
case k4X:
|
||||
{
|
||||
m_encodingScale = 4;
|
||||
if (m_aSource->StatusIsFatal())
|
||||
{
|
||||
CloneError(m_aSource);
|
||||
@@ -44,12 +45,11 @@ void Encoder::InitEncoder(bool reverseDirection, EncodingType encodingType)
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
int32_t index = 0;
|
||||
m_encoder = initializeEncoder(m_aSource->GetModuleForRouting(), m_aSource->GetChannelForRouting(),
|
||||
m_aSource->GetAnalogTriggerForRouting(),
|
||||
m_bSource->GetModuleForRouting(), m_bSource->GetChannelForRouting(),
|
||||
m_bSource->GetAnalogTriggerForRouting(),
|
||||
reverseDirection, &index, &status);
|
||||
reverseDirection, &m_index, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
m_counter = NULL;
|
||||
SetMaxPeriod(.5);
|
||||
@@ -58,15 +58,19 @@ void Encoder::InitEncoder(bool reverseDirection, EncodingType encodingType)
|
||||
case k1X:
|
||||
case k2X:
|
||||
{
|
||||
m_encodingScale = encodingType == k1X ? 1 : 2;
|
||||
m_counter = new Counter(m_encodingType, m_aSource, m_bSource, reverseDirection);
|
||||
index = m_counter->GetIndex();
|
||||
m_index = m_counter->GetFPGAIndex();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
wpi_setErrorWithContext(-1, "Invalid encodingType argument");
|
||||
break;
|
||||
}
|
||||
m_distancePerPulse = 1.0;
|
||||
m_pidSource = kDistance;
|
||||
|
||||
HALReport(HALUsageReporting::kResourceType_Encoder, index, encodingType);
|
||||
HALReport(HALUsageReporting::kResourceType_Encoder, m_index, encodingType);
|
||||
LiveWindow::GetInstance()->AddSensor("Encoder", m_aSource->GetChannelForRouting(), this);
|
||||
}
|
||||
|
||||
@@ -178,6 +182,12 @@ Encoder::~Encoder()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The encoding scale factor 1x, 2x, or 4x, per the requested encodingType.
|
||||
* Used to divide raw edge counts down to spec'd counts.
|
||||
*/
|
||||
int32_t Encoder::GetEncodingScale() { return m_encodingScale; }
|
||||
|
||||
/**
|
||||
* Gets the raw value from the encoder.
|
||||
* The raw value is the actual count unscaled by the 1x, 2x, or 4x scale
|
||||
@@ -232,7 +242,7 @@ void Encoder::Reset()
|
||||
/**
|
||||
* Returns the period of the most recent pulse.
|
||||
* Returns the period of the most recent Encoder pulse in seconds.
|
||||
* This method compenstates for the decoding type.
|
||||
* This method compensates for the decoding type.
|
||||
*
|
||||
* @deprecated Use GetRate() in favor of this method. This returns unscaled periods and GetRate() scales using value from SetDistancePerPulse().
|
||||
*
|
||||
|
||||
@@ -37,6 +37,7 @@ public:
|
||||
// CounterBase interface
|
||||
int32_t Get();
|
||||
int32_t GetRaw();
|
||||
int32_t GetEncodingScale();
|
||||
void Reset();
|
||||
double GetPeriod();
|
||||
void SetMaxPeriod(double maxPeriod);
|
||||
@@ -59,6 +60,11 @@ public:
|
||||
void InitTable(ITable *subTable);
|
||||
ITable * GetTable();
|
||||
|
||||
int32_t FPGAEncoderIndex()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
private:
|
||||
void InitEncoder(int channelA, int channelB, bool _reverseDirection, EncodingType encodingType);
|
||||
double DecodingScaleFactor();
|
||||
@@ -70,6 +76,7 @@ private:
|
||||
int channelA, channelB;
|
||||
double m_distancePerPulse; // distance of travel for each encoder tick
|
||||
EncodingType m_encodingType; // Encoding type
|
||||
int32_t m_encodingScale; // 1x, 2x, or 4x, per the encodingType
|
||||
PIDSourceParameter m_pidSource; // Encoder parameter that sources a PID controller
|
||||
bool m_reverseDirection;
|
||||
SimEncoder* impl;
|
||||
|
||||
@@ -28,6 +28,9 @@ void Encoder::InitEncoder(int channelA, int channelB, bool reverseDirection, Enc
|
||||
this->channelA = channelA;
|
||||
this->channelB = channelB;
|
||||
m_encodingType = encodingType;
|
||||
m_encodingScale = encodingType == k4X ? 4
|
||||
: encodingType == k2X ? 2
|
||||
: 1;
|
||||
|
||||
int32_t index = 0;
|
||||
m_distancePerPulse = 1.0;
|
||||
@@ -188,6 +191,12 @@ double Encoder::DecodingScaleFactor()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The encoding scale factor 1x, 2x, or 4x, per the requested encodingType.
|
||||
* Used to divide raw edge counts down to spec'd counts.
|
||||
*/
|
||||
int32_t Encoder::GetEncodingScale() { return m_encodingScale; }
|
||||
|
||||
/**
|
||||
* Gets the raw value from the encoder.
|
||||
* The raw value is the actual count unscaled by the 1x, 2x, or 4x scale
|
||||
|
||||
@@ -216,6 +216,13 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
m_counter = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Counter's FPGA index
|
||||
*/
|
||||
public int getFPGAIndex() {
|
||||
return m_index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the upsource for the counter as a digital input channel.
|
||||
*
|
||||
|
||||
@@ -52,6 +52,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
// tick
|
||||
private Counter m_counter; // Counter object for 1x and 2x encoding
|
||||
private EncodingType m_encodingType = EncodingType.k4X;
|
||||
private int m_encodingScale; // 1x, 2x, or 4x, per the encodingType
|
||||
private boolean m_allocatedA;
|
||||
private boolean m_allocatedB;
|
||||
private boolean m_allocatedI;
|
||||
@@ -77,6 +78,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
private void initEncoder(boolean reverseDirection) {
|
||||
switch (m_encodingType.value) {
|
||||
case EncodingType.k4X_val:
|
||||
m_encodingScale = 4;
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
@@ -98,8 +100,10 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
break;
|
||||
case EncodingType.k2X_val:
|
||||
case EncodingType.k1X_val:
|
||||
m_encodingScale = m_encodingType == EncodingType.k1X ? 1 : 2;
|
||||
m_counter = new Counter(m_encodingType, m_aSource, m_bSource,
|
||||
reverseDirection);
|
||||
m_index = m_counter.getFPGAIndex();
|
||||
break;
|
||||
}
|
||||
m_distancePerPulse = 1.0;
|
||||
@@ -375,6 +379,21 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
this(aSource, bSource, indexSource, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Encoder's FPGA index
|
||||
*/
|
||||
public int getFPGAIndex() {
|
||||
return m_index;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the encoding scale factor 1x, 2x, or 4x, per the requested
|
||||
* encodingType. Used to divide raw edge counts down to spec'd counts.
|
||||
*/
|
||||
public int getEncodingScale() {
|
||||
return m_encodingScale;
|
||||
}
|
||||
|
||||
public void free() {
|
||||
if (m_aSource != null && m_allocatedA) {
|
||||
m_aSource.free();
|
||||
|
||||
@@ -29,6 +29,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
private int m_index;
|
||||
private double m_distancePerPulse; // distance of travel for each encoder tick
|
||||
private EncodingType m_encodingType = EncodingType.k4X;
|
||||
private int m_encodingScale; // 1x, 2x, or 4x, per the encodingType
|
||||
private boolean m_allocatedA;
|
||||
private boolean m_allocatedB;
|
||||
private boolean m_allocatedI;
|
||||
@@ -56,6 +57,9 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
private void initEncoder(int aChannel, int bChannel, boolean reverseDirection) {
|
||||
m_distancePerPulse = 1.0;
|
||||
m_pidSource = PIDSourceParameter.kDistance;
|
||||
m_encodingScale = m_encodingType == EncodingType.k4X ? 4
|
||||
: m_encodingType == EncodingType.k2X ? 2
|
||||
: 1;
|
||||
|
||||
LiveWindow.addSensor("Encoder", aChannel, this);
|
||||
|
||||
@@ -142,6 +146,21 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
initEncoder(aChannel, bChannel, reverseDirection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Encoder's FPGA index
|
||||
*/
|
||||
public int getFPGAEncoderIndex() {
|
||||
return m_index;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the encoding scale factor 1x, 2x, or 4x, per the requested
|
||||
* encodingType. Used to divide raw edge counts down to spec'd counts.
|
||||
*/
|
||||
public int getEncodingScale() {
|
||||
return m_encodingScale;
|
||||
}
|
||||
|
||||
public void free() {}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user