WPILib 2012
WPILibRoboticsLibraryforFRC
Public Types | Public Member Functions
Encoder Class Reference

#include <Encoder.h>

Inheritance diagram for Encoder:
SensorBase CounterBase PIDSource ErrorBase

List of all members.

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 ()

Detailed Description

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.


Constructor & Destructor Documentation

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.

Parameters:
aChannelThe a channel digital input channel.
bChannelThe b channel digital input channel.
reverseDirectionrepresents the orientation of the encoder and inverts the output values if necessary so forward represents positive values.
encodingTypeeither 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.

Parameters:
aModuleNumberThe a channel digital input module.
aChannelThe a channel digital input channel.
bModuleNumberThe b channel digital input module.
bChannelThe b channel digital input channel.
reverseDirectionrepresents the orientation of the encoder and inverts the output values if necessary so forward represents positive values.
encodingTypeeither 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.

Parameters:
aSourceThe source that should be used for the a channel.
bSourcethe source that should be used for the b channel.
reverseDirectionrepresents the orientation of the encoder and inverts the output values if necessary so forward represents positive values.
encodingTypeeither 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.

Parameters:
aSourceThe source that should be used for the a channel.
bSourcethe source that should be used for the b channel.
reverseDirectionrepresents the orientation of the encoder and inverts the output values if necessary so forward represents positive values.
encodingTypeeither 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]

Free the resources for an Encoder. Frees the FPGA resources associated with an Encoder.


Member Function Documentation

INT32 Encoder::Get ( ) [virtual]

Gets the current count. Returns the current count on the Encoder. This method compensates for the decoding type.

Returns:
Current count from the Encoder adjusted for the 1x, 2x, or 4x scale factor.

Implements CounterBase.

bool Encoder::GetDirection ( ) [virtual]

The last direction the encoder value changed.

Returns:
The last direction the encoder value changed.

Implements CounterBase.

double Encoder::GetDistance ( )

Get the distance the robot has driven since the last reset.

Returns:
The distance driven since the last reset as scaled by the value from SetDistancePerPulse().
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.

Deprecated:
Use GetRate() in favor of this method. This returns unscaled periods and GetRate() scales using value from SetDistancePerPulse().
Returns:
Period in seconds of the most recent pulse.

Implements CounterBase.

double Encoder::GetRate ( )

Get the current rate of the encoder. Units are distance per second as scaled by the value from SetDistancePerPulse().

Returns:
The current rate of the encoder.
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.

Returns:
Current raw count from the encoder
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.

Returns:
True if the encoder is considered stopped.

Implements CounterBase.

double Encoder::PIDGet ( ) [virtual]

Implement the PIDSource interface.

Returns:
The current value of the selected source parameter.

Implements PIDSource.

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.

Parameters:
distancePerPulseThe 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.

Deprecated:
Use SetMinRate() in favor of this method. This takes unscaled periods and SetMinRate() scales using value from SetDistancePerPulse().
Parameters:
maxPeriodThe 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.

Parameters:
minRateThe 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.

Parameters:
pidSourceAn 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.

Parameters:
reverseDirectiontrue 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.


The documentation for this class was generated from the following files:
 All Classes Functions Variables