[hal, wpilib] Incorporate pneumatic control type into wpilibc/j (#3728)

This commit is contained in:
Thad House
2021-11-23 20:32:02 -08:00
committed by GitHub
parent 9aba2b7583
commit b156db400d
35 changed files with 693 additions and 216 deletions

View File

@@ -64,7 +64,8 @@ HAL_REVPHHandle HAL_InitializeREVPH(int32_t module,
SimREVPHData[module].initialized = true;
// Enable closed loop
SimREVPHData[module].closedLoopEnabled = true;
SimREVPHData[module].compressorConfigType =
HAL_REVPHCompressorConfigType_kDigital;
return handle;
}
@@ -97,26 +98,73 @@ HAL_Bool HAL_GetREVPHCompressor(HAL_REVPHHandle handle, int32_t* status) {
return SimREVPHData[pcm->module].compressorOn;
}
void HAL_SetREVPHClosedLoopControl(HAL_REVPHHandle handle, HAL_Bool enabled,
int32_t* status) {
void HAL_SetREVPHCompressorConfig(HAL_REVPHHandle handle,
const HAL_REVPHCompressorConfig* config,
int32_t* status) {
auto pcm = pcmHandles->Get(handle);
if (pcm == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
SimREVPHData[pcm->module].closedLoopEnabled = enabled;
// TODO
// SimREVPHData[pcm->module].compressorConfigType = config.
}
HAL_Bool HAL_GetREVPHClosedLoopControl(HAL_REVPHHandle handle,
int32_t* status) {
void HAL_SetREVPHClosedLoopControlDisabled(HAL_REVPHHandle handle,
int32_t* status) {
auto pcm = pcmHandles->Get(handle);
if (pcm == nullptr) {
*status = HAL_HANDLE_ERROR;
return false;
return;
}
SimREVPHData[pcm->module].compressorConfigType =
HAL_REVPHCompressorConfigType_kDisabled;
}
return SimREVPHData[pcm->module].closedLoopEnabled;
void HAL_SetREVPHClosedLoopControlDigital(HAL_REVPHHandle handle,
int32_t* status) {
auto pcm = pcmHandles->Get(handle);
if (pcm == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
SimREVPHData[pcm->module].compressorConfigType =
HAL_REVPHCompressorConfigType_kDigital;
}
void HAL_SetREVPHClosedLoopControlAnalog(HAL_REVPHHandle handle,
double minAnalogVoltage,
double maxAnalogVoltage,
int32_t* status) {
auto pcm = pcmHandles->Get(handle);
if (pcm == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
SimREVPHData[pcm->module].compressorConfigType =
HAL_REVPHCompressorConfigType_kAnalog;
}
void HAL_SetREVPHClosedLoopControlHybrid(HAL_REVPHHandle handle,
double minAnalogVoltage,
double maxAnalogVoltage,
int32_t* status) {
auto pcm = pcmHandles->Get(handle);
if (pcm == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
SimREVPHData[pcm->module].compressorConfigType =
HAL_REVPHCompressorConfigType_kHybrid;
}
HAL_REVPHCompressorConfigType HAL_GetREVPHCompressorConfig(
HAL_REVPHHandle handle, int32_t* status) {
auto pcm = pcmHandles->Get(handle);
if (pcm == nullptr) {
*status = HAL_HANDLE_ERROR;
return HAL_REVPHCompressorConfigType_kDisabled;
}
return SimREVPHData[pcm->module].compressorConfigType;
}
HAL_Bool HAL_GetREVPHPressureSwitch(HAL_REVPHHandle handle, int32_t* status) {

View File

@@ -21,7 +21,7 @@ void REVPHData::ResetData() {
}
initialized.Reset(false);
compressorOn.Reset(false);
closedLoopEnabled.Reset(true);
compressorConfigType.Reset(HAL_REVPHCompressorConfigType_kDisabled);
pressureSwitch.Reset(false);
compressorCurrent.Reset(0.0);
}
@@ -39,7 +39,8 @@ HAL_SIMDATAVALUE_DEFINE_CAPI_CHANNEL(HAL_Bool, HALSIM, REVPHSolenoidOutput,
SimREVPHData, solenoidOutput)
DEFINE_CAPI(HAL_Bool, Initialized, initialized)
DEFINE_CAPI(HAL_Bool, CompressorOn, compressorOn)
DEFINE_CAPI(HAL_Bool, ClosedLoopEnabled, closedLoopEnabled)
DEFINE_CAPI(HAL_REVPHCompressorConfigType, CompressorConfigType,
compressorConfigType)
DEFINE_CAPI(HAL_Bool, PressureSwitch, pressureSwitch)
DEFINE_CAPI(double, CompressorCurrent, compressorCurrent)
@@ -69,7 +70,7 @@ void HALSIM_RegisterREVPHAllNonSolenoidCallbacks(int32_t index,
HAL_Bool initialNotify) {
REGISTER(initialized);
REGISTER(compressorOn);
REGISTER(closedLoopEnabled);
REGISTER(compressorConfigType);
REGISTER(pressureSwitch);
REGISTER(compressorCurrent);
}

View File

@@ -13,7 +13,7 @@ class REVPHData {
HAL_SIMDATAVALUE_DEFINE_NAME(Initialized)
HAL_SIMDATAVALUE_DEFINE_NAME(SolenoidOutput)
HAL_SIMDATAVALUE_DEFINE_NAME(CompressorOn)
HAL_SIMDATAVALUE_DEFINE_NAME(ClosedLoopEnabled)
HAL_SIMDATAVALUE_DEFINE_NAME(CompressorConfigType)
HAL_SIMDATAVALUE_DEFINE_NAME(PressureSwitch)
HAL_SIMDATAVALUE_DEFINE_NAME(CompressorCurrent)
@@ -22,6 +22,11 @@ class REVPHData {
return false;
}
static inline HAL_Value MakeCompressorConfigTypeValue(
HAL_REVPHCompressorConfigType value) {
return HAL_MakeEnum(value);
}
public:
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetInitializedName> initialized{
false};
@@ -30,8 +35,10 @@ class REVPHData {
solenoidOutput[kNumREVPHChannels];
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetCompressorOnName> compressorOn{
false};
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetClosedLoopEnabledName>
closedLoopEnabled{true};
SimDataValue<HAL_REVPHCompressorConfigType, MakeCompressorConfigTypeValue,
GetCompressorConfigTypeName>
compressorConfigType{HAL_REVPHCompressorConfigType::
HAL_REVPHCompressorConfigType_kDisabled};
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetPressureSwitchName> pressureSwitch{
false};
SimDataValue<double, HAL_MakeDouble, GetCompressorCurrentName>