Adds RobotController class (#828)

Unifies random functionality from other classes
Deprecates all old functions.
This commit is contained in:
Thad House
2017-12-10 21:52:49 -08:00
committed by Peter Johnson
parent 88a6b4ac38
commit 8b7aa61091
21 changed files with 668 additions and 19 deletions

View File

@@ -121,7 +121,7 @@ public class AnalogPotentiometer extends SensorBase implements Potentiometer, Se
if (m_analogInput == null) {
return m_offset;
}
return (m_analogInput.getVoltage() / ControllerPower.getVoltage5V()) * m_fullRange + m_offset;
return (m_analogInput.getVoltage() / RobotController.getVoltage5V()) * m_fullRange + m_offset;
}
@Override

View File

@@ -9,12 +9,18 @@ package edu.wpi.first.wpilibj;
import edu.wpi.first.wpilibj.hal.PowerJNI;
/**
* Old Controller PR class.
* @deprecated Use RobotController class instead
*/
@Deprecated
public class ControllerPower {
/**
* Get the input voltage to the robot controller.
*
* @return The controller input voltage value in Volts
*/
@Deprecated
public static double getInputVoltage() {
return PowerJNI.getVinVoltage();
}
@@ -24,6 +30,7 @@ public class ControllerPower {
*
* @return The controller input current value in Amps
*/
@Deprecated
public static double getInputCurrent() {
return PowerJNI.getVinCurrent();
}
@@ -33,6 +40,7 @@ public class ControllerPower {
*
* @return The controller 3.3V rail voltage value in Volts
*/
@Deprecated
public static double getVoltage3V3() {
return PowerJNI.getUserVoltage3V3();
}
@@ -42,6 +50,7 @@ public class ControllerPower {
*
* @return The controller 3.3V rail output current value in Volts
*/
@Deprecated
public static double getCurrent3V3() {
return PowerJNI.getUserCurrent3V3();
}
@@ -52,6 +61,7 @@ public class ControllerPower {
*
* @return The controller 3.3V rail enabled value
*/
@Deprecated
public static boolean getEnabled3V3() {
return PowerJNI.getUserActive3V3();
}
@@ -61,6 +71,7 @@ public class ControllerPower {
*
* @return The number of faults
*/
@Deprecated
public static int getFaultCount3V3() {
return PowerJNI.getUserCurrentFaults3V3();
}
@@ -70,6 +81,7 @@ public class ControllerPower {
*
* @return The controller 5V rail voltage value in Volts
*/
@Deprecated
public static double getVoltage5V() {
return PowerJNI.getUserVoltage5V();
}
@@ -79,6 +91,7 @@ public class ControllerPower {
*
* @return The controller 5V rail output current value in Amps
*/
@Deprecated
public static double getCurrent5V() {
return PowerJNI.getUserCurrent5V();
}
@@ -89,6 +102,7 @@ public class ControllerPower {
*
* @return The controller 5V rail enabled value
*/
@Deprecated
public static boolean getEnabled5V() {
return PowerJNI.getUserActive5V();
}
@@ -98,6 +112,7 @@ public class ControllerPower {
*
* @return The number of faults
*/
@Deprecated
public static int getFaultCount5V() {
return PowerJNI.getUserCurrentFaults5V();
}
@@ -107,6 +122,7 @@ public class ControllerPower {
*
* @return The controller 6V rail voltage value in Volts
*/
@Deprecated
public static double getVoltage6V() {
return PowerJNI.getUserVoltage6V();
}
@@ -116,6 +132,7 @@ public class ControllerPower {
*
* @return The controller 6V rail output current value in Amps
*/
@Deprecated
public static double getCurrent6V() {
return PowerJNI.getUserCurrent6V();
}
@@ -126,6 +143,7 @@ public class ControllerPower {
*
* @return The controller 6V rail enabled value
*/
@Deprecated
public static boolean getEnabled6V() {
return PowerJNI.getUserActive6V();
}
@@ -135,6 +153,7 @@ public class ControllerPower {
*
* @return The number of faults
*/
@Deprecated
public static int getFaultCount6V() {
return PowerJNI.getUserCurrentFaults6V();
}

View File

@@ -642,7 +642,9 @@ public class DriverStation implements RobotState.Interface {
* 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.
* @deprecated Use RobotController.isSysActive()
*/
@Deprecated
public boolean isSysActive() {
return HAL.getSystemActive();
}
@@ -651,7 +653,9 @@ public class DriverStation implements RobotState.Interface {
* Check if the system is browned out.
*
* @return True if the system is browned out
* @deprecated Use RobotController.isBrownedOut()
*/
@Deprecated
public boolean isBrownedOut() {
return HAL.getBrownedOut();
}
@@ -812,7 +816,9 @@ public class DriverStation implements RobotState.Interface {
* Read the battery voltage.
*
* @return The battery voltage in Volts.
* @deprecated Use RobotController.getBatteryVoltage
*/
@Deprecated
public double getBatteryVoltage() {
return PowerJNI.getVinVoltage();
}

View File

@@ -128,7 +128,7 @@ public class Notifier {
try {
m_periodic = false;
m_period = delay;
m_expirationTime = Utility.getFPGATime() * 1e-6 + delay;
m_expirationTime = RobotController.getFPGATime() * 1e-6 + delay;
updateAlarm();
} finally {
m_processLock.unlock();
@@ -148,7 +148,7 @@ public class Notifier {
try {
m_periodic = true;
m_period = period;
m_expirationTime = Utility.getFPGATime() * 1e-6 + period;
m_expirationTime = RobotController.getFPGATime() * 1e-6 + period;
updateAlarm();
} finally {
m_processLock.unlock();

View File

@@ -0,0 +1,231 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017 FIRST. All Rights Reserved. */
/* 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;
import edu.wpi.first.wpilibj.can.CANJNI;
import edu.wpi.first.wpilibj.can.CANStatus;
import edu.wpi.first.wpilibj.hal.HAL;
import edu.wpi.first.wpilibj.hal.HALUtil;
import edu.wpi.first.wpilibj.hal.PowerJNI;
/**
* Contains functions for roboRIO functionality.
*/
public final class RobotController {
private RobotController() {
}
/**
* Return the FPGA Version number. For now, expect this to be the current
* year.
*
* @return FPGA Version number.
*/
@SuppressWarnings("AbbreviationAsWordInName")
int getFPGAVersion() {
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")
long getFPGARevision() {
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.
*/
public double getBatteryVoltage() {
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.
*/
public boolean isSysActive() {
return HAL.getSystemActive();
}
/**
* Check if the system is browned out.
*
* @return True if the system is browned out
*/
public boolean isBrownedOut() {
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;
}
}

View File

@@ -11,7 +11,9 @@ import edu.wpi.first.wpilibj.hal.HALUtil;
/**
* Contains global utility functions.
* @deprecated Use RobotController class instead
*/
@Deprecated
public final class Utility {
private Utility() {
@@ -21,8 +23,10 @@ public final class Utility {
* Return the FPGA Version number. For now, expect this to be 2009.
*
* @return FPGA Version number.
* @deprecated Use RobotController.getFPGAVersion()
*/
@SuppressWarnings("AbbreviationAsWordInName")
@Deprecated
int getFPGAVersion() {
return HALUtil.getFPGAVersion();
}
@@ -33,8 +37,10 @@ public final class Utility {
* significant bits are the Build Number.
*
* @return FPGA Revision number.
* @deprecated Use RobotController.getFPGARevision()
*/
@SuppressWarnings("AbbreviationAsWordInName")
@Deprecated
long getFPGARevision() {
return (long) HALUtil.getFPGARevision();
}
@@ -43,7 +49,10 @@ public final class Utility {
* Read the microsecond timer from the FPGA.
*
* @return The current time in microseconds according to the FPGA.
* @deprecated Use RobotController.getFPGATime()
*/
@Deprecated
@SuppressWarnings("AbbreviationAsWordInName")
public static long getFPGATime() {
return HALUtil.getFPGATime();
}
@@ -52,7 +61,9 @@ public final class Utility {
* Get the state of the "USER" button on the roboRIO.
*
* @return true if the button is currently pressed down
* @deprecated Use RobotController.getUserButton()
*/
@Deprecated
public static boolean getUserButton() {
return HALUtil.getFPGAButton();
}

View File

@@ -8,8 +8,8 @@
package edu.wpi.first.wpilibj.internal;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.RobotController;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Utility;
/**
* Timer objects measure accumulated time in milliseconds. The timer object functions like a
@@ -43,7 +43,7 @@ public class HardwareTimer implements Timer.StaticInterface {
*/
@Override
public double getFPGATimestamp() {
return Utility.getFPGATime() / 1000000.0;
return RobotController.getFPGATime() / 1000000.0;
}
@Override
@@ -70,7 +70,7 @@ public class HardwareTimer implements Timer.StaticInterface {
}
private double getMsClock() {
return Utility.getFPGATime() / 1000.0;
return RobotController.getFPGATime() / 1000.0;
}
/**