RobotCore 1.0
WPILib port to raspberry Pi
Loading...
Searching...
No Matches
RobotController.java
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5package org.wpilib.system;
6
7import static org.wpilib.units.Units.Amps;
8import static org.wpilib.units.Units.Celsius;
9import static org.wpilib.units.Units.Nanoseconds;
10import static org.wpilib.units.Units.Volts;
11
12import java.util.function.LongSupplier;
13import org.wpilib.hardware.bus.CANPort;
14import org.wpilib.hardware.hal.HAL;
15import org.wpilib.hardware.hal.HALUtil;
16import org.wpilib.hardware.hal.PowerJNI;
17import org.wpilib.hardware.hal.can.CANJNI;
18import org.wpilib.hardware.hal.can.CANStatus;
19import org.wpilib.units.measure.Current;
20import org.wpilib.units.measure.Temperature;
21import org.wpilib.units.measure.Time;
22import org.wpilib.units.measure.Voltage;
23
25public final class RobotController {
26 private static LongSupplier m_timeSource = RobotController::getMonotonicTime;
27
28 private RobotController() {
29 throw new UnsupportedOperationException("This is a utility class!");
30 }
31
37 public static String getSerialNumber() {
38 return HALUtil.getSerialNumber();
39 }
40
49 public static String getComments() {
50 return HALUtil.getComments();
51 }
52
58 public static int getTeamNumber() {
59 return HALUtil.getTeamNumber();
60 }
61
68 public static void setTimeSource(LongSupplier supplier) {
69 m_timeSource = supplier;
70 }
71
79 public static long getTime() {
80 return m_timeSource.getAsLong();
81 }
82
90 public static Time getMeasureTime() {
91 return Nanoseconds.of(m_timeSource.getAsLong());
92 }
93
99 public static long getMonotonicTime() {
100 return HALUtil.getMonotonicTime();
101 }
102
108 public static Time getMeasureMonotonicTime() {
109 return Nanoseconds.of(HALUtil.getMonotonicTime());
110 }
111
117 public static double getBatteryVoltage() {
118 return PowerJNI.getVinVoltage();
119 }
120
126 public static Voltage getMeasureBatteryVoltage() {
127 return Volts.of(PowerJNI.getVinVoltage());
128 }
129
136 public static boolean isSysActive() {
137 return HAL.getSystemActive();
138 }
139
145 public static boolean isBrownedOut() {
146 return HAL.getBrownedOut();
147 }
148
155 public static int getCommsDisableCount() {
156 return HAL.getCommsDisableCount();
157 }
158
164 public static boolean getRSLState() {
165 return HAL.getRSLState();
166 }
167
173 public static boolean isSystemTimeValid() {
174 return HAL.getSystemTimeValid();
175 }
176
182 public static double getInputVoltage() {
183 return PowerJNI.getVinVoltage();
184 }
185
191 public static Voltage getMeasureInputVoltage() {
192 return Volts.of(PowerJNI.getVinVoltage());
193 }
194
200 public static double getVoltage3V3() {
201 return PowerJNI.getUserVoltage3V3();
202 }
203
209 public static Voltage getMeasureVoltage3V3() {
210 return Volts.of(PowerJNI.getUserVoltage3V3());
211 }
212
218 public static double getCurrent3V3() {
219 return PowerJNI.getUserCurrent3V3();
220 }
221
227 public static Current getMeasureCurrent3V3() {
228 return Amps.of(PowerJNI.getUserCurrent3V3());
229 }
230
236 public static void setEnabled3V3(boolean enabled) {
237 PowerJNI.setUserEnabled3V3(enabled);
238 }
239
246 public static boolean getEnabled3V3() {
247 return PowerJNI.getUserActive3V3();
248 }
249
255 public static int getFaultCount3V3() {
256 return PowerJNI.getUserCurrentFaults3V3();
257 }
258
260 public static void resetRailFaultCounts() {
261 PowerJNI.resetUserCurrentFaults();
262 }
263
273 public static void setBrownoutVoltages(double brownoutVoltage, double recoveryVoltage) {
274 PowerJNI.setBrownoutVoltages(brownoutVoltage, recoveryVoltage);
275 }
276
286 public static void setBrownoutVoltages(Voltage brownoutVoltage, Voltage recoveryVoltage) {
287 PowerJNI.setBrownoutVoltages(
288 brownoutVoltage.baseUnitMagnitude(), recoveryVoltage.baseUnitMagnitude());
289 }
290
296 public static double getCPUTemp() {
297 return PowerJNI.getCPUTemp();
298 }
299
305 public static Temperature getMeasureCPUTemp() {
306 return Celsius.of(PowerJNI.getCPUTemp());
307 }
308
315 public static CANStatus getCANStatus(CANPort busId) {
316 CANStatus status = new CANStatus();
317 CANJNI.getCANStatus(busId.value, status);
318 return status;
319 }
320}
static void setEnabled3V3(boolean enabled)
static void setTimeSource(LongSupplier supplier)
static CANStatus getCANStatus(CANPort busId)
static void setBrownoutVoltages(double brownoutVoltage, double recoveryVoltage)
static void setBrownoutVoltages(Voltage brownoutVoltage, Voltage recoveryVoltage)