Class EncoderJNI

java.lang.Object
org.wpilib.hardware.hal.JNIWrapper
org.wpilib.hardware.hal.EncoderJNI

public class EncoderJNI extends JNIWrapper
Encoder JNI Functions.
See Also:
  • "wpi/hal/Encoder.h"
  • Method Details

    • initializeEncoder

      public static int initializeEncoder(int aChannel, int bChannel, boolean reverseDirection, int encodingType)
      Initializes an encoder.
      Parameters:
      aChannel - the A channel
      bChannel - the B channel
      reverseDirection - true to reverse the counting direction from standard, otherwise false
      encodingType - the encoding type
      Returns:
      the created encoder handle
      See Also:
      • "HAL_InitializeEncoder"
    • freeEncoder

      public static void freeEncoder(int encoderHandle)
      Frees an encoder.
      Parameters:
      encoderHandle - the encoder handle
      See Also:
      • "HAL_FreeEncoder"
    • setEncoderSimDevice

      public static void setEncoderSimDevice(int handle, int device)
      Indicates the encoder is used by a simulated device.
      Parameters:
      handle - the encoder handle
      device - simulated device handle
      See Also:
      • "HAL_SetEncoderSimDevice"
    • getEncoder

      public static int getEncoder(int encoderHandle)
      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

      public static int getEncoderRaw(int encoderHandle)
      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

      public static int getEncodingScaleFactor(int encoderHandle)
      Gets the scale value used to convert raw encoder counts to scaled counts.

      Raw counts divided by this value produce the scaled encoder count.

      Parameters:
      encoderHandle - the encoder handle
      Returns:
      the encoder scale value
      See Also:
      • "HAL_GetEncoderEncodingScale"
    • resetEncoder

      public static void resetEncoder(int encoderHandle)
      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"
    • getEncoderStopped

      public static boolean getEncoderStopped(int encoderHandle)
      Determines if the clock is stopped.

      Determines if the encoder's current rate is zero.

      Parameters:
      encoderHandle - the encoder handle
      Returns:
      true if the encoder's current rate is zero
      See Also:
      • "HAL_GetEncoderStopped"
    • getEncoderDirection

      public static boolean getEncoderDirection(int encoderHandle)
      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

      public static double getEncoderDistance(int encoderHandle)
      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

      public static double getEncoderRate(int encoderHandle)
      Gets the current rate of the encoder.

      This is the encoder rate 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"
    • setEncoderRateWindow

      public static void setEncoderRateWindow(int encoderHandle, int windowMilliseconds)
      Sets the time window used to calculate the encoder rate.
      Parameters:
      encoderHandle - the encoder handle
      windowMilliseconds - the rate calculation window in milliseconds; valid values are 5 through 255
      See Also:
      • "HAL_SetEncoderRateWindow"
    • setEncoderDistancePerPulse

      public static void setEncoderDistancePerPulse(int encoderHandle, double distancePerPulse)
      Sets the distance traveled per encoder pulse. This is used as a scaling factor for the rate and distance calls.
      Parameters:
      encoderHandle - the encoder handle
      distancePerPulse - the distance traveled per encoder pulse (units user defined)
      See Also:
      • "HAL_SetEncoderDistancePerPulse"
    • setEncoderReverseDirection

      public static void setEncoderReverseDirection(int encoderHandle, boolean reverseDirection)
      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 handle
      reverseDirection - true to reverse the direction, false to not.
      See Also:
      • "HAL_SetEncoderReverseDirection"
    • getEncoderFPGAIndex

      public static int getEncoderFPGAIndex(int encoderHandle)
      Gets the FPGA index of the encoder.
      Parameters:
      encoderHandle - the encoder handle
      Returns:
      the FPGA index of the encoder
      See Also:
      • "HAL_GetEncoderFPGAIndex"
    • getEncoderEncodingScale

      public static int getEncoderEncodingScale(int encoderHandle)
      Gets the scale value used to convert raw encoder counts to scaled counts.

      Raw counts divided by this value produce the scaled encoder count.

      Parameters:
      encoderHandle - the encoder handle
      Returns:
      the encoder scale value
      See Also:
      • "HAL_GetEncoderEncodingScale"
    • getEncoderDecodingScaleFactor

      public static double getEncoderDecodingScaleFactor(int encoderHandle)
      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

      public static double getEncoderDistancePerPulse(int encoderHandle)
      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

      public static int getEncoderEncodingType(int encoderHandle)
      Gets the encoding type of the encoder.
      Parameters:
      encoderHandle - the encoder handle
      Returns:
      the encoding type
      See Also:
      • "HAL_GetEncoderEncodingType"