From 4a287344f48da1102f9b71c5c3507fe1a72f9055 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 4 Apr 2023 15:02:56 +0200 Subject: [PATCH 1/3] add sanity range check --- mission/controller/ThermalController.cpp | 6 ++++-- mission/controller/ThermalController.h | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/mission/controller/ThermalController.cpp b/mission/controller/ThermalController.cpp index 5e34d191..562a665b 100644 --- a/mission/controller/ThermalController.cpp +++ b/mission/controller/ThermalController.cpp @@ -1560,9 +1560,11 @@ void ThermalController::ctrlComponentTemperature(HeaterContext& htrCtx) { } resetSensorsArray(); } -bool ThermalController::selectAndReadSensorTemp() { +bool ThermalController::selectAndReadSensorTemp(HeaterContext& htrCtx) { for (unsigned i = 0; i < numSensors; i++) { - if (sensors[i].first and sensors[i].second != INVALID_TEMPERATURE) { + if (sensors[i].first and sensors[i].second != INVALID_TEMPERATURE and + sensors[i].second > SANITY_LIMIT_LOWER_TEMP and + sensors[i].second < SANITY_LIMIT_UPPER_TEMP) { sensorTemp = sensors[i].second; thermalStates[thermalComponent].errorCounter = 0; return true; diff --git a/mission/controller/ThermalController.h b/mission/controller/ThermalController.h index 0ceb9cae..9ad72ed0 100644 --- a/mission/controller/ThermalController.h +++ b/mission/controller/ThermalController.h @@ -31,8 +31,8 @@ * limit is exceeded to avoid reaching NOP limit */ struct TempLimits { - TempLimits(float nopLowerLimit, float opLowerLimit, float cutOffLimit, float opUpperLimit, - float nopUpperLimit) + TempLimits(float opLowerLimit, float cutOffLimit, float opUpperLimit, + float nopUpperLimit, float sanityUpperLimit) : opLowerLimit(opLowerLimit), opUpperLimit(opUpperLimit), cutOffLimit(cutOffLimit), @@ -91,6 +91,8 @@ class ThermalController : public ExtendedControllerBase { public: static const uint16_t INVALID_TEMPERATURE = 999; static const uint8_t NUMBER_OF_SENSORS = 16; + static constexpr uint16_t SANITY_LIMIT_LOWER_TEMP = -80; + static constexpr uint16_t SANITY_LIMIT_UPPER_TEMP = 160; ThermalController(object_id_t objectId, HeaterHandler& heater); @@ -218,7 +220,7 @@ class ThermalController : public ExtendedControllerBase { lp_var_t tempAdcPayloadPcdu = lp_var_t(objects::PLPCDU_HANDLER, plpcdu::TEMP); // TempLimits - TempLimits acsBoardLimits = TempLimits(-40.0, -40.0, 80.0, 85.0, 85.0); + TempLimits acsBoardLimits = TempLimits(5-40.0, -40.0, 80.0, 85.0, 85.0); TempLimits mgtLimits = TempLimits(-40.0, -40.0, 65.0, 70.0, 70.0); TempLimits rwLimits = TempLimits(-40.0, -40.0, 80.0, 85.0, 85.0); TempLimits strLimits = TempLimits(-30.0, -20.0, 65.0, 70.0, 80.0); @@ -299,7 +301,7 @@ class ThermalController : public ExtendedControllerBase { void heaterCtrlTempTooHighHandler(HeaterContext& heaterContext, const char* whatLimit); bool chooseHeater(heater::Switchers& switchNr, heater::Switchers redSwitchNr); - bool selectAndReadSensorTemp(); + bool selectAndReadSensorTemp(HeaterContext& htrCtx); void ctrlAcsBoard(); void ctrlMgt(); From 908927ed9f8de24f8bb35694cfb0727602eb3e4d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 4 Apr 2023 15:09:51 +0200 Subject: [PATCH 2/3] some fixes --- mission/controller/ThermalController.cpp | 37 ++++++++++++++---------- mission/controller/ThermalController.h | 10 +++---- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/mission/controller/ThermalController.cpp b/mission/controller/ThermalController.cpp index 562a665b..ebbb42a3 100644 --- a/mission/controller/ThermalController.cpp +++ b/mission/controller/ThermalController.cpp @@ -988,13 +988,15 @@ void ThermalController::ctrlAcsBoard() { sensors[4].first = sensorTemperatures.tcsBoard.isValid(); sensors[4].second = sensorTemperatures.tcsBoard.value; numSensors = 5; - if (selectAndReadSensorTemp()) { - if (chooseHeater(switchNr, redSwitchNr)) { - HeaterContext htrCtx(switchNr, redSwitchNr, acsBoardLimits); - checkLimitsAndCtrlHeater(htrCtx); + { + HeaterContext htrCtx(switchNr, redSwitchNr, acsBoardLimits); + if (selectAndReadSensorTemp(htrCtx)) { + if (chooseHeater(switchNr, redSwitchNr)) { + checkLimitsAndCtrlHeater(htrCtx); + } + resetSensorsArray(); + return; } - resetSensorsArray(); - return; } resetSensorsArray(); // B side @@ -1007,15 +1009,18 @@ void ThermalController::ctrlAcsBoard() { sensors[3].first = sensorTemperatures.tcsBoard.isValid(); sensors[3].second = sensorTemperatures.tcsBoard.value; numSensors = 4; - if (selectAndReadSensorTemp()) { - if (chooseHeater(switchNr, redSwitchNr)) { - HeaterContext htrCtx(switchNr, redSwitchNr, acsBoardLimits); - checkLimitsAndCtrlHeater(htrCtx); - } - } else { - if (chooseHeater(switchNr, redSwitchNr)) { - if (heaterHandler.getSwitchState(switchNr)) { - heaterHandler.switchHeater(switchNr, HeaterHandler::SwitchState::OFF); + + { + HeaterContext htrCtx(switchNr, redSwitchNr, acsBoardLimits); + if (selectAndReadSensorTemp(htrCtx)) { + if (chooseHeater(switchNr, redSwitchNr)) { + checkLimitsAndCtrlHeater(htrCtx); + } + } else { + if (chooseHeater(switchNr, redSwitchNr)) { + if (heaterHandler.getSwitchState(switchNr)) { + heaterHandler.switchHeater(switchNr, HeaterHandler::SwitchState::OFF); + } } } } @@ -1546,7 +1551,7 @@ void ThermalController::performThermalModuleCtrl(const HeaterSwitchStates& heate heaterTransitionControl(heaterSwitchStates); } void ThermalController::ctrlComponentTemperature(HeaterContext& htrCtx) { - if (selectAndReadSensorTemp()) { + if (selectAndReadSensorTemp(htrCtx)) { if (chooseHeater(htrCtx.switchNr, htrCtx.redSwitchNr)) { checkLimitsAndCtrlHeater(htrCtx); } diff --git a/mission/controller/ThermalController.h b/mission/controller/ThermalController.h index 9ad72ed0..d531e813 100644 --- a/mission/controller/ThermalController.h +++ b/mission/controller/ThermalController.h @@ -31,8 +31,8 @@ * limit is exceeded to avoid reaching NOP limit */ struct TempLimits { - TempLimits(float opLowerLimit, float cutOffLimit, float opUpperLimit, - float nopUpperLimit, float sanityUpperLimit) + TempLimits(float nopLowerLimit, float opLowerLimit, float cutOffLimit, float opUpperLimit, + float nopUpperLimit) : opLowerLimit(opLowerLimit), opUpperLimit(opUpperLimit), cutOffLimit(cutOffLimit), @@ -91,8 +91,8 @@ class ThermalController : public ExtendedControllerBase { public: static const uint16_t INVALID_TEMPERATURE = 999; static const uint8_t NUMBER_OF_SENSORS = 16; - static constexpr uint16_t SANITY_LIMIT_LOWER_TEMP = -80; - static constexpr uint16_t SANITY_LIMIT_UPPER_TEMP = 160; + static constexpr int16_t SANITY_LIMIT_LOWER_TEMP = -80; + static constexpr int16_t SANITY_LIMIT_UPPER_TEMP = 160; ThermalController(object_id_t objectId, HeaterHandler& heater); @@ -220,7 +220,7 @@ class ThermalController : public ExtendedControllerBase { lp_var_t tempAdcPayloadPcdu = lp_var_t(objects::PLPCDU_HANDLER, plpcdu::TEMP); // TempLimits - TempLimits acsBoardLimits = TempLimits(5-40.0, -40.0, 80.0, 85.0, 85.0); + TempLimits acsBoardLimits = TempLimits(-40.0, -40.0, 80.0, 85.0, 85.0); TempLimits mgtLimits = TempLimits(-40.0, -40.0, 65.0, 70.0, 70.0); TempLimits rwLimits = TempLimits(-40.0, -40.0, 80.0, 85.0, 85.0); TempLimits strLimits = TempLimits(-30.0, -20.0, 65.0, 70.0, 80.0); From a76074acf53d62ce1d15b5ad28804334cda3816e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 4 Apr 2023 17:53:38 +0200 Subject: [PATCH 3/3] changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 206b2fff..842ca54f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,11 @@ will consitute of a breaking change warranting a new major release: # [unreleased] +## Changed + +- TCS controller now does a sanity check on the temperature values: Values below -80 C or above + 160 C are ignored. + # [v1.43.0] 2023-04-04 - q7s-package: v2.4.0