Package edu.wpi.first.wpilibj.simulation
Class EncoderSim
- java.lang.Object
-
- edu.wpi.first.wpilibj.simulation.EncoderSim
-
public class EncoderSim extends Object
Class to control a simulated encoder.
-
-
Constructor Summary
Constructors Constructor Description EncoderSim(Encoder encoder)
Constructs from an Encoder object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static EncoderSim
createForChannel(int channel)
Creates an EncoderSim for a digital input channel.static EncoderSim
createForIndex(int index)
Creates an EncoderSim for a simulated index.int
getCount()
Read the count of the encoder.boolean
getDirection()
Get the direction of the encoder.double
getDistance()
Read the distance of the encoder.boolean
getInitialized()
Read the Initialized value of the encoder.double
getMaxPeriod()
Get the max period of the encoder.double
getPeriod()
Read the period of the encoder.double
getRate()
Get the rate of the encoder.boolean
getReset()
Check if the encoder has been reset.boolean
getReverseDirection()
Get the reverse direction of the encoder.int
getSamplesToAverage()
Get the samples-to-average value.CallbackStore
registerCountCallback(NotifyCallback callback, boolean initialNotify)
Register a callback on the count property of the encoder.CallbackStore
registerDirectionCallback(NotifyCallback callback, boolean initialNotify)
Register a callback on the direction of the encoder.CallbackStore
registerInitializedCallback(NotifyCallback callback, boolean initialNotify)
Register a callback on the Initialized property of the encoder.CallbackStore
registerMaxPeriodCallback(NotifyCallback callback, boolean initialNotify)
Register a callback to be run whenever the max period of the encoder is changed.CallbackStore
registerPeriodCallback(NotifyCallback callback, boolean initialNotify)
Register a callback on the period of the encoder.CallbackStore
registerResetCallback(NotifyCallback callback, boolean initialNotify)
Register a callback to be called whenever the encoder is reset.CallbackStore
registerReverseDirectionCallback(NotifyCallback callback, boolean initialNotify)
Register a callback on the reverse direction.CallbackStore
registerSamplesToAverageCallback(NotifyCallback callback, boolean initialNotify)
Register a callback on the samples-to-average value of this encoder.void
resetData()
Resets all simulation data for this encoder.void
setCount(int count)
Change the count of the encoder.void
setDirection(boolean direction)
Set the direction of the encoder.void
setDistance(double distance)
Change the encoder distance.void
setInitialized(boolean initialized)
Change the Initialized value of the encoder.void
setMaxPeriod(double maxPeriod)
Change the max period of the encoder.void
setPeriod(double period)
Change the encoder period.void
setRate(double rate)
Change the rate of the encoder.void
setReset(boolean reset)
Change the reset property of the encoder.void
setReverseDirection(boolean reverseDirection)
Set the reverse direction.void
setSamplesToAverage(int samplesToAverage)
Set the samples-to-average value.
-
-
-
Constructor Detail
-
EncoderSim
public EncoderSim(Encoder encoder)
Constructs from an Encoder object.- Parameters:
encoder
- Encoder to simulate
-
-
Method Detail
-
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 changedinitialNotify
- 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 changedinitialNotify
- 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 changedinitialNotify
- 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 callbackinitialNotify
- 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 callbackinitialNotify
- 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 changedinitialNotify
- 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 changedinitialNotify
- 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 changedinitialNotify
- 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.
-
-