Class EncoderJNI

java.lang.Object
edu.wpi.first.hal.JNIWrapper
edu.wpi.first.hal.EncoderJNI

public class EncoderJNI
extends JNIWrapper
Encoder JNI Functions.
See Also:
"hal/Encoder.h"
  • Nested Class Summary

    Nested classes/interfaces inherited from class edu.wpi.first.hal.JNIWrapper

    JNIWrapper.Helper
  • 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.

    Methods inherited from class edu.wpi.first.hal.JNIWrapper

    forceLoad, suppressUnused

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • 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 trigger
      digitalSourceHandleB - the B source handle (either a digital or analog trigger)
      analogTriggerTypeB - the analog trigger type of the B source if it is an analog trigger
      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 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

      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"
    • getEncoderPeriod

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

      public static void setEncoderMaxPeriod​(int encoderHandle, double maxPeriod)
      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 handle
      maxPeriod - the maximum period where the counted device is considered moving in seconds
      See Also:
      "HAL_SetEncoderMaxPeriod"
    • getEncoderStopped

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

      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 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

      public static void setEncoderMinRate​(int encoderHandle, double minRate)
      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 handle
      minRate - 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

      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"
    • setEncoderSamplesToAverage

      public static void setEncoderSamplesToAverage​(int encoderHandle, int samplesToAverage)
      Sets the number of encoder samples to average when calculating encoder rate.
      Parameters:
      encoderHandle - the encoder handle
      samplesToAverage - the number of samples to average
      See Also:
      "HAL_SetEncoderSamplesToAverage"
    • getEncoderSamplesToAverage

      public static int getEncoderSamplesToAverage​(int encoderHandle)
      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 handle
      digitalSourceHandle - the index source handle (either a HAL_AnalogTriggerHandle or a HAL_DigitalHandle)
      analogTriggerType - the analog trigger type if the source is an analog trigger
      indexingType - the index triggering type
      See Also:
      "HAL_SetEncoderIndexSource"
    • 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 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

      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"