From 209e0c68fb990f2e43d7faaf921ef597ad41e721 Mon Sep 17 00:00:00 2001 From: meggert Date: Tue, 26 Sep 2023 11:56:04 +0200 Subject: [PATCH] fixes --- mission/controller/PowerController.cpp | 19 +++++++++++++------ mission/power/defs.h | 3 +-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/mission/controller/PowerController.cpp b/mission/controller/PowerController.cpp index c47e2c21..1e45a902 100644 --- a/mission/controller/PowerController.cpp +++ b/mission/controller/PowerController.cpp @@ -150,6 +150,8 @@ void PowerController::calculateStateOfCharge() { pwrCtrlCoreHk.setValidity(false, true); } } + // store time for next run + oldTime = now; return; } @@ -171,12 +173,12 @@ void PowerController::calculateStateOfCharge() { pwrCtrlCoreHk.coulombCounterCharge.setValid(false); } } + // store time for next run + oldTime = now; return; } result = calculateCoulombCounterCharge(); - // store time for next run - oldTime = now; if (result != returnvalue::OK) { // notifying events have already been triggered { @@ -191,6 +193,8 @@ void PowerController::calculateStateOfCharge() { pwrCtrlCoreHk.coulombCounterCharge.setValid(false); } } + // store time for next run + oldTime = now; return; } @@ -204,6 +208,8 @@ void PowerController::calculateStateOfCharge() { pwrCtrlCoreHk.setValidity(true, true); } } + // store time for next run + oldTime = now; } void PowerController::watchStateOfCharge() { @@ -231,13 +237,14 @@ ReturnValue_t PowerController::calculateCoulombCounterCharge() { sif::error << "Power Controller::Time delta too large for Coulomb Counter" << std::endl; return returnvalue::FAILED; } - if ((not pwrCtrlCoreHk.coulombCounterCharge.isValid()) or - (bpxBatteryHk.battVoltage.value > coulombCounterVoltageUpperThreshold and - pwrCtrlCoreHk.coulombCounterCharge.value >= coulombCounterChargeUpperThreshold)) { + if (not pwrCtrlCoreHk.coulombCounterCharge.isValid()) { coulombCounterCharge = openCircuitVoltageCharge; } else { coulombCounterCharge = coulombCounterCharge + iBat * CONVERT_FROM_MILLI * timeDiff * SECONDS_TO_HOURS; + if (coulombCounterCharge >= coulombCounterChargeUpperThreshold) { + coulombCounterCharge = coulombCounterChargeUpperThreshold; + } } return returnvalue::OK; } @@ -261,7 +268,7 @@ ReturnValue_t PowerController::updateEpsData() { } float PowerController::charge2stateOfCharge(float capacity) { - return capacity / batteryMaximumCapacity; + return capacity / coulombCounterChargeUpperThreshold; } float PowerController::linearInterpolation(float x, float x0, float x1, float y0, float y1) { diff --git a/mission/power/defs.h b/mission/power/defs.h index 87fc3f08..375aaf6e 100644 --- a/mission/power/defs.h +++ b/mission/power/defs.h @@ -54,8 +54,7 @@ static constexpr Event DATASET_READ_FAILED = event::makeEvent(SUBSYSTEM_ID, 4, s //! P1: 1 too high, 0 too low static constexpr Event VOLTAGE_OUT_OF_BOUNDS = event::makeEvent(SUBSYSTEM_ID, 5, severity::HIGH); //! [EXPORT] : [COMMENT] Time difference for Coulomb Counter was too large. -static constexpr Event TIMEDELTA_OUT_OF_BOUNDS = - event::makeEvent(SUBSYSTEM_ID, 6, severity::MEDIUM); +static constexpr Event TIMEDELTA_OUT_OF_BOUNDS = event::makeEvent(SUBSYSTEM_ID, 6, severity::LOW); enum class States { IDLE, SWITCHING_POWER, CHECKING_POWER, MODE_COMMANDING }; enum class OpCodes { NONE, TO_OFF_DONE, TO_NOT_OFF_DONE, TIMEOUT_OCCURED };