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 007import edu.wpi.first.hal.HAL; 008import edu.wpi.first.hal.HALUtil; 009import edu.wpi.first.hal.PowerJNI; 010import edu.wpi.first.hal.can.CANJNI; 011import edu.wpi.first.hal.can.CANStatus; 012 013/** Contains functions for roboRIO functionality. */ 014public final class RobotController { 015 private RobotController() { 016 throw new UnsupportedOperationException("This is a utility class!"); 017 } 018 019 /** 020 * Return the FPGA Version number. For now, expect this to be the current year. 021 * 022 * @return FPGA Version number. 023 */ 024 public static int getFPGAVersion() { 025 return HALUtil.getFPGAVersion(); 026 } 027 028 /** 029 * Return the FPGA Revision number. The format of the revision is 3 numbers. The 12 most 030 * significant bits are the Major Revision. the next 8 bits are the Minor Revision. The 12 least 031 * significant bits are the Build Number. 032 * 033 * @return FPGA Revision number. 034 */ 035 public static long getFPGARevision() { 036 return HALUtil.getFPGARevision(); 037 } 038 039 /** 040 * Return the serial number of the roboRIO. 041 * 042 * @return The serial number of the roboRIO. 043 */ 044 public static String getSerialNumber() { 045 return HALUtil.getSerialNumber(); 046 } 047 048 /** 049 * Return the comments from the roboRIO web interface. 050 * 051 * <p>The comments string is cached after the first call to this function on the RoboRIO - restart 052 * the robot code to reload the comments string after changing it in the web interface. 053 * 054 * @return the comments from the roboRIO web interface. 055 */ 056 public static String getComments() { 057 return HALUtil.getComments(); 058 } 059 060 /** 061 * Returns the team number configured for the robot controller. 062 * 063 * @return team number, or 0 if not found. 064 */ 065 public static int getTeamNumber() { 066 return HALUtil.getTeamNumber(); 067 } 068 069 /** 070 * Read the microsecond timer from the FPGA. 071 * 072 * @return The current time in microseconds according to the FPGA. 073 */ 074 public static long getFPGATime() { 075 return HALUtil.getFPGATime(); 076 } 077 078 /** 079 * Get the state of the "USER" button on the roboRIO. 080 * 081 * @return true if the button is currently pressed down 082 */ 083 public static boolean getUserButton() { 084 return HALUtil.getFPGAButton(); 085 } 086 087 /** 088 * Read the battery voltage. 089 * 090 * @return The battery voltage in Volts. 091 */ 092 public static double getBatteryVoltage() { 093 return PowerJNI.getVinVoltage(); 094 } 095 096 /** 097 * Gets a value indicating whether the FPGA outputs are enabled. The outputs may be disabled if 098 * the robot is disabled or e-stopped, the watchdog has expired, or if the roboRIO browns out. 099 * 100 * @return True if the FPGA outputs are enabled. 101 */ 102 public static boolean isSysActive() { 103 return HAL.getSystemActive(); 104 } 105 106 /** 107 * Check if the system is browned out. 108 * 109 * @return True if the system is browned out 110 */ 111 public static boolean isBrownedOut() { 112 return HAL.getBrownedOut(); 113 } 114 115 /** 116 * Gets the current state of the Robot Signal Light (RSL). 117 * 118 * @return The current state of the RSL- true if on, false if off 119 */ 120 public static boolean getRSLState() { 121 return HAL.getRSLState(); 122 } 123 124 /** 125 * Gets if the system time is valid. 126 * 127 * @return True if the system time is valid, false otherwise 128 */ 129 public static boolean isSystemTimeValid() { 130 return HAL.getSystemTimeValid(); 131 } 132 133 /** 134 * Get the input voltage to the robot controller. 135 * 136 * @return The controller input voltage value in Volts 137 */ 138 public static double getInputVoltage() { 139 return PowerJNI.getVinVoltage(); 140 } 141 142 /** 143 * Get the input current to the robot controller. 144 * 145 * @return The controller input current value in Amps 146 */ 147 public static double getInputCurrent() { 148 return PowerJNI.getVinCurrent(); 149 } 150 151 /** 152 * Get the voltage of the 3.3V rail. 153 * 154 * @return The controller 3.3V rail voltage value in Volts 155 */ 156 public static double getVoltage3V3() { 157 return PowerJNI.getUserVoltage3V3(); 158 } 159 160 /** 161 * Get the current output of the 3.3V rail. 162 * 163 * @return The controller 3.3V rail output current value in Amps 164 */ 165 public static double getCurrent3V3() { 166 return PowerJNI.getUserCurrent3V3(); 167 } 168 169 /** 170 * Enables or disables the 3.3V rail. 171 * 172 * @param enabled whether to enable the 3.3V rail. 173 */ 174 public static void setEnabled3V3(boolean enabled) { 175 PowerJNI.setUserEnabled3V3(enabled); 176 } 177 178 /** 179 * Get the enabled state of the 3.3V rail. The rail may be disabled due to a controller brownout, 180 * a short circuit on the rail, or controller over-voltage. 181 * 182 * @return The controller 3.3V rail enabled value 183 */ 184 public static boolean getEnabled3V3() { 185 return PowerJNI.getUserActive3V3(); 186 } 187 188 /** 189 * Get the count of the total current faults on the 3.3V rail since the controller has booted. 190 * 191 * @return The number of faults 192 */ 193 public static int getFaultCount3V3() { 194 return PowerJNI.getUserCurrentFaults3V3(); 195 } 196 197 /** 198 * Get the voltage of the 5V rail. 199 * 200 * @return The controller 5V rail voltage value in Volts 201 */ 202 public static double getVoltage5V() { 203 return PowerJNI.getUserVoltage5V(); 204 } 205 206 /** 207 * Get the current output of the 5V rail. 208 * 209 * @return The controller 5V rail output current value in Amps 210 */ 211 public static double getCurrent5V() { 212 return PowerJNI.getUserCurrent5V(); 213 } 214 215 /** 216 * Enables or disables the 5V rail. 217 * 218 * @param enabled whether to enable the 5V rail. 219 */ 220 public static void setEnabled5V(boolean enabled) { 221 PowerJNI.setUserEnabled5V(enabled); 222 } 223 224 /** 225 * Get the enabled state of the 5V rail. The rail may be disabled due to a controller brownout, a 226 * short circuit on the rail, or controller over-voltage. 227 * 228 * @return The controller 5V rail enabled value 229 */ 230 public static boolean getEnabled5V() { 231 return PowerJNI.getUserActive5V(); 232 } 233 234 /** 235 * Get the count of the total current faults on the 5V rail since the controller has booted. 236 * 237 * @return The number of faults 238 */ 239 public static int getFaultCount5V() { 240 return PowerJNI.getUserCurrentFaults5V(); 241 } 242 243 /** 244 * Get the voltage of the 6V rail. 245 * 246 * @return The controller 6V rail voltage value in Volts 247 */ 248 public static double getVoltage6V() { 249 return PowerJNI.getUserVoltage6V(); 250 } 251 252 /** 253 * Get the current output of the 6V rail. 254 * 255 * @return The controller 6V rail output current value in Amps 256 */ 257 public static double getCurrent6V() { 258 return PowerJNI.getUserCurrent6V(); 259 } 260 261 /** 262 * Enables or disables the 6V rail. 263 * 264 * @param enabled whether to enable the 6V rail. 265 */ 266 public static void setEnabled6V(boolean enabled) { 267 PowerJNI.setUserEnabled6V(enabled); 268 } 269 270 /** 271 * Get the enabled state of the 6V rail. The rail may be disabled due to a controller brownout, a 272 * short circuit on the rail, or controller over-voltage. 273 * 274 * @return The controller 6V rail enabled value 275 */ 276 public static boolean getEnabled6V() { 277 return PowerJNI.getUserActive6V(); 278 } 279 280 /** 281 * Get the count of the total current faults on the 6V rail since the controller has booted. 282 * 283 * @return The number of faults 284 */ 285 public static int getFaultCount6V() { 286 return PowerJNI.getUserCurrentFaults6V(); 287 } 288 289 /** 290 * Get the current brownout voltage setting. 291 * 292 * @return The brownout voltage 293 */ 294 public static double getBrownoutVoltage() { 295 return PowerJNI.getBrownoutVoltage(); 296 } 297 298 /** 299 * Set the voltage the roboRIO will brownout and disable all outputs. 300 * 301 * <p>Note that this only does anything on the roboRIO 2. On the roboRIO it is a no-op. 302 * 303 * @param brownoutVoltage The brownout voltage 304 */ 305 public static void setBrownoutVoltage(double brownoutVoltage) { 306 PowerJNI.setBrownoutVoltage(brownoutVoltage); 307 } 308 309 /** 310 * Get the current CPU temperature in degrees Celsius. 311 * 312 * @return current CPU temperature in degrees Celsius 313 */ 314 public static double getCPUTemp() { 315 return PowerJNI.getCPUTemp(); 316 } 317 318 /** 319 * Get the current status of the CAN bus. 320 * 321 * @return The status of the CAN bus 322 */ 323 public static CANStatus getCANStatus() { 324 CANStatus status = new CANStatus(); 325 CANJNI.getCANStatus(status); 326 return status; 327 } 328}