Now you can download a copy of these docs so you can use them offline! Download now
Encoder Class Reference

#include <Encoder.h>

Inheritance diagram for Encoder:
Collaboration diagram for Encoder:

Public Member Functions

 Encoder (uint32_t aChannel, uint32_t bChannel, bool reverseDirection=false, EncodingType encodingType=k4X)
 
 Encoder (uint8_t aModuleNumber, uint32_t aChannel, uint8_t bModuleNumber, uint32_t _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_t Get ()
 
int32_t 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 SetSamplesToAverage (int samplesToAverage)
 
int GetSamplesToAverage ()
 
void SetPIDSourceParameter (PIDSourceParameter pidSource)
 
double PIDGet ()
 
void UpdateTable ()
 
void StartLiveWindowMode ()
 
void StopLiveWindowMode ()
 
std::string GetSmartDashboardType ()
 
void InitTable (ITable *subTable)
 
ITableGetTable ()
 
- Public Member Functions inherited from SensorBase
 SensorBase ()
 
virtual ~SensorBase ()
 
- Public Member Functions inherited from ErrorBase
virtual ErrorGetError ()
 Retrieve the current error. Get the current error information associated with this sensor.
 
virtual const ErrorGetError () const
 
virtual void SetErrnoError (const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
 Set error information associated with a C library call that set an error to the "errno" global variable. More...
 
virtual void SetImaqError (int success, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
 Set the current error information associated from the nivision Imaq API. More...
 
virtual void SetError (Error::Code code, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetWPIError (const char *errorMessage, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void CloneError (ErrorBase *rhs) const
 
virtual void ClearError () const
 Clear the current error information associated with this sensor.
 
virtual bool StatusIsFatal () const
 Check if the current error code represents a fatal error. More...
 

Additional Inherited Members

- Public Types inherited from CounterBase
enum  EncodingType { k1X, k2X, k4X }
 
- Public Types inherited from PIDSource
enum  PIDSourceParameter { kDistance, kRate, kAngle }
 
- Static Public Member Functions inherited from SensorBase
static void DeleteSingletons ()
 
static uint32_t GetDefaultAnalogModule ()
 
static uint32_t GetDefaultDigitalModule ()
 
static uint32_t GetDefaultSolenoidModule ()
 
static bool CheckAnalogModule (uint8_t moduleNumber)
 
static bool CheckDigitalModule (uint8_t moduleNumber)
 
static bool CheckPWMModule (uint8_t moduleNumber)
 
static bool CheckRelayModule (uint8_t moduleNumber)
 
static bool CheckSolenoidModule (uint8_t moduleNumber)
 
static bool CheckDigitalChannel (uint32_t channel)
 
static bool CheckRelayChannel (uint32_t channel)
 
static bool CheckPWMChannel (uint32_t channel)
 
static bool CheckAnalogChannel (uint32_t channel)
 
static bool CheckSolenoidChannel (uint32_t channel)
 
- Static Public Member Functions inherited from ErrorBase
static void SetGlobalError (Error::Code code, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber)
 
static void SetGlobalWPIError (const char *errorMessage, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber)
 
static ErrorGetGlobalError ()
 
- Static Public Attributes inherited from SensorBase
static const uint32_t kSystemClockTicksPerMicrosecond = 40
 
static const uint32_t kDigitalChannels = 14
 
static const uint32_t kAnalogChannels = 8
 
static const uint32_t kAnalogModules = 2
 
static const uint32_t kDigitalModules = 2
 
static const uint32_t kSolenoidChannels = 8
 
static const uint32_t kSolenoidModules = 2
 
static const uint32_t kPwmChannels = 10
 
static const uint32_t kRelayChannels = 8
 
static const uint32_t kChassisSlots = 8
 
- Protected Member Functions inherited from SensorBase
void AddToSingletonList ()
 
- Protected Member Functions inherited from ErrorBase
 ErrorBase ()
 Initialize the instance status to 0 for now.
 
- Protected Attributes inherited from ErrorBase
Error m_error
 
- Static Protected Attributes inherited from ErrorBase
static SEM_ID _globalErrorMutex = semMCreate(SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE)
 
static Error _globalError
 

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 28 of file Encoder.h.

Constructor & Destructor Documentation

Encoder::~Encoder ( )
virtual

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

Definition at line 193 of file Encoder.cpp.

Member Function Documentation

int32_t 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.

Definition at line 269 of file Encoder.cpp.

bool Encoder::GetDirection ( )
virtual

The last direction the encoder value changed.

Returns
The last direction the encoder value changed.

Implements CounterBase.

Definition at line 385 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 425 of file Encoder.cpp.

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.

Definition at line 301 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 437 of file Encoder.cpp.

int32_t 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 247 of file Encoder.cpp.

int Encoder::GetSamplesToAverage ( )

Get the Samples to Average which specifies the number of samples of the timer to average when calculating the period. Perform averaging to account for mechanical imperfections or as oversampling to increase resolution.

Returns
SamplesToAverage The number of samples being averaged (from 1 to 127)

Definition at line 524 of file Encoder.cpp.

std::string Encoder::GetSmartDashboardType ( )
virtual
Returns
the string representation of the named data type that will be used by the smart dashboard for this sendable

Implements Sendable.

Definition at line 589 of file Encoder.cpp.

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.

Definition at line 365 of file Encoder.cpp.

ITable * Encoder::GetTable ( )
virtual
Returns
the table that is currently associated with the sendable

Implements Sendable.

Definition at line 601 of file Encoder.cpp.

void Encoder::InitTable ( ITable subtable)
virtual

Initializes a table for this sendable object.

Parameters
subtableThe table to put the values in.

Implements Sendable.

Definition at line 596 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 559 of file Encoder.cpp.

void Encoder::Reset ( )
virtual

Reset the Encoder distance to zero. Resets the current count to zero on the encoder.

Implements CounterBase.

Definition at line 279 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
distancePerPulseThe scale factor that will be used to convert pulses to useful units.

Definition at line 465 of file Encoder.cpp.

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.

Definition at line 343 of file Encoder.cpp.

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

Definition at line 448 of file Encoder.cpp.

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.

Definition at line 548 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
reverseDirectiontrue if the encoder direction should be reversed

Definition at line 477 of file Encoder.cpp.

void Encoder::SetSamplesToAverage ( int  samplesToAverage)

Set the Samples to Average which specifies the number of samples of the timer to average when calculating the period. Perform averaging to account for mechanical imperfections or as oversampling to increase resolution.

Parameters
samplesToAverageThe number of samples to average from 1 to 127.

Definition at line 499 of file Encoder.cpp.

void Encoder::Start ( )
virtual

Start the Encoder. Starts counting pulses on the Encoder device.

Implements CounterBase.

Definition at line 212 of file Encoder.cpp.

void Encoder::StartLiveWindowMode ( )
virtual

Start having this sendable object automatically respond to value changes reflect the value on the table.

Implements LiveWindowSendable.

Definition at line 581 of file Encoder.cpp.

void Encoder::Stop ( )
virtual

Stops counting pulses on the Encoder device. The value is not changed.

Implements CounterBase.

Definition at line 228 of file Encoder.cpp.

void Encoder::StopLiveWindowMode ( )
virtual

Stop having this sendable object automatically respond to value changes.

Implements LiveWindowSendable.

Definition at line 585 of file Encoder.cpp.

void Encoder::UpdateTable ( )
virtual

Update the table for this sendable object with the latest values.

Implements LiveWindowSendable.

Definition at line 573 of file Encoder.cpp.


The documentation for this class was generated from the following files:

Generated on Wed Jan 15 2014 01:08:06 for WPILibC++ by doxygen 1.8.6