Package edu.wpi.first.wpilibj.simulation
Class DigitalPWMSim
java.lang.Object
edu.wpi.first.wpilibj.simulation.DigitalPWMSim
Class to control a simulated digital PWM output.
This is for duty cycle PWM outputs on a DigitalOutput, not for the servo style PWM outputs on a PWM channel.
-
Constructor Summary
ConstructorDescriptionDigitalPWMSim
(DigitalOutput digitalOutput) Constructs from a DigitalOutput object. -
Method Summary
Modifier and TypeMethodDescriptionstatic DigitalPWMSim
createForChannel
(int channel) Creates an DigitalPWMSim for a digital I/O channel.static DigitalPWMSim
createForIndex
(int index) Creates an DigitalPWMSim for a simulated index.double
Read the duty cycle value.boolean
Check whether this PWM output has been initialized.int
getPin()
Check the pin number.registerDutyCycleCallback
(NotifyCallback callback, boolean initialNotify) Register a callback to be run whenever the duty cycle value changes.registerInitializedCallback
(NotifyCallback callback, boolean initialNotify) Register a callback to be run when this PWM output is initialized.registerPinCallback
(NotifyCallback callback, boolean initialNotify) Register a callback to be run whenever the pin changes.void
Reset all simulation data.void
setDutyCycle
(double dutyCycle) Set the duty cycle value of this PWM output.void
setInitialized
(boolean initialized) Define whether this PWM output has been initialized.void
setPin
(int pin) Change the pin number.
-
Constructor Details
-
DigitalPWMSim
Constructs from a DigitalOutput object.- Parameters:
digitalOutput
- DigitalOutput to simulate
-
-
Method Details
-
createForChannel
Creates an DigitalPWMSim for a digital I/O channel.- Parameters:
channel
- DIO channel- Returns:
- Simulated object
- Throws:
NoSuchElementException
- if no Digital PWM is configured for that channel
-
createForIndex
Creates an DigitalPWMSim for a simulated index. The index is incremented for each simulated DigitalPWM.- Parameters:
index
- simulator index- Returns:
- Simulated object
-
registerInitializedCallback
Register a callback to be run when this PWM output is initialized.- Parameters:
callback
- the callbackinitialNotify
- whether to run the callback with the initial state- Returns:
- the
CallbackStore
object associated with this callback.
-
getInitialized
Check whether this PWM output has been initialized.- Returns:
- true if initialized
-
setInitialized
Define whether this PWM output has been initialized.- Parameters:
initialized
- whether this object is initialized
-
registerDutyCycleCallback
Register a callback to be run whenever the duty cycle value changes.- Parameters:
callback
- the callbackinitialNotify
- whether to call the callback with the initial state- Returns:
- the
CallbackStore
object associated with this callback.
-
getDutyCycle
Read the duty cycle value.- Returns:
- the duty cycle value of this PWM output
-
setDutyCycle
Set the duty cycle value of this PWM output.- Parameters:
dutyCycle
- the new value
-
registerPinCallback
Register a callback to be run whenever the pin changes.- Parameters:
callback
- the callbackinitialNotify
- whether to call the callback with the initial state- Returns:
- the
CallbackStore
object associated with this callback.
-
getPin
Check the pin number.- Returns:
- the pin number
-
setPin
Change the pin number.- Parameters:
pin
- the new pin number
-
resetData
Reset all simulation data.
-