001// Copyright (c) FIRST and other WPILib contributors. 002// Open Source Software; you can modify and/or share it under the terms of 003// the WPILib BSD license file in the root directory of this project. 004 005package edu.wpi.first.wpilibj; 006 007public interface PneumaticsBase extends AutoCloseable { 008 /** 009 * For internal use to get a module for a specific type. 010 * 011 * @param module module number 012 * @param type module type 013 * @return module 014 */ 015 static PneumaticsBase getForType(int module, PneumaticsModuleType type) { 016 if (type == PneumaticsModuleType.CTREPCM) { 017 return new PneumaticsControlModule(module); 018 } else if (type == PneumaticsModuleType.REVPH) { 019 return new PneumaticHub(module); 020 } 021 throw new IllegalArgumentException("Unknown module type"); 022 } 023 024 /** 025 * For internal use to get the default for a specific type. 026 * 027 * @param type module type 028 * @return module default 029 */ 030 static int getDefaultForType(PneumaticsModuleType type) { 031 if (type == PneumaticsModuleType.CTREPCM) { 032 return SensorUtil.getDefaultCTREPCMModule(); 033 } else if (type == PneumaticsModuleType.REVPH) { 034 return SensorUtil.getDefaultREVPHModule(); 035 } 036 throw new IllegalArgumentException("Unknown module type"); 037 } 038 039 /** 040 * Sets solenoids on a pneumatics module. 041 * 042 * @param mask mask 043 * @param values values 044 */ 045 void setSolenoids(int mask, int values); 046 047 /** 048 * Gets a bitmask of solenoid values. 049 * 050 * @return values 051 */ 052 int getSolenoids(); 053 054 /** 055 * Get module number for this module. 056 * 057 * @return module number 058 */ 059 int getModuleNumber(); 060 061 /** 062 * Get a bitmask of disabled solenoids. 063 * 064 * @return bitmask of disabled solenoids 065 */ 066 int getSolenoidDisabledList(); 067 068 /** 069 * Fire a single solenoid shot. 070 * 071 * @param index solenoid index 072 */ 073 void fireOneShot(int index); 074 075 /** 076 * Set the duration for a single solenoid shot. 077 * 078 * @param index solenoid index 079 * @param durMs shot duration 080 */ 081 void setOneShotDuration(int index, int durMs); 082 083 /** 084 * Returns whether the compressor is active or not. 085 * 086 * @return True if the compressor is on - otherwise false. 087 */ 088 boolean getCompressor(); 089 090 /** 091 * Returns the state of the pressure switch. 092 * 093 * @return True if pressure switch indicates that the system is not full, otherwise false. 094 */ 095 boolean getPressureSwitch(); 096 097 /** 098 * Returns the current drawn by the compressor in amps. 099 * 100 * @return The current drawn by the compressor. 101 */ 102 double getCompressorCurrent(); 103 104 /** Disables the compressor. */ 105 void disableCompressor(); 106 107 /** 108 * Enables the compressor in digital mode using the digital pressure switch. The compressor will 109 * turn on when the pressure switch indicates that the system is not full, and will turn off when 110 * the pressure switch indicates that the system is full. 111 */ 112 void enableCompressorDigital(); 113 114 /** 115 * If supported by the device, enables the compressor in analog mode. This mode uses an analog 116 * pressure sensor connected to analog channel 0 to cycle the compressor. The compressor will turn 117 * on when the pressure drops below {@code minPressure} and will turn off when the pressure 118 * reaches {@code maxPressure}. This mode is only supported by the REV PH with the REV Analog 119 * Pressure Sensor connected to analog channel 0. 120 * 121 * <p>On CTRE PCM, this will enable digital control. 122 * 123 * @param minPressure The minimum pressure in PSI. The compressor will turn on when the pressure 124 * drops below this value. 125 * @param maxPressure The maximum pressure in PSI. The compressor will turn off when the pressure 126 * reaches this value. 127 */ 128 void enableCompressorAnalog(double minPressure, double maxPressure); 129 130 /** 131 * If supported by the device, enables the compressor in hybrid mode. This mode uses both a 132 * digital pressure switch and an analog pressure sensor connected to analog channel 0 to cycle 133 * the compressor. This mode is only supported by the REV PH with the REV Analog Pressure Sensor 134 * connected to analog channel 0. 135 * 136 * <p>The compressor will turn on when <i>both</i>: 137 * 138 * <ul> 139 * <li>The digital pressure switch indicates the system is not full AND 140 * <li>The analog pressure sensor indicates that the pressure in the system is below the 141 * specified minimum pressure. 142 * </ul> 143 * 144 * <p>The compressor will turn off when <i>either</i>: 145 * 146 * <ul> 147 * <li>The digital pressure switch is disconnected or indicates that the system is full OR 148 * <li>The pressure detected by the analog sensor is greater than the specified maximum 149 * pressure. 150 * </ul> 151 * 152 * <p>On CTRE PCM, this will enable digital control. 153 * 154 * @param minPressure The minimum pressure in PSI. The compressor will turn on when the pressure 155 * drops below this value and the pressure switch indicates that the system is not full. 156 * @param maxPressure The maximum pressure in PSI. The compressor will turn off when the pressure 157 * reaches this value or the pressure switch is disconnected or indicates that the system is 158 * full. 159 */ 160 void enableCompressorHybrid(double minPressure, double maxPressure); 161 162 /** 163 * If supported by the device, returns the raw voltage of the specified analog input channel. 164 * 165 * <p>This function is only supported by the REV PH. On CTRE PCM, this will return 0. 166 * 167 * @param channel The analog input channel to read voltage from. 168 * @return The voltage of the specified analog input channel. 169 */ 170 double getAnalogVoltage(int channel); 171 172 /** 173 * If supported by the device, returns the pressure (in PSI) read by an analog pressure sensor on 174 * the specified analog input channel. 175 * 176 * <p>This function is only supported by the REV PH. On CTRE PCM, this will return 0. 177 * 178 * @param channel The analog input channel to read pressure from. 179 * @return The pressure (in PSI) read by an analog pressure sensor on the specified analog input 180 * channel. 181 */ 182 double getPressure(int channel); 183 184 /** 185 * Returns the active compressor configuration. 186 * 187 * @return The active compressor configuration. 188 */ 189 CompressorConfigType getCompressorConfigType(); 190 191 /** 192 * Check if a solenoid channel is valid. 193 * 194 * @param channel Channel to check 195 * @return True if channel exists 196 */ 197 boolean checkSolenoidChannel(int channel); 198 199 /** 200 * Check to see if the masked solenoids can be reserved, and if not reserve them. 201 * 202 * @param mask The bitmask of solenoids to reserve 203 * @return 0 if successful; mask of solenoids that couldn't be allocated otherwise 204 */ 205 int checkAndReserveSolenoids(int mask); 206 207 /** 208 * Unreserve the masked solenoids. 209 * 210 * @param mask The bitmask of solenoids to unreserve 211 */ 212 void unreserveSolenoids(int mask); 213 214 /** 215 * Reserve the compressor. 216 * 217 * @return true if successful; false if compressor already reserved 218 */ 219 boolean reserveCompressor(); 220 221 /** Unreserve the compressor. */ 222 void unreserveCompressor(); 223 224 @Override 225 void close(); 226 227 /** 228 * Create a solenoid object for the specified channel. 229 * 230 * @param channel solenoid channel 231 * @return Solenoid object 232 */ 233 Solenoid makeSolenoid(int channel); 234 235 /** 236 * Create a double solenoid object for the specified channels. 237 * 238 * @param forwardChannel solenoid channel for forward 239 * @param reverseChannel solenoid channel for reverse 240 * @return DoubleSolenoid object 241 */ 242 DoubleSolenoid makeDoubleSolenoid(int forwardChannel, int reverseChannel); 243 244 /** 245 * Create a compressor object. 246 * 247 * @return Compressor object 248 */ 249 Compressor makeCompressor(); 250}