Skip to content

Commit

Permalink
Some DC fixes (#481)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
corneliusclaussen authored Dec 26, 2023
1 parent 6baeb91 commit d0c77e0
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 30 deletions.
11 changes: 9 additions & 2 deletions modules/DPM1000/main/power_supply_DCImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions modules/DPM1000/main/power_supply_DCImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
40 changes: 23 additions & 17 deletions modules/EnergyManager/BrokerFastCharging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
17 changes: 9 additions & 8 deletions modules/EvseManager/Charger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 0 additions & 3 deletions modules/EvseManager/EvseManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d0c77e0

Please sign in to comment.