Skip to content

Commit

Permalink
Throw an error if duplicate entries in the voltage table produce zero…
Browse files Browse the repository at this point in the history
… slope
  • Loading branch information
brtietz committed May 4, 2023
1 parent 4e0a4ca commit cd6fbe6
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions shared/lib_battery_voltage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ void voltage_table_t::initialize() {
double V0 = params->voltage_table[i - 1][1];
slope = (V - V0) / (DOD - DOD0);
intercept = V0 - (slope * DOD0);

if (fabs(slope) < 1e-7)
throw std::runtime_error("voltage_table_t error: Battery voltage matrix cannot have two identical voltages.");
}
slopes.emplace_back(slope);
intercepts.emplace_back(intercept);
Expand Down

0 comments on commit cd6fbe6

Please sign in to comment.