From d0c77e08a9385cb6a706605994667c48f1d49cdf Mon Sep 17 00:00:00 2001 From: corneliusclaussen <62659547+corneliusclaussen@users.noreply.github.com> Date: Tue, 26 Dec 2023 17:16:48 +0100 Subject: [PATCH] Some DC fixes (#481) * Fix energymanagement for DC at startup for 0W * Legacy wakeup only for AC, do not reset SLAC twice on startup * Fix DPM1000 current reporting * fix type; add .value to total_power --------- Signed-off-by: Cornelius Claussen --- modules/DPM1000/main/power_supply_DCImpl.cpp | 11 +++++- modules/DPM1000/main/power_supply_DCImpl.hpp | 1 + modules/EnergyManager/BrokerFastCharging.cpp | 40 +++++++++++--------- modules/EvseManager/Charger.cpp | 17 +++++---- modules/EvseManager/EvseManager.cpp | 3 -- 5 files changed, 42 insertions(+), 30 deletions(-) diff --git a/modules/DPM1000/main/power_supply_DCImpl.cpp b/modules/DPM1000/main/power_supply_DCImpl.cpp index ad58223d4..58c30cb94 100644 --- a/modules/DPM1000/main/power_supply_DCImpl.cpp +++ b/modules/DPM1000/main/power_supply_DCImpl.cpp @@ -121,10 +121,13 @@ void power_supply_DCImpl::init() { if (mod->config.series_parallel_mode == "Series") { series_parallel_mode = 1050.; config_min_voltage_limit = 300.; + parallel_mode = false; } else if (mod->config.series_parallel_mode == "Parallel") { series_parallel_mode = 520.; - if (config_voltage_limit > 520) + if (config_voltage_limit > 520) { config_voltage_limit = 520; + } + parallel_mode = true; } // WTF: This really uses a float to set one of the three modes automatic, series or parallel. @@ -169,7 +172,11 @@ void power_supply_DCImpl::ready() { } // Publish voltage and current var - vc.current_A = tmp * 100.; + // Current scaling depends on series/parallel mode operation. + vc.current_A = tmp; + if (parallel_mode) { + vc.current_A *= 2.; + } publish_voltage_current(vc); // read alarm flags diff --git a/modules/DPM1000/main/power_supply_DCImpl.hpp b/modules/DPM1000/main/power_supply_DCImpl.hpp index 37c4d16c1..31e406f2a 100644 --- a/modules/DPM1000/main/power_supply_DCImpl.hpp +++ b/modules/DPM1000/main/power_supply_DCImpl.hpp @@ -62,6 +62,7 @@ class power_supply_DCImpl : public power_supply_DCImplBase { float config_min_voltage_limit{50.}; Everest::Gpio discharge_gpio; + bool parallel_mode{false}; // ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1 }; diff --git a/modules/EnergyManager/BrokerFastCharging.cpp b/modules/EnergyManager/BrokerFastCharging.cpp index cd154fb67..1db1d84f1 100644 --- a/modules/EnergyManager/BrokerFastCharging.cpp +++ b/modules/EnergyManager/BrokerFastCharging.cpp @@ -194,24 +194,30 @@ bool BrokerFastCharging::buy_ampere(const types::energy::ScheduleReqEntry& _offe // we have an additional watt limit if (total_power.has_value()) { - // is the watt limit high enough? - if (total_power.value() >= max_current.value() * max_phases * local_market.nominal_ac_voltage()) { - // yes, buy both ampere and watt - // EVLOG_info << "[OK leftovers] total power is big enough for trade of " - // << a * max_phases * local_market.nominal_ac_voltage(); - buy_ampere_unchecked(index, (import ? +1 : -1) * max_current.value()); - buy_watt_unchecked(index, (import ? +1 : -1) * max_current.value() * max_phases * - local_market.nominal_ac_voltage()); - return true; + if (total_power.value() > 0) { + // is the watt limit high enough? + if (total_power.value() >= max_current.value() * max_phases * local_market.nominal_ac_voltage()) { + // yes, buy both ampere and watt + // EVLOG_info << "[OK leftovers] total power is big enough for trade of " + // << a * max_phases * local_market.nominal_ac_voltage(); + buy_ampere_unchecked(index, (import ? +1 : -1) * max_current.value()); + buy_watt_unchecked(index, (import ? +1 : -1) * max_current.value() * max_phases * + local_market.nominal_ac_voltage()); + return true; + } else { + // watt limit is lower, try to reduce ampere + float reduced_ampere = total_power.value() / max_phases / local_market.nominal_ac_voltage(); + // EVLOG_info << "[OK leftovers] total power is not big enough, buy reduced current " << + // reduced_ampere + // << reduced_ampere * max_phases * local_market.nominal_ac_voltage(); + buy_ampere_unchecked(index, (import ? +1 : -1) * reduced_ampere); + buy_watt_unchecked(index, (import ? +1 : -1) * reduced_ampere * max_phases * + local_market.nominal_ac_voltage()); + return true; + } } else { - // watt limit is lower, try to reduce ampere - float reduced_ampere = total_power.value() / max_phases / local_market.nominal_ac_voltage(); - // EVLOG_info << "[OK leftovers] total power is not big enough, buy reduced current " << reduced_ampere - // << reduced_ampere * max_phases * local_market.nominal_ac_voltage(); - buy_ampere_unchecked(index, (import ? +1 : -1) * reduced_ampere); - buy_watt_unchecked(index, (import ? +1 : -1) * reduced_ampere * max_phases * - local_market.nominal_ac_voltage()); - return true; + // Don't buy anything if the total power limit is 0 + return false; } } else { buy_ampere_unchecked(index, (import ? +1 : -1) * max_current.value()); diff --git a/modules/EvseManager/Charger.cpp b/modules/EvseManager/Charger.cpp index 33869ecb3..33177a3d9 100644 --- a/modules/EvseManager/Charger.cpp +++ b/modules/EvseManager/Charger.cpp @@ -423,15 +423,16 @@ void Charger::runStateMachine() { pauseChargingWaitForPower(); } } - } - if (!hlc_charging_active && !legacy_wakeup_done && timeInCurrentState > legacy_wakeup_timeout) { - session_log.evse( - false, "EV did not transition to state C, trying one legacy wakeup according to IEC61851-1 A.5.3"); - legacy_wakeup_done = true; - t_step_EF_returnState = EvseState::PrepareCharging; - t_step_EF_returnPWM = ampereToDutyCycle(getMaxCurrent()); - currentState = EvseState::T_step_EF; + if (!hlc_charging_active && !legacy_wakeup_done && timeInCurrentState > legacy_wakeup_timeout) { + session_log.evse( + false, + "EV did not transition to state C, trying one legacy wakeup according to IEC61851-1 A.5.3"); + legacy_wakeup_done = true; + t_step_EF_returnState = EvseState::PrepareCharging; + t_step_EF_returnPWM = ampereToDutyCycle(getMaxCurrent()); + currentState = EvseState::T_step_EF; + } } // if (charge_mode == ChargeMode::DC) { diff --git a/modules/EvseManager/EvseManager.cpp b/modules/EvseManager/EvseManager.cpp index 8a04541c1..53202a576 100644 --- a/modules/EvseManager/EvseManager.cpp +++ b/modules/EvseManager/EvseManager.cpp @@ -654,9 +654,6 @@ void EvseManager::ready() { } if (slac_enabled) { - // Reset once on startup and disable modem - r_slac[0]->call_reset(false); - r_slac[0]->subscribe_state([this](const std::string& s) { session_log.evse(true, fmt::format("SLAC {}", s)); // Notify charger whether matching was started (or is done) or not