Class Compressor

java.lang.Object
org.wpilib.hardware.pneumatic.Compressor
All Implemented Interfaces:
AutoCloseable, TelemetryLoggable

public class Compressor extends Object implements TelemetryLoggable, AutoCloseable
Class for operating a compressor connected to a pneumatics module. The module will automatically run in closed loop mode by default whenever a Solenoid object is created. For most cases, a Compressor object does not need to be instantiated or used in a robot program. This class is only required in cases where the robot program needs a more detailed status of the compressor or to enable/disable closed loop control.

Note: you cannot operate the compressor directly from this class as doing so would circumvent the safety provided by using the pressure switch and closed loop control. You can only turn off closed loop control, thereby stopping the compressor from operating.

  • Constructor Details

    • Compressor

      public Compressor(CANPort busId, int module, PneumaticsModuleType moduleType)
      Constructs a compressor for a specified module and type.
      Parameters:
      busId - The bus ID
      module - The module ID to use.
      moduleType - The module type to use.
    • Compressor

      public Compressor(CANPort busId, PneumaticsModuleType moduleType)
      Constructs a compressor for a default module and specified type.
      Parameters:
      busId - The bus ID
      moduleType - The module type to use.
  • Method Details

    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • isEnabled

      public boolean isEnabled()
      Returns whether the compressor is active or not.
      Returns:
      true if the compressor is on - otherwise false.
    • getPressureSwitchValue

      public boolean getPressureSwitchValue()
      Returns the state of the pressure switch.
      Returns:
      True if pressure switch indicates that the system is not full, otherwise false.
    • getCurrent

      public double getCurrent()
      Get the current drawn by the compressor.
      Returns:
      Current drawn by the compressor in amps.
    • getAnalogVoltage

      public double getAnalogVoltage()
      If supported by the device, returns the analog input voltage (on channel 0).

      This function is only supported by the REV PH. On CTRE PCM, this will return 0.

      Returns:
      The analog input voltage, in volts.
    • getPressure

      public double getPressure()
      If supported by the device, returns the pressure (in PSI) read by the analog pressure sensor (on channel 0).

      This function is only supported by the REV PH with the REV Analog Pressure Sensor. On CTRE PCM, this will return 0.

      Returns:
      The pressure (in PSI) read by the analog pressure sensor.
    • disable

      public void disable()
      Disable the compressor.
    • enableDigital

      public void enableDigital()
      Enables the compressor in digital mode using the digital pressure switch. The compressor will turn on when the pressure switch indicates that the system is not full, and will turn off when the pressure switch indicates that the system is full.
    • enableAnalog

      public void enableAnalog(double minPressure, double maxPressure)
      If supported by the device, enables the compressor in analog mode. This mode uses an analog pressure sensor connected to analog channel 0 to cycle the compressor. The compressor will turn on when the pressure drops below minPressure and will turn off when the pressure reaches maxPressure. This mode is only supported by the REV PH with the REV Analog Pressure Sensor connected to analog channel 0.

      On CTRE PCM, this will enable digital control.

      Parameters:
      minPressure - The minimum pressure in PSI. The compressor will turn on when the pressure drops below this value.
      maxPressure - The maximum pressure in PSI. The compressor will turn off when the pressure reaches this value.
    • enableHybrid

      public void enableHybrid(double minPressure, double maxPressure)
      If supported by the device, enables the compressor in hybrid mode. This mode uses both a digital pressure switch and an analog pressure sensor connected to analog channel 0 to cycle the compressor. This mode is only supported by the REV PH with the REV Analog Pressure Sensor connected to analog channel 0.

      The compressor will turn on when both:

      • The digital pressure switch indicates the system is not full AND
      • The analog pressure sensor indicates that the pressure in the system is below the specified minimum pressure.

      The compressor will turn off when either:

      • The digital pressure switch is disconnected or indicates that the system is full OR
      • The pressure detected by the analog sensor is greater than the specified maximum pressure.

      On CTRE PCM, this will enable digital control.

      Parameters:
      minPressure - The minimum pressure in PSI. The compressor will turn on when the pressure drops below this value and the pressure switch indicates that the system is not full.
      maxPressure - The maximum pressure in PSI. The compressor will turn off when the pressure reaches this value or the pressure switch is disconnected or indicates that the system is full.
    • getConfigType

      public CompressorConfigType getConfigType()
      Returns the active compressor configuration.
      Returns:
      The active compressor configuration.
    • 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