mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
[hal, wpilib] Add brownout voltage configuration (#3632)
This commit is contained in:
@@ -103,4 +103,22 @@ int32_t HAL_GetUserCurrentFaults3V3(int32_t* status) {
|
||||
power->readFaultCounts_OverCurrentFaultCount3V3(status));
|
||||
}
|
||||
|
||||
void HAL_SetBrownoutVoltage(double voltage, int32_t* status) {
|
||||
initializePower(status);
|
||||
if (voltage < 0) {
|
||||
voltage = 0;
|
||||
}
|
||||
if (voltage > 50) {
|
||||
voltage = 50;
|
||||
}
|
||||
power->writeBrownoutVoltage250mV(static_cast<unsigned char>(voltage * 4),
|
||||
status);
|
||||
}
|
||||
|
||||
double HAL_GetBrownoutVoltage(int32_t* status) {
|
||||
initializePower(status);
|
||||
auto brownout = power->readBrownoutVoltage250mV(status);
|
||||
return brownout / 4.0;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -27,6 +27,7 @@ DEFINE_CAPI(HAL_Bool, UserActive3V3, false)
|
||||
DEFINE_CAPI(int32_t, UserFaults6V, 0)
|
||||
DEFINE_CAPI(int32_t, UserFaults5V, 0)
|
||||
DEFINE_CAPI(int32_t, UserFaults3V3, 0)
|
||||
DEFINE_CAPI(double, BrownoutVoltage, 6.75)
|
||||
|
||||
void HALSIM_RegisterRoboRioAllCallbacks(HAL_NotifyCallback callback,
|
||||
void* param, HAL_Bool initialNotify) {}
|
||||
|
||||
@@ -222,4 +222,33 @@ Java_edu_wpi_first_hal_PowerJNI_getUserCurrentFaults3V3
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_PowerJNI
|
||||
* Method: setBrownoutVoltage
|
||||
* Signature: (D)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_PowerJNI_setBrownoutVoltage
|
||||
(JNIEnv* env, jclass, jdouble brownoutVoltage)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_SetBrownoutVoltage(brownoutVoltage, &status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_PowerJNI
|
||||
* Method: getBrownoutVoltage
|
||||
* Signature: ()D
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL
|
||||
Java_edu_wpi_first_hal_PowerJNI_getBrownoutVoltage
|
||||
(JNIEnv* env, jclass)
|
||||
{
|
||||
int32_t status = 0;
|
||||
double val = HAL_GetBrownoutVoltage(&status);
|
||||
CheckStatus(env, status);
|
||||
return val;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -774,6 +774,57 @@ Java_edu_wpi_first_hal_simulation_RoboRioDataJNI_setUserFaults3V3
|
||||
HALSIM_SetRoboRioUserFaults3V3(value);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_RoboRioDataJNI
|
||||
* Method: registerBrownoutVoltageCallback
|
||||
* Signature: (Ljava/lang/Object;Z)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_RoboRioDataJNI_registerBrownoutVoltageCallback
|
||||
(JNIEnv* env, jclass, jobject callback, jboolean initialNotify)
|
||||
{
|
||||
return sim::AllocateCallbackNoIndex(
|
||||
env, callback, initialNotify,
|
||||
&HALSIM_RegisterRoboRioBrownoutVoltageCallback);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_RoboRioDataJNI
|
||||
* Method: cancelBrownoutVoltageCallback
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_RoboRioDataJNI_cancelBrownoutVoltageCallback
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
return sim::FreeCallbackNoIndex(env, handle,
|
||||
&HALSIM_CancelRoboRioBrownoutVoltageCallback);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_RoboRioDataJNI
|
||||
* Method: getBrownoutVoltage
|
||||
* Signature: ()D
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_RoboRioDataJNI_getBrownoutVoltage
|
||||
(JNIEnv*, jclass)
|
||||
{
|
||||
return HALSIM_GetRoboRioBrownoutVoltage();
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_RoboRioDataJNI
|
||||
* Method: setBrownoutVoltage
|
||||
* Signature: (D)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_RoboRioDataJNI_setBrownoutVoltage
|
||||
(JNIEnv*, jclass, jdouble value)
|
||||
{
|
||||
HALSIM_SetRoboRioBrownoutVoltage(value);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_RoboRioDataJNI
|
||||
* Method: resetData
|
||||
|
||||
@@ -115,6 +115,24 @@ HAL_Bool HAL_GetUserActive3V3(int32_t* status);
|
||||
* @return the number of 3V3 fault counts
|
||||
*/
|
||||
int32_t HAL_GetUserCurrentFaults3V3(int32_t* status);
|
||||
|
||||
/**
|
||||
* Get the current brownout voltage seting.
|
||||
*
|
||||
* Note that this only does anything on the roboRIO 2.
|
||||
* On the roboRIO it is a no-op.
|
||||
*
|
||||
* @return The brownout voltage
|
||||
*/
|
||||
double HAL_GetBrownoutVoltage(int32_t* status);
|
||||
|
||||
/**
|
||||
* Set the voltage the roborio will brownout and disable all outputs.
|
||||
*
|
||||
* @param brownoutVoltage The brownout voltage
|
||||
*/
|
||||
void HAL_SetBrownoutVoltage(double voltage, int32_t* status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
@@ -115,6 +115,12 @@ void HALSIM_CancelRoboRioUserFaults3V3Callback(int32_t uid);
|
||||
int32_t HALSIM_GetRoboRioUserFaults3V3(void);
|
||||
void HALSIM_SetRoboRioUserFaults3V3(int32_t userFaults3V3);
|
||||
|
||||
int32_t HALSIM_RegisterRoboRioBrownoutVoltageCallback(
|
||||
HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify);
|
||||
void HALSIM_CancelRoboRioBrownoutVoltageCallback(int32_t uid);
|
||||
double HALSIM_GetRoboRioBrownoutVoltage(void);
|
||||
void HALSIM_SetRoboRioBrownoutVoltage(double brownoutVoltage);
|
||||
|
||||
void HALSIM_RegisterRoboRioAllCallbacks(HAL_NotifyCallback callback,
|
||||
void* param, HAL_Bool initialNotify);
|
||||
|
||||
|
||||
@@ -56,4 +56,10 @@ HAL_Bool HAL_GetUserActive3V3(int32_t* status) {
|
||||
int32_t HAL_GetUserCurrentFaults3V3(int32_t* status) {
|
||||
return SimRoboRioData->userFaults3V3;
|
||||
}
|
||||
void HAL_SetBrownoutVoltage(double voltage, int32_t* status) {
|
||||
SimRoboRioData->brownoutVoltage = voltage;
|
||||
}
|
||||
double HAL_GetBrownoutVoltage(int32_t* status) {
|
||||
return SimRoboRioData->brownoutVoltage;
|
||||
}
|
||||
} // extern "C"
|
||||
|
||||
@@ -31,6 +31,7 @@ void RoboRioData::ResetData() {
|
||||
userFaults6V.Reset(0);
|
||||
userFaults5V.Reset(0);
|
||||
userFaults3V3.Reset(0);
|
||||
brownoutVoltage.Reset(6.75);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
@@ -57,6 +58,7 @@ DEFINE_CAPI(HAL_Bool, UserActive3V3, userActive3V3)
|
||||
DEFINE_CAPI(int32_t, UserFaults6V, userFaults6V)
|
||||
DEFINE_CAPI(int32_t, UserFaults5V, userFaults5V)
|
||||
DEFINE_CAPI(int32_t, UserFaults3V3, userFaults3V3)
|
||||
DEFINE_CAPI(double, BrownoutVoltage, brownoutVoltage)
|
||||
|
||||
#define REGISTER(NAME) \
|
||||
SimRoboRioData->NAME.RegisterCallback(callback, param, initialNotify)
|
||||
@@ -78,5 +80,6 @@ void HALSIM_RegisterRoboRioAllCallbacks(HAL_NotifyCallback callback,
|
||||
REGISTER(userFaults6V);
|
||||
REGISTER(userFaults5V);
|
||||
REGISTER(userFaults3V3);
|
||||
REGISTER(brownoutVoltage);
|
||||
}
|
||||
} // extern "C"
|
||||
|
||||
@@ -24,6 +24,7 @@ class RoboRioData {
|
||||
HAL_SIMDATAVALUE_DEFINE_NAME(UserFaults6V)
|
||||
HAL_SIMDATAVALUE_DEFINE_NAME(UserFaults5V)
|
||||
HAL_SIMDATAVALUE_DEFINE_NAME(UserFaults3V3)
|
||||
HAL_SIMDATAVALUE_DEFINE_NAME(BrownoutVoltage)
|
||||
|
||||
public:
|
||||
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetFPGAButtonName> fpgaButton{false};
|
||||
@@ -46,6 +47,8 @@ class RoboRioData {
|
||||
SimDataValue<int32_t, HAL_MakeInt, GetUserFaults6VName> userFaults6V{0};
|
||||
SimDataValue<int32_t, HAL_MakeInt, GetUserFaults5VName> userFaults5V{0};
|
||||
SimDataValue<int32_t, HAL_MakeInt, GetUserFaults3V3Name> userFaults3V3{0};
|
||||
SimDataValue<double, HAL_MakeDouble, GetBrownoutVoltageName> brownoutVoltage{
|
||||
6.75};
|
||||
|
||||
virtual void ResetData();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user