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.hal; 006 007/** 008 * REV Pneumatic Hub (PH) HAL JNI functions. 009 * 010 * @see "REVPH.h" 011 */ 012public class REVPHJNI extends JNIWrapper { 013 /** Disabled. */ 014 public static final int COMPRESSOR_CONFIG_TYPE_DISABLED = 0; 015 016 /** Digital. */ 017 public static final int COMPRESSOR_CONFIG_TYPE_DIGITAL = 1; 018 019 /** Analog. */ 020 public static final int COMPRESSOR_CONFIG_TYPE_ANALOG = 2; 021 022 /** Hybrid. */ 023 public static final int COMPRESSOR_CONFIG_TYPE_HYBRID = 3; 024 025 /** 026 * Initializes a PH. 027 * 028 * @param module the CAN ID to initialize 029 * @return the created PH handle 030 * @see "HAL_InitializeREVPH" 031 */ 032 public static native int initialize(int module); 033 034 /** 035 * Frees a PH handle. 036 * 037 * @param handle the PH handle 038 * @see "HAL_FreeREVPH" 039 */ 040 public static native void free(int handle); 041 042 /** 043 * Checks if a solenoid channel number is valid. 044 * 045 * @param channel the channel to check 046 * @return true if the channel is valid, otherwise false 047 * @see "HAL_CheckREVPHSolenoidChannel" 048 */ 049 public static native boolean checkSolenoidChannel(int channel); 050 051 /** 052 * Get whether compressor is turned on. 053 * 054 * @param handle the PH handle 055 * @return true if the compressor is turned on 056 * @see "HAL_GetREVPHCompressor" 057 */ 058 public static native boolean getCompressor(int handle); 059 060 /** 061 * Send compressor configuration to the PH. 062 * 063 * @param handle the PH handle 064 * @param minAnalogVoltage The compressor will turn on when the analog pressure sensor voltage 065 * drops below this value 066 * @param maxAnalogVoltage The compressor will turn off when the analog pressure sensor reaches 067 * this value. 068 * @param forceDisable Disable Compressor 069 * @param useDigital use the digital pressure switch 070 * @see "HAL_SetREVPHCompressorConfig" 071 */ 072 public static native void setCompressorConfig( 073 int handle, 074 double minAnalogVoltage, 075 double maxAnalogVoltage, 076 boolean forceDisable, 077 boolean useDigital); 078 079 /** 080 * Disable Compressor. 081 * 082 * @param handle the PH handle 083 * @see "HAL_SetREVPHClosedLoopControlDisabled" 084 */ 085 public static native void setClosedLoopControlDisabled(int handle); 086 087 /** 088 * Enables the compressor in digital mode using the digital pressure switch. The compressor will 089 * turn on when the pressure switch indicates that the system is not full, and will turn off when 090 * the pressure switch indicates that the system is full. 091 * 092 * @param handle the PH handle 093 * @see "HAL_SetREVPHClosedLoopControlDigital" 094 */ 095 public static native void setClosedLoopControlDigital(int handle); 096 097 /** 098 * Enables the compressor in analog mode. This mode uses an analog pressure sensor connected to 099 * analog channel 0 to cycle the compressor. The compressor will turn on when the pressure drops 100 * below minAnalogVoltage and will turn off when the pressure reaches maxAnalogVoltage. This mode 101 * is only supported by the REV PH with the REV Analog Pressure Sensor connected to analog channel 102 * 0. 103 * 104 * @param handle the PH handle 105 * @param minAnalogVoltage The compressor will turn on when the analog pressure sensor voltage 106 * drops below this value 107 * @param maxAnalogVoltage The compressor will turn off when the analog pressure sensor reaches 108 * this value. 109 * @see "HAL_SetREVPHClosedLoopControlAnalog" 110 */ 111 public static native void setClosedLoopControlAnalog( 112 int handle, double minAnalogVoltage, double maxAnalogVoltage); 113 114 /** 115 * Enables the compressor in hybrid mode. This mode uses both a digital pressure switch and an 116 * analog pressure sensor connected to analog channel 0 to cycle the compressor. 117 * 118 * <p>The compressor will turn on when \a both: 119 * 120 * <p>- The digital pressure switch indicates the system is not full AND - The analog pressure 121 * sensor indicates that the pressure in the system is below the specified minimum pressure. 122 * 123 * <p>The compressor will turn off when \a either: 124 * 125 * <p>- The digital pressure switch is disconnected or indicates that the system is full OR - The 126 * pressure detected by the analog sensor is greater than the specified maximum pressure. 127 * 128 * @param handle the PH handle 129 * @param minAnalogVoltage The compressor will turn on when the analog pressure sensor voltage 130 * drops below this value and the pressure switch indicates that the system is not full. 131 * @param maxAnalogVoltage The compressor will turn off when the analog pressure sensor reaches 132 * this value or the pressure switch is disconnected or indicates that the system is full. 133 * @see "HAL_SetREVPHClosedLoopControlHybrid" 134 */ 135 public static native void setClosedLoopControlHybrid( 136 int handle, double minAnalogVoltage, double maxAnalogVoltage); 137 138 /** 139 * Get compressor configuration from the PH. 140 * 141 * @param handle the PH handle 142 * @return compressor configuration 143 * @see "HAL_GetREVPHCompressorConfig" 144 */ 145 public static native int getCompressorConfig(int handle); 146 147 /** 148 * Returns the state of the digital pressure switch. 149 * 150 * @param handle the PH handle 151 * @return True if pressure switch indicates that the system is full, otherwise false. 152 * @see "HAL_GetREVPHPressureSwitch" 153 */ 154 public static native boolean getPressureSwitch(int handle); 155 156 /** 157 * Returns the raw voltage of the specified analog input channel. 158 * 159 * @param handle the PH handle 160 * @param channel The analog input channel to read voltage from. 161 * @return The voltage of the specified analog input channel in volts. 162 * @see "HAL_GetREVPHAnalogVoltage" 163 */ 164 public static native double getAnalogVoltage(int handle, int channel); 165 166 /** 167 * Returns the current drawn by the compressor. 168 * 169 * @param handle the PH handle 170 * @return The current drawn by the compressor in amps. 171 * @see "HAL_GetREVPHCompressorCurrent" 172 */ 173 public static native double getCompressorCurrent(int handle); 174 175 /** 176 * Gets a bitmask of solenoid values. 177 * 178 * @param handle the PH handle 179 * @return Bitmask containing the state of the solenoids. The LSB represents solenoid 0. 180 * @see "HAL_GetREVPHSolenoids" 181 */ 182 public static native int getSolenoids(int handle); 183 184 /** 185 * Sets solenoids on a PH. 186 * 187 * @param handle the PH handle 188 * @param mask Bitmask indicating which solenoids to set. The LSB represents solenoid 0. 189 * @param values Bitmask indicating the desired states of the solenoids. The LSB represents 190 * solenoid 0. 191 * @see "HAL_SetREVPHSolenoids" 192 */ 193 public static native void setSolenoids(int handle, int mask, int values); 194 195 /** 196 * Fire a single solenoid shot for the specified duration. 197 * 198 * @param handle the PH handle 199 * @param index solenoid index 200 * @param durMs shot duration in ms 201 * @see "HAL_FireREVPHOneShot" 202 */ 203 public static native void fireOneShot(int handle, int index, int durMs); 204 205 /** 206 * Clears the sticky faults. 207 * 208 * @param handle the PH handle 209 * @see "HAL_ClearREVPHStickyFaults" 210 */ 211 public static native void clearStickyFaults(int handle); 212 213 /** 214 * Returns the current input voltage for the PH. 215 * 216 * @param handle the PH handle 217 * @return The input voltage in volts. 218 * @see "HAL_GetREVPHVoltage" 219 */ 220 public static native double getInputVoltage(int handle); 221 222 /** 223 * Returns the current voltage of the regulated 5v supply. 224 * 225 * @param handle the PH handle 226 * @return The current voltage of the 5v supply in volts. 227 * @see "HAL_GetREVPH5VVoltage" 228 */ 229 public static native double get5VVoltage(int handle); 230 231 /** 232 * Returns the total current drawn by all solenoids. 233 * 234 * @param handle the PH handle 235 * @return Total current drawn by all solenoids in amps. 236 * @see "HAL_GetREVPHSolenoidCurrent" 237 */ 238 public static native double getSolenoidCurrent(int handle); 239 240 /** 241 * Returns the current voltage of the solenoid power supply. 242 * 243 * @param handle the PH handle 244 * @return The current voltage of the solenoid power supply in volts. 245 * @see "HAL_GetREVPHSolenoidVoltage" 246 */ 247 public static native double getSolenoidVoltage(int handle); 248 249 /** 250 * Returns the sticky faults currently active on this device. 251 * 252 * @param handle the PH handle 253 * @return The sticky faults. 254 * @see "HAL_GetREVPHStickyFaults" 255 */ 256 public static native int getStickyFaultsNative(int handle); 257 258 /** 259 * Returns the sticky faults currently active on this device. 260 * 261 * @param handle the PH handle 262 * @return The sticky faults. 263 * @see "HAL_GetREVPHStickyFaults" 264 */ 265 public static REVPHStickyFaults getStickyFaults(int handle) { 266 return new REVPHStickyFaults(getStickyFaultsNative(handle)); 267 } 268 269 /** 270 * Returns the faults currently active on the PH. 271 * 272 * @param handle the PH handle 273 * @return The faults. 274 * @see "HAL_GetREVPHFaults" 275 */ 276 public static native int getFaultsNative(int handle); 277 278 /** 279 * Returns the faults currently active on the PH. 280 * 281 * @param handle the PH handle 282 * @return The faults. 283 * @see "HAL_GetREVPHFaults" 284 */ 285 public static REVPHFaults getFaults(int handle) { 286 return new REVPHFaults(getFaultsNative(handle)); 287 } 288 289 /** 290 * Get a bitmask of disabled solenoids. 291 * 292 * @param handle the PH handle 293 * @return Bitmask indicating disabled solenoids. The LSB represents solenoid 0. 294 * @see "HAL_GetREVPHSolenoidDisabledList" 295 */ 296 public static native int getSolenoidDisabledList(int handle); 297 298 /** 299 * Returns the hardware and firmware versions of the PH. 300 * 301 * @param handle the PH handle 302 * @return The hardware and firmware versions. 303 * @see "HAL_GetREVPHVersion" 304 */ 305 public static native REVPHVersion getVersion(int handle); 306 307 /** Utility class. */ 308 private REVPHJNI() {} 309}