Package edu.wpi.first.wpilibj
Class PWM
java.lang.Object
edu.wpi.first.wpilibj.PWM
- All Implemented Interfaces:
Sendable,AutoCloseable
Class implements the PWM generation in the FPGA.
The values supplied as arguments for PWM outputs range from -1.0 to 1.0. They are mapped to the microseconds to keep the pulse high, with a range of 0 (off) to 4096. Changes are immediately sent to the FPGA, and the update occurs at the next FPGA cycle (5.05ms). There is no delay.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumRepresents the output period in microseconds. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Free the resource associated with the PWM channel and set the value to 0.intGets the channel number associated with the PWM Object.intGet the underlying handle.intGet the PWM value directly from the hardware.voidinitSendable(SendableBuilder builder) Initializes thisSendableobject.final voidTemporarily disables the PWM output.voidSets the PWM output period.voidsetPulseTimeMicroseconds(int microsecondPulseTime) Set the PWM value directly to the hardware.voidsetSimDevice(SimDevice device) Indicates this input is used by a simulated device.
-
Constructor Details
-
PWM
Allocate a PWM given a channel.Checks channel value range and allocates the appropriate channel. The allocation is only done to help users ensure that they don't double assign channels.
By default, adds itself to SendableRegistry.
- Parameters:
channel- The PWM channel number. 0-9 are on-board, 10-19 are on the MXP port
-
PWM
Allocate a PWM given a channel.- Parameters:
channel- The PWM channel number. 0-9 are on-board, 10-19 are on the MXP portregisterSendable- If true, adds this instance to SendableRegistry
-
-
Method Details
-
close
Free the resource associated with the PWM channel and set the value to 0.- Specified by:
closein interfaceAutoCloseable
-
getChannel
Gets the channel number associated with the PWM Object.- Returns:
- The channel number.
-
setPulseTimeMicroseconds
Set the PWM value directly to the hardware.Write a microsecond pulse value to a PWM channel.
- Parameters:
microsecondPulseTime- Microsecond pulse PWM value. Range 0 - 4096.
-
getPulseTimeMicroseconds
Get the PWM value directly from the hardware.Read a raw value from a PWM channel.
- Returns:
- Microsecond pulse PWM control value. Range: 0 - 4096.
-
setDisabled
Temporarily disables the PWM output. The next set call will re-enable the output. -
setOutputPeriod
Sets the PWM output period.- Parameters:
mult- The output period to apply to this channel
-
getHandle
Get the underlying handle.- Returns:
- Underlying PWM handle
-
setSimDevice
Indicates this input is used by a simulated device.- Parameters:
device- simulated device handle
-
initSendable
Description copied from interface:SendableInitializes thisSendableobject.- Specified by:
initSendablein interfaceSendable- Parameters:
builder- sendable builder
-