DutyCycle

class wpilib.DutyCycle(self: wpilib.DutyCycle, source: wpilib.DigitalSource) → None

Bases: wpilib.ErrorBase, wpilib.Sendable

Class to read a duty cycle PWM input.

PWM input signals are specified with a frequency and a ratio of high to low in that frequency. There are 8 of these in the roboRIO, and they can be attached to any DigitalSource.

These can be combined as the input of an AnalogTrigger to a Counter in order to implement rollover checking.

Constructs a DutyCycle input from a DigitalSource input.

This class does not own the inputted source.

Parameters

source – The DigitalSource to use.

getFPGAIndex(self: wpilib.DutyCycle) → int

Get the FPGA index for the DutyCycle.

Returns

the FPGA index

getFrequency(self: wpilib.DutyCycle) → int

Get the frequency of the duty cycle signal.

Returns

frequency in Hertz

getOutput(self: wpilib.DutyCycle) → float

Get the output ratio of the duty cycle signal.

0 means always low, 1 means always high.

Returns

output ratio between 0 and 1

getOutputRaw(self: wpilib.DutyCycle) → int

Get the raw output ratio of the duty cycle signal.

0 means always low, an output equal to GetOutputScaleFactor() means always high.

Returns

output ratio in raw units

getOutputScaleFactor(self: wpilib.DutyCycle) → int

Get the scale factor of the output.

An output equal to this value is always high, and then linearly scales down to 0. Divide the result of getOutputRaw by this in order to get the percentage between 0 and 1.

Returns

the output scale factor

getSourceChannel(self: wpilib.DutyCycle) → int

Get the channel of the source.

Returns

the source channel