WPILib 2012
WPILibRoboticsLibraryforFRC
|
#include <Encoder.h>
Public Types | |
enum | PIDSourceParameter { kDistance, kRate } |
Public Member Functions | |
Encoder (UINT32 aChannel, UINT32 bChannel, bool reverseDirection=false, EncodingType encodingType=k4X) | |
Encoder (UINT8 aModuleNumber, UINT32 aChannel, UINT8 bModuleNumber, UINT32 _bChannel, bool reverseDirection=false, EncodingType encodingType=k4X) | |
Encoder (DigitalSource *aSource, DigitalSource *bSource, bool reverseDirection=false, EncodingType encodingType=k4X) | |
Encoder (DigitalSource &aSource, DigitalSource &bSource, bool reverseDirection=false, EncodingType encodingType=k4X) | |
virtual | ~Encoder () |
void | Start () |
INT32 | Get () |
INT32 | GetRaw () |
void | Reset () |
void | Stop () |
double | GetPeriod () |
void | SetMaxPeriod (double maxPeriod) |
bool | GetStopped () |
bool | GetDirection () |
double | GetDistance () |
double | GetRate () |
void | SetMinRate (double minRate) |
void | SetDistancePerPulse (double distancePerPulse) |
void | SetReverseDirection (bool reverseDirection) |
void | SetPIDSourceParameter (PIDSourceParameter pidSource) |
double | PIDGet () |
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.
Encoder::Encoder | ( | UINT32 | aChannel, |
UINT32 | bChannel, | ||
bool | reverseDirection = false , |
||
EncodingType | encodingType = k4X |
||
) |
Encoder constructor. Construct a Encoder given a and b channels assuming the default module.
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. |
Encoder::Encoder | ( | UINT8 | aModuleNumber, |
UINT32 | aChannel, | ||
UINT8 | bModuleNumber, | ||
UINT32 | bChannel, | ||
bool | reverseDirection = false , |
||
EncodingType | encodingType = k4X |
||
) |
Encoder constructor. Construct a Encoder given a and b modules and channels fully specified.
aModuleNumber | The a channel digital input module. |
aChannel | The a channel digital input channel. |
bModuleNumber | 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. |
Encoder::Encoder | ( | DigitalSource * | aSource, |
DigitalSource * | bSource, | ||
bool | reverseDirection = false , |
||
EncodingType | encodingType = k4X |
||
) |
Encoder constructor. Construct a Encoder given a and b channels as digital inputs. This is used in the case where the digital inputs are shared. The Encoder class will not allocate the digital inputs and assume that they already are counted.
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. |
Encoder::Encoder | ( | DigitalSource & | aSource, |
DigitalSource & | bSource, | ||
bool | reverseDirection = false , |
||
EncodingType | encodingType = k4X |
||
) |
Encoder constructor. Construct a Encoder given a and b channels as digital inputs. This is used in the case where the digital inputs are shared. The Encoder class will not allocate the digital inputs and assume that they already are counted.
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. |
Encoder::~Encoder | ( | ) | [virtual] |
INT32 Encoder::Get | ( | ) | [virtual] |
Gets the current count. Returns the current count on the Encoder. This method compensates for the decoding type.
Implements CounterBase.
bool Encoder::GetDirection | ( | ) | [virtual] |
The last direction the encoder value changed.
Implements CounterBase.
double Encoder::GetDistance | ( | ) |
Get the distance the robot has driven since the last reset.
double Encoder::GetPeriod | ( | ) | [virtual] |
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.
Implements CounterBase.
double Encoder::GetRate | ( | ) |
Get the current rate of the encoder. Units are distance per second as scaled by the value from SetDistancePerPulse().
INT32 Encoder::GetRaw | ( | ) |
Gets the raw value from the encoder. The raw value is the actual count unscaled by the 1x, 2x, or 4x scale factor.
bool Encoder::GetStopped | ( | ) | [virtual] |
Determine if the encoder is stopped. Using the MaxPeriod value, a boolean is returned that is true if the encoder is considered stopped and false if it is still moving. A stopped encoder is one where the most recent pulse width exceeds the MaxPeriod.
Implements CounterBase.
double Encoder::PIDGet | ( | ) | [virtual] |
void Encoder::Reset | ( | ) | [virtual] |
Reset the Encoder distance to zero. Resets the current count to zero on the encoder.
Implements CounterBase.
void Encoder::SetDistancePerPulse | ( | double | distancePerPulse | ) |
Set the distance per pulse for this encoder. This sets the multiplier used to determine the distance driven based on the count value from the encoder. Do not include the decoding type in this scale. The library already compensates for the decoding type. Set this value based on the encoder's rated Pulses per Revolution and factor in gearing reductions following the encoder shaft. This distance can be in any units you like, linear or angular.
distancePerPulse | The scale factor that will be used to convert pulses to useful units. |
void Encoder::SetMaxPeriod | ( | double | maxPeriod | ) | [virtual] |
Sets the maximum period for stopped detection. Sets the value that represents the maximum period of the Encoder before it will assume that the attached device is stopped. This timeout allows users to determine if the wheels or other shaft has stopped rotating. This method compensates for the decoding type.
maxPeriod | The maximum time between rising and falling edges before the FPGA will report the device stopped. This is expressed in seconds. |
Implements CounterBase.
void Encoder::SetMinRate | ( | double | minRate | ) |
Set the minimum rate of the device before the hardware reports it stopped.
minRate | The minimum rate. The units are in distance per second as scaled by the value from SetDistancePerPulse(). |
void Encoder::SetPIDSourceParameter | ( | PIDSourceParameter | pidSource | ) |
Set which parameter of the encoder you are using as a process control variable.
pidSource | An enum to select the parameter. |
void Encoder::SetReverseDirection | ( | bool | reverseDirection | ) |
Set the direction sensing for this encoder. This sets the direction sensing on the encoder so that it could count in the correct software direction regardless of the mounting.
reverseDirection | true if the encoder direction should be reversed |
void Encoder::Start | ( | ) | [virtual] |
Start the Encoder. Starts counting pulses on the Encoder device.
Implements CounterBase.
void Encoder::Stop | ( | ) | [virtual] |
Stops counting pulses on the Encoder device. The value is not changed.
Implements CounterBase.