Package edu.wpi.first.wpilibj.simulation
Class DutyCycleSim
java.lang.Object
edu.wpi.first.wpilibj.simulation.DutyCycleSim
public class DutyCycleSim extends Object
Class to control a simulated duty cycle digital input.
-
Constructor Summary
Constructors Constructor Description DutyCycleSim(DutyCycle dutyCycle)Constructs from a DutyCycle object. -
Method Summary
Modifier and Type Method Description static DutyCycleSimcreateForChannel(int channel)Creates a DutyCycleSim for a digital input channel.static DutyCycleSimcreateForIndex(int index)Creates a DutyCycleSim for a simulated index.intgetFrequency()Measure the frequency.booleangetInitialized()Check whether this duty cycle input has been initialized.doublegetOutput()Measure the output from this duty cycle port.CallbackStoreregisterFrequencyCallback(NotifyCallback callback, boolean initialNotify)Register a callback to be run whenever the frequency changes.CallbackStoreregisterInitializedCallback(NotifyCallback callback, boolean initialNotify)Register a callback to be run when this duty cycle input is initialized.CallbackStoreregisterOutputCallback(NotifyCallback callback, boolean initialNotify)Register a callback to be run whenever the output changes.voidresetData()Reset all simulation data for the duty cycle output.voidsetFrequency(int frequency)Change the duty cycle frequency.voidsetInitialized(boolean initialized)Define whether this duty cycle input has been initialized.voidsetOutput(double output)Change the duty cycle output.
-
Constructor Details
-
DutyCycleSim
Constructs from a DutyCycle object.- Parameters:
dutyCycle- DutyCycle to simulate
-
-
Method Details
-
createForChannel
Creates a DutyCycleSim for a digital input channel.- Parameters:
channel- digital input channel- Returns:
- Simulated object
- Throws:
NoSuchElementException- if no DutyCycle is configured for that channel
-
createForIndex
Creates a DutyCycleSim for a simulated index. The index is incremented for each simulated DutyCycle.- Parameters:
index- simulator index- Returns:
- Simulated object
-
registerInitializedCallback
Register a callback to be run when this duty cycle input is initialized.- Parameters:
callback- the callbackinitialNotify- whether to run the callback with the initial state- Returns:
- the
CallbackStoreobject associated with this callback. Save a reference to this object so GC doesn't cancel the callback.
-
getInitialized
Check whether this duty cycle input has been initialized.- Returns:
- true if initialized
-
setInitialized
Define whether this duty cycle input has been initialized.- Parameters:
initialized- whether this object is initialized
-
registerFrequencyCallback
Register a callback to be run whenever the frequency changes.- Parameters:
callback- the callbackinitialNotify- whether to call the callback with the initial state- Returns:
- the
CallbackStoreobject associated with this callback. Save a reference to this object so GC doesn't cancel the callback.
-
getFrequency
Measure the frequency.- Returns:
- the duty cycle frequency
-
setFrequency
Change the duty cycle frequency.- Parameters:
frequency- the new frequency
-
registerOutputCallback
Register a callback to be run whenever the output changes.- Parameters:
callback- the callbackinitialNotify- whether to call the callback with the initial state- Returns:
- the
CallbackStoreobject associated with this callback. Save a reference to this object so GC doesn't cancel the callback.
-
getOutput
Measure the output from this duty cycle port.- Returns:
- the output value
-
setOutput
Change the duty cycle output.- Parameters:
output- the new output value
-
resetData
Reset all simulation data for the duty cycle output.
-