|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.wpi.first.wpilibj.SensorBase
edu.wpi.first.wpilibj.Encoder
public class Encoder
Class to read quad encoders. Quadrature encoders are devices that count shaft rotation and can sense direction. The output of the QuadEncoder class is an integer that can count either up or down, and can go negative for reverse direction counting. When creating QuadEncoders, a direction is supplied that changes the sense of the output to make code more readable if the encoder is mounted such that forward movement generates negative values. Quadrature encoders have two digital outputs, an A Channel and a B Channel that are out of phase with each other to allow the FPGA to do direction sensing.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface edu.wpi.first.wpilibj.CounterBase |
---|
CounterBase.EncodingType |
Nested classes/interfaces inherited from interface edu.wpi.first.wpilibj.PIDSource |
---|
PIDSource.PIDSourceParameter |
Field Summary | |
---|---|
protected DigitalSource |
m_aSource
The a source |
protected DigitalSource |
m_bSource
The b source |
protected DigitalSource |
m_indexSource
The index source |
Fields inherited from class edu.wpi.first.wpilibj.SensorBase |
---|
kAnalogChannels, kAnalogModules, kDigitalChannels, kPwmChannels, kRelayChannels, kSolenoidChannels, kSolenoidModules, kSystemClockTicksPerMicrosecond |
Constructor Summary | |
---|---|
Encoder(DigitalSource aSource,
DigitalSource bSource)
Encoder constructor. |
|
Encoder(DigitalSource aSource,
DigitalSource bSource,
boolean reverseDirection)
Encoder constructor. |
|
Encoder(DigitalSource aSource,
DigitalSource bSource,
boolean reverseDirection,
CounterBase.EncodingType encodingType)
Encoder constructor. |
|
Encoder(DigitalSource aSource,
DigitalSource bSource,
DigitalSource indexSource)
Encoder constructor. |
|
Encoder(DigitalSource aSource,
DigitalSource bSource,
DigitalSource indexSource,
boolean reverseDirection)
Encoder constructor. |
|
Encoder(int aChannel,
int bChannel)
Encoder constructor. |
|
Encoder(int aChannel,
int bChannel,
boolean reverseDirection)
Encoder constructor. |
|
Encoder(int aChannel,
int bChannel,
boolean reverseDirection,
CounterBase.EncodingType encodingType)
Encoder constructor. |
|
Encoder(int aChannel,
int bChannel,
int indexChannel)
Encoder constructor. |
|
Encoder(int aChannel,
int bChannel,
int indexChannel,
boolean reverseDirection)
Encoder constructor. |
|
Encoder(int aSlot,
int aChannel,
int bSlot,
int bChannel)
Encoder constructor. |
|
Encoder(int aSlot,
int aChannel,
int bSlot,
int bChannel,
boolean reverseDirection)
Encoder constructor. |
|
Encoder(int aSlot,
int aChannel,
int bSlot,
int bChannel,
boolean reverseDirection,
CounterBase.EncodingType encodingType)
Encoder constructor. |
|
Encoder(int aSlot,
int aChannel,
int bSlot,
int bChannel,
int indexSlot,
int indexChannel)
Encoder constructor. |
|
Encoder(int aSlot,
int aChannel,
int bSlot,
int bChannel,
int indexSlot,
int indexChannel,
boolean reverseDirection)
Encoder constructor. |
Method Summary | |
---|---|
void |
free()
Free the resources used by this object |
int |
get()
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. |
double |
getPeriod()
Deprecated. Use getRate() in favor of this method. This returns unscaled periods and getRate() scales using value from setDistancePerPulse(). |
double |
getRate()
Get the current rate of the encoder. |
int |
getRaw()
Gets the raw value from the encoder. |
int |
getSamplesToAverage()
Get the Samples to Average which specifies the number of samples of the timer to average when calculating the period. |
java.lang.String |
getSmartDashboardType()
|
boolean |
getStopped()
Determine if the encoder is stopped. |
ITable |
getTable()
|
void |
initTable(ITable subtable)
Initializes a table for this sendable object. |
double |
pidGet()
Implement the PIDSource interface. |
void |
reset()
Reset the Encoder distance to zero. |
void |
setDistancePerPulse(double distancePerPulse)
Set the distance per pulse for this 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 |
setPIDSourceParameter(PIDSource.PIDSourceParameter pidSource)
Set which parameter of the encoder you are using as a process control variable. |
void |
setReverseDirection(boolean reverseDirection)
Set the direction sensing for this encoder. |
void |
setSamplesToAverage(int samplesToAverage)
Set the Samples to Average which specifies the number of samples of the timer to average when calculating the period. |
void |
start()
Start the Encoder. |
void |
startLiveWindowMode()
Start having this sendable object automatically respond to value changes reflect the value on the table. |
void |
stop()
Stops counting pulses on the Encoder device. |
void |
stopLiveWindowMode()
Stop having this sendable object automatically respond to value changes. |
void |
updateTable()
Update the table for this sendable object with the latest values. |
Methods inherited from class edu.wpi.first.wpilibj.SensorBase |
---|
checkAnalogChannel, checkAnalogModule, checkDigitalChannel, checkDigitalModule, checkPWMChannel, checkPWMModule, checkRelayChannel, checkRelayModule, checkSolenoidChannel, checkSolenoidModule, getDefaultAnalogModule, getDefaultDigitalModule, getDefaultSolenoidModule, setDefaultAnalogModule, setDefaultDigitalModule, setDefaultSolenoidModule |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected DigitalSource m_aSource
protected DigitalSource m_bSource
protected DigitalSource m_indexSource
Constructor Detail |
---|
public Encoder(int aSlot, int aChannel, int bSlot, int bChannel, boolean reverseDirection)
aSlot
- The a channel digital input module.aChannel
- The a channel digital input channel.bSlot
- The b channel digital input module.bChannel
- The b channel digital input channel.reverseDirection
- represents the orientation of the encoder and inverts the output values
if necessary so forward represents positive values.public Encoder(int aSlot, int aChannel, int bSlot, int bChannel)
aSlot
- The a channel digital input module.aChannel
- The a channel digital input channel.bSlot
- The b channel digital input module.bChannel
- The b channel digital input channel.public Encoder(int aSlot, int aChannel, int bSlot, int bChannel, boolean reverseDirection, CounterBase.EncodingType encodingType)
aSlot
- The a channel digital input module.aChannel
- The a channel digital input channel.bSlot
- The b channel digital input module.bChannel
- The b channel digital input channel.reverseDirection
- represents the orientation of the encoder and inverts the output values
if necessary so forward represents positive values.encodingType
- 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(int aSlot, int aChannel, int bSlot, int bChannel, int indexSlot, int indexChannel, boolean reverseDirection)
aSlot
- The a channel digital input module.aChannel
- The a channel digital input channel.bSlot
- The b channel digital input module.bChannel
- The b channel digital input channel.indexSlot
- The index channel digital input module.indexChannel
- The index channel digital input channel.reverseDirection
- represents the orientation of the encoder and inverts the output values
if necessary so forward represents positive values.public Encoder(int aSlot, int aChannel, int bSlot, int bChannel, int indexSlot, int indexChannel)
aSlot
- The a channel digital input module.aChannel
- The a channel digital input channel.bSlot
- The b channel digital input module.bChannel
- The b channel digital input channel.indexSlot
- The index channel digital input module.indexChannel
- The index channel digital input channel.public Encoder(int aChannel, int bChannel, boolean reverseDirection)
aChannel
- The a channel digital input channel.bChannel
- The b channel digital input channel.reverseDirection
- represents the orientation of the encoder and inverts the output values
if necessary so forward represents positive values.public Encoder(int aChannel, int bChannel)
aChannel
- The a channel digital input channel.bChannel
- The b channel digital input channel.public Encoder(int aChannel, int bChannel, boolean reverseDirection, CounterBase.EncodingType encodingType)
aChannel
- The a channel digital input channel.bChannel
- The b channel digital input channel.reverseDirection
- represents the orientation of the encoder and inverts the output values
if necessary so forward represents positive values.encodingType
- 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(int aChannel, int bChannel, int indexChannel, boolean reverseDirection)
aChannel
- The a channel digital input channel.bChannel
- The b channel digital input channel.indexChannel
- The index channel digital input channel.reverseDirection
- represents the orientation of the encoder and inverts the output values
if necessary so forward represents positive values.public Encoder(int aChannel, int bChannel, int indexChannel)
aChannel
- The a channel digital input channel.bChannel
- The b channel digital input channel.indexChannel
- The index channel digital input channel.public Encoder(DigitalSource aSource, DigitalSource 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(DigitalSource aSource, DigitalSource 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(DigitalSource aSource, DigitalSource bSource, boolean reverseDirection, CounterBase.EncodingType encodingType)
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.encodingType
- 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(DigitalSource aSource, DigitalSource bSource, DigitalSource indexSource, boolean reverseDirection)
aSource
- The source that should be used for the a channel.bSource
- the source that should be used for the b channel.indexSource
- 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.public Encoder(DigitalSource aSource, DigitalSource bSource, DigitalSource indexSource)
aSource
- The source that should be used for the a channel.bSource
- the source that should be used for the b channel.indexSource
- the source that should be used for the index channel.Method Detail |
---|
public void free()
SensorBase
free
in class SensorBase
public void start()
start
in interface CounterBase
public void stop()
stop
in interface CounterBase
public int getRaw()
public int get()
get
in interface CounterBase
public void reset()
reset
in interface CounterBase
public double getPeriod()
getPeriod
in interface CounterBase
public void setMaxPeriod(double maxPeriod)
setMaxPeriod
in interface CounterBase
maxPeriod
- 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 interface CounterBase
public boolean getDirection()
getDirection
in interface CounterBase
public double getDistance()
public double getRate()
public 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 distancePerPulse)
distancePerPulse
- The scale factor that will be used to convert pulses to useful units.public void setReverseDirection(boolean reverseDirection)
reverseDirection
- true if the encoder direction should be reversedpublic void setSamplesToAverage(int samplesToAverage)
samplesToAverage
- The number of samples to average from 1 to 127.public int getSamplesToAverage()
public void setPIDSourceParameter(PIDSource.PIDSourceParameter pidSource)
pidSource
- An enum to select the parameter.public double pidGet()
pidGet
in interface PIDSource
public java.lang.String getSmartDashboardType()
getSmartDashboardType
in interface Sendable
public void initTable(ITable subtable)
initTable
in interface Sendable
subtable
- The table to put the values in.public ITable getTable()
getTable
in interface Sendable
public void updateTable()
updateTable
in interface LiveWindowSendable
public void startLiveWindowMode()
startLiveWindowMode
in interface LiveWindowSendable
public void stopLiveWindowMode()
stopLiveWindowMode
in interface LiveWindowSendable
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |