Class EncoderSim

java.lang.Object
edu.wpi.first.wpilibj.simulation.EncoderSim

public class EncoderSim
extends Object
Class to control a simulated encoder.
  • Constructor Details

  • Method Details

    • createForChannel

      public static EncoderSim createForChannel​(int channel)
      Creates an EncoderSim for a digital input channel. Encoders take two channels, so either one may be specified.
      Parameters:
      channel - digital input channel
      Returns:
      Simulated object
      Throws:
      NoSuchElementException - if no Encoder is configured for that channel
    • createForIndex

      public static EncoderSim createForIndex​(int index)
      Creates an EncoderSim for a simulated index. The index is incremented for each simulated Encoder.
      Parameters:
      index - simulator index
      Returns:
      Simulated object
    • registerInitializedCallback

      public CallbackStore registerInitializedCallback​(NotifyCallback callback, boolean initialNotify)
      Register a callback on the Initialized property of the encoder.
      Parameters:
      callback - the callback that will be called whenever the Initialized property is changed
      initialNotify - if true, the callback will be run on the initial value
      Returns:
      the CallbackStore object associated with this callback. Save a reference to this object so GC doesn't cancel the callback.
    • getInitialized

      public boolean getInitialized()
      Read the Initialized value of the encoder.
      Returns:
      true if initialized
    • setInitialized

      public void setInitialized​(boolean initialized)
      Change the Initialized value of the encoder.
      Parameters:
      initialized - the new value
    • registerCountCallback

      public CallbackStore registerCountCallback​(NotifyCallback callback, boolean initialNotify)
      Register a callback on the count property of the encoder.
      Parameters:
      callback - the callback that will be called whenever the count property is changed
      initialNotify - if true, the callback will be run on the initial value
      Returns:
      the CallbackStore object associated with this callback. Save a reference to this object so GC doesn't cancel the callback.
    • getCount

      public int getCount()
      Read the count of the encoder.
      Returns:
      the count
    • setCount

      public void setCount​(int count)
      Change the count of the encoder.
      Parameters:
      count - the new count
    • registerPeriodCallback

      public CallbackStore registerPeriodCallback​(NotifyCallback callback, boolean initialNotify)
      Register a callback on the period of the encoder.
      Parameters:
      callback - the callback that will be called whenever the period is changed
      initialNotify - if true, the callback will be run on the initial value
      Returns:
      the CallbackStore object associated with this callback. Save a reference to this object so GC doesn't cancel the callback.
    • getPeriod

      public double getPeriod()
      Read the period of the encoder.
      Returns:
      the encoder period
    • setPeriod

      public void setPeriod​(double period)
      Change the encoder period.
      Parameters:
      period - the new period
    • registerResetCallback

      public CallbackStore registerResetCallback​(NotifyCallback callback, boolean initialNotify)
      Register a callback to be called whenever the encoder is reset.
      Parameters:
      callback - the callback
      initialNotify - whether to run the callback on the initial value
      Returns:
      the CallbackStore object associated with this callback. Save a reference to this object so GC doesn't cancel the callback.
    • getReset

      public boolean getReset()
      Check if the encoder has been reset.
      Returns:
      true if reset
    • setReset

      public void setReset​(boolean reset)
      Change the reset property of the encoder.
      Parameters:
      reset - the new value
    • registerMaxPeriodCallback

      public CallbackStore registerMaxPeriodCallback​(NotifyCallback callback, boolean initialNotify)
      Register a callback to be run whenever the max period of the encoder is changed.
      Parameters:
      callback - the callback
      initialNotify - whether to run the callback on the initial value
      Returns:
      the CallbackStore object associated with this callback. Save a reference to this object so GC doesn't cancel the callback.
    • getMaxPeriod

      public double getMaxPeriod()
      Get the max period of the encoder.
      Returns:
      the max period of the encoder
    • setMaxPeriod

      public void setMaxPeriod​(double maxPeriod)
      Change the max period of the encoder.
      Parameters:
      maxPeriod - the new value
    • registerDirectionCallback

      public CallbackStore registerDirectionCallback​(NotifyCallback callback, boolean initialNotify)
      Register a callback on the direction of the encoder.
      Parameters:
      callback - the callback that will be called whenever the direction is changed
      initialNotify - if true, the callback will be run on the initial value
      Returns:
      the CallbackStore object associated with this callback. Save a reference to this object so GC doesn't cancel the callback.
    • getDirection

      public boolean getDirection()
      Get the direction of the encoder.
      Returns:
      the direction of the encoder
    • setDirection

      public void setDirection​(boolean direction)
      Set the direction of the encoder.
      Parameters:
      direction - the new direction
    • registerReverseDirectionCallback

      public CallbackStore registerReverseDirectionCallback​(NotifyCallback callback, boolean initialNotify)
      Register a callback on the reverse direction.
      Parameters:
      callback - the callback that will be called whenever the reverse direction is changed
      initialNotify - if true, the callback will be run on the initial value
      Returns:
      the CallbackStore object associated with this callback. Save a reference to this object so GC doesn't cancel the callback.
    • getReverseDirection

      public boolean getReverseDirection()
      Get the reverse direction of the encoder.
      Returns:
      the reverse direction of the encoder
    • setReverseDirection

      public void setReverseDirection​(boolean reverseDirection)
      Set the reverse direction.
      Parameters:
      reverseDirection - the new value
    • registerSamplesToAverageCallback

      public CallbackStore registerSamplesToAverageCallback​(NotifyCallback callback, boolean initialNotify)
      Register a callback on the samples-to-average value of this encoder.
      Parameters:
      callback - the callback that will be called whenever the samples-to-average is changed
      initialNotify - if true, the callback will be run on the initial value
      Returns:
      the CallbackStore object associated with this callback. Save a reference to this object so GC doesn't cancel the callback.
    • getSamplesToAverage

      public int getSamplesToAverage()
      Get the samples-to-average value.
      Returns:
      the samples-to-average value
    • setSamplesToAverage

      public void setSamplesToAverage​(int samplesToAverage)
      Set the samples-to-average value.
      Parameters:
      samplesToAverage - the new value
    • setDistance

      public void setDistance​(double distance)
      Change the encoder distance.
      Parameters:
      distance - the new distance
    • getDistance

      public double getDistance()
      Read the distance of the encoder.
      Returns:
      the encoder distance
    • setRate

      public void setRate​(double rate)
      Change the rate of the encoder.
      Parameters:
      rate - the new rate
    • getRate

      public double getRate()
      Get the rate of the encoder.
      Returns:
      the rate of change
    • resetData

      public void resetData()
      Resets all simulation data for this encoder.