WPILibC++ 2023.4.3
Encoder Functions

Functions

 HAL_ENUM (HAL_EncoderIndexingType)
 The type of index pulse for the encoder. More...
 
 HAL_ENUM (HAL_EncoderEncodingType)
 The encoding scaling of the encoder. More...
 
HAL_EncoderHandle HAL_InitializeEncoder (HAL_Handle digitalSourceHandleA, HAL_AnalogTriggerType analogTriggerTypeA, HAL_Handle digitalSourceHandleB, HAL_AnalogTriggerType analogTriggerTypeB, HAL_Bool reverseDirection, HAL_EncoderEncodingType encodingType, int32_t *status)
 Initializes an encoder. More...
 
void HAL_FreeEncoder (HAL_EncoderHandle encoderHandle, int32_t *status)
 Frees an encoder. More...
 
void HAL_SetEncoderSimDevice (HAL_EncoderHandle handle, HAL_SimDeviceHandle device)
 Indicates the encoder is used by a simulated device. More...
 
int32_t HAL_GetEncoder (HAL_EncoderHandle encoderHandle, int32_t *status)
 Gets the current counts of the encoder after encoding type scaling. More...
 
int32_t HAL_GetEncoderRaw (HAL_EncoderHandle encoderHandle, int32_t *status)
 Gets the raw counts of the encoder. More...
 
int32_t HAL_GetEncoderEncodingScale (HAL_EncoderHandle encoderHandle, int32_t *status)
 Gets the encoder scale value. More...
 
void HAL_ResetEncoder (HAL_EncoderHandle encoderHandle, int32_t *status)
 Reads the current encoder value. More...
 
double HAL_GetEncoderPeriod (HAL_EncoderHandle encoderHandle, int32_t *status)
 
void HAL_SetEncoderMaxPeriod (HAL_EncoderHandle encoderHandle, double maxPeriod, int32_t *status)
 Sets the maximum period where the device is still considered "moving". More...
 
HAL_Bool HAL_GetEncoderStopped (HAL_EncoderHandle encoderHandle, int32_t *status)
 Determines if the clock is stopped. More...
 
HAL_Bool HAL_GetEncoderDirection (HAL_EncoderHandle encoderHandle, int32_t *status)
 Gets the last direction the encoder value changed. More...
 
double HAL_GetEncoderDistance (HAL_EncoderHandle encoderHandle, int32_t *status)
 Gets the current distance traveled by the encoder. More...
 
double HAL_GetEncoderRate (HAL_EncoderHandle encoderHandle, int32_t *status)
 Gets the current rate of the encoder. More...
 
void HAL_SetEncoderMinRate (HAL_EncoderHandle encoderHandle, double minRate, int32_t *status)
 Sets the minimum rate to be considered moving by the encoder. More...
 
void HAL_SetEncoderDistancePerPulse (HAL_EncoderHandle encoderHandle, double distancePerPulse, int32_t *status)
 Sets the distance traveled per encoder pulse. More...
 
void HAL_SetEncoderReverseDirection (HAL_EncoderHandle encoderHandle, HAL_Bool reverseDirection, int32_t *status)
 Sets if to reverse the direction of the encoder. More...
 
void HAL_SetEncoderSamplesToAverage (HAL_EncoderHandle encoderHandle, int32_t samplesToAverage, int32_t *status)
 Sets the number of encoder samples to average when calculating encoder rate. More...
 
int32_t HAL_GetEncoderSamplesToAverage (HAL_EncoderHandle encoderHandle, int32_t *status)
 Gets the current samples to average value. More...
 
void HAL_SetEncoderIndexSource (HAL_EncoderHandle encoderHandle, HAL_Handle digitalSourceHandle, HAL_AnalogTriggerType analogTriggerType, HAL_EncoderIndexingType type, int32_t *status)
 Sets the source for an index pulse on the encoder. More...
 
int32_t HAL_GetEncoderFPGAIndex (HAL_EncoderHandle encoderHandle, int32_t *status)
 Gets the FPGA index of the encoder. More...
 
double HAL_GetEncoderDecodingScaleFactor (HAL_EncoderHandle encoderHandle, int32_t *status)
 Gets the decoding scale factor of the encoder. More...
 
double HAL_GetEncoderDistancePerPulse (HAL_EncoderHandle encoderHandle, int32_t *status)
 Gets the user set distance per pulse of the encoder. More...
 
HAL_EncoderEncodingType HAL_GetEncoderEncodingType (HAL_EncoderHandle encoderHandle, int32_t *status)
 Gets the encoding type of the encoder. More...
 

Detailed Description

Function Documentation

◆ HAL_ENUM() [1/2]

HAL_ENUM ( HAL_EncoderEncodingType  )

The encoding scaling of the encoder.

◆ HAL_ENUM() [2/2]

HAL_ENUM ( HAL_EncoderIndexingType  )

The type of index pulse for the encoder.

◆ HAL_FreeEncoder()

void HAL_FreeEncoder ( HAL_EncoderHandle  encoderHandle,
int32_t *  status 
)

Frees an encoder.

