Class EncoderSim
java.lang.Object
org.wpilib.simulation.EncoderSim
Class to control a simulated encoder.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic EncoderSimcreateForChannel(int channel) Creates an EncoderSim for a digital input channel.static EncoderSimcreateForIndex(int index) Creates an EncoderSim for a simulated index.intgetCount()Read the count of the encoder.booleanGet the direction of the encoder.doubleRead the distance of the encoder.doubleGet the distance per pulse value.booleanRead the Initialized value of the encoder.doublegetRate()Get the rate of the encoder.booleangetReset()Check if the encoder has been reset.booleanGet the reverse direction of the encoder.registerCountCallback(NotifyCallback callback, boolean initialNotify) Register a callback on the count property of the encoder.registerDirectionCallback(NotifyCallback callback, boolean initialNotify) Register a callback on the direction of the encoder.registerDistancePerPulseCallback(NotifyCallback callback, boolean initialNotify) Register a callback on the distance per pulse value of this encoder.registerInitializedCallback(NotifyCallback callback, boolean initialNotify) Register a callback on the Initialized property of the encoder.registerRateCallback(NotifyCallback callback, boolean initialNotify) Register a callback on the rate of the encoder.registerResetCallback(NotifyCallback callback, boolean initialNotify) Register a callback to be called whenever the encoder is reset.registerReverseDirectionCallback(NotifyCallback callback, boolean initialNotify) Register a callback on the reverse direction.voidResets all simulation data for this encoder.voidsetCount(int count) Change the count of the encoder.voidsetDirection(boolean direction) Set the direction of the encoder.voidsetDistance(double distance) Change the encoder distance.voidsetDistancePerPulse(double distancePerPulse) Set the distance per pulse value.voidsetInitialized(boolean initialized) Change the Initialized value of the encoder.voidsetRate(double rate) Change the rate of the encoder.voidsetReset(boolean reset) Change the reset property of the encoder.voidsetReverseDirection(boolean reverseDirection) Set the reverse direction.
-
Constructor Details
-
EncoderSim
Constructs from an Encoder object.- Parameters:
encoder- Encoder to simulate
-
-
Method Details
-
createForChannel
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
Creates an EncoderSim for a simulated index. The index is incremented for each simulated Encoder.- Parameters:
index- simulator index- Returns:
- Simulated object
-
registerInitializedCallback
Register a callback on the Initialized property of the encoder.- Parameters:
callback- the callback that will be called whenever the Initialized property is changedinitialNotify- if true, the callback will be run on the initial value- Returns:
- the
CallbackStoreobject associated with this 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
Register a callback on the count property of the encoder.- Parameters:
callback- the callback that will be called whenever the count property is changedinitialNotify- if true, the callback will be run on the initial value- Returns:
- the
CallbackStoreobject associated with this 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
-
registerRateCallback
Register a callback on the rate of the encoder.- Parameters:
callback- the callback that will be called whenever the rate is changedinitialNotify- if true, the callback will be run on the initial value- Returns:
- the
CallbackStoreobject associated with this callback.
-
registerResetCallback
Register a callback to be called whenever the encoder is reset.- Parameters:
callback- the callbackinitialNotify- whether to run the callback on the initial value- Returns:
- the
CallbackStoreobject associated with this 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
-
registerDirectionCallback
Register a callback on the direction of the encoder.- Parameters:
callback- the callback that will be called whenever the direction is changedinitialNotify- if true, the callback will be run on the initial value- Returns:
- the
CallbackStoreobject associated with this 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 changedinitialNotify- if true, the callback will be run on the initial value- Returns:
- the
CallbackStoreobject associated with this 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
-
registerDistancePerPulseCallback
public CallbackStore registerDistancePerPulseCallback(NotifyCallback callback, boolean initialNotify) Register a callback on the distance per pulse value of this encoder.- Parameters:
callback- the callback that will be called whenever the distance per pulse is changedinitialNotify- if true, the callback will be run on the initial value- Returns:
- the
CallbackStoreobject associated with this callback.
-
getDistancePerPulse
public double getDistancePerPulse()Get the distance per pulse value.- Returns:
- the distance per pulse value
-
setDistancePerPulse
public void setDistancePerPulse(double distancePerPulse) Set the distance per pulse value.- Parameters:
distancePerPulse- the new distancePerPulse
-
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.
-