SoC Calculator #754

Merged
muellerr merged 74 commits from soc-calculator into main 2023-10-11 10:50:48 +02:00
2 changed files with 10 additions and 8 deletions
Showing only changes of commit 0ad3f508a9 - Show all commits

View File

@ -212,7 +212,7 @@ void PowerController::watchStateOfCharge() {
ReturnValue_t PowerController::calculateOpenCircuitVoltageCharge() {
float vBatCorrected =
(bpxBatteryHk.battVoltage.value - iBat * batteryInternalResistance) * MILLIVOLT2VOLT;
(bpxBatteryHk.battVoltage.value - iBat * batteryInternalResistance) * CONVERT_FROM_MILLI;
uint8_t lookUpTableIdx = LOOK_UP_TABLE_MAX_IDX;
ReturnValue_t result = lookUpTableOcvIdxFinder(vBatCorrected, lookUpTableIdx);
if (result != returnvalue::OK) {
@ -236,7 +236,8 @@ ReturnValue_t PowerController::calculateCoulombCounterCharge() {
pwrCtrlCoreHk.coulombCounterCharge.value >= coulombCounterChargeUpperThreshold)) {
coulombCounterCharge = openCircuitVoltageCharge;
} else {
coulombCounterCharge = pwrCtrlCoreHk.coulombCounterCharge.value + iBat * timeDiff;
coulombCounterCharge =
coulombCounterCharge + iBat * CONVERT_FROM_MILLI * timeDiff * SECONDS_TO_HOURS;
}
return returnvalue::OK;
}

View File

@ -58,7 +58,7 @@ class PowerController : public ExtendedControllerBase, public ReceivesParameterM
float coulombCounterVoltageUpperThreshold = 16.2e3; // [mV]
double maxAllowedTimeDiff = 0.5; // [s]
// OCV Look-up-Table
// OCV Look-up-Table {[Ah],[V]}
static constexpr uint8_t LOOK_UP_TABLE_MAX_IDX = 99;
float lookUpTableOcv[2][100] = {
{0.00000000e+00, 3.16227766e-04, 4.52809661e-04, 6.48382625e-04, 9.28425483e-04,
@ -100,12 +100,13 @@ class PowerController : public ExtendedControllerBase, public ReceivesParameterM
// Variables
timeval now;
timeval oldTime;
int16_t iBat = 0.0; // [mA]
float openCircuitVoltageCharge = 0.0; // [mC]
float coulombCounterCharge = 0; // [mC]
float coulombCounterChargeUpperThreshold = 0.0; // [mC]
int16_t iBat = 0; // [mA]
float openCircuitVoltageCharge = 0.0; // [Ah]
float coulombCounterCharge = 0.0; // [Ah]
float coulombCounterChargeUpperThreshold = 0.0; // [Ah]
static constexpr float MILLIVOLT2VOLT = 1e-3;
static constexpr float CONVERT_FROM_MILLI = 1e-3;
static constexpr float SECONDS_TO_HOURS = 1. / (60. * 60.);
static constexpr int16_t INVALID_TOTAL_BATTERY_CURRENT = 0;
static constexpr float INVALID_SOC = -1;