Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DC Power supply: Add charging phase information #803

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions interfaces/ISO15118_charger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ vars:
start_cable_check:
description: The charger should now start a cable check
type: "null"
start_pre_charge:
description: The charger should now start the pre charge phase
type: "null"
dc_open_contactor:
description: The contactor should be opened
type: "null"
Expand Down
9 changes: 8 additions & 1 deletion interfaces/power_supply_DC.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@ cmds:
setMode:
description: Set operation mode of the bidirectional DC power supply
arguments:
value:
mode:
description: Operation mode of power supply
type: string
$ref: /power_supply_DC#/Mode
phase:
description: >-
Charging phase for this mode change. This information should normally not be needed by the power supply,
as it should always just operate in CCCV mode. Some special setups however are handling CableCheck/PreCharge/Charge
a little bit different internally.
type: string
$ref: /power_supply_DC#/ChargingPhase
setExportVoltageCurrent:
description: Set output target voltage limit. Must be within reported limits.
arguments:
Expand Down
5 changes: 3 additions & 2 deletions modules/DPM1000/main/power_supply_DCImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,9 @@ void power_supply_DCImpl::ready() {
}
}

void power_supply_DCImpl::handle_setMode(types::power_supply_DC::Mode& value) {
if (value == types::power_supply_DC::Mode::Export) {
void power_supply_DCImpl::handle_setMode(types::power_supply_DC::Mode& mode,
types::power_supply_DC::ChargingPhase& phase) {
if (mode == types::power_supply_DC::Mode::Export) {
can_broker->set_state(true);
} else {
can_broker->set_state(false);
Expand Down
3 changes: 2 additions & 1 deletion modules/DPM1000/main/power_supply_DCImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class power_supply_DCImpl : public power_supply_DCImplBase {

protected:
// command handler functions (virtual)
virtual void handle_setMode(types::power_supply_DC::Mode& value) override;
virtual void handle_setMode(types::power_supply_DC::Mode& mode,
types::power_supply_DC::ChargingPhase& phase) override;
virtual void handle_setExportVoltageCurrent(double& voltage, double& current) override;
virtual void handle_setImportVoltageCurrent(double& voltage, double& current) override;

Expand Down
39 changes: 28 additions & 11 deletions modules/EvseManager/EvseManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,21 @@ void EvseManager::ready() {
r_hlc[0]->call_update_dc_present_values(present_values);

// Cable check for DC charging
r_hlc[0]->subscribe_start_cable_check([this] { cable_check(); });
r_hlc[0]->subscribe_start_cable_check([this] {
power_supply_DC_charging_phase = types::power_supply_DC::ChargingPhase::CableCheck;
cable_check();
});

// Cable check for DC charging
r_hlc[0]->subscribe_start_pre_charge(
[this] { power_supply_DC_charging_phase = types::power_supply_DC::ChargingPhase::PreCharge; });

// Notification that current demand has started
r_hlc[0]->subscribe_current_demand_started([this] {
charger->notify_currentdemand_started();
power_supply_DC_charging_phase = types::power_supply_DC::ChargingPhase::Charging;
current_demand_active = true;
apply_new_target_voltage_current();
charger->notify_currentdemand_started();
});

r_hlc[0]->subscribe_current_demand_finished([this] {
Expand Down Expand Up @@ -1500,8 +1509,9 @@ void EvseManager::cable_check() {

void EvseManager::powersupply_DC_on() {
if (not powersupply_dc_is_on) {
session_log.evse(false, "DC power supply: switch ON called");
r_powersupply_DC[0]->call_setMode(types::power_supply_DC::Mode::Export);
session_log.evse(false, "DC power supply: switch ON called, ChargingPhase: " +
types::power_supply_DC::charging_phase_to_string(power_supply_DC_charging_phase));
r_powersupply_DC[0]->call_setMode(types::power_supply_DC::Mode::Export, power_supply_DC_charging_phase);
powersupply_dc_is_on = true;
}
}
Expand All @@ -1513,6 +1523,9 @@ bool EvseManager::powersupply_DC_set(double _voltage, double _current) {
double current = _current;
static bool last_is_actually_exporting_to_grid{false};

const bool charging_phase_changed = last_power_supply_DC_charging_phase not_eq power_supply_DC_charging_phase;
last_power_supply_DC_charging_phase = power_supply_DC_charging_phase;

// Some cars always request integer ampere values, so if we offer 14.34A they will request 14.0A.
// On low power DC charging this makes quite a difference
// this option will deliver the offered ampere value in those cases
Expand All @@ -1529,12 +1542,13 @@ bool EvseManager::powersupply_DC_set(double _voltage, double _current) {

auto caps = get_powersupply_capabilities();

if ((config.hack_allow_bpt_with_iso2 or config.sae_j2847_2_bpt_enabled) and current_demand_active and
is_actually_exporting_to_grid) {
if ((((config.hack_allow_bpt_with_iso2 or config.sae_j2847_2_bpt_enabled) and is_actually_exporting_to_grid) or
charging_phase_changed) and
current_demand_active) {
if (not last_is_actually_exporting_to_grid) {
// switching from import from grid to export to grid
session_log.evse(false, "DC power supply: switch ON in import mode");
r_powersupply_DC[0]->call_setMode(types::power_supply_DC::Mode::Import);
r_powersupply_DC[0]->call_setMode(types::power_supply_DC::Mode::Import, power_supply_DC_charging_phase);
}
last_is_actually_exporting_to_grid = is_actually_exporting_to_grid;
// Hack: we are exporting to grid but are in ISO-2 mode
Expand Down Expand Up @@ -1565,11 +1579,13 @@ bool EvseManager::powersupply_DC_set(double _voltage, double _current) {

} else {

if ((config.hack_allow_bpt_with_iso2 or config.sae_j2847_2_bpt_enabled) and current_demand_active and
last_is_actually_exporting_to_grid) {
if ((((config.hack_allow_bpt_with_iso2 or config.sae_j2847_2_bpt_enabled) and
last_is_actually_exporting_to_grid) or
charging_phase_changed) and
current_demand_active) {
// switching from export to grid to import from grid
session_log.evse(false, "DC power supply: switch ON in export mode");
r_powersupply_DC[0]->call_setMode(types::power_supply_DC::Mode::Export);
r_powersupply_DC[0]->call_setMode(types::power_supply_DC::Mode::Export, power_supply_DC_charging_phase);
last_is_actually_exporting_to_grid = is_actually_exporting_to_grid;
}

Expand Down Expand Up @@ -1600,9 +1616,10 @@ bool EvseManager::powersupply_DC_set(double _voltage, double _current) {
}

void EvseManager::powersupply_DC_off() {
power_supply_DC_charging_phase = types::power_supply_DC::ChargingPhase::Other;
if (powersupply_dc_is_on) {
session_log.evse(false, "DC power supply OFF");
r_powersupply_DC[0]->call_setMode(types::power_supply_DC::Mode::Off);
r_powersupply_DC[0]->call_setMode(types::power_supply_DC::Mode::Off, power_supply_DC_charging_phase);
powersupply_dc_is_on = false;
}
}
Expand Down
6 changes: 6 additions & 0 deletions modules/EvseManager/EvseManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,12 @@ class EvseManager : public Everest::ModuleBase {
std::mutex powermeter_mutex;
std::condition_variable powermeter_cv;
bool initial_powermeter_value_received{false};

std::atomic<types::power_supply_DC::ChargingPhase> power_supply_DC_charging_phase{
types::power_supply_DC::ChargingPhase::Other};

types::power_supply_DC::ChargingPhase last_power_supply_DC_charging_phase{
types::power_supply_DC::ChargingPhase::Other};
// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1
};

Expand Down
1 change: 1 addition & 0 deletions modules/EvseV2G/din_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,7 @@ enum v2g_event din_handle_request(v2g_connection* conn) {
dlog(DLOG_LEVEL_TRACE, "Handling PreChargeReq");
conn->ctx->current_v2g_msg = V2G_PRE_CHARGE_MSG;
if (conn->ctx->last_v2g_msg == V2G_CABLE_CHECK_MSG) {
conn->ctx->p_charger->publish_start_pre_charge(nullptr);
dlog(DLOG_LEVEL_INFO, "Precharge-phase started");
}
exi_out->V2G_Message.Body.PreChargeRes_isUsed = 1u;
Expand Down
1 change: 1 addition & 0 deletions modules/EvseV2G/iso_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2123,6 +2123,7 @@ enum v2g_event iso_handle_request(v2g_connection* conn) {
conn->ctx->current_v2g_msg = V2G_PRE_CHARGE_MSG;
/* At first send mqtt charging phase signal to the customer interface */
if (conn->ctx->last_v2g_msg == V2G_CABLE_CHECK_MSG) {
conn->ctx->p_charger->publish_start_pre_charge(nullptr);
dlog(DLOG_LEVEL_INFO, "Precharge-phase started");
}

Expand Down
5 changes: 3 additions & 2 deletions modules/MicroMegaWattBSP/dc_supply/power_supply_DCImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ void power_supply_DCImpl::ready() {
publish_capabilities(caps);
}

void power_supply_DCImpl::handle_setMode(types::power_supply_DC::Mode& value) {
void power_supply_DCImpl::handle_setMode(types::power_supply_DC::Mode& mode,
types::power_supply_DC::ChargingPhase& phase) {
// your code for cmd setMode goes here
if (value == types::power_supply_DC::Mode::Export) {
if (mode == types::power_supply_DC::Mode::Export) {
mod->serial.setOutputVoltageCurrent(req_voltage, req_current);
is_on = true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class power_supply_DCImpl : public power_supply_DCImplBase {

protected:
// command handler functions (virtual)
virtual void handle_setMode(types::power_supply_DC::Mode& value) override;
virtual void handle_setMode(types::power_supply_DC::Mode& mode,
types::power_supply_DC::ChargingPhase& phase) override;
virtual void handle_setExportVoltageCurrent(double& voltage, double& current) override;
virtual void handle_setImportVoltageCurrent(double& voltage, double& current) override;

Expand Down
1 change: 0 additions & 1 deletion modules/simulation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
ev_add_module(DCSupplySimulator)
ev_add_module(IMDSimulator)
ev_add_module(JsEvManager)
ev_add_module(JsDCSupplySimulator)
ev_add_module(JsSlacSimulator)
ev_add_module(JsYetiSimulator)
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,26 @@ void power_supply_DCImpl::ready() {
publish_capabilities(get_capabilities_from_config(config));
}

void power_supply_DCImpl::handle_setMode(types::power_supply_DC::Mode& value) {
mode = value;
void power_supply_DCImpl::handle_setMode(types::power_supply_DC::Mode& _mode,
types::power_supply_DC::ChargingPhase& phase) {
mode = _mode;

EVLOG_info << "Set mode: " << types::power_supply_DC::mode_to_string(mode)
<< " ChargingPhase: " << types::power_supply_DC::charging_phase_to_string(phase);

std::scoped_lock access_lock(power_supply_values_mutex);
if ((value == types::power_supply_DC::Mode::Off) || (value == types::power_supply_DC::Mode::Fault)) {
if ((mode == types::power_supply_DC::Mode::Off) || (mode == types::power_supply_DC::Mode::Fault)) {
connector_voltage = 0.0;
connector_current = 0.0;
} else if (value == types::power_supply_DC::Mode::Export) {
} else if (mode == types::power_supply_DC::Mode::Export) {
connector_voltage = settings_connector_export_voltage;
connector_current = settings_connector_max_export_current;
} else if (value == types::power_supply_DC::Mode::Import) {
} else if (mode == types::power_supply_DC::Mode::Import) {
connector_voltage = settings_connector_import_voltage;
connector_current = settings_connector_max_import_current;
}

mod->p_main->publish_mode(value);
mod->p_main->publish_mode(mode);
}

void power_supply_DCImpl::clampVoltageCurrent(double& voltage, double& current) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class power_supply_DCImpl : public power_supply_DCImplBase {

protected:
// command handler functions (virtual)
virtual void handle_setMode(types::power_supply_DC::Mode& value) override;
virtual void handle_setMode(types::power_supply_DC::Mode& mode,
types::power_supply_DC::ChargingPhase& phase) override;
virtual void handle_setExportVoltageCurrent(double& voltage, double& current) override;
virtual void handle_setImportVoltageCurrent(double& voltage, double& current) override;

Expand Down
Empty file.
Loading
Loading