[sim] Add initialized flag for all solenoids on a PCM (#2897)

This allows much easier/faster checking for whether any solenoid has been
initialized on a particular PCM.
This commit is contained in:
Peter Johnson
2020-11-30 19:20:16 -08:00
committed by GitHub
parent bdf5ba91a4
commit f5a6fc0703
4 changed files with 24 additions and 1 deletions

View File

@@ -75,6 +75,7 @@ HAL_SolenoidHandle HAL_InitializeSolenoidPort(HAL_PortHandle portHandle,
solenoidPort->channel = static_cast<uint8_t>(channel);
HALSIM_SetPCMSolenoidInitialized(module, channel, true);
HALSIM_SetPCMAnySolenoidInitialized(module, true);
return handle;
}
@@ -83,6 +84,15 @@ void HAL_FreeSolenoidPort(HAL_SolenoidHandle solenoidPortHandle) {
if (port == nullptr) return;
solenoidHandles->Free(solenoidPortHandle);
HALSIM_SetPCMSolenoidInitialized(port->module, port->channel, false);
int count = 0;
for (int i = 0; i < kNumSolenoidChannels; ++i) {
if (HALSIM_GetPCMSolenoidInitialized(port->module, i)) {
++count;
}
}
if (count == 0) {
HALSIM_SetPCMAnySolenoidInitialized(port->module, false);
}
}
HAL_Bool HAL_CheckSolenoidModule(int32_t module) {
return module < kNumPCMModules && module >= 0;

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
/* Copyright (c) 2017-2020 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. */
@@ -25,6 +25,7 @@ void PCMData::ResetData() {
solenoidInitialized[i].Reset(false);
solenoidOutput[i].Reset(false);
}
anySolenoidInitialized.Reset(false);
compressorInitialized.Reset(false);
compressorOn.Reset(false);
closedLoopEnabled.Reset(true);
@@ -43,6 +44,7 @@ HAL_SIMDATAVALUE_DEFINE_CAPI_CHANNEL(HAL_Bool, HALSIM, PCMSolenoidInitialized,
SimPCMData, solenoidInitialized)
HAL_SIMDATAVALUE_DEFINE_CAPI_CHANNEL(HAL_Bool, HALSIM, PCMSolenoidOutput,
SimPCMData, solenoidOutput)
DEFINE_CAPI(HAL_Bool, AnySolenoidInitialized, anySolenoidInitialized)
DEFINE_CAPI(HAL_Bool, CompressorInitialized, compressorInitialized)
DEFINE_CAPI(HAL_Bool, CompressorOn, compressorOn)
DEFINE_CAPI(HAL_Bool, ClosedLoopEnabled, closedLoopEnabled)

View File

@@ -15,6 +15,7 @@ namespace hal {
class PCMData {
HAL_SIMDATAVALUE_DEFINE_NAME(SolenoidInitialized)
HAL_SIMDATAVALUE_DEFINE_NAME(SolenoidOutput)
HAL_SIMDATAVALUE_DEFINE_NAME(AnySolenoidInitialized)
HAL_SIMDATAVALUE_DEFINE_NAME(CompressorInitialized)
HAL_SIMDATAVALUE_DEFINE_NAME(CompressorOn)
HAL_SIMDATAVALUE_DEFINE_NAME(ClosedLoopEnabled)
@@ -37,6 +38,8 @@ class PCMData {
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetSolenoidOutputName,
GetSolenoidOutputDefault>
solenoidOutput[kNumSolenoidChannels];
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetAnySolenoidInitializedName>
anySolenoidInitialized{false};
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetCompressorInitializedName>
compressorInitialized{false};
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetCompressorOnName> compressorOn{