Class DigitalPWMSim

java.lang.Object
edu.wpi.first.wpilibj.simulation.DigitalPWMSim

public class DigitalPWMSim
extends Object
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 Details

  • Method Details

    • createForChannel

      public static DigitalPWMSim createForChannel​(int channel)
      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

      public static DigitalPWMSim createForIndex​(int index)
      Creates an DigitalPWMSim for a simulated index. The index is incremented for each simulated DigitalPWM.
      Parameters:
      index - simulator index
      Returns:
      Simulated object
    • registerInitializedCallback

      public CallbackStore registerInitializedCallback​(NotifyCallback callback, boolean initialNotify)
      Register a callback to be run when this PWM output is initialized.
      Parameters:
      callback - the callback
      initialNotify - whether to run the callback with the initial state
      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()
      Check whether this PWM output has been initialized.
      Returns:
      true if initialized
    • setInitialized

      public void setInitialized​(boolean initialized)
      Define whether this PWM output has been initialized.
      Parameters:
      initialized - whether this object is initialized
    • registerDutyCycleCallback

      public CallbackStore registerDutyCycleCallback​(NotifyCallback callback, boolean initialNotify)
      Register a callback to be run whenever the duty cycle value changes.
      Parameters:
      callback - the callback
      initialNotify - whether to call the callback with the initial state
      Returns:
      the CallbackStore object associated with this callback. Save a reference to this object so GC doesn't cancel the callback.
    • getDutyCycle

      public double getDutyCycle()
      Read the duty cycle value.
      Returns:
      the duty cycle value of this PWM output
    • setDutyCycle

      public void setDutyCycle​(double dutyCycle)
      Set the duty cycle value of this PWM output.
      Parameters:
      dutyCycle - the new value
    • registerPinCallback

      public CallbackStore registerPinCallback​(NotifyCallback callback, boolean initialNotify)
      Register a callback to be run whenever the pin changes.
      Parameters:
      callback - the callback
      initialNotify - whether to call the callback with the initial state
      Returns:
      the CallbackStore object associated with this callback. Save a reference to this object so GC doesn't cancel the callback.
    • getPin

      public int getPin()
      Check the pin number.
      Returns:
      the pin number
    • setPin

      public void setPin​(int pin)
      Change the pin number.
      Parameters:
      pin - the new pin number
    • resetData

      public void resetData()
      Reset all simulation data.