From 715a69db893ba61ddd0af4febbcd56cb57d66e07 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 15 Mar 2023 15:43:20 +0100 Subject: [PATCH] this should cover upper bound checking when heater is off --- mission/controller/ThermalController.cpp | 58 ++++++++++++++---------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/mission/controller/ThermalController.cpp b/mission/controller/ThermalController.cpp index e22d2b8a..42d79a2a 100644 --- a/mission/controller/ThermalController.cpp +++ b/mission/controller/ThermalController.cpp @@ -1539,8 +1539,33 @@ void ThermalController::checkLimitsAndCtrlHeater(heater::Switchers switchNr, const TempLimits& tempLimit) { componentAboveCutOffLimit = false; componentAboveUpperLimit = false; - // if Heater off + auto tempTooHighHandler = [&](const char* whatLimit, bool heaterIsOn) { + heaterHandler.switchHeater(switchNr, HeaterHandler::SwitchState::OFF); + sif::info << "ThermalController::checkLimitsAndCtrlHeater: Reached " << whatLimit << ": Heater " + << static_cast(thermalComponent) << " OFF" << std::endl; + heaterStates[switchNr].switchTransition = true; + if (heaterIsOn) { + heaterHandler.switchHeater(redSwitchNr, HeaterHandler::SwitchState::OFF); + heaterStates[redSwitchNr].switchTransition = true; + } + }; + auto checkUpperLimits = [&](bool heaterIsOn) { + if (sensorTemp >= tempLimit.nopUpperLimit) { + componentAboveUpperLimit = true; + tempTooHighHandler("NOP-Limit", heaterIsOn); + overHeatEventToTrigger = ThermalComponentIF::COMPONENT_TEMP_OOL_HIGH; + return true; + } else if (sensorTemp >= tempLimit.opUpperLimit) { + componentAboveUpperLimit = true; + tempTooHighHandler("OP-Limit", heaterIsOn); + overHeatEventToTrigger = ThermalComponentIF::COMPONENT_TEMP_HIGH; + return true; + } + return false; + }; + // Stay passive during switch transitions, wait for heater switching to complete. if (not heaterStates[switchNr].switchTransition) { + // Heater off if (not heaterHandler.checkSwitchState(switchNr)) { // TODO: check NOP limit and maybe trigger fdir if (sensorTemp < tempLimit.opLowerLimit) { @@ -1552,10 +1577,11 @@ void ThermalController::checkLimitsAndCtrlHeater(heater::Switchers switchNr, } else { thermalStates[thermalComponent].heating = false; } - - // if Heater on + checkUpperLimits(false); + // Heater on } else if (heaterHandler.checkSwitchState(switchNr)) { if (thermalStates[thermalComponent].heating) { + // We are already in a heating cycle, so need to check whether heating task is complete. if (sensorTemp >= tempLimit.opLowerLimit + TEMP_OFFSET) { heaterHandler.switchHeater(switchNr, HeaterHandler::SwitchState::OFF); sif::info << "ThermalController::checkLimitsAndCtrlHeater: Heater " @@ -1564,28 +1590,14 @@ void ThermalController::checkLimitsAndCtrlHeater(heater::Switchers switchNr, thermalStates[thermalComponent].heating = false; } } else { - auto tempTooHighHandler = [&](const char* whatLimit) { - heaterHandler.switchHeater(switchNr, HeaterHandler::SwitchState::OFF); - sif::info << "ThermalController::checkLimitsAndCtrlHeater: Reached " << whatLimit - << ": Heater " << static_cast(thermalComponent) << " OFF" << std::endl; - heaterStates[switchNr].switchTransition = true; - if (heaterHandler.checkSwitchState(redSwitchNr)) { - heaterHandler.switchHeater(redSwitchNr, HeaterHandler::SwitchState::OFF); - heaterStates[redSwitchNr].switchTransition = true; - } - }; - if (sensorTemp >= tempLimit.nopUpperLimit) { - componentAboveUpperLimit = true; - tempTooHighHandler("NOP-Limit"); - overHeatEventToTrigger = ThermalComponentIF::COMPONENT_TEMP_OOL_HIGH; - } else if (sensorTemp >= tempLimit.opUpperLimit) { - componentAboveUpperLimit = true; - tempTooHighHandler("OP-Limit"); - overHeatEventToTrigger = ThermalComponentIF::COMPONENT_TEMP_HIGH; - } + // This can happen if heater is used as alternative heater (no regular heating cycle), so we + // should still check the upper limits. + bool tooHighHandlerAlreadyCalled = checkUpperLimits(true); if (sensorTemp >= tempLimit.cutOffLimit) { componentAboveCutOffLimit = true; - tempTooHighHandler("CutOff-Limit"); + if (not tooHighHandlerAlreadyCalled) { + tempTooHighHandler("CutOff-Limit", true); + } } } }