public class Encoder extends CounterBase implements SensorModule, PIDSource, RateSource
| Modifier and Type | Class and Description |
|---|---|
static class |
Encoder.IndexingType
The different types of indexing available
|
CounterBase.EncodingTypePIDSource.PIDSourceType| Modifier and Type | Field and Description |
|---|---|
private boolean |
m_allocatedA |
private boolean |
m_allocatedB |
private boolean |
m_allocatedI |
protected DigitalIO |
m_aSource
The a source
|
protected DigitalIO |
m_bSource
The b source
|
private Counter |
m_counter |
private double |
m_distancePerPulse |
private java.nio.ByteBuffer |
m_encoder |
private int |
m_encodingScale |
private CounterBase.EncodingType |
m_encodingType |
protected DigitalIO |
m_indexSource
The index source
|
private PIDSource.PIDSourceType |
m_pidSType |
m_index| Modifier | Constructor and Description |
|---|---|
|
Encoder(DigitalIO.DigitalChannel aChannel,
DigitalIO.DigitalChannel bChannel)
Encoder constructor.
|
|
Encoder(DigitalIO.DigitalChannel aChannel,
DigitalIO.DigitalChannel bChannel,
boolean reverseDirection)
Encoder constructor.
|
|
Encoder(DigitalIO.DigitalChannel aChannel,
DigitalIO.DigitalChannel bChannel,
boolean reverseDirection,
CounterBase.EncodingType eType)
Encoder constructor.
|
|
Encoder(DigitalIO.DigitalChannel aChannel,
DigitalIO.DigitalChannel bChannel,
DigitalIO.DigitalChannel iChannel)
Encoder constructor.
|
|
Encoder(DigitalIO.DigitalChannel aChannel,
DigitalIO.DigitalChannel bChannel,
DigitalIO.DigitalChannel iChannel,
boolean reverseDirection)
Encoder constructor.
|
|
Encoder(DigitalIO aSource,
DigitalIO bSource)
Encoder constructor.
|
|
Encoder(DigitalIO aSource,
DigitalIO bSource,
boolean reverseDirection)
Encoder constructor.
|
|
Encoder(DigitalIO aSource,
DigitalIO bSource,
boolean reverseDirection,
CounterBase.EncodingType eType)
Encoder constructor.
|
|
Encoder(DigitalIO aSource,
DigitalIO bSource,
DigitalIO iSource)
Encoder constructor.
|
|
Encoder(DigitalIO aSource,
DigitalIO bSource,
DigitalIO iSource,
boolean reverseDirection)
Encoder constructor.
|
private |
Encoder(DigitalIO aSource,
DigitalIO bSource,
DigitalIO iSource,
boolean reverseDirection,
CounterBase.EncodingType eType)
Encoder constructor.
|
| Modifier and Type | Method and Description |
|---|---|
double |
decodingScaleFactor()
The scale needed to convert a raw counter value into a number of encoder
pulses.
|
void |
disableModule()
Disable the module
|
void |
enableModule()
Enable the module
|
void |
free() |
int |
get()
Gets the current count.
|
int |
getCount()
Gets the current count.
|
boolean |
getDirection()
The last direction the encoder value changed.
|
double |
getDistance()
Get the distance the robot has driven since the last reset.
|
int |
getEncodingScale() |
boolean |
getModuleEnabled() |
double |
getPeriod()
Returns the period of the most recent pulse.
|
double |
getRate()
Get the current rate of the encoder.
|
int |
getRaw()
Gets the raw value from the encoder.
|
int |
getSamplesPerAverage()
Get the Samples to Average which specifies the number of samples of the
timer to average when calculating the period.
|
boolean |
getStopped()
Determine if the encoder is stopped.
|
double |
pidGet() |
void |
reset()
Reset the Encoder distance to zero.
|
void |
setDistancePerPulse(double distance)
Set the distance per pulse for this encoder.
|
void |
setIndexSource(DigitalIO.DigitalChannel channel)
Set the index source for the encoder.
|
void |
setIndexSource(DigitalIO.DigitalChannel channel,
Encoder.IndexingType iType)
Set the index source for the encoder.
|
void |
setIndexSource(DigitalIO source)
Set the index source for the encoder.
|
void |
setIndexSource(DigitalIO source,
Encoder.IndexingType iType)
Set the index source for the encoder.
|
void |
setMaxPeriod(double maxPeriod)
Sets the maximum period for stopped detection.
|
void |
setMinRate(double minRate)
Set the minimum rate of the device before the hardware reports it
stopped.
|
void |
setPIDSourceType(PIDSource.PIDSourceType sType)
Set which parameter of the encoder you are using as a process control
variable.
|
void |
setReverseDirection(boolean reverse)
Set the direction sensing for this encoder.
|
void |
setSamplesPerAverage(int samples)
Set the Samples to Average which specifies the number of samples of the
timer to average when calculating the period.
|
getFPGAIndexprotected DigitalIO m_aSource
protected DigitalIO m_bSource
protected DigitalIO m_indexSource
private java.nio.ByteBuffer m_encoder
private double m_distancePerPulse
private Counter m_counter
private CounterBase.EncodingType m_encodingType
private int m_encodingScale
private boolean m_allocatedA
private boolean m_allocatedB
private boolean m_allocatedI
private PIDSource.PIDSourceType m_pidSType
public Encoder(DigitalIO.DigitalChannel aChannel, DigitalIO.DigitalChannel bChannel)
aChannel - The a channel DigitalIO.DigitalChannel.bChannel - The b channel DigitalIO.DigitalChannel.public Encoder(DigitalIO aSource, DigitalIO bSource)
aSource - The source that should be used for the a channel.bSource - the source that should be used for the b channel.public Encoder(DigitalIO.DigitalChannel aChannel, DigitalIO.DigitalChannel bChannel, boolean reverseDirection)
aChannel - The a channel DigitalIO.DigitalChannel.bChannel - The b channel DigitalIO.DigitalChannel.reverseDirection - represents the orientation of the encoder
and inverts the output values if necessary so forward represents
positive values.public Encoder(DigitalIO aSource, DigitalIO bSource, boolean reverseDirection)
aSource - The source that should be used for the a channel.bSource - the source that should be used for the b channel.reverseDirection - represents the orientation of the encoder
and inverts the output values if necessary so forward represents
positive values.public Encoder(DigitalIO.DigitalChannel aChannel, DigitalIO.DigitalChannel bChannel, DigitalIO.DigitalChannel iChannel)
aChannel - The a channel DigitalIO.DigitalChannel.bChannel - The b channel DigitalIO.DigitalChannel.iChannel - The index channel DigitalIO.DigitalChannel.public Encoder(DigitalIO aSource, DigitalIO bSource, DigitalIO iSource)
aSource - The source that should be used for the a channel.bSource - the source that should be used for the b channel.iSource - the source that should be used for the index channel.public Encoder(DigitalIO.DigitalChannel aChannel, DigitalIO.DigitalChannel bChannel, boolean reverseDirection, CounterBase.EncodingType eType)
aChannel - The a channel DigitalIO.DigitalChannel.bChannel - The b channel DigitalIO.DigitalChannel.reverseDirection - represents the orientation of the encoder
and inverts the output values if necessary so forward represents
positive values.eType - either k1X, k2X, or k4X to indicate 1X, 2X or 4X
decoding. If 4X is selected, then an encoder FPGA object is used
and the returned counts will be 4x the encoder spec'd value since
all rising and falling edges are counted. If 1X or 2X are selected
then a counter object will be used and the returned value will either
exactly match the spec'd count or be double (2x) the spec'd count.public Encoder(DigitalIO aSource, DigitalIO bSource, boolean reverseDirection, CounterBase.EncodingType eType)
aSource - The source that should be used for the a channel.bSource - the source that should be used for the b channel.reverseDirection - represents the orientation of the encoder
and inverts the output values if necessary so forward represents
positive values.eType - either k1X, k2X, or k4X to indicate 1X, 2X or 4X
decoding. If 4X is selected, then an encoder FPGA object is used
and the returned counts will be 4x the encoder spec'd value since
all rising and falling edges are counted. If 1X or 2X are selected
then a counter object will be used and the returned value will either
exactly match the spec'd count or be double (2x) the spec'd count.public Encoder(DigitalIO.DigitalChannel aChannel, DigitalIO.DigitalChannel bChannel, DigitalIO.DigitalChannel iChannel, boolean reverseDirection)
aChannel - The a channel DigitalIO.DigitalChannel.bChannel - The b channel DigitalIO.DigitalChannel.iChannel - The index channel DigitalIO.DigitalChannel.reverseDirection - represents the orientation of the encoder
and inverts the output values if necessary so forward represents
positive values.public Encoder(DigitalIO aSource, DigitalIO bSource, DigitalIO iSource, boolean reverseDirection)
aSource - The source that should be used for the a channel.bSource - the source that should be used for the b channel.iSource - the source that should be used for the index channel.reverseDirection - represents the orientation of the encoder
and inverts the output values if necessary so forward represents
positive values.private Encoder(DigitalIO aSource, DigitalIO bSource, DigitalIO iSource, boolean reverseDirection, CounterBase.EncodingType eType)
aSource - The source that should be used for the a channel.bSource - the source that should be used for the b channel.iSource - the source that should be used for the index channel.reverseDirection - represents the orientation of the encoder
and inverts the output values if necessary so forward represents
positive values.eType - either k1X, k2X, or k4X to indicate 1X, 2X or 4X
decoding. If 4X is selected, then an encoder FPGA object is used
and the returned counts will be 4x the encoder spec'd value since
all rising and falling edges are counted. If 1X or 2X are selected
then a counter object will be used and the returned value will either
exactly match the spec'd count or be double (2x) the spec'd count.public int getEncodingScale()
public void free()
public int getRaw()
public int get()
get in class CounterBasepublic int getCount()
getCount in interface CounterSourcegetCount in class CounterBasepublic void reset()
reset in interface CounterSourcereset in class CounterBasepublic double getPeriod()
getPeriod in class CounterBasepublic void setMaxPeriod(double maxPeriod)
setMaxPeriod in class CounterBasemaxPeriod - The maximum time between rising and falling edges before the
FPGA will report the device stopped. This is expressed in seconds.public boolean getStopped()
getStopped in class CounterBasepublic boolean getDirection()
getDirection in class CounterBasepublic double decodingScaleFactor()
public double getDistance()
public double getRate()
getRate in interface RateSourcepublic void setMinRate(double minRate)
minRate - The minimum rate. The units are in distance per second
as scaled by the value from setDistancePerPulse().public void setDistancePerPulse(double distance)
distance - The scale factor that will be used to convert
pulses to useful units.public void setReverseDirection(boolean reverse)
reverse - true if the encoder direction should be reversedpublic void setSamplesPerAverage(int samples)
samples - The number of samples to average from 1 to 127.public int getSamplesPerAverage()
public void setPIDSourceType(PIDSource.PIDSourceType sType)
sType - An enum to select the parameter.public void setIndexSource(DigitalIO.DigitalChannel channel, Encoder.IndexingType iType)
channel - A DigitalIO.DigitalChannel to set as the encoder indexiType - The state that will cause the encoder to resetpublic void setIndexSource(DigitalIO source, Encoder.IndexingType iType)
source - A digital source to set as the encoder indexiType - The state that will cause the encoder to resetpublic void setIndexSource(DigitalIO.DigitalChannel channel)
channel - A DigitalIO.DigitalChannel to set as the encoder indexpublic void setIndexSource(DigitalIO source)
source - A digital source to set as the encoder indexpublic void enableModule()
enableModule in interface Modulepublic void disableModule()
disableModule in interface Modulepublic boolean getModuleEnabled()
getModuleEnabled in interface Module