001/*----------------------------------------------------------------------------*/ 002/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */ 003/* Open Source Software - may be modified and shared by FRC teams. The code */ 004/* must be accompanied by the FIRST BSD license file in the root directory of */ 005/* the project. */ 006/*----------------------------------------------------------------------------*/ 007 008package edu.wpi.first.wpilibj; 009 010import edu.wpi.first.wpilibj.can.CANJNI; 011import edu.wpi.first.wpilibj.can.CANStatus; 012import edu.wpi.first.wpilibj.hal.HAL; 013import edu.wpi.first.wpilibj.hal.HALUtil; 014import edu.wpi.first.wpilibj.hal.PowerJNI; 015 016/** 017 * Contains functions for roboRIO functionality. 018 */ 019public final class RobotController { 020 private RobotController() { 021 } 022 023 /** 024 * Return the FPGA Version number. For now, expect this to be the current 025 * year. 026 * 027 * @return FPGA Version number. 028 */ 029 @SuppressWarnings("AbbreviationAsWordInName") 030 public static int getFPGAVersion() { 031 return HALUtil.getFPGAVersion(); 032 } 033 034 /** 035 * Return the FPGA Revision number. The format of the revision is 3 numbers. The 12 most 036 * significant bits are the Major Revision. the next 8 bits are the Minor Revision. The 12 least 037 * significant bits are the Build Number. 038 * 039 * @return FPGA Revision number. 040 */ 041 @SuppressWarnings("AbbreviationAsWordInName") 042 public static long getFPGARevision() { 043 return (long) HALUtil.getFPGARevision(); 044 } 045 046 /** 047 * Read the microsecond timer from the FPGA. 048 * 049 * @return The current time in microseconds according to the FPGA. 050 */ 051 public static long getFPGATime() { 052 return HALUtil.getFPGATime(); 053 } 054 055 /** 056 * Get the state of the "USER" button on the roboRIO. 057 * 058 * @return true if the button is currently pressed down 059 */ 060 public static boolean getUserButton() { 061 return HALUtil.getFPGAButton(); 062 } 063 064 /** 065 * Read the battery voltage. 066 * 067 * @return The battery voltage in Volts. 068 */ 069 public static double getBatteryVoltage() { 070 return PowerJNI.getVinVoltage(); 071 } 072 073 /** 074 * Gets a value indicating whether the FPGA outputs are enabled. The outputs may be disabled if 075 * the robot is disabled or e-stopped, the watchdog has expired, or if the roboRIO browns out. 076 * 077 * @return True if the FPGA outputs are enabled. 078 */ 079 public static boolean isSysActive() { 080 return HAL.getSystemActive(); 081 } 082 083 /** 084 * Check if the system is browned out. 085 * 086 * @return True if the system is browned out 087 */ 088 public static boolean isBrownedOut() { 089 return HAL.getBrownedOut(); 090 } 091 092 /** 093 * Get the input voltage to the robot controller. 094 * 095 * @return The controller input voltage value in Volts 096 */ 097 public static double getInputVoltage() { 098 return PowerJNI.getVinVoltage(); 099 } 100 101 /** 102 * Get the input current to the robot controller. 103 * 104 * @return The controller input current value in Amps 105 */ 106 public static double getInputCurrent() { 107 return PowerJNI.getVinCurrent(); 108 } 109 110 /** 111 * Get the voltage of the 3.3V rail. 112 * 113 * @return The controller 3.3V rail voltage value in Volts 114 */ 115 public static double getVoltage3V3() { 116 return PowerJNI.getUserVoltage3V3(); 117 } 118 119 /** 120 * Get the current output of the 3.3V rail. 121 * 122 * @return The controller 3.3V rail output current value in Volts 123 */ 124 public static double getCurrent3V3() { 125 return PowerJNI.getUserCurrent3V3(); 126 } 127 128 /** 129 * Get the enabled state of the 3.3V rail. The rail may be disabled due to a controller brownout, 130 * a short circuit on the rail, or controller over-voltage. 131 * 132 * @return The controller 3.3V rail enabled value 133 */ 134 public static boolean getEnabled3V3() { 135 return PowerJNI.getUserActive3V3(); 136 } 137 138 /** 139 * Get the count of the total current faults on the 3.3V rail since the controller has booted. 140 * 141 * @return The number of faults 142 */ 143 public static int getFaultCount3V3() { 144 return PowerJNI.getUserCurrentFaults3V3(); 145 } 146 147 /** 148 * Get the voltage of the 5V rail. 149 * 150 * @return The controller 5V rail voltage value in Volts 151 */ 152 public static double getVoltage5V() { 153 return PowerJNI.getUserVoltage5V(); 154 } 155 156 /** 157 * Get the current output of the 5V rail. 158 * 159 * @return The controller 5V rail output current value in Amps 160 */ 161 public static double getCurrent5V() { 162 return PowerJNI.getUserCurrent5V(); 163 } 164 165 /** 166 * Get the enabled state of the 5V rail. The rail may be disabled due to a controller brownout, a 167 * short circuit on the rail, or controller over-voltage. 168 * 169 * @return The controller 5V rail enabled value 170 */ 171 public static boolean getEnabled5V() { 172 return PowerJNI.getUserActive5V(); 173 } 174 175 /** 176 * Get the count of the total current faults on the 5V rail since the controller has booted. 177 * 178 * @return The number of faults 179 */ 180 public static int getFaultCount5V() { 181 return PowerJNI.getUserCurrentFaults5V(); 182 } 183 184 /** 185 * Get the voltage of the 6V rail. 186 * 187 * @return The controller 6V rail voltage value in Volts 188 */ 189 public static double getVoltage6V() { 190 return PowerJNI.getUserVoltage6V(); 191 } 192 193 /** 194 * Get the current output of the 6V rail. 195 * 196 * @return The controller 6V rail output current value in Amps 197 */ 198 public static double getCurrent6V() { 199 return PowerJNI.getUserCurrent6V(); 200 } 201 202 /** 203 * Get the enabled state of the 6V rail. The rail may be disabled due to a controller brownout, a 204 * short circuit on the rail, or controller over-voltage. 205 * 206 * @return The controller 6V rail enabled value 207 */ 208 public static boolean getEnabled6V() { 209 return PowerJNI.getUserActive6V(); 210 } 211 212 /** 213 * Get the count of the total current faults on the 6V rail since the controller has booted. 214 * 215 * @return The number of faults 216 */ 217 public static int getFaultCount6V() { 218 return PowerJNI.getUserCurrentFaults6V(); 219 } 220 221 /** 222 * Get the current status of the CAN bus. 223 * 224 * @return The status of the CAN bus 225 */ 226 public static CANStatus getCANStatus() { 227 CANStatus status = new CANStatus(); 228 CANJNI.GetCANStatus(status); 229 return status; 230 } 231}