Parameters
[in]encoderHandlethe encoder handle
[out]statusError status variable. 0 on success.

◆ HAL_GetEncoder()

int32_t HAL_GetEncoder ( HAL_EncoderHandle  encoderHandle,
int32_t *  status 
)

Gets the current counts of the encoder after encoding type scaling.

This is scaled by the value passed duing initialization to encodingType.

Parameters
[in]encoderHandlethe encoder handle
[out]statusError status variable. 0 on success.
Returns
the current scaled count

◆ HAL_GetEncoderDecodingScaleFactor()

double HAL_GetEncoderDecodingScaleFactor ( HAL_EncoderHandle  encoderHandle,
int32_t *  status 
)

Gets the decoding scale factor of the encoder.

This is used to perform the scaling from raw to type scaled values.

Parameters
[in]encoderHandlethe encoder handle
[out]statusError status variable. 0 on success.
Returns
the scale value for the encoder

◆ HAL_GetEncoderDirection()

HAL_Bool HAL_GetEncoderDirection ( HAL_EncoderHandle  encoderHandle,
int32_t *  status 
)

Gets the last direction the encoder value changed.

Parameters
[in]encoderHandlethe encoder handle
[out]statusError status variable. 0 on success.
Returns
the last direction the encoder value changed

◆ HAL_GetEncoderDistance()

double HAL_GetEncoderDistance ( HAL_EncoderHandle  encoderHandle,
int32_t *  status 
)

Gets the current distance traveled by the encoder.

This is the encoder count scaled by the distance per pulse set for the encoder.

Parameters
[in]encoderHandlethe encoder handle
[out]statusError status variable. 0 on success.
Returns
the encoder distance (units are determined by the units passed to HAL_SetEncoderDistancePerPulse)

◆ HAL_GetEncoderDistancePerPulse()

double HAL_GetEncoderDistancePerPulse ( HAL_EncoderHandle  encoderHandle,
int32_t *  status 
)

Gets the user set distance per pulse of the encoder.

Parameters
[in]encoderHandlethe encoder handle
[out]statusError status variable. 0 on success.
Returns
the set distance per pulse

◆ HAL_GetEncoderEncodingScale()

int32_t HAL_GetEncoderEncodingScale ( HAL_EncoderHandle  encoderHandle,
int32_t *  status 
)

Gets the encoder scale value.

This is set by the value passed during initialization to encodingType.

Parameters
[in]encoderHandlethe encoder handle
[out]statusError status variable. 0 on success.
Returns
the encoder scale value

◆ HAL_GetEncoderEncodingType()

HAL_EncoderEncodingType HAL_GetEncoderEncodingType ( HAL_EncoderHandle  encoderHandle,
int32_t *  status 
)

Gets the encoding type of the encoder.

Parameters
[in]encoderHandlethe encoder handle
[out]statusError status variable. 0 on success.
Returns
the encoding type

◆ HAL_GetEncoderFPGAIndex()

int32_t HAL_GetEncoderFPGAIndex ( HAL_EncoderHandle  encoderHandle,
int32_t *  status 
)

Gets the FPGA index of the encoder.

Parameters
[in]encoderHandlethe encoder handle
[out]statusError status variable. 0 on success.
Returns
the FPGA index of the encoder

◆ HAL_GetEncoderPeriod()

double HAL_GetEncoderPeriod ( HAL_EncoderHandle  encoderHandle,
int32_t *  status 
)

◆ HAL_GetEncoderRate()

double HAL_GetEncoderRate ( HAL_EncoderHandle  encoderHandle,
int32_t *  status 
)

Gets the current rate of the encoder.

This is the encoder period scaled by the distance per pulse set for the encoder.

Parameters
[in]encoderHandlethe encoder handle
[out]statusError status variable. 0 on success.
Returns
the encoder rate (units are determined by the units passed to HAL_SetEncoderDistancePerPulse, time value is seconds)

◆ HAL_GetEncoderRaw()

int32_t HAL_GetEncoderRaw ( HAL_EncoderHandle  encoderHandle,
int32_t *  status 
)

Gets the raw counts of the encoder.

This is not scaled by any values.

Parameters
[in]encoderHandlethe encoder handle
[out]statusError status variable. 0 on success.
Returns
the raw encoder count

◆ HAL_GetEncoderSamplesToAverage()

int32_t HAL_GetEncoderSamplesToAverage ( HAL_EncoderHandle  encoderHandle,
int32_t *  status 
)

Gets the current samples to average value.

Parameters
[in]encoderHandlethe encoder handle
[out]statusError status variable. 0 on success.
Returns
the current samples to average value

◆ HAL_GetEncoderStopped()

HAL_Bool HAL_GetEncoderStopped ( HAL_EncoderHandle  encoderHandle,
int32_t *  status 
)

Determines if the clock is stopped.

Determines if the clocked input is stopped based on the MaxPeriod value set using the SetMaxPeriod method. If the clock exceeds the MaxPeriod, then the device (and encoder) are assumed to be stopped and it returns true.

Parameters
[in]encoderHandlethe encoder handle
[out]statusError status variable. 0 on success.
Returns
true if the most recent encoder period exceeds the MaxPeriod value set by SetMaxPeriod

