2017-12-10 21:52:49 -08:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2018-01-02 09:20:21 -08:00
|
|
|
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
|
2017-12-10 21:52:49 -08:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
package edu.wpi.first.wpilibj;
|
|
|
|
|
|
2018-09-20 21:59:46 -07:00
|
|
|
import edu.wpi.first.hal.HAL;
|
|
|
|
|
import edu.wpi.first.hal.HALUtil;
|
|
|
|
|
import edu.wpi.first.hal.PowerJNI;
|
|
|
|
|
import edu.wpi.first.hal.can.CANJNI;
|
|
|
|
|
import edu.wpi.first.hal.can.CANStatus;
|
2017-12-10 21:52:49 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Contains functions for roboRIO functionality.
|
|
|
|
|
*/
|
|
|
|
|
public final class RobotController {
|
|
|
|
|
private RobotController() {
|
2018-05-24 20:39:15 -04:00
|
|
|
throw new UnsupportedOperationException("This is a utility class!");
|
2017-12-10 21:52:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the FPGA Version number. For now, expect this to be the current
|
|
|
|
|
* year.
|
|
|
|
|
*
|
|
|
|
|
* @return FPGA Version number.
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("AbbreviationAsWordInName")
|
2017-12-25 18:26:05 -08:00
|
|
|
public static int getFPGAVersion() {
|
2017-12-10 21:52:49 -08:00
|
|
|
return HALUtil.getFPGAVersion();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the FPGA Revision number. The format of the revision is 3 numbers. The 12 most
|
|
|
|
|
* significant bits are the Major Revision. the next 8 bits are the Minor Revision. The 12 least
|
|
|
|
|
* significant bits are the Build Number.
|
|
|
|
|
*
|
|
|
|
|
* @return FPGA Revision number.
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("AbbreviationAsWordInName")
|
2017-12-25 18:26:05 -08:00
|
|
|
public static long getFPGARevision() {
|
2017-12-10 21:52:49 -08:00
|
|
|
return (long) HALUtil.getFPGARevision();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Read the microsecond timer from the FPGA.
|
|
|
|
|
*
|
|
|
|
|
* @return The current time in microseconds according to the FPGA.
|
|
|
|
|
*/
|
|
|
|
|
public static long getFPGATime() {
|
|
|
|
|
return HALUtil.getFPGATime();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the state of the "USER" button on the roboRIO.
|
|
|
|
|
*
|
|
|
|
|
* @return true if the button is currently pressed down
|
|
|
|
|
*/
|
|
|
|
|
public static boolean getUserButton() {
|
|
|
|
|
return HALUtil.getFPGAButton();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Read the battery voltage.
|
|
|
|
|
*
|
|
|
|
|
* @return The battery voltage in Volts.
|
|
|
|
|
*/
|
2018-01-04 23:12:13 -06:00
|
|
|
public static double getBatteryVoltage() {
|
2017-12-10 21:52:49 -08:00
|
|
|
return PowerJNI.getVinVoltage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets a value indicating whether the FPGA outputs are enabled. The outputs may be disabled if
|
|
|
|
|
* the robot is disabled or e-stopped, the watchdog has expired, or if the roboRIO browns out.
|
|
|
|
|
*
|
|
|
|
|
* @return True if the FPGA outputs are enabled.
|
|
|
|
|
*/
|
2017-12-11 11:48:54 -08:00
|
|
|
public static boolean isSysActive() {
|
2017-12-10 21:52:49 -08:00
|
|
|
return HAL.getSystemActive();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if the system is browned out.
|
|
|
|
|
*
|
|
|
|
|
* @return True if the system is browned out
|
|
|
|
|
*/
|
2017-12-11 11:48:54 -08:00
|
|
|
public static boolean isBrownedOut() {
|
2017-12-10 21:52:49 -08:00
|
|
|
return HAL.getBrownedOut();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the input voltage to the robot controller.
|
|
|
|
|
*
|
|
|
|
|
* @return The controller input voltage value in Volts
|
|
|
|
|
*/
|
|
|
|
|
public static double getInputVoltage() {
|
|
|
|
|
return PowerJNI.getVinVoltage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the input current to the robot controller.
|
|
|
|
|
*
|
|
|
|
|
* @return The controller input current value in Amps
|
|
|
|
|
*/
|
|
|
|
|
public static double getInputCurrent() {
|
|
|
|
|
return PowerJNI.getVinCurrent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the voltage of the 3.3V rail.
|
|
|
|
|
*
|
|
|
|
|
* @return The controller 3.3V rail voltage value in Volts
|
|
|
|
|
*/
|
|
|
|
|
public static double getVoltage3V3() {
|
|
|
|
|
return PowerJNI.getUserVoltage3V3();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the current output of the 3.3V rail.
|
|
|
|
|
*
|
|
|
|
|
* @return The controller 3.3V rail output current value in Volts
|
|
|
|
|
*/
|
|
|
|
|
public static double getCurrent3V3() {
|
|
|
|
|
return PowerJNI.getUserCurrent3V3();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the enabled state of the 3.3V rail. The rail may be disabled due to a controller brownout,
|
|
|
|
|
* a short circuit on the rail, or controller over-voltage.
|
|
|
|
|
*
|
|
|
|
|
* @return The controller 3.3V rail enabled value
|
|
|
|
|
*/
|
|
|
|
|
public static boolean getEnabled3V3() {
|
|
|
|
|
return PowerJNI.getUserActive3V3();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the count of the total current faults on the 3.3V rail since the controller has booted.
|
|
|
|
|
*
|
|
|
|
|
* @return The number of faults
|
|
|
|
|
*/
|
|
|
|
|
public static int getFaultCount3V3() {
|
|
|
|
|
return PowerJNI.getUserCurrentFaults3V3();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the voltage of the 5V rail.
|
|
|
|
|
*
|
|
|
|
|
* @return The controller 5V rail voltage value in Volts
|
|
|
|
|
*/
|
|
|
|
|
public static double getVoltage5V() {
|
|
|
|
|
return PowerJNI.getUserVoltage5V();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the current output of the 5V rail.
|
|
|
|
|
*
|
|
|
|
|
* @return The controller 5V rail output current value in Amps
|
|
|
|
|
*/
|
|
|
|
|
public static double getCurrent5V() {
|
|
|
|
|
return PowerJNI.getUserCurrent5V();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the enabled state of the 5V rail. The rail may be disabled due to a controller brownout, a
|
|
|
|
|
* short circuit on the rail, or controller over-voltage.
|
|
|
|
|
*
|
|
|
|
|
* @return The controller 5V rail enabled value
|
|
|
|
|
*/
|
|
|
|
|
public static boolean getEnabled5V() {
|
|
|
|
|
return PowerJNI.getUserActive5V();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the count of the total current faults on the 5V rail since the controller has booted.
|
|
|
|
|
*
|
|
|
|
|
* @return The number of faults
|
|
|
|
|
*/
|
|
|
|
|
public static int getFaultCount5V() {
|
|
|
|
|
return PowerJNI.getUserCurrentFaults5V();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the voltage of the 6V rail.
|
|
|
|
|
*
|
|
|
|
|
* @return The controller 6V rail voltage value in Volts
|
|
|
|
|
*/
|
|
|
|
|
public static double getVoltage6V() {
|
|
|
|
|
return PowerJNI.getUserVoltage6V();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the current output of the 6V rail.
|
|
|
|
|
*
|
|
|
|
|
* @return The controller 6V rail output current value in Amps
|
|
|
|
|
*/
|
|
|
|
|
public static double getCurrent6V() {
|
|
|
|
|
return PowerJNI.getUserCurrent6V();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the enabled state of the 6V rail. The rail may be disabled due to a controller brownout, a
|
|
|
|
|
* short circuit on the rail, or controller over-voltage.
|
|
|
|
|
*
|
|
|
|
|
* @return The controller 6V rail enabled value
|
|
|
|
|
*/
|
|
|
|
|
public static boolean getEnabled6V() {
|
|
|
|
|
return PowerJNI.getUserActive6V();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the count of the total current faults on the 6V rail since the controller has booted.
|
|
|
|
|
*
|
|
|
|
|
* @return The number of faults
|
|
|
|
|
*/
|
|
|
|
|
public static int getFaultCount6V() {
|
|
|
|
|
return PowerJNI.getUserCurrentFaults6V();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the current status of the CAN bus.
|
|
|
|
|
*
|
|
|
|
|
* @return The status of the CAN bus
|
|
|
|
|
*/
|
|
|
|
|
public static CANStatus getCANStatus() {
|
|
|
|
|
CANStatus status = new CANStatus();
|
|
|
|
|
CANJNI.GetCANStatus(status);
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
}
|