Class EncoderJNI
public class EncoderJNI extends JNIWrapper
- See Also:
- "hal/Encoder.h"
-
Nested Class Summary
-
Constructor Summary
Constructors Constructor Description EncoderJNI()
-
Method Summary
Modifier and Type Method Description static void
freeEncoder(int encoderHandle)
Frees an encoder.static int
getEncoder(int encoderHandle)
Gets the current counts of the encoder after encoding type scaling.static double
getEncoderDecodingScaleFactor(int encoderHandle)
Gets the decoding scale factor of the encoder.static boolean
getEncoderDirection(int encoderHandle)
Gets the last direction the encoder value changed.static double
getEncoderDistance(int encoderHandle)
Gets the current distance traveled by the encoder.static double
getEncoderDistancePerPulse(int encoderHandle)
Gets the user set distance per pulse of the encoder.static int
getEncoderEncodingScale(int encoderHandle)
Gets the encoder scale value.static int
getEncoderEncodingType(int encoderHandle)
Gets the encoding type of the encoder.static int
getEncoderFPGAIndex(int encoderHandle)
Gets the FPGA index of the encoder.static double
getEncoderPeriod(int encoderHandle)
Gets the Period of the most recent count.static double
getEncoderRate(int encoderHandle)
Gets the current rate of the encoder.static int
getEncoderRaw(int encoderHandle)
Gets the raw counts of the encoder.static int
getEncoderSamplesToAverage(int encoderHandle)
Gets the current samples to average value.static boolean
getEncoderStopped(int encoderHandle)
Determines if the clock is stopped.static int
getEncodingScaleFactor(int encoderHandle)
Gets the encoder scale value.static int
initializeEncoder(int digitalSourceHandleA, int analogTriggerTypeA, int digitalSourceHandleB, int analogTriggerTypeB, boolean reverseDirection, int encodingType)
Initializes an encoder.static void
resetEncoder(int encoderHandle)
Reads the current encoder value.static void
setEncoderDistancePerPulse(int encoderHandle, double distancePerPulse)
Sets the distance traveled per encoder pulse.static void
setEncoderIndexSource(int encoderHandle, int digitalSourceHandle, int analogTriggerType, int indexingType)
Sets the source for an index pulse on the encoder.static void
setEncoderMaxPeriod(int encoderHandle, double maxPeriod)
Sets the maximum period where the device is still considered "moving".static void
setEncoderMinRate(int encoderHandle, double minRate)
Sets the minimum rate to be considered moving by the encoder.static void
setEncoderReverseDirection(int encoderHandle, boolean reverseDirection)
Sets if to reverse the direction of the encoder.static void
setEncoderSamplesToAverage(int encoderHandle, int samplesToAverage)
Sets the number of encoder samples to average when calculating encoder rate.static void
setEncoderSimDevice(int handle, int device)
Indicates the encoder is used by a simulated device.
-
Constructor Details
-
EncoderJNI
public EncoderJNI()
-
-
Method Details
-
initializeEncoder
public static int initializeEncoder(int digitalSourceHandleA, int analogTriggerTypeA, int digitalSourceHandleB, int analogTriggerTypeB, boolean reverseDirection, int encodingType)Initializes an encoder.- Parameters:
digitalSourceHandleA
- the A source handle (either a digital or analog trigger)analogTriggerTypeA
- the analog trigger type of the A source if it is an analog triggerdigitalSourceHandleB
- the B source handle (either a digital or analog trigger)analogTriggerTypeB
- the analog trigger type of the B source if it is an analog triggerreverseDirection
- true to reverse the counting direction from standard, otherwise falseencodingType
- the encoding type- Returns:
- the created encoder handle
- See Also:
- "HAL_InitializeEncoder"
-
freeEncoder
Frees an encoder.- Parameters:
encoderHandle
- the encoder handle- See Also:
- "HAL_FreeEncoder"
-
setEncoderSimDevice
Indicates the encoder is used by a simulated device.- Parameters:
handle
- the encoder handledevice
- simulated device handle- See Also:
- "HAL_SetEncoderSimDevice"
-
getEncoder
Gets the current counts of the encoder after encoding type scaling.This is scaled by the value passed during initialization to encodingType.
- Parameters:
encoderHandle
- the encoder handle- Returns:
- the current scaled count
- See Also:
- "HAL_GetEncoder"
-
getEncoderRaw
Gets the raw counts of the encoder.This is not scaled by any values.
- Parameters:
encoderHandle
- the encoder handle- Returns:
- the raw encoder count
- See Also:
- "HAL_GetEncoderRaw"
-
getEncodingScaleFactor
Gets the encoder scale value.This is set by the value passed during initialization to encodingType.
- Parameters:
encoderHandle
- the encoder handle- Returns:
- the encoder scale value
- See Also:
- "HAL_GetEncoderEncodingScale"
-
resetEncoder
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:
encoderHandle
- the encoder handle- See Also:
- "HAL_ResetEncoder"
-
getEncoderPeriod
Gets the Period of the most recent count.Returns the time interval of the most recent count. This can be used for velocity calculations to determine shaft speed.
- Parameters:
encoderHandle
- the encoder handle- Returns:
- the period of the last two pulses in units of seconds
- See Also:
- "HAL_GetEncoderPeriod"
-
setEncoderMaxPeriod
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 getEncoderStopped method.
- Parameters:
encoderHandle
- the encoder handlemaxPeriod
- the maximum period where the counted device is considered moving in seconds- See Also:
- "HAL_SetEncoderMaxPeriod"
-
getEncoderStopped
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:
encoderHandle
- the encoder handle- Returns:
- true if the most recent encoder period exceeds the MaxPeriod value set by SetMaxPeriod
- See Also:
- "HAL_GetEncoderStopped"
-
getEncoderDirection
Gets the last direction the encoder value changed.- Parameters:
encoderHandle
- the encoder handle- Returns:
- the last direction the encoder value changed
- See Also:
- "HAL_GetEncoderDirection"
-
getEncoderDistance
Gets the current distance traveled by the encoder.This is the encoder count scaled by the distance per pulse set for the encoder.
- Parameters:
encoderHandle
- the encoder handle- Returns:
- the encoder distance (units are determined by the units passed to setEncoderDistancePerPulse)
- See Also:
- "HAL_GetEncoderDistance"
-
getEncoderRate
Gets the current rate of the encoder.This is the encoder period scaled by the distance per pulse set for the encoder.
- Parameters:
encoderHandle
- the encoder handle- Returns:
- the encoder rate (units are determined by the units passed to setEncoderDistancePerPulse, time value is seconds)
- See Also:
- "HAL_GetEncoderRate"
-
setEncoderMinRate
Sets the minimum rate to be considered moving by the encoder.Units need to match what is set by setEncoderDistancePerPulse, with time as seconds.
- Parameters:
encoderHandle
- the encoder handleminRate
- the minimum rate to be considered moving (units are determined by the units passed to setEncoderDistancePerPulse, time value is seconds)- See Also:
- "HAL_SetEncoderMinRate"
-
setEncoderDistancePerPulse
Sets the distance traveled per encoder pulse. This is used as a scaling factor for the rate and distance calls.- Parameters:
encoderHandle
- the encoder handledistancePerPulse
- the distance traveled per encoder pulse (units user defined)- See Also:
- "HAL_SetEncoderDistancePerPulse"
-
setEncoderReverseDirection
Sets if to reverse the direction of the encoder.Note that this is not a toggle. It is an absolute set.
- Parameters:
encoderHandle
- the encoder handlereverseDirection
- true to reverse the direction, false to not.- See Also:
- "HAL_SetEncoderReverseDirection"
-
setEncoderSamplesToAverage
Sets the number of encoder samples to average when calculating encoder rate.- Parameters:
encoderHandle
- the encoder handlesamplesToAverage
- the number of samples to average- See Also:
- "HAL_SetEncoderSamplesToAverage"
-
getEncoderSamplesToAverage
Gets the current samples to average value.- Parameters:
encoderHandle
- the encoder handle- Returns:
- the current samples to average value
- See Also:
- "HAL_GetEncoderSamplesToAverage"
-
setEncoderIndexSource
public static void setEncoderIndexSource(int encoderHandle, int digitalSourceHandle, int analogTriggerType, int indexingType)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:
encoderHandle
- the encoder handledigitalSourceHandle
- the index source handle (either a HAL_AnalogTriggerHandle or a HAL_DigitalHandle)analogTriggerType
- the analog trigger type if the source is an analog triggerindexingType
- the index triggering type- See Also:
- "HAL_SetEncoderIndexSource"
-
getEncoderFPGAIndex
Gets the FPGA index of the encoder.- Parameters:
encoderHandle
- the encoder handle- Returns:
- the FPGA index of the encoder
- See Also:
- "HAL_GetEncoderFPGAIndex"
-
getEncoderEncodingScale
Gets the encoder scale value.This is set by the value passed during initialization to encodingType.
- Parameters:
encoderHandle
- the encoder handle- Returns:
- the encoder scale value
- See Also:
- "HAL_GetEncoderEncodingScale"
-
getEncoderDecodingScaleFactor
Gets the decoding scale factor of the encoder.This is used to perform the scaling from raw to type scaled values.
- Parameters:
encoderHandle
- the encoder handle- Returns:
- the scale value for the encoder
- See Also:
- "HAL_GetEncoderDecodingScaleFactor"
-
getEncoderDistancePerPulse
Gets the user set distance per pulse of the encoder.- Parameters:
encoderHandle
- the encoder handle- Returns:
- the set distance per pulse
- See Also:
- "HAL_GetEncoderDistancePerPulse"
-
getEncoderEncodingType
Gets the encoding type of the encoder.- Parameters:
encoderHandle
- the encoder handle- Returns:
- the encoding type
- See Also:
- "HAL_GetEncoderEncodingType"
-