Package edu.wpi.first.wpilibj
Class DutyCycle
java.lang.Object
edu.wpi.first.wpilibj.DutyCycle
- All Implemented Interfaces:
Sendable,AutoCloseable
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.
-
Constructor Summary
ConstructorsConstructorDescriptionDutyCycle(DigitalSource digitalSource) Constructs a DutyCycle input from a DigitalSource input. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the DutyCycle and free all resources.final intGet the FPGA index for the DutyCycle.intGet the frequency of the duty cycle signal.intGet the raw high time of the duty cycle signal.doubleGet the output ratio of the duty cycle signal.intGet the scale factor of the output.intGet the channel of the source.voidinitSendable(SendableBuilder builder) Initializes thisSendableobject.
-
Constructor Details
-
DutyCycle
Constructs a DutyCycle input from a DigitalSource input.This class does not own the inputted source.
- Parameters:
digitalSource- The DigitalSource to use.
-
-
Method Details
-
close
Close the DutyCycle and free all resources.- Specified by:
closein interfaceAutoCloseable
-
getFrequency
Get the frequency of the duty cycle signal.- Returns:
- frequency in Hertz
-
getOutput
Get the output ratio of the duty cycle signal.0 means always low, 1 means always high.
- Returns:
- output ratio between 0 and 1
-
getHighTimeNanoseconds
Get the raw high time of the duty cycle signal.- Returns:
- high time of last pulse in nanoseconds
-
getOutputScaleFactor
Get the scale factor of the output.An output equal to this value is always high, and then linearly scales down to 0. Divide a raw result by this in order to get the percentage between 0 and 1. Used by DMA.
- Returns:
- the output scale factor
-
getFPGAIndex
Get the FPGA index for the DutyCycle.- Returns:
- the FPGA index
-
getSourceChannel
Get the channel of the source.- Returns:
- the source channel
-
initSendable
Description copied from interface:SendableInitializes thisSendableobject.- Specified by:
initSendablein interfaceSendable- Parameters:
builder- sendable builder
-