Class CounterJNI

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

public class CounterJNI extends JNIWrapper
Counter HAL JNI functions.
See Also:
  • "hal/Counter.h"
  • Method Details

    • initializeCounter

      public static int initializeCounter(int channel, boolean risingEdge)
      Initializes a counter.
      Parameters:
      channel - the DIO channel
      risingEdge - true to trigger on rising
      Returns:
      the created handle
      See Also:
      • "HAL_InitializeCounter"
    • freeCounter

      public static void freeCounter(int counterHandle)
      Frees a counter.
      Parameters:
      counterHandle - the counter handle
      See Also:
      • "HAL_FreeCounter"
    • setCounterEdgeConfiguration

      public static void setCounterEdgeConfiguration(int counterHandle, boolean risingEdge)
      Sets the up source to either detect rising edges or falling edges.

      Note that both are allowed to be set true at the same time without issues.

      Parameters:
      counterHandle - the counter handle
      risingEdge - true to trigger on rising
      See Also:
      • "HAL_SetCounterUpSourceEdge"
    • resetCounter

      public static void resetCounter(int counterHandle)
      Resets the Counter to zero.

      Sets the counter value to zero. This does not effect the running state of the counter, just sets the current value to zero.

      Parameters:
      counterHandle - the counter handle
      See Also:
      • "HAL_ResetCounter"
    • getCounter

      public static int getCounter(int counterHandle)
      Reads the current counter value.

      Reads 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:
      counterHandle - the counter handle
      Returns:
      the current counter value
      See Also:
      • "HAL_GetCounter"
    • getCounterPeriod

      public static double getCounterPeriod(int counterHandle)
      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:
      counterHandle - the counter handle
      Returns:
      the period of the last two pulses in units of seconds
      See Also:
      • "HAL_GetCounterPeriod"
    • setCounterMaxPeriod

      public static void setCounterMaxPeriod(int counterHandle, 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 counter using the HAL_GetCounterStopped method.

      Parameters:
      counterHandle - the counter handle
      maxPeriod - the maximum period where the counted device is considered moving in seconds
      See Also:
      • "HAL_SetCounterMaxPeriod"
    • getCounterStopped

      public static boolean getCounterStopped(int counterHandle)
      Determines if the clock is stopped.

      Determine 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 counter) are assumed to be stopped and it returns true.

      Parameters:
      counterHandle - the counter handle
      Returns:
      true if the most recent counter period exceeds the MaxPeriod value set by SetMaxPeriod
      See Also:
      • "HAL_GetCounterStopped"