Class PWM

java.lang.Object
org.wpilib.hardware.discrete.PWM
All Implemented Interfaces:
AutoCloseable, TelemetryLoggable

public class PWM extends Object implements TelemetryLoggable, 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.

  • Constructor Details

    • PWM

      public PWM(int channel)
      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.

      Parameters:
      channel - The SmartIO channel number.
  • Method Details

    • close

      public void close()
      Free the resource associated with the PWM channel and set the value to 0.
      Specified by:
      close in interface AutoCloseable
    • getChannel

      public int getChannel()
      Gets the channel number associated with the PWM Object.
      Returns:
      The channel number.
    • setPulseTimeMicroseconds

      public final void setPulseTimeMicroseconds(int microsecondPulseTime)
      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

      public final int 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

      public final void setDisabled()
      Temporarily disables the PWM output. The next set call will re-enable the output.
    • setOutputPeriod

      public void setOutputPeriod(int millisecondPeriod)
      Sets the PWM output period.
      Parameters:
      millisecondPeriod - The output period to apply to this channel, in milliseconds. Valid values are 5ms, 10ms, and 20ms. Default is 20 ms.
    • getHandle

      public int getHandle()
      Get the underlying handle.
      Returns:
      Underlying PWM handle
    • setSimDevice

      public void setSimDevice(SimDevice device)
      Indicates this input is used by a simulated device.
      Parameters:
      device - simulated device handle
    • logTo

      public void logTo(TelemetryTable table)
      Description copied from interface: TelemetryLoggable
      Logs the object to a TelemetryTable.
      Specified by:
      logTo in interface TelemetryLoggable
      Parameters:
      table - telemetry table
    • getTelemetryType

      public String getTelemetryType()
      Description copied from interface: TelemetryLoggable
      Gets the telemetry table type. Default is no specified table type (null). A mismatch in type during logging results in a reported warning, so this should always return the same value.
      Specified by:
      getTelemetryType in interface TelemetryLoggable
      Returns:
      Table type