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 (long) 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 * Read the microsecond timer from the FPGA. 062 * 063 * @return The current time in microseconds according to the FPGA. 064 */ 065 public static long getFPGATime() { 066 return HALUtil.getFPGATime(); 067 } 068 069 /** 070 * Get the state of the "USER" button on the roboRIO. 071 * 072 * @return true if the button is currently pressed down 073 */ 074 public static boolean getUserButton() { 075 return HALUtil.getFPGAButton(); 076 } 077 078 /** 079 * Read the battery voltage. 080 * 081 * @return The battery voltage in Volts. 082 */ 083 public static double getBatteryVoltage() { 084 return PowerJNI.getVinVoltage(); 085 } 086 087 /** 088 * Gets a value indicating whether the FPGA outputs are enabled. The outputs may be disabled if 089 * the robot is disabled or e-stopped, the watchdog has expired, or if the roboRIO browns out. 090 * 091 * @return True if the FPGA outputs are enabled. 092 */ 093 public static boolean isSysActive() { 094 return HAL.getSystemActive(); 095 } 096 097 /** 098 * Check if the system is browned out. 099 * 100 * @return True if the system is browned out 101 */ 102 public static boolean isBrownedOut() { 103 return HAL.getBrownedOut(); 104 } 105 106 /** 107 * Gets the current state of the Robot Signal Light (RSL). 108 * 109 * @return The current state of the RSL- true if on, false if off 110 */ 111 public static boolean getRSLState() { 112 return HAL.getRSLState(); 113 } 114 115 /** 116 * Get the input voltage to the robot controller. 117 * 118 * @return The controller input voltage value in Volts 119 */ 120 public static double getInputVoltage() { 121 return PowerJNI.getVinVoltage(); 122 } 123 124 /** 125 * Get the input current to the robot controller. 126 * 127 * @return The controller input current value in Amps 128 */ 129 public static double getInputCurrent() { 130 return PowerJNI.getVinCurrent(); 131 } 132 133 /** 134 * Get the voltage of the 3.3V rail. 135 * 136 * @return The controller 3.3V rail voltage value in Volts 137 */ 138 public static double getVoltage3V3() { 139 return PowerJNI.getUserVoltage3V3(); 140 } 141 142 /** 143 * Get the current output of the 3.3V rail. 144 * 145 * @return The controller 3.3V rail output current value in Amps 146 */ 147 public static double getCurrent3V3() { 148 return PowerJNI.getUserCurrent3V3(); 149 } 150 151 /** 152 * Get the enabled state of the 3.3V rail. The rail may be disabled due to a controller brownout, 153 * a short circuit on the rail, or controller over-voltage. 154 * 155 * @return The controller 3.3V rail enabled value 156 */ 157 public static boolean getEnabled3V3() { 158 return PowerJNI.getUserActive3V3(); 159 } 160 161 /** 162 * Get the count of the total current faults on the 3.3V rail since the controller has booted. 163 * 164 * @return The number of faults 165 */ 166 public static int getFaultCount3V3() { 167 return PowerJNI.getUserCurrentFaults3V3(); 168 } 169 170 /** 171 * Get the voltage of the 5V rail. 172 * 173 * @return The controller 5V rail voltage value in Volts 174 */ 175 public static double getVoltage5V() { 176 return PowerJNI.getUserVoltage5V(); 177 } 178 179 /** 180 * Get the current output of the 5V rail. 181 * 182 * @return The controller 5V rail output current value in Amps 183 */ 184 public static double getCurrent5V() { 185 return PowerJNI.getUserCurrent5V(); 186 } 187 188 /** 189 * Get the enabled state of the 5V rail. The rail may be disabled due to a controller brownout, a 190 * short circuit on the rail, or controller over-voltage. 191 * 192 * @return The controller 5V rail enabled value 193 */ 194 public static boolean getEnabled5V() { 195 return PowerJNI.getUserActive5V(); 196 } 197 198 /** 199 * Get the count of the total current faults on the 5V rail since the controller has booted. 200 * 201 * @return The number of faults 202 */ 203 public static int getFaultCount5V() { 204 return PowerJNI.getUserCurrentFaults5V(); 205 } 206 207 /** 208 * Get the voltage of the 6V rail. 209 * 210 * @return The controller 6V rail voltage value in Volts 211 */ 212 public static double getVoltage6V() { 213 return PowerJNI.getUserVoltage6V(); 214 } 215 216 /** 217 * Get the current output of the 6V rail. 218 * 219 * @return The controller 6V rail output current value in Amps 220 */ 221 public static double getCurrent6V() { 222 return PowerJNI.getUserCurrent6V(); 223 } 224 225 /** 226 * Get the enabled state of the 6V rail. The rail may be disabled due to a controller brownout, a 227 * short circuit on the rail, or controller over-voltage. 228 * 229 * @return The controller 6V rail enabled value 230 */ 231 public static boolean getEnabled6V() { 232 return PowerJNI.getUserActive6V(); 233 } 234 235 /** 236 * Get the count of the total current faults on the 6V rail since the controller has booted. 237 * 238 * @return The number of faults 239 */ 240 public static int getFaultCount6V() { 241 return PowerJNI.getUserCurrentFaults6V(); 242 } 243 244 /** 245 * Get the current brownout voltage setting. 246 * 247 * @return The brownout voltage 248 */ 249 public static double getBrownoutVoltage() { 250 return PowerJNI.getBrownoutVoltage(); 251 } 252 253 /** 254 * Set the voltage the roboRIO will brownout and disable all outputs. 255 * 256 * <p>Note that this only does anything on the roboRIO 2. On the roboRIO it is a no-op. 257 * 258 * @param brownoutVoltage The brownout voltage 259 */ 260 public static void setBrownoutVoltage(double brownoutVoltage) { 261 PowerJNI.setBrownoutVoltage(brownoutVoltage); 262 } 263 264 /** 265 * Get the current status of the CAN bus. 266 * 267 * @return The status of the CAN bus 268 */ 269 public static CANStatus getCANStatus() { 270 CANStatus status = new CANStatus(); 271 CANJNI.getCANStatus(status); 272 return status; 273 } 274}