diff --git a/wpilibc/src/main/native/cpp/AnalogPotentiometer.cpp b/wpilibc/src/main/native/cpp/AnalogPotentiometer.cpp index e7dc559c02..fe07b56925 100644 --- a/wpilibc/src/main/native/cpp/AnalogPotentiometer.cpp +++ b/wpilibc/src/main/native/cpp/AnalogPotentiometer.cpp @@ -7,7 +7,7 @@ #include "AnalogPotentiometer.h" -#include "ControllerPower.h" +#include "RobotController.h" #include "SmartDashboard/SendableBuilder.h" using namespace frc; @@ -67,7 +67,7 @@ AnalogPotentiometer::AnalogPotentiometer(std::shared_ptr input, * fullRange and offset). */ double AnalogPotentiometer::Get() const { - return (m_analog_input->GetVoltage() / ControllerPower::GetVoltage5V()) * + return (m_analog_input->GetVoltage() / RobotController::GetVoltage5V()) * m_fullRange + m_offset; } diff --git a/wpilibc/src/main/native/cpp/ControllerPower.cpp b/wpilibc/src/main/native/cpp/ControllerPower.cpp index 373f5e2815..37fb6a0439 100644 --- a/wpilibc/src/main/native/cpp/ControllerPower.cpp +++ b/wpilibc/src/main/native/cpp/ControllerPower.cpp @@ -20,6 +20,7 @@ using namespace frc; * Get the input voltage to the robot controller. * * @return The controller input voltage value in Volts + * @deprecated Use RobotController static class method */ double ControllerPower::GetInputVoltage() { int32_t status = 0; @@ -32,6 +33,7 @@ double ControllerPower::GetInputVoltage() { * Get the input current to the robot controller. * * @return The controller input current value in Amps + * @deprecated Use RobotController static class method */ double ControllerPower::GetInputCurrent() { int32_t status = 0; @@ -44,6 +46,7 @@ double ControllerPower::GetInputCurrent() { * Get the voltage of the 6V rail. * * @return The controller 6V rail voltage value in Volts + * @deprecated Use RobotController static class method */ double ControllerPower::GetVoltage6V() { int32_t status = 0; @@ -56,6 +59,7 @@ double ControllerPower::GetVoltage6V() { * Get the current output of the 6V rail. * * @return The controller 6V rail output current value in Amps + * @deprecated Use RobotController static class method */ double ControllerPower::GetCurrent6V() { int32_t status = 0; @@ -69,6 +73,7 @@ double ControllerPower::GetCurrent6V() { * controller brownout, a short circuit on the rail, or controller over-voltage. * * @return The controller 6V rail enabled value. True for enabled. + * @deprecated Use RobotController static class method */ bool ControllerPower::GetEnabled6V() { int32_t status = 0; @@ -82,6 +87,7 @@ bool ControllerPower::GetEnabled6V() { * has booted. * * @return The number of faults. + * @deprecated Use RobotController static class method */ int ControllerPower::GetFaultCount6V() { int32_t status = 0; @@ -94,6 +100,7 @@ int ControllerPower::GetFaultCount6V() { * Get the voltage of the 5V rail. * * @return The controller 5V rail voltage value in Volts + * @deprecated Use RobotController static class method */ double ControllerPower::GetVoltage5V() { int32_t status = 0; @@ -106,6 +113,7 @@ double ControllerPower::GetVoltage5V() { * Get the current output of the 5V rail. * * @return The controller 5V rail output current value in Amps + * @deprecated Use RobotController static class method */ double ControllerPower::GetCurrent5V() { int32_t status = 0; @@ -119,6 +127,7 @@ double ControllerPower::GetCurrent5V() { * controller brownout, a short circuit on the rail, or controller over-voltage. * * @return The controller 5V rail enabled value. True for enabled. + * @deprecated Use RobotController static class method */ bool ControllerPower::GetEnabled5V() { int32_t status = 0; @@ -132,6 +141,7 @@ bool ControllerPower::GetEnabled5V() { * has booted. * * @return The number of faults + * @deprecated Use RobotController static class method */ int ControllerPower::GetFaultCount5V() { int32_t status = 0; @@ -144,6 +154,7 @@ int ControllerPower::GetFaultCount5V() { * Get the voltage of the 3.3V rail. * * @return The controller 3.3V rail voltage value in Volts + * @deprecated Use RobotController static class method */ double ControllerPower::GetVoltage3V3() { int32_t status = 0; @@ -156,6 +167,7 @@ double ControllerPower::GetVoltage3V3() { * Get the current output of the 3.3V rail. * * @return The controller 3.3V rail output current value in Amps + * @deprecated Use RobotController static class method */ double ControllerPower::GetCurrent3V3() { int32_t status = 0; @@ -169,6 +181,7 @@ double ControllerPower::GetCurrent3V3() { * controller brownout, a short circuit on the rail, or controller over-voltage. * * @return The controller 3.3V rail enabled value. True for enabled. + * @deprecated Use RobotController static class method */ bool ControllerPower::GetEnabled3V3() { int32_t status = 0; @@ -182,6 +195,7 @@ bool ControllerPower::GetEnabled3V3() { * controller has booted. * * @return The number of faults + * @deprecated Use RobotController static class method */ int ControllerPower::GetFaultCount3V3() { int32_t status = 0; diff --git a/wpilibc/src/main/native/cpp/DriverStation.cpp b/wpilibc/src/main/native/cpp/DriverStation.cpp index 3c4db14f7d..9cd9d7d68a 100644 --- a/wpilibc/src/main/native/cpp/DriverStation.cpp +++ b/wpilibc/src/main/native/cpp/DriverStation.cpp @@ -466,6 +466,7 @@ bool DriverStation::IsFMSAttached() const { * watchdog has expired, or if the roboRIO browns out. * * @return True if the FPGA outputs are enabled. + * @deprecated Use RobotController static class method */ bool DriverStation::IsSysActive() const { int32_t status = 0; @@ -478,6 +479,7 @@ bool DriverStation::IsSysActive() const { * Check if the system is browned out. * * @return True if the system is browned out + * @deprecated Use RobotController static class method */ bool DriverStation::IsBrownedOut() const { int32_t status = 0; diff --git a/wpilibc/src/main/native/cpp/RobotController.cpp b/wpilibc/src/main/native/cpp/RobotController.cpp new file mode 100644 index 0000000000..81796552da --- /dev/null +++ b/wpilibc/src/main/native/cpp/RobotController.cpp @@ -0,0 +1,291 @@ +/*----------------------------------------------------------------------------*/ +/* 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. */ +/*----------------------------------------------------------------------------*/ + +#include "RobotController.h" + +#include + +#include "ErrorBase.h" + +namespace frc { + +/** + * Return the FPGA Version number. + * + * For now, expect this to be competition year. + * + * @return FPGA Version number. + */ +int RobotController::GetFPGAVersion() { + int32_t status = 0; + int version = HAL_GetFPGAVersion(&status); + wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); + return version; +} + +/** + * 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. + */ +int64_t RobotController::GetFPGARevision() { + int32_t status = 0; + int64_t revision = HAL_GetFPGARevision(&status); + wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); + return revision; +} + +/** + * Read the microsecond-resolution timer on the FPGA. + * + * @return The current time in microseconds according to the FPGA (since FPGA + * reset). + */ +uint64_t RobotController::GetFPGATime() { + int32_t status = 0; + uint64_t time = HAL_GetFPGATime(&status); + wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); + return time; +} + +/** + * Get the state of the "USER" button on the roboRIO. + * + * @return True if the button is currently pressed down + */ +bool RobotController::GetUserButton() { + int32_t status = 0; + + bool value = HAL_GetFPGAButton(&status); + wpi_setGlobalError(status); + + return value; +} + +/** + * Check if 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. + */ +bool RobotController::IsSysActive() { + int32_t status = 0; + bool retVal = HAL_GetSystemActive(&status); + wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); + return retVal; +} + +/** + * Check if the system is browned out. + * + * @return True if the system is browned out + */ +bool RobotController::IsBrownedOut() { + int32_t status = 0; + bool retVal = HAL_GetBrownedOut(&status); + wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); + return retVal; +} + +/** + * Get the input voltage to the robot controller. + * + * @return The controller input voltage value in Volts + */ +double RobotController::GetInputVoltage() { + int32_t status = 0; + double retVal = HAL_GetVinVoltage(&status); + wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); + return retVal; +} + +/** + * Get the input current to the robot controller. + * + * @return The controller input current value in Amps + */ +double RobotController::GetInputCurrent() { + int32_t status = 0; + double retVal = HAL_GetVinCurrent(&status); + wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); + return retVal; +} + +/** + * Get the voltage of the 6V rail. + * + * @return The controller 6V rail voltage value in Volts + */ +double RobotController::GetVoltage6V() { + int32_t status = 0; + double retVal = HAL_GetUserVoltage6V(&status); + wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); + return retVal; +} + +/** + * Get the current output of the 6V rail. + * + * @return The controller 6V rail output current value in Amps + */ +double RobotController::GetCurrent6V() { + int32_t status = 0; + double retVal = HAL_GetUserCurrent6V(&status); + wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); + return retVal; +} + +/** + * 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. True for enabled. + */ +bool RobotController::GetEnabled6V() { + int32_t status = 0; + bool retVal = HAL_GetUserActive6V(&status); + wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); + return retVal; +} + +/** + * Get the count of the total current faults on the 6V rail since the controller + * has booted. + * + * @return The number of faults. + */ +int RobotController::GetFaultCount6V() { + int32_t status = 0; + int retVal = HAL_GetUserCurrentFaults6V(&status); + wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); + return retVal; +} + +/** + * Get the voltage of the 5V rail. + * + * @return The controller 5V rail voltage value in Volts + */ +double RobotController::GetVoltage5V() { + int32_t status = 0; + double retVal = HAL_GetUserVoltage5V(&status); + wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); + return retVal; +} + +/** + * Get the current output of the 5V rail. + * + * @return The controller 5V rail output current value in Amps + */ +double RobotController::GetCurrent5V() { + int32_t status = 0; + double retVal = HAL_GetUserCurrent5V(&status); + wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); + return retVal; +} + +/** + * 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. True for enabled. + */ +bool RobotController::GetEnabled5V() { + int32_t status = 0; + bool retVal = HAL_GetUserActive5V(&status); + wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); + return retVal; +} + +/** + * Get the count of the total current faults on the 5V rail since the controller + * has booted. + * + * @return The number of faults + */ +int RobotController::GetFaultCount5V() { + int32_t status = 0; + int retVal = HAL_GetUserCurrentFaults5V(&status); + wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); + return retVal; +} + +/** + * Get the voltage of the 3.3V rail. + * + * @return The controller 3.3V rail voltage value in Volts + */ +double RobotController::GetVoltage3V3() { + int32_t status = 0; + double retVal = HAL_GetUserVoltage3V3(&status); + wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); + return retVal; +} + +/** + * Get the current output of the 3.3V rail. + * + * @return The controller 3.3V rail output current value in Amps + */ +double RobotController::GetCurrent3V3() { + int32_t status = 0; + double retVal = HAL_GetUserCurrent3V3(&status); + wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); + return retVal; +} + +/** + * 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. True for enabled. + */ +bool RobotController::GetEnabled3V3() { + int32_t status = 0; + bool retVal = HAL_GetUserActive3V3(&status); + wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); + return retVal; +} + +/** + * Get the count of the total current faults on the 3.3V rail since the + * controller has booted. + * + * @return The number of faults + */ +int RobotController::GetFaultCount3V3() { + int32_t status = 0; + int retVal = HAL_GetUserCurrentFaults3V3(&status); + wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); + return retVal; +} + +CANStatus RobotController::GetCANStatus() { + int32_t status = 0; + float percentBusUtilization = 0; + uint32_t busOffCount = 0; + uint32_t txFullCount = 0; + uint32_t receiveErrorCount = 0; + uint32_t transmitErrorCount = 0; + HAL_CAN_GetCANStatus(&percentBusUtilization, &busOffCount, &txFullCount, + &receiveErrorCount, &transmitErrorCount, &status); + if (status != 0) { + wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); + return {}; + } + return {percentBusUtilization, static_cast(busOffCount), + static_cast(txFullCount), static_cast(receiveErrorCount), + static_cast(transmitErrorCount)}; +} +} // namespace frc diff --git a/wpilibc/src/main/native/cpp/Timer.cpp b/wpilibc/src/main/native/cpp/Timer.cpp index e216d55283..818111a268 100644 --- a/wpilibc/src/main/native/cpp/Timer.cpp +++ b/wpilibc/src/main/native/cpp/Timer.cpp @@ -13,7 +13,7 @@ #include #include "DriverStation.h" -#include "Utility.h" +#include "RobotController.h" namespace frc { @@ -168,8 +168,7 @@ bool Timer::HasPeriodPassed(double period) { */ double Timer::GetFPGATimestamp() { // FPGA returns the timestamp in microseconds - // Call the helper GetFPGATime() in Utility.cpp - return GetFPGATime() * 1.0e-6; + return RobotController::GetFPGATime() * 1.0e-6; } /** diff --git a/wpilibc/src/main/native/cpp/Utility.cpp b/wpilibc/src/main/native/cpp/Utility.cpp index 02c82bbc5d..bd666ac6a3 100644 --- a/wpilibc/src/main/native/cpp/Utility.cpp +++ b/wpilibc/src/main/native/cpp/Utility.cpp @@ -145,6 +145,7 @@ namespace frc { * For now, expect this to be competition year. * * @return FPGA Version number. + * @deprecated Use RobotController static class method */ int GetFPGAVersion() { int32_t status = 0; @@ -161,6 +162,7 @@ int GetFPGAVersion() { * significant bits are the Build Number. * * @return FPGA Revision number. + * @deprecated Use RobotController static class method */ int64_t GetFPGARevision() { int32_t status = 0; @@ -174,6 +176,7 @@ int64_t GetFPGARevision() { * * @return The current time in microseconds according to the FPGA (since FPGA * reset). + * @deprecated Use RobotController static class method */ uint64_t GetFPGATime() { int32_t status = 0; @@ -186,6 +189,7 @@ uint64_t GetFPGATime() { * Get the state of the "USER" button on the roboRIO. * * @return True if the button is currently pressed down + * @deprecated Use RobotController static class method */ bool GetUserButton() { int32_t status = 0; diff --git a/wpilibc/src/main/native/include/ControllerPower.h b/wpilibc/src/main/native/include/ControllerPower.h index 663dee6796..4271249ec0 100644 --- a/wpilibc/src/main/native/include/ControllerPower.h +++ b/wpilibc/src/main/native/include/ControllerPower.h @@ -7,23 +7,39 @@ #pragma once +#include + namespace frc { class ControllerPower { public: + WPI_DEPRECATED("Use RobotController static class method") static double GetInputVoltage(); + WPI_DEPRECATED("Use RobotController static class method") static double GetInputCurrent(); + WPI_DEPRECATED("Use RobotController static class method") static double GetVoltage3V3(); + WPI_DEPRECATED("Use RobotController static class method") static double GetCurrent3V3(); + WPI_DEPRECATED("Use RobotController static class method") static bool GetEnabled3V3(); + WPI_DEPRECATED("Use RobotController static class method") static int GetFaultCount3V3(); + WPI_DEPRECATED("Use RobotController static class method") static double GetVoltage5V(); + WPI_DEPRECATED("Use RobotController static class method") static double GetCurrent5V(); + WPI_DEPRECATED("Use RobotController static class method") static bool GetEnabled5V(); + WPI_DEPRECATED("Use RobotController static class method") static int GetFaultCount5V(); + WPI_DEPRECATED("Use RobotController static class method") static double GetVoltage6V(); + WPI_DEPRECATED("Use RobotController static class method") static double GetCurrent6V(); + WPI_DEPRECATED("Use RobotController static class method") static bool GetEnabled6V(); + WPI_DEPRECATED("Use RobotController static class method") static int GetFaultCount6V(); }; diff --git a/wpilibc/src/main/native/include/DriverStation.h b/wpilibc/src/main/native/include/DriverStation.h index a585ff0839..8a15158118 100644 --- a/wpilibc/src/main/native/include/DriverStation.h +++ b/wpilibc/src/main/native/include/DriverStation.h @@ -15,6 +15,7 @@ #include #include +#include #include #include "ErrorBase.h" @@ -68,7 +69,9 @@ class DriverStation : public ErrorBase, public RobotStateInterface { bool IsDSAttached() const; bool IsNewControlData() const; bool IsFMSAttached() const; + WPI_DEPRECATED("Use RobotController static class method") bool IsSysActive() const; + WPI_DEPRECATED("Use RobotController static class method") bool IsBrownedOut() const; std::string GetGameSpecificMessage() const; diff --git a/wpilibc/src/main/native/include/RobotController.h b/wpilibc/src/main/native/include/RobotController.h new file mode 100644 index 0000000000..e14a1c1bfd --- /dev/null +++ b/wpilibc/src/main/native/include/RobotController.h @@ -0,0 +1,47 @@ +/*----------------------------------------------------------------------------*/ +/* 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. */ +/*----------------------------------------------------------------------------*/ + +#pragma once + +#include + +namespace frc { + +struct CANStatus { + float percentBusUtilization; + int busOffCount; + int txFullCount; + int receiveErrorCount; + int transmitErrorCount; +}; + +class RobotController { + public: + RobotController() = delete; + static int GetFPGAVersion(); + static int64_t GetFPGARevision(); + static uint64_t GetFPGATime(); + static bool GetUserButton(); + static bool IsSysActive(); + static bool IsBrownedOut(); + static double GetInputVoltage(); + static double GetInputCurrent(); + static double GetVoltage3V3(); + static double GetCurrent3V3(); + static bool GetEnabled3V3(); + static int GetFaultCount3V3(); + static double GetVoltage5V(); + static double GetCurrent5V(); + static bool GetEnabled5V(); + static int GetFaultCount5V(); + static double GetVoltage6V(); + static double GetCurrent6V(); + static bool GetEnabled6V(); + static int GetFaultCount6V(); + static CANStatus GetCANStatus(); +}; +} // namespace frc diff --git a/wpilibc/src/main/native/include/Utility.h b/wpilibc/src/main/native/include/Utility.h index 4ffe7ef15c..48362571a2 100644 --- a/wpilibc/src/main/native/include/Utility.h +++ b/wpilibc/src/main/native/include/Utility.h @@ -17,6 +17,7 @@ #include #include +#include #define wpi_assert(condition) \ wpi_assert_impl(condition, #condition, "", __FILE__, __LINE__, __FUNCTION__) @@ -54,9 +55,13 @@ void wpi_suspendOnAssertEnabled(bool enabled); namespace frc { +WPI_DEPRECATED("Use RobotController static class method") int GetFPGAVersion(); +WPI_DEPRECATED("Use RobotController static class method") int64_t GetFPGARevision(); +WPI_DEPRECATED("Use RobotController static class method") uint64_t GetFPGATime(); +WPI_DEPRECATED("Use RobotController static class method") bool GetUserButton(); std::string GetStackTrace(int offset); diff --git a/wpilibc/src/main/native/include/WPILib.h b/wpilibc/src/main/native/include/WPILib.h index 6039e0f654..2b9e6698a9 100644 --- a/wpilibc/src/main/native/include/WPILib.h +++ b/wpilibc/src/main/native/include/WPILib.h @@ -67,6 +67,7 @@ #include "Preferences.h" #include "Relay.h" #include "RobotBase.h" +#include "RobotController.h" #include "RobotDrive.h" #include "SD540.h" #include "SPI.h" diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogPotentiometer.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogPotentiometer.java index 161225d6d9..c7b7aea3a8 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogPotentiometer.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogPotentiometer.java @@ -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 diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ControllerPower.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ControllerPower.java index d3aa7d19ff..d3b7f1cb17 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ControllerPower.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ControllerPower.java @@ -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(); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java index b966c35f62..0a740ecd09 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java @@ -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(); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Notifier.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Notifier.java index bc6e73d53f..d913133239 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Notifier.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Notifier.java @@ -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(); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotController.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotController.java new file mode 100644 index 0000000000..71a54ad970 --- /dev/null +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotController.java @@ -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; + } +} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Utility.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Utility.java index 2004b8eea0..0a9e44c5f1 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Utility.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Utility.java @@ -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(); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/internal/HardwareTimer.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/internal/HardwareTimer.java index 22188425a6..425fdf63dc 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/internal/HardwareTimer.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/internal/HardwareTimer.java @@ -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; } /** diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AbstractInterruptTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AbstractInterruptTest.java index 36450017a7..dce6fe3721 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AbstractInterruptTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AbstractInterruptTest.java @@ -99,7 +99,7 @@ public abstract class AbstractInterruptTest extends AbstractComsSetup { @Override public void interruptFired(int interruptAssertedMask, InterruptCounter param) { - m_interruptFireTime.set(Utility.getFPGATime()); + m_interruptFireTime.set(RobotController.getFPGATime()); m_counter.increment(); try { // This won't cause the test to fail @@ -132,7 +132,7 @@ public abstract class AbstractInterruptTest extends AbstractComsSetup { Timer.delay(0.01); // Note: Utility.getFPGATime() is used because double values can turn over // after the robot has been running for a long time - final long interruptTriggerTime = Utility.getFPGATime(); + final long interruptTriggerTime = RobotController.getFPGATime(); setInterruptHigh(); // Delay until the interrupt is complete @@ -205,11 +205,11 @@ public abstract class AbstractInterruptTest extends AbstractComsSetup { // Note: the long time value is used because doubles can flip if the robot // is left running for long enough - final long startTimeStamp = Utility.getFPGATime(); + final long startTimeStamp = RobotController.getFPGATime(); new Thread(runnable).start(); // Delay for twice as long as the timeout so the test should fail first getInterruptable().waitForInterrupt(synchronousTimeout * 2); - final long stopTimeStamp = Utility.getFPGATime(); + final long stopTimeStamp = RobotController.getFPGATime(); // Then // The test will not have timed out and: diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/DriverStationTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/DriverStationTest.java index b4814268e4..d181772d1b 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/DriverStationTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/DriverStationTest.java @@ -28,13 +28,13 @@ public class DriverStationTest extends AbstractComsSetup { @Test public void waitForDataTest() { - long startTime = Utility.getFPGATime(); + long startTime = RobotController.getFPGATime(); // Wait for data 50 times for (int i = 0; i < 50; i++) { DriverStation.getInstance().waitForData(); } - long endTime = Utility.getFPGATime(); + long endTime = RobotController.getFPGATime(); long difference = endTime - startTime; assertEquals("DriverStation waitForData did not wait long enough", TIMER_RUNTIME, difference, diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/TimerTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/TimerTest.java index 507461287f..78d2a4c349 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/TimerTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/TimerTest.java @@ -29,11 +29,11 @@ public class TimerTest extends AbstractComsSetup { @Test public void delayTest() { // Given - long startTime = Utility.getFPGATime(); + long startTime = RobotController.getFPGATime(); // When Timer.delay(TIMER_RUNTIME / 1000000); - long endTime = Utility.getFPGATime(); + long endTime = RobotController.getFPGATime(); long difference = endTime - startTime; // Then