From 3222a5b796cfbf2e4e95b32b5bd853c66b24ad00 Mon Sep 17 00:00:00 2001 From: Brian Mirletz Date: Mon, 9 Oct 2023 16:44:02 -0600 Subject: [PATCH] update resilience tests and fix voltage at 100 percent dod --- shared/lib_battery_voltage.cpp | 4 ++-- test/shared_test/lib_resilience_test.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/shared/lib_battery_voltage.cpp b/shared/lib_battery_voltage.cpp index 8b6e0d02f..8c53f3db7 100644 --- a/shared/lib_battery_voltage.cpp +++ b/shared/lib_battery_voltage.cpp @@ -190,8 +190,8 @@ double voltage_table_t::calculate_voltage(double DOD, double I) { row++; } // - if (DOD < tolerance) { - I = 0.0; // At full, current must go to zero + if (DOD < tolerance || DOD > 100. - tolerance) { + I = 0.0; // At full or empty, current must go to zero } return fmax(slopes[row] * DOD + intercepts[row], 0) - I * params->resistance; diff --git a/test/shared_test/lib_resilience_test.cpp b/test/shared_test/lib_resilience_test.cpp index 9d72619cb..8531e2220 100644 --- a/test/shared_test/lib_resilience_test.cpp +++ b/test/shared_test/lib_resilience_test.cpp @@ -329,13 +329,13 @@ TEST_F(ResilienceTest_lib_resilience, VoltageTable) cap.updateCapacity(current, 1); volt.updateVoltage(cap.q0(), cap.qmax(), cap.I(), 0, 0.); EXPECT_NEAR(cap.SOC(), 44.445, 1e-3); - EXPECT_NEAR(volt.cell_voltage(), 1.773, 1e-3); + EXPECT_NEAR(volt.cell_voltage(), 1.873, 1e-3); current = -1; cap.updateCapacity(current, 1); volt.updateVoltage(cap.q0(), cap.qmax(), cap.I(), 0, 0.); EXPECT_NEAR(cap.SOC(), 88.889, 1e-3); - EXPECT_NEAR(volt.cell_voltage(), 2.777, 1e-3); + EXPECT_NEAR(volt.cell_voltage(), 2.877, 1e-3); } TEST_F(ResilienceTest_lib_resilience, DischargeVoltageTable){ @@ -359,7 +359,7 @@ TEST_F(ResilienceTest_lib_resilience, DischargeVoltageTable){ cap.updateCapacity(req_cur, 1); volt.updateVoltage(cap.q0(), cap.qmax(), cap.I(), 0, 1); double v = volt.cell_voltage(); - EXPECT_NEAR(req_cur * v, 0.5, 1e-2); + EXPECT_NEAR(req_cur * v, 0.48, 1e-2); // test max discharge cap = capacity_lithium_ion_t(2.25, 50, 100, 0, 1); @@ -397,7 +397,7 @@ TEST_F(ResilienceTest_lib_resilience, ChargeVoltageTable){ cap.updateCapacity(req_cur, 1); volt.updateVoltage(cap.q0(), cap.qmax(), cap.I(), 0, 1); double v = volt.cell_voltage(); - EXPECT_NEAR(req_cur * v, -1.5, 1e-2); + EXPECT_NEAR(req_cur * v, -1.58, 1e-2); // test max charge double max_p = volt.calculate_max_charge_w(cap.q0(), cap.qmax(), 0, ¤t);