- FRC Game Manual
- FRC Game Q&A

# Generating and Storing Pressure

Pressure is created using a pneumatic compressor and stored in pneumatic tanks. The compressor must be on the robot and powered by the robot’s pneumatics module. The “Closed Loop” mode on the Compressor is enabled by default, and it is not recommended that teams change this setting. When closed loop control is enabled the pneumatic module will automatically turn the compressor on when the digital pressure switch is closed (below the pressure threshold) and turn it off when the pressure switch is open (~120PSI). When closed loop control is disabled the compressor will not be turned on. Using the `Compressor` (Java / C++) class, users can query the status of the compressor. The state (currently on or off), pressure switch state, and compressor current can all be queried from the Compressor object, as shown by the following code from the Solenoid example project (Java, C++):

Note

The Compressor object is only needed if you want the ability to turn off the compressor, change the pressure sensor (PH only), or query compressor status.

Construct a `Compressor` object:

REV Pneumatic Hub (PH)
Java

      // Compressor connected to a PH with a default CAN ID (1)
      private final Compressor m_compressor = new Compressor(PneumaticsModuleType.REVPH);

C++ (Header)

      // Compressor connected to a PH with a default CAN ID
      frc::Compressor m_compressor{frc::PneumaticsModuleType::REVPH};

CTRE Pneumatics Control Module (PCM)
Java

      // Compressor connected to a PCM with a default CAN ID (0)
      private final Compressor m_compressor = new Compressor(PneumaticsModuleType.CTREPCM);

C++ (Header)

      // Compressor connected to a PH with a default CAN ID

Querying compressor current and state:

Java

              // Get compressor current draw.
              return m_compressor.getCurrent();
              // Get whether the compressor is active.
              return m_compressor.isEnabled();
              // Get the digital pressure switch connected to the PCM/PH.
              // The switch is open when the pressure is over ~120 PSI.
              return m_compressor.getPressureSwitchValue();

C++ (Source)

        // Get compressor current draw.
        units::ampere_t compressorCurrent = m_compressor.GetCurrent();
        return compressorCurrent.value();
        // Get whether the compressor is active.
        return m_compressor.IsEnabled();
        // Get the digital pressure switch connected to the PCM/PH.
        // The switch is open when the pressure is over ~120 PSI.
        return m_compressor.GetPressureSwitchValue();

Enable/disable digital closed-loop compressor control (enabled by default):

Java

                  // Disable closed-loop mode on the compressor.
                  m_compressor.disable();
                  // Enable closed-loop mode based on the digital pressure switch connected to the
                  // PCM/PH.
                  // The switch is open when the pressure is over ~120 PSI.
                  m_compressor.enableDigital();

C++ (Source)

            // Disable closed-loop mode on the compressor.
            m_compressor.Disable();
            // Enable closed-loop mode based on the digital pressure switch
            // connected to the PCM/PH. The switch is open when the pressure is over
            // ~120 PSI.
            m_compressor.EnableDigital();

The Pneumatic Hub also has methods for enabling compressor control using the REV Analog Pressure Sensor:

Java

              // Enable closed-loop mode based on the analog pressure sensor connected to the PH.
              // The compressor will run while the pressure reported by the sensor is in the
              // specified range ([70 PSI, 120 PSI] in this example).
              // Analog mode exists only on the PH! On the PCM, this enables digital control.
              m_compressor.enableAnalog(70, 120);
              // Enable closed-loop mode based on both the digital pressure switch AND the analog
              // pressure sensor connected to the PH.
              // The compressor will run while the pressure reported by the analog sensor is in the
              // specified range ([70 PSI, 120 PSI] in this example) AND the digital switch reports
              // that the system is not full.
              // Hybrid mode exists only on the PH! On the PCM, this enables digital control.
              m_compressor.enableHybrid(70, 120);

C++ (Source)

          // Enable closed-loop mode based on the analog pressure sensor connected
          // to the PH. The compressor will run while the pressure reported by the
          // sensor is in the specified range ([70 PSI, 120 PSI] in this example).
          // Analog mode exists only on the PH! On the PCM, this enables digital
          // control.
          m_compressor.EnableAnalog(70_psi, 120_psi);
          // Enable closed-loop mode based on both the digital pressure switch AND the analog
          // pressure sensor connected to the PH.
          // The compressor will run while the pressure reported by the analog sensor is in the
          // specified range ([70 PSI, 120 PSI] in this example) AND the digital switch reports
          // that the system is not full.
          // Hybrid mode exists only on the PH! On the PCM, this enables digital control.
          m_compressor.EnableHybrid(70_psi, 120_psi);

## Pressure Transducers

A pressure transducer is a sensor where analog voltage is proportial to the measured pressure.

### Pneumatic Hub

The Pneumatic Hub has analog inputs that may be used to read a pressure transducer using the Compressor class.

Java

      // Compressor connected to a PH with a default CAN ID (1)
      private final Compressor m_compressor = new Compressor(PneumaticsModuleType.REVPH);

              // Get the pressure (in PSI) from the analog sensor connected to the PH.
              // This function is supported only on the PH!
              // On a PCM, this function will return 0.
              return m_compressor.getPressure();

C++ (Header)

      // Compressor connected to a PH with a default CAN ID
      frc::Compressor m_compressor{frc::PneumaticsModuleType::REVPH};

C++ (Source)

        // Get the pressure (in PSI) from the analog sensor connected to the PH.
        // This function is supported only on the PH!
        // On a PCM, this function will return 0.
        units::pounds_per_square_inch_t pressure = m_compressor.GetPressure();
        return pressure.value();

### roboRIO

A pressure transducer can be connected to the Analog Input ports on the roboRIO, and can be read by the `AnalogInput` or `AnalogPotentiometer` classes in WPILib.

Java

      // External analog pressure sensor
      // product-specific voltage->pressure conversion, see product manual
      // in this case, 250(V/5)-25
      // the scale parameter in the AnalogPotentiometer constructor is scaled from 1 instead of 5,
      // so if r is the raw AnalogPotentiometer output, the pressure is 250r-25
      static final double kScale = 250;
      static final double kOffset = -25;
      private final AnalogPotentiometer m_pressureTransducer =
          new AnalogPotentiometer(/* the AnalogIn port*/ 2, kScale, kOffset);

        // Get the pressure (in PSI) from an analog pressure sensor connected to the RIO.
        return m_pressureTransducer.get();

C++ (Header)

      // External analog pressure sensor
      // product-specific voltage->pressure conversion, see product manual
      // in this case, 250(V/5)-25
      // the scale parameter in the AnalogPotentiometer constructor is scaled from
      // 1 instead of 5, so if r is the raw AnalogPotentiometer output, the
      // pressure is 250r-25
      static constexpr double kScale = 250;
      static constexpr double kOffset = -25;
      frc::AnalogPotentiometer m_pressureTransducer{/* the AnalogIn port*/ 2,
                                                    kScale, kOffset};

C++ (Source)

      // Get the pressure (in PSI) from an analog pressure sensor connected to
      // the RIO.
      return units::pounds_per_square_inch_t{m_pressureTransducer.Get()};