SoC Calculator #754

Merged
muellerr merged 74 commits from soc-calculator into main 2023-10-11 10:50:48 +02:00
Showing only changes of commit 5f9247ee1e - Show all commits

View File

@ -48,6 +48,7 @@ ReturnValue_t PowerController::getParameter(uint8_t domainId, uint8_t parameterI
ReturnValue_t result = calculateCoulombCounterChargeUpperThreshold(); ReturnValue_t result = calculateCoulombCounterChargeUpperThreshold();
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
coulombCounterVoltageUpperThreshold = oldCoulombCounterVoltageUpperThreshold; coulombCounterVoltageUpperThreshold = oldCoulombCounterVoltageUpperThreshold;
return returnvalue::FAILED;
} }
break; break;
} }
@ -268,7 +269,7 @@ ReturnValue_t PowerController::calculateOpenCircuitVoltageCharge() {
float vBatCorrected = float vBatCorrected =
(bpxBatteryHk.battVoltage.value - iBat * batteryInternalResistance) * CONVERT_FROM_MILLI; (bpxBatteryHk.battVoltage.value - iBat * batteryInternalResistance) * CONVERT_FROM_MILLI;
uint8_t lookUpTableIdx = LOOK_UP_TABLE_MAX_IDX; uint8_t lookUpTableIdx = LOOK_UP_TABLE_MAX_IDX;
ReturnValue_t result = lookUpTableOcvIdxFinder(vBatCorrected, lookUpTableIdx); ReturnValue_t result = lookUpTableOcvIdxFinder(vBatCorrected, lookUpTableIdx, false);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
@ -328,16 +329,16 @@ float PowerController::linearInterpolation(float x, float x0, float x1, float y0
return y0 + (x - x0) * (y1 - y0) / (x1 - x0); return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
} }
ReturnValue_t PowerController::lookUpTableOcvIdxFinder(float voltage, uint8_t &idx) { ReturnValue_t PowerController::lookUpTableOcvIdxFinder(float voltage, uint8_t &idx, bool paramCmd) {
if (voltage >= lookUpTableOcv[1][99]) { if (voltage >= lookUpTableOcv[1][99]) {
if (not voltageOutOfBoundsFlag) { if (not voltageOutOfBoundsFlag and not paramCmd) {
triggerEvent(power::VOLTAGE_OUT_OF_BOUNDS, 0, static_cast<uint32_t>(voltage * 10)); triggerEvent(power::VOLTAGE_OUT_OF_BOUNDS, 0, static_cast<uint32_t>(voltage * 10));
voltageOutOfBoundsFlag = true; voltageOutOfBoundsFlag = true;
} }
sif::error << "Power Controller::Voltage is too high: " << voltage << std::endl; sif::error << "Power Controller::Voltage is too high: " << voltage << std::endl;
return returnvalue::FAILED; return returnvalue::FAILED;
} else if (voltage <= lookUpTableOcv[1][0]) { } else if (voltage <= lookUpTableOcv[1][0]) {
if (not voltageOutOfBoundsFlag) { if (not voltageOutOfBoundsFlag and not paramCmd) {
triggerEvent(power::VOLTAGE_OUT_OF_BOUNDS, 1, static_cast<uint32_t>(voltage * 10)); triggerEvent(power::VOLTAGE_OUT_OF_BOUNDS, 1, static_cast<uint32_t>(voltage * 10));
voltageOutOfBoundsFlag = true; voltageOutOfBoundsFlag = true;
} }
@ -354,7 +355,7 @@ ReturnValue_t PowerController::lookUpTableOcvIdxFinder(float voltage, uint8_t &i
ReturnValue_t PowerController::calculateCoulombCounterChargeUpperThreshold() { ReturnValue_t PowerController::calculateCoulombCounterChargeUpperThreshold() {
uint8_t lookUpTableIdx = LOOK_UP_TABLE_MAX_IDX; uint8_t lookUpTableIdx = LOOK_UP_TABLE_MAX_IDX;
ReturnValue_t result = ReturnValue_t result =
lookUpTableOcvIdxFinder(coulombCounterVoltageUpperThreshold, lookUpTableIdx); lookUpTableOcvIdxFinder(coulombCounterVoltageUpperThreshold, lookUpTableIdx, true);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }