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
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.double
getDistancePerPulse()
Get the distance per pulse value.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
registerDistancePerPulseCallback(NotifyCallback callback, boolean initialNotify)
Register a callback on the distance per pulse value of this 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
setDistancePerPulse(double samplesToAverage)
Set the distance per pulse value.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 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
CallbackStore
object associated with this callback. Save a reference to this object so GC doesn't cancel the callback.
-
getInitialized
Read the Initialized value of the encoder.- Returns:
- true if initialized
-
setInitialized
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
CallbackStore
object associated with this callback. Save a reference to this object so GC doesn't cancel the callback.
-
getCount
Read the count of the encoder.- Returns:
- the count
-
setCount
Change the count of the encoder.- Parameters:
count
- the new count
-
registerPeriodCallback
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
Read the period of the encoder.- Returns:
- the encoder period
-
setPeriod
Change the encoder period.- Parameters:
period
- the new period
-
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
CallbackStore
object associated with this callback. Save a reference to this object so GC doesn't cancel the callback.
-
getReset
Check if the encoder has been reset.- Returns:
- true if reset
-
setReset
Change the reset property of the encoder.- Parameters:
reset
- the new value
-
registerMaxPeriodCallback
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
Get the max period of the encoder.- Returns:
- the max period of the encoder
-
setMaxPeriod
Change the max period of the encoder.- Parameters:
maxPeriod
- 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
CallbackStore
object associated with this callback. Save a reference to this object so GC doesn't cancel the callback.
-
getDirection
Get the direction of the encoder.- Returns:
- the direction of the encoder
-
setDirection
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
Get the reverse direction of the encoder.- Returns:
- the reverse direction of the encoder
-
setReverseDirection
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
Get the samples-to-average value.- Returns:
- the samples-to-average value
-
setSamplesToAverage
Set the samples-to-average value.- Parameters:
samplesToAverage
- 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
CallbackStore
object associated with this callback. Save a reference to this object so GC doesn't cancel the callback.
-
getDistancePerPulse
Get the distance per pulse value.- Returns:
- the distance per pulse value
-
setDistancePerPulse
Set the distance per pulse value.- Parameters:
samplesToAverage
- the new value
-
setDistance
Change the encoder distance.- Parameters:
distance
- the new distance
-
getDistance
Read the distance of the encoder.- Returns:
- the encoder distance
-
setRate
Change the rate of the encoder.- Parameters:
rate
- the new rate
-
getRate
Get the rate of the encoder.- Returns:
- the rate of change
-
resetData
Resets all simulation data for this encoder.
-