Encoder Class Reference
#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 () |
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.
Definition at line 27 of file Encoder.h.
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:
-
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.
Definition at line 112 of file Encoder.cpp.
| 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:
-
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.
Definition at line 86 of file Encoder.cpp.
| 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:
-
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.
Definition at line 138 of file Encoder.cpp.
| 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:
-
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.
Definition at line 167 of file Encoder.cpp.
| Encoder::~Encoder | ( | ) | [virtual] |
Free the resources for an Encoder. Frees the FPGA resources associated with an Encoder.
Definition at line 182 of file Encoder.cpp.
Member Function Documentation
| INT32 Encoder::Get | ( | ) |
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.
Definition at line 258 of file Encoder.cpp.
| bool Encoder::GetDirection | ( | ) |
The last direction the encoder value changed.
- Returns:
- The last direction the encoder value changed.
Definition at line 374 of file Encoder.cpp.
| 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().
Definition at line 414 of file Encoder.cpp.
| double Encoder::GetPeriod | ( | ) |
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.
Definition at line 290 of file Encoder.cpp.
| 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.
Definition at line 426 of file Encoder.cpp.
| 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
Definition at line 236 of file Encoder.cpp.
| bool Encoder::GetStopped | ( | ) |
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.
Definition at line 354 of file Encoder.cpp.
| double Encoder::PIDGet | ( | ) | [virtual] |
Implement the PIDSource interface.
- Returns:
- The current value of the selected source parameter.
Implements PIDSource.
Definition at line 497 of file Encoder.cpp.
| void Encoder::Reset | ( | ) |
Reset the Encoder distance to zero. Resets the current count to zero on the encoder.
Definition at line 268 of file Encoder.cpp.
| 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:
-
distancePerPulse The scale factor that will be used to convert pulses to useful units.
Definition at line 454 of file Encoder.cpp.
| void Encoder::SetMaxPeriod | ( | double | maxPeriod | ) |
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:
-
maxPeriod The maximum time between rising and falling edges before the FPGA will report the device stopped. This is expressed in seconds.
Definition at line 332 of file Encoder.cpp.
| void Encoder::SetMinRate | ( | double | minRate | ) |
Set the minimum rate of the device before the hardware reports it stopped.
- Parameters:
-
minRate The minimum rate. The units are in distance per second as scaled by the value from SetDistancePerPulse().
Definition at line 437 of file Encoder.cpp.
| void Encoder::SetPIDSourceParameter | ( | PIDSourceParameter | pidSource | ) |
Set which parameter of the encoder you are using as a process control variable.
- Parameters:
-
pidSource An enum to select the parameter.
Definition at line 486 of file Encoder.cpp.
| 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:
-
reverseDirection true if the encoder direction should be reversed
Definition at line 466 of file Encoder.cpp.
| void Encoder::Start | ( | ) |
Start the Encoder. Starts counting pulses on the Encoder device.
Definition at line 201 of file Encoder.cpp.
| void Encoder::Stop | ( | ) |
Stops counting pulses on the Encoder device. The value is not changed.
Definition at line 217 of file Encoder.cpp.
The documentation for this class was generated from the following files:
Generated on Thu Jan 12 2012 22:35:31 for WPILibC++ by
1.7.1