[hal] Expose power rail disable and cpu temp functionality (#5477)

This commit is contained in:
Ryan Blue
2023-08-04 02:48:29 -04:00
committed by GitHub
parent 3ad5d2e42d
commit e2d17a24a6
12 changed files with 255 additions and 9 deletions

View File

@@ -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();
}

View File

@@ -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"

View File

@@ -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) {

View File

@@ -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"

View File

@@ -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

View File

@@ -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

View File

@@ -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"

View File

@@ -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"

View File

@@ -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<int32_t, HAL_MakeInt, GetUserFaults3V3Name> userFaults3V3{0};
SimDataValue<double, HAL_MakeDouble, GetBrownoutVoltageName> brownoutVoltage{
6.75};
SimDataValue<double, HAL_MakeDouble, GetCPUTempName> cpuTemp{100};
int32_t RegisterSerialNumberCallback(HAL_RoboRioStringCallback callback,
void* param, HAL_Bool initialNotify);

View File

@@ -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;

View File

@@ -8,6 +8,7 @@
#include <string>
#include <units/temperature.h>
#include <units/voltage.h>
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.
*

View File

@@ -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.
*