#include <Encoder.h>
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) |
ITable * | GetTable () |
Public Member Functions inherited from SensorBase | |
SensorBase () | |
virtual | ~SensorBase () |
Public Member Functions inherited from ErrorBase | |
virtual Error & | GetError () |
Retrieve the current error. Get the current error information associated with this sensor. | |
virtual const Error & | GetError () 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 Error & | GetGlobalError () |
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 |
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.
|
virtual |
Free the resources for an Encoder. Frees the FPGA resources associated with an Encoder.
Definition at line 193 of file Encoder.cpp.
|
virtual |
Gets the current count. Returns the current count on the Encoder. This method compensates for the decoding type.
Implements CounterBase.
Definition at line 269 of file Encoder.cpp.
|
virtual |
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.
Definition at line 425 of file Encoder.cpp.
|
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.
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().
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.
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.
Definition at line 524 of file Encoder.cpp.
|
virtual |
Implements Sendable.
Definition at line 589 of file Encoder.cpp.
|
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.
Definition at line 365 of file Encoder.cpp.
|
virtual |
Implements Sendable.
Definition at line 601 of file Encoder.cpp.
|
virtual |
Initializes a table for this sendable object.
subtable | The table to put the values in. |
Implements Sendable.
Definition at line 596 of file Encoder.cpp.
|
virtual |
Implement the PIDSource interface.
Implements PIDSource.
Definition at line 559 of file Encoder.cpp.
|
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.
distancePerPulse | The scale factor that will be used to convert pulses to useful units. |
Definition at line 465 of file Encoder.cpp.
|
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.
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.
minRate | The 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.
pidSource | An 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.
reverseDirection | true 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.
samplesToAverage | The number of samples to average from 1 to 127. |
Definition at line 499 of file Encoder.cpp.
|
virtual |
Start the Encoder. Starts counting pulses on the Encoder device.
Implements CounterBase.
Definition at line 212 of file Encoder.cpp.
|
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.
|
virtual |
Stops counting pulses on the Encoder device. The value is not changed.
Implements CounterBase.
Definition at line 228 of file Encoder.cpp.
|
virtual |
Stop having this sendable object automatically respond to value changes.
Implements LiveWindowSendable.
Definition at line 585 of file Encoder.cpp.
|
virtual |
Update the table for this sendable object with the latest values.
Implements LiveWindowSendable.
Definition at line 573 of file Encoder.cpp.