◆ HAL_InitializeEncoder()

HAL_EncoderHandle HAL_InitializeEncoder ( HAL_Handle  digitalSourceHandleA,
HAL_AnalogTriggerType  analogTriggerTypeA,
HAL_Handle  digitalSourceHandleB,
HAL_AnalogTriggerType  analogTriggerTypeB,
HAL_Bool  reverseDirection,
HAL_EncoderEncodingType  encodingType,
int32_t *  status 
)

Initializes an encoder.

Parameters
[in]digitalSourceHandleAthe A source (either a HAL_DigitalHandle or a HAL_AnalogTriggerHandle)
[in]analogTriggerTypeAthe analog trigger type of the A source if it is an analog trigger
[in]digitalSourceHandleBthe B source (either a HAL_DigitalHandle or a HAL_AnalogTriggerHandle)
[in]analogTriggerTypeBthe analog trigger type of the B source if it is an analog trigger
[in]reverseDirectiontrue to reverse the counting direction from standard, otherwise false
[in]encodingTypethe encoding type
[out]statusError status variable. 0 on success.
Returns
the created encoder handle

◆ HAL_ResetEncoder()

void HAL_ResetEncoder ( HAL_EncoderHandle  encoderHandle,
int32_t *  status 
)

Reads the current encoder value.

Read the value at this instant. It may still be running, so it reflects the current value. Next time it is read, it might have a different value.

Parameters
[in]encoderHandlethe encoder handle
[out]statusError status variable. 0 on success.

◆ HAL_SetEncoderDistancePerPulse()

void HAL_SetEncoderDistancePerPulse ( HAL_EncoderHandle  encoderHandle,
double  distancePerPulse,
int32_t *  status 
)

Sets the distance traveled per encoder pulse.

This is used as a scaling factor for the rate and distance calls.

Parameters
[in]encoderHandlethe encoder handle
[in]distancePerPulsethe distance traveled per encoder pulse (units user defined)
[out]statusError status variable. 0 on success.

◆ HAL_SetEncoderIndexSource()

void HAL_SetEncoderIndexSource ( HAL_EncoderHandle  encoderHandle,
HAL_Handle  digitalSourceHandle,
HAL_AnalogTriggerType  analogTriggerType,
HAL_EncoderIndexingType  type,
int32_t *  status 
)

Sets the source for an index pulse on the encoder.

The index pulse can be used to cause an encoder to reset based on an external input.

Parameters
[in]encoderHandlethe encoder handle
[in]digitalSourceHandlethe index source handle (either a HAL_AnalogTriggerHandle or a HAL_DigitalHandle)
[in]analogTriggerTypethe analog trigger type if the source is an analog trigger
[in]typethe index triggering type
[out]statusError status variable. 0 on success.

◆ HAL_SetEncoderMaxPeriod()

void HAL_SetEncoderMaxPeriod ( HAL_EncoderHandle  encoderHandle,
double  maxPeriod,
int32_t *  status 
)

Sets the maximum period where the device is still considered "moving".

Sets the maximum period where the device is considered moving. This value is used to determine the "stopped" state of the encoder using the HAL_GetEncoderStopped method.

Parameters
[in]encoderHandlethe encoder handle
[in]maxPeriodthe maximum period where the counted device is considered moving in seconds
[out]statusError status variable. 0 on success.

◆ HAL_SetEncoderMinRate()

void HAL_SetEncoderMinRate ( HAL_EncoderHandle  encoderHandle,
double  minRate,
int32_t *  status 
)

Sets the minimum rate to be considered moving by the encoder.

Units need to match what is set by HAL_SetEncoderDistancePerPulse, with time as seconds.

Parameters
[in]encoderHandlethe encoder handle
[in]minRatethe minimum rate to be considered moving (units are determined by the units passed to HAL_SetEncoderDistancePerPulse, time value is seconds)
[out]statusError status variable. 0 on success.

◆ HAL_SetEncoderReverseDirection()

void HAL_SetEncoderReverseDirection ( HAL_EncoderHandle  encoderHandle,
HAL_Bool  reverseDirection,
int32_t *  status 
)

Sets if to reverse the direction of the encoder.

Note that this is not a toggle. It is an absolute set.

Parameters
[in]encoderHandlethe encoder handle
[in]reverseDirectiontrue to reverse the direction, false to not.
[out]statusError status variable. 0 on success.

◆ HAL_SetEncoderSamplesToAverage()

void HAL_SetEncoderSamplesToAverage ( HAL_EncoderHandle  encoderHandle,
int32_t  samplesToAverage,
int32_t *  status 
)

Sets the number of encoder samples to average when calculating encoder rate.

Parameters
[in]encoderHandlethe encoder handle
[in]samplesToAveragethe number of samples to average
[out]statusError status variable. 0 on success.

◆ HAL_SetEncoderSimDevice()

void HAL_SetEncoderSimDevice ( HAL_EncoderHandle  handle,
HAL_SimDeviceHandle  device 
)

Indicates the encoder is used by a simulated device.

Parameters
handlethe encoder handle
devicesimulated device handle