WPILibC++  2020.3.2
Encoder.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <stdint.h>
11 
12 #include "hal/AnalogTrigger.h"
13 #include "hal/Types.h"
14 
21 // clang-format off
25 HAL_ENUM(HAL_EncoderIndexingType) {
26  HAL_kResetWhileHigh,
27  HAL_kResetWhileLow,
28  HAL_kResetOnFallingEdge,
29  HAL_kResetOnRisingEdge
30 };
31 
35 HAL_ENUM(HAL_EncoderEncodingType) {
36  HAL_Encoder_k1X,
37  HAL_Encoder_k2X,
38  HAL_Encoder_k4X
39 };
40 // clang-format on
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
62 HAL_EncoderHandle HAL_InitializeEncoder(
63  HAL_Handle digitalSourceHandleA, HAL_AnalogTriggerType analogTriggerTypeA,
64  HAL_Handle digitalSourceHandleB, HAL_AnalogTriggerType analogTriggerTypeB,
65  HAL_Bool reverseDirection, HAL_EncoderEncodingType encodingType,
66  int32_t* status);
67 
73 void HAL_FreeEncoder(HAL_EncoderHandle encoderHandle, int32_t* status);
74 
81 void HAL_SetEncoderSimDevice(HAL_EncoderHandle handle,
82  HAL_SimDeviceHandle device);
83 
92 int32_t HAL_GetEncoder(HAL_EncoderHandle encoderHandle, int32_t* status);
93 
102 int32_t HAL_GetEncoderRaw(HAL_EncoderHandle encoderHandle, int32_t* status);
103 
112 int32_t HAL_GetEncoderEncodingScale(HAL_EncoderHandle encoderHandle,
113  int32_t* status);
114 
124 void HAL_ResetEncoder(HAL_EncoderHandle encoderHandle, int32_t* status);
125 
126 /*
127  * Gets the Period of the most recent count.
128  *
129  * Returns the time interval of the most recent count. This can be used for
130  * velocity calculations to determine shaft speed.
131  *
132  * @param encoderHandle the encoder handle
133  * @returns the period of the last two pulses in units of seconds
134  */
135 double HAL_GetEncoderPeriod(HAL_EncoderHandle encoderHandle, int32_t* status);
136 
148 void HAL_SetEncoderMaxPeriod(HAL_EncoderHandle encoderHandle, double maxPeriod,
149  int32_t* status);
150 
162 HAL_Bool HAL_GetEncoderStopped(HAL_EncoderHandle encoderHandle,
163  int32_t* status);
164 
171 HAL_Bool HAL_GetEncoderDirection(HAL_EncoderHandle encoderHandle,
172  int32_t* status);
173 
184 double HAL_GetEncoderDistance(HAL_EncoderHandle encoderHandle, int32_t* status);
185 
196 double HAL_GetEncoderRate(HAL_EncoderHandle encoderHandle, int32_t* status);
197 
209 void HAL_SetEncoderMinRate(HAL_EncoderHandle encoderHandle, double minRate,
210  int32_t* status);
211 
220 void HAL_SetEncoderDistancePerPulse(HAL_EncoderHandle encoderHandle,
221  double distancePerPulse, int32_t* status);
222 
231 void HAL_SetEncoderReverseDirection(HAL_EncoderHandle encoderHandle,
232  HAL_Bool reverseDirection, int32_t* status);
233 
240 void HAL_SetEncoderSamplesToAverage(HAL_EncoderHandle encoderHandle,
241  int32_t samplesToAverage, int32_t* status);
242 
249 int32_t HAL_GetEncoderSamplesToAverage(HAL_EncoderHandle encoderHandle,
250  int32_t* status);
251 
265 void HAL_SetEncoderIndexSource(HAL_EncoderHandle encoderHandle,
266  HAL_Handle digitalSourceHandle,
267  HAL_AnalogTriggerType analogTriggerType,
268  HAL_EncoderIndexingType type, int32_t* status);
269 
276 int32_t HAL_GetEncoderFPGAIndex(HAL_EncoderHandle encoderHandle,
277  int32_t* status);
278 
287 double HAL_GetEncoderDecodingScaleFactor(HAL_EncoderHandle encoderHandle,
288  int32_t* status);
289 
296 double HAL_GetEncoderDistancePerPulse(HAL_EncoderHandle encoderHandle,
297  int32_t* status);
298 
305 HAL_EncoderEncodingType HAL_GetEncoderEncodingType(
306  HAL_EncoderHandle encoderHandle, int32_t* status);
307 #ifdef __cplusplus
308 } // extern "C"
309 #endif
310 
HAL_GetEncoderDistancePerPulse
double HAL_GetEncoderDistancePerPulse(HAL_EncoderHandle encoderHandle, int32_t *status)
Gets the user set distance per pulse of the encoder.
HAL_SetEncoderSimDevice
void HAL_SetEncoderSimDevice(HAL_EncoderHandle handle, HAL_SimDeviceHandle device)
Indicates the encoder is used by a simulated device.
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.
HAL_GetEncoderRaw
int32_t HAL_GetEncoderRaw(HAL_EncoderHandle encoderHandle, int32_t *status)
Gets the raw counts of the encoder.
HAL_ENUM
HAL_ENUM(HAL_EncoderIndexingType)
The type of index pulse for the encoder.
Definition: Encoder.h:25
HAL_SetEncoderMaxPeriod
void HAL_SetEncoderMaxPeriod(HAL_EncoderHandle encoderHandle, double maxPeriod, int32_t *status)
Sets the maximum period where the device is still considered "moving".
HAL_GetEncoderDirection
HAL_Bool HAL_GetEncoderDirection(HAL_EncoderHandle encoderHandle, int32_t *status)
Gets the last direction the encoder value changed.
HAL_GetEncoder
int32_t HAL_GetEncoder(HAL_EncoderHandle encoderHandle, int32_t *status)
Gets the current counts of the encoder after encoding type scaling.
HAL_GetEncoderSamplesToAverage
int32_t HAL_GetEncoderSamplesToAverage(HAL_EncoderHandle encoderHandle, int32_t *status)
Gets the current samples to average value.
HAL_GetEncoderDecodingScaleFactor
double HAL_GetEncoderDecodingScaleFactor(HAL_EncoderHandle encoderHandle, int32_t *status)
Gets the decoding scale factor of the encoder.
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.
HAL_SetEncoderDistancePerPulse
void HAL_SetEncoderDistancePerPulse(HAL_EncoderHandle encoderHandle, double distancePerPulse, int32_t *status)
Sets the distance traveled per encoder pulse.
HAL_GetEncoderEncodingScale
int32_t HAL_GetEncoderEncodingScale(HAL_EncoderHandle encoderHandle, int32_t *status)
Gets the encoder scale value.
HAL_GetEncoderEncodingType
HAL_EncoderEncodingType HAL_GetEncoderEncodingType(HAL_EncoderHandle encoderHandle, int32_t *status)
Gets the encoding type of the encoder.
HAL_GetEncoderRate
double HAL_GetEncoderRate(HAL_EncoderHandle encoderHandle, int32_t *status)
Gets the current rate of the encoder.
HAL_GetEncoderStopped
HAL_Bool HAL_GetEncoderStopped(HAL_EncoderHandle encoderHandle, int32_t *status)
Determines if the clock is stopped.
HAL_FreeEncoder
void HAL_FreeEncoder(HAL_EncoderHandle encoderHandle, int32_t *status)
Frees an encoder.
HAL_GetEncoderDistance
double HAL_GetEncoderDistance(HAL_EncoderHandle encoderHandle, int32_t *status)
Gets the current distance traveled by the encoder.
HAL_SetEncoderReverseDirection
void HAL_SetEncoderReverseDirection(HAL_EncoderHandle encoderHandle, HAL_Bool reverseDirection, int32_t *status)
Sets if to reverse the direction of the encoder.
HAL_GetEncoderFPGAIndex
int32_t HAL_GetEncoderFPGAIndex(HAL_EncoderHandle encoderHandle, int32_t *status)
Gets the FPGA index of the encoder.
HAL_SetEncoderMinRate
void HAL_SetEncoderMinRate(HAL_EncoderHandle encoderHandle, double minRate, int32_t *status)
Sets the minimum rate to be considered moving by the encoder.
HAL_ResetEncoder
void HAL_ResetEncoder(HAL_EncoderHandle encoderHandle, int32_t *status)
Reads the current encoder value.
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.