DigitalPWMSim

class wpilib.simulation.DigitalPWMSim(digitalOutput: wpilib._wpilib.DigitalOutput)

Bases: pybind11_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.

Constructs from a DigitalOutput object.

Parameters:

digitalOutput – DigitalOutput to simulate

static createForChannel(channel: int) wpilib.simulation._simulation.DigitalPWMSim

Creates an DigitalPWMSim for a digital I/O channel.

Parameters:

channel – DIO channel

Returns:

Simulated object @throws std::out_of_range if no Digital PWM is configured for that channel

static createForIndex(index: int) wpilib.simulation._simulation.DigitalPWMSim

Creates an DigitalPWMSim for a simulated index. The index is incremented for each simulated DigitalPWM.

Parameters:

index – simulator index

Returns:

Simulated object

getDutyCycle() float

Read the duty cycle value.

Returns:

the duty cycle value of this PWM output

getInitialized() bool

Check whether this PWM output has been initialized.

Returns:

true if initialized

getPin() int

Check the pin number.

Returns:

the pin number

registerDutyCycleCallback(callback: Callable[[str, HAL_Value], None], initialNotify: bool) wpilib.simulation._simulation.CallbackStore

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

registerInitializedCallback(callback: Callable[[str, HAL_Value], None], initialNotify: bool) wpilib.simulation._simulation.CallbackStore

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

registerPinCallback(callback: Callable[[str, HAL_Value], None], initialNotify: bool) wpilib.simulation._simulation.CallbackStore

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

resetData() None

Reset all simulation data.

setDutyCycle(dutyCycle: float) None

Set the duty cycle value of this PWM output.

Parameters:

dutyCycle – the new value

setInitialized(initialized: bool) None

Define whether this PWM output has been initialized.

Parameters:

initialized – whether this object is initialized

setPin(pin: int) None

Change the pin number.

Parameters:

pin – the new pin number