diff --git a/hal/src/main/java/edu/wpi/first/hal/PowerJNI.java b/hal/src/main/java/edu/wpi/first/hal/PowerJNI.java index a59058cb48..8dd9548cca 100644 --- a/hal/src/main/java/edu/wpi/first/hal/PowerJNI.java +++ b/hal/src/main/java/edu/wpi/first/hal/PowerJNI.java @@ -42,6 +42,13 @@ public class PowerJNI extends JNIWrapper { */ public static native double getUserCurrent6V(); + /** + * Enables or disables the 6V rail. + * + * @param enabled whether the rail should be enabled + */ + public static native void setUserEnabled6V(boolean enabled); + /** * Gets the active state of the 6V rail. * @@ -74,6 +81,13 @@ public class PowerJNI extends JNIWrapper { */ public static native double getUserCurrent5V(); + /** + * Enables or disables the 5V rail. + * + * @param enabled whether the rail should be enabled + */ + public static native void setUserEnabled5V(boolean enabled); + /** * Gets the active state of the 5V rail. * @@ -106,6 +120,13 @@ public class PowerJNI extends JNIWrapper { */ public static native double getUserCurrent3V3(); + /** + * Enables or disables the 3V3 rail. + * + * @param enabled whether the rail should be enabled + */ + public static native void setUserEnabled3V3(boolean enabled); + /** * Gets the active state of the 3V3 rail. * @@ -139,4 +160,11 @@ public class PowerJNI extends JNIWrapper { * @see "HAL_GetBrownoutVoltage" */ public static native double getBrownoutVoltage(); + + /** + * Get the current CPU temperature in degrees Celsius. + * + * @return current CPU temperature in degrees Celsius + */ + public static native double getCPUTemp(); } diff --git a/hal/src/main/native/athena/Power.cpp b/hal/src/main/native/athena/Power.cpp index e911d5d13b..249ab98e06 100644 --- a/hal/src/main/native/athena/Power.cpp +++ b/hal/src/main/native/athena/Power.cpp @@ -61,6 +61,11 @@ int32_t HAL_GetUserCurrentFaults6V(int32_t* status) { power->readFaultCounts_OverCurrentFaultCount6V(status)); } +void HAL_SetUserRailEnabled6V(HAL_Bool enabled, int32_t* status) { + initializePower(status); + power->writeDisable_User6V(!enabled, status); +} + double HAL_GetUserVoltage5V(int32_t* status) { initializePower(status); return power->readUserVoltage5V(status) / 4.096 * 0.005962 - 0.013; @@ -82,6 +87,11 @@ int32_t HAL_GetUserCurrentFaults5V(int32_t* status) { power->readFaultCounts_OverCurrentFaultCount5V(status)); } +void HAL_SetUserRailEnabled5V(HAL_Bool enabled, int32_t* status) { + initializePower(status); + power->writeDisable_User5V(!enabled, status); +} + double HAL_GetUserVoltage3V3(int32_t* status) { initializePower(status); return power->readUserVoltage3V3(status) / 4.096 * 0.004902 - 0.01; @@ -103,6 +113,11 @@ int32_t HAL_GetUserCurrentFaults3V3(int32_t* status) { power->readFaultCounts_OverCurrentFaultCount3V3(status)); } +void HAL_SetUserRailEnabled3V3(HAL_Bool enabled, int32_t* status) { + initializePower(status); + power->writeDisable_User3V3(!enabled, status); +} + void HAL_SetBrownoutVoltage(double voltage, int32_t* status) { initializePower(status); if (voltage < 0) { @@ -121,4 +136,9 @@ double HAL_GetBrownoutVoltage(int32_t* status) { return brownout / 4.0; } +double HAL_GetCPUTemp(int32_t* status) { + initializePower(status); + return power->readOnChipTemperature(status) / 4096.0 * 503.975 - 273.15; +} + } // extern "C" diff --git a/hal/src/main/native/athena/mockdata/RoboRioData.cpp b/hal/src/main/native/athena/mockdata/RoboRioData.cpp index 9392fcb6f4..750c95fbcd 100644 --- a/hal/src/main/native/athena/mockdata/RoboRioData.cpp +++ b/hal/src/main/native/athena/mockdata/RoboRioData.cpp @@ -28,6 +28,7 @@ DEFINE_CAPI(int32_t, UserFaults6V, 0) DEFINE_CAPI(int32_t, UserFaults5V, 0) DEFINE_CAPI(int32_t, UserFaults3V3, 0) DEFINE_CAPI(double, BrownoutVoltage, 6.75) +DEFINE_CAPI(int32_t, CPUTemp, 16) int32_t HALSIM_RegisterRoboRioSerialNumberCallback( HAL_RoboRioStringCallback callback, void* param, HAL_Bool initialNotify) { diff --git a/hal/src/main/native/cpp/jni/PowerJNI.cpp b/hal/src/main/native/cpp/jni/PowerJNI.cpp index 92b174d935..20962053e2 100644 --- a/hal/src/main/native/cpp/jni/PowerJNI.cpp +++ b/hal/src/main/native/cpp/jni/PowerJNI.cpp @@ -72,6 +72,20 @@ Java_edu_wpi_first_hal_PowerJNI_getUserCurrent6V return val; } +/* + * Class: edu_wpi_first_hal_PowerJNI + * Method: setUserEnabled6V + * Signature: (Z)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_hal_PowerJNI_setUserEnabled6V + (JNIEnv* env, jclass, jboolean enabled) +{ + int32_t status = 0; + HAL_SetUserRailEnabled6V(enabled, &status); + CheckStatus(env, status); +} + /* * Class: edu_wpi_first_hal_PowerJNI * Method: getUserActive6V @@ -132,6 +146,20 @@ Java_edu_wpi_first_hal_PowerJNI_getUserCurrent5V return val; } +/* + * Class: edu_wpi_first_hal_PowerJNI + * Method: setUserEnabled5V + * Signature: (Z)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_hal_PowerJNI_setUserEnabled5V + (JNIEnv* env, jclass, jboolean enabled) +{ + int32_t status = 0; + HAL_SetUserRailEnabled5V(enabled, &status); + CheckStatus(env, status); +} + /* * Class: edu_wpi_first_hal_PowerJNI * Method: getUserActive5V @@ -192,6 +220,20 @@ Java_edu_wpi_first_hal_PowerJNI_getUserCurrent3V3 return val; } +/* + * Class: edu_wpi_first_hal_PowerJNI + * Method: setUserEnabled3V3 + * Signature: (Z)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_hal_PowerJNI_setUserEnabled3V3 + (JNIEnv* env, jclass, jboolean enabled) +{ + int32_t status = 0; + HAL_SetUserRailEnabled3V3(enabled, &status); + CheckStatus(env, status); +} + /* * Class: edu_wpi_first_hal_PowerJNI * Method: getUserActive3V3 @@ -251,4 +293,19 @@ Java_edu_wpi_first_hal_PowerJNI_getBrownoutVoltage return val; } +/* + * Class: edu_wpi_first_hal_PowerJNI + * Method: getCPUTemp + * Signature: ()D + */ +JNIEXPORT jdouble JNICALL +Java_edu_wpi_first_hal_PowerJNI_getCPUTemp + (JNIEnv* env, jclass) +{ + int32_t status = 0; + double val = HAL_GetCPUTemp(&status); + CheckStatus(env, status); + return val; +} + } // extern "C" diff --git a/hal/src/main/native/include/hal/Power.h b/hal/src/main/native/include/hal/Power.h index 2bd983a359..b2a01692e9 100644 --- a/hal/src/main/native/include/hal/Power.h +++ b/hal/src/main/native/include/hal/Power.h @@ -66,6 +66,14 @@ HAL_Bool HAL_GetUserActive6V(int32_t* status); */ int32_t HAL_GetUserCurrentFaults6V(int32_t* status); +/** + * Enables or disables the 6V rail. + * + * @param enabled whether the rail should be enabled + * @param[out] status the error code, or 0 for success + */ +void HAL_SetUserRailEnabled6V(HAL_Bool enabled, int32_t* status); + /** * Gets the 5V rail voltage. * @@ -98,6 +106,14 @@ HAL_Bool HAL_GetUserActive5V(int32_t* status); */ int32_t HAL_GetUserCurrentFaults5V(int32_t* status); +/** + * Enables or disables the 5V rail. + * + * @param enabled whether the rail should be enabled + * @param[out] status the error code, or 0 for success + */ +void HAL_SetUserRailEnabled5V(HAL_Bool enabled, int32_t* status); + /** * Gets the 3V3 rail voltage. * @@ -130,6 +146,14 @@ HAL_Bool HAL_GetUserActive3V3(int32_t* status); */ int32_t HAL_GetUserCurrentFaults3V3(int32_t* status); +/** + * Enables or disables the 3V3 rail. + * + * @param enabled whether the rail should be enabled + * @param[out] status the error code, or 0 for success + */ +void HAL_SetUserRailEnabled3V3(HAL_Bool enabled, int32_t* status); + /** * Get the current brownout voltage setting. * @@ -149,6 +173,14 @@ double HAL_GetBrownoutVoltage(int32_t* status); */ void HAL_SetBrownoutVoltage(double voltage, int32_t* status); +/** + * Get the current CPU temperature in degrees Celsius + * + * @param[out] status the error code, or 0 for success + * @return current CPU temperature in degrees Celsius + */ +double HAL_GetCPUTemp(int32_t* status); + #ifdef __cplusplus } // extern "C" #endif diff --git a/hal/src/main/native/include/hal/simulation/RoboRioData.h b/hal/src/main/native/include/hal/simulation/RoboRioData.h index 864be5cf10..f074c3464f 100644 --- a/hal/src/main/native/include/hal/simulation/RoboRioData.h +++ b/hal/src/main/native/include/hal/simulation/RoboRioData.h @@ -141,6 +141,13 @@ void HALSIM_SetRoboRioComments(const char* comments, size_t size); void HALSIM_RegisterRoboRioAllCallbacks(HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify); +int32_t HALSIM_RegisterRoboRioCPUTempCallback(HAL_NotifyCallback callback, + void* param, + HAL_Bool initialNotify); +void HALSIM_CancelRoboRioCPUTempCallback(int32_t uid); +HAL_Bool HALSIM_GetRoboRioCPUTemp(void); +void HALSIM_SetRoboRioUserCPUTemp(HAL_Bool userActive3V3); + #ifdef __cplusplus } // extern "C" #endif diff --git a/hal/src/main/native/sim/Power.cpp b/hal/src/main/native/sim/Power.cpp index 08d56389d6..1eca18f3d6 100644 --- a/hal/src/main/native/sim/Power.cpp +++ b/hal/src/main/native/sim/Power.cpp @@ -32,6 +32,7 @@ HAL_Bool HAL_GetUserActive6V(int32_t* status) { int32_t HAL_GetUserCurrentFaults6V(int32_t* status) { return SimRoboRioData->userFaults6V; } +void HAL_SetUserRailEnabled6V(HAL_Bool enabled, int32_t* status) {} double HAL_GetUserVoltage5V(int32_t* status) { return SimRoboRioData->userVoltage5V; } @@ -44,6 +45,7 @@ HAL_Bool HAL_GetUserActive5V(int32_t* status) { int32_t HAL_GetUserCurrentFaults5V(int32_t* status) { return SimRoboRioData->userFaults5V; } +void HAL_SetUserRailEnabled5V(HAL_Bool enabled, int32_t* status) {} double HAL_GetUserVoltage3V3(int32_t* status) { return SimRoboRioData->userVoltage3V3; } @@ -56,10 +58,14 @@ HAL_Bool HAL_GetUserActive3V3(int32_t* status) { int32_t HAL_GetUserCurrentFaults3V3(int32_t* status) { return SimRoboRioData->userFaults3V3; } +void HAL_SetUserRailEnabled3V3(HAL_Bool enabled, int32_t* status) {} void HAL_SetBrownoutVoltage(double voltage, int32_t* status) { SimRoboRioData->brownoutVoltage = voltage; } double HAL_GetBrownoutVoltage(int32_t* status) { return SimRoboRioData->brownoutVoltage; } +double HAL_GetCPUTemp(int32_t* status) { + return SimRoboRioData->cpuTemp; +} } // extern "C" diff --git a/hal/src/main/native/sim/mockdata/RoboRioData.cpp b/hal/src/main/native/sim/mockdata/RoboRioData.cpp index b73b0d90d7..a9da3a2d37 100644 --- a/hal/src/main/native/sim/mockdata/RoboRioData.cpp +++ b/hal/src/main/native/sim/mockdata/RoboRioData.cpp @@ -32,6 +32,7 @@ void RoboRioData::ResetData() { userFaults5V.Reset(0); userFaults3V3.Reset(0); brownoutVoltage.Reset(6.75); + cpuTemp.Reset(100); m_serialNumber = ""; m_comments = ""; } @@ -132,6 +133,7 @@ DEFINE_CAPI(int32_t, UserFaults6V, userFaults6V) DEFINE_CAPI(int32_t, UserFaults5V, userFaults5V) DEFINE_CAPI(int32_t, UserFaults3V3, userFaults3V3) DEFINE_CAPI(double, BrownoutVoltage, brownoutVoltage) +DEFINE_CAPI(int32_t, CPUTemp, cpuTemp) int32_t HALSIM_RegisterRoboRioSerialNumberCallback( HAL_RoboRioStringCallback callback, void* param, HAL_Bool initialNotify) { @@ -187,5 +189,6 @@ void HALSIM_RegisterRoboRioAllCallbacks(HAL_NotifyCallback callback, REGISTER(userFaults5V); REGISTER(userFaults3V3); REGISTER(brownoutVoltage); + REGISTER(cpuTemp); } } // extern "C" diff --git a/hal/src/main/native/sim/mockdata/RoboRioDataInternal.h b/hal/src/main/native/sim/mockdata/RoboRioDataInternal.h index c3ff17a4a2..354ebd4b9e 100644 --- a/hal/src/main/native/sim/mockdata/RoboRioDataInternal.h +++ b/hal/src/main/native/sim/mockdata/RoboRioDataInternal.h @@ -30,6 +30,7 @@ class RoboRioData { HAL_SIMDATAVALUE_DEFINE_NAME(UserFaults5V) HAL_SIMDATAVALUE_DEFINE_NAME(UserFaults3V3) HAL_SIMDATAVALUE_DEFINE_NAME(BrownoutVoltage) + HAL_SIMDATAVALUE_DEFINE_NAME(CPUTemp) HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(SerialNumber) HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(Comments); @@ -57,6 +58,7 @@ class RoboRioData { SimDataValue userFaults3V3{0}; SimDataValue brownoutVoltage{ 6.75}; + SimDataValue cpuTemp{100}; int32_t RegisterSerialNumberCallback(HAL_RoboRioStringCallback callback, void* param, HAL_Bool initialNotify); diff --git a/wpilibc/src/main/native/cpp/RobotController.cpp b/wpilibc/src/main/native/cpp/RobotController.cpp index 035493f2a5..5d38c57e85 100644 --- a/wpilibc/src/main/native/cpp/RobotController.cpp +++ b/wpilibc/src/main/native/cpp/RobotController.cpp @@ -111,6 +111,12 @@ double RobotController::GetCurrent3V3() { return retVal; } +void RobotController::SetEnabled3V3(bool enabled) { + int32_t status = 0; + HAL_SetUserRailEnabled3V3(enabled, &status); + FRC_CheckErrorStatus(status, "SetEnabled3V3"); +} + bool RobotController::GetEnabled3V3() { int32_t status = 0; bool retVal = HAL_GetUserActive3V3(&status); @@ -139,6 +145,12 @@ double RobotController::GetCurrent5V() { return retVal; } +void RobotController::SetEnabled5V(bool enabled) { + int32_t status = 0; + HAL_SetUserRailEnabled5V(enabled, &status); + FRC_CheckErrorStatus(status, "SetEnabled5V"); +} + bool RobotController::GetEnabled5V() { int32_t status = 0; bool retVal = HAL_GetUserActive5V(&status); @@ -167,6 +179,12 @@ double RobotController::GetCurrent6V() { return retVal; } +void RobotController::SetEnabled6V(bool enabled) { + int32_t status = 0; + HAL_SetUserRailEnabled6V(enabled, &status); + FRC_CheckErrorStatus(status, "SetEnabled6V"); +} + bool RobotController::GetEnabled6V() { int32_t status = 0; bool retVal = HAL_GetUserActive6V(&status); @@ -194,6 +212,13 @@ void RobotController::SetBrownoutVoltage(units::volt_t brownoutVoltage) { FRC_CheckErrorStatus(status, "SetBrownoutVoltage"); } +units::celsius_t RobotController::GetCPUTemp() { + int32_t status = 0; + double retVal = HAL_GetCPUTemp(&status); + FRC_CheckErrorStatus(status, "GetCPUTemp"); + return units::celsius_t{retVal}; +} + CANStatus RobotController::GetCANStatus() { int32_t status = 0; float percentBusUtilization = 0; diff --git a/wpilibc/src/main/native/include/frc/RobotController.h b/wpilibc/src/main/native/include/frc/RobotController.h index a4cafd6f6f..777af4129c 100644 --- a/wpilibc/src/main/native/include/frc/RobotController.h +++ b/wpilibc/src/main/native/include/frc/RobotController.h @@ -8,6 +8,7 @@ #include +#include #include namespace frc { @@ -136,9 +137,16 @@ class RobotController { static double GetCurrent3V3(); /** - * 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. + * Enables or disables the 3.3V rail. + * + * @param enabled whether to enable the 3.3V rail. + */ + static void SetEnabled3V3(bool enabled); + + /** + * Get the enabled state of the 3.3V rail. The rail may be disabled due to + * calling SetEnabled3V3(), a controller brownout, a short circuit on the + * rail, or controller over-voltage. * * @return The controller 3.3V rail enabled value. True for enabled. */ @@ -167,9 +175,16 @@ class RobotController { static double GetCurrent5V(); /** - * 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. + * Enables or disables the 5V rail. + * + * @param enabled whether to enable the 5V rail. + */ + static void SetEnabled5V(bool enabled); + + /** + * Get the enabled state of the 5V rail. The rail may be disabled due to + * calling SetEnabled5V(), a controller brownout, a short circuit on the rail, + * or controller over-voltage. * * @return The controller 5V rail enabled value. True for enabled. */ @@ -198,9 +213,16 @@ class RobotController { static double GetCurrent6V(); /** - * 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. + * Enables or disables the 6V rail. + * + * @param enabled whether to enable the 6V rail. + */ + static void SetEnabled6V(bool enabled); + + /** + * Get the enabled state of the 6V rail. The rail may be disabled due to + * calling SetEnabled6V(), a controller brownout, a short circuit on the rail, + * or controller over-voltage. * * @return The controller 6V rail enabled value. True for enabled. */ @@ -231,6 +253,13 @@ class RobotController { */ static void SetBrownoutVoltage(units::volt_t brownoutVoltage); + /** + * Get the current CPU temperature. + * + * @return current CPU temperature + */ + static units::celsius_t GetCPUTemp(); + /** * Get the current status of the CAN bus. * diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotController.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotController.java index f49308dee3..af44387159 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotController.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotController.java @@ -148,6 +148,15 @@ public final class RobotController { return PowerJNI.getUserCurrent3V3(); } + /** + * Enables or disables the 3.3V rail. + * + * @param enabled whether to enable the 3.3V rail. + */ + public static void setEnabled3V3(boolean enabled) { + PowerJNI.setUserEnabled3V3(enabled); + } + /** * 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. @@ -185,6 +194,15 @@ public final class RobotController { return PowerJNI.getUserCurrent5V(); } + /** + * Enables or disables the 5V rail. + * + * @param enabled whether to enable the 5V rail. + */ + public static void setEnabled5V(boolean enabled) { + PowerJNI.setUserEnabled5V(enabled); + } + /** * 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. @@ -222,6 +240,15 @@ public final class RobotController { return PowerJNI.getUserCurrent6V(); } + /** + * Enables or disables the 6V rail. + * + * @param enabled whether to enable the 6V rail. + */ + public static void setEnabled6V(boolean enabled) { + PowerJNI.setUserEnabled6V(enabled); + } + /** * 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. @@ -261,6 +288,15 @@ public final class RobotController { PowerJNI.setBrownoutVoltage(brownoutVoltage); } + /** + * Get the current CPU temperature in degrees Celsius. + * + * @return current CPU temperature in degrees Celsius + */ + public static double getCPUTemp() { + return PowerJNI.getCPUTemp(); + } + /** * Get the current status of the CAN bus. *