From 7b580467ef23949c2c12284c0e7a82c650a8f8c2 Mon Sep 17 00:00:00 2001 From: florinmihut Date: Mon, 16 Dec 2024 16:23:16 +0100 Subject: [PATCH 1/3] Introduce EVSE Manager configuration option for failing charging if the powermeter has errors Signed-off-by: florinmihut --- modules/EvseManager/ErrorHandling.cpp | 23 ++++++++++++++++++++--- modules/EvseManager/ErrorHandling.hpp | 5 ++++- modules/EvseManager/EvseManager.cpp | 7 ++++++- modules/EvseManager/EvseManager.hpp | 6 +++--- modules/EvseManager/manifest.yaml | 13 +++++++++---- 5 files changed, 42 insertions(+), 12 deletions(-) diff --git a/modules/EvseManager/ErrorHandling.cpp b/modules/EvseManager/ErrorHandling.cpp index 2f6ac049e..f27b4920f 100644 --- a/modules/EvseManager/ErrorHandling.cpp +++ b/modules/EvseManager/ErrorHandling.cpp @@ -15,6 +15,7 @@ static const struct IgnoreErrors { ErrorList ac_rcd{"ac_rcd/VendorWarning"}; ErrorList imd{"isolation_monitor/VendorWarning"}; ErrorList powersupply{"power_supply_DC/VendorWarning"}; + ErrorList powermeter{}; } ignore_errors; ErrorHandling::ErrorHandling(const std::unique_ptr& _r_bsp, @@ -23,14 +24,16 @@ ErrorHandling::ErrorHandling(const std::unique_ptr& _r_b const std::vector>& _r_ac_rcd, const std::unique_ptr& _p_evse, const std::vector>& _r_imd, - const std::vector>& _r_powersupply) : + const std::vector>& _r_powersupply, + const std::vector>& _r_powermeter) : r_bsp(_r_bsp), r_hlc(_r_hlc), r_connector_lock(_r_connector_lock), r_ac_rcd(_r_ac_rcd), p_evse(_p_evse), r_imd(_r_imd), - r_powersupply(_r_powersupply) { + r_powersupply(_r_powersupply), + r_powermeter(_r_powermeter) { // Subscribe to bsp driver to receive Errors from the bsp hardware r_bsp->subscribe_all_errors([this](const Everest::error::Error& error) { process_error(); }, @@ -59,6 +62,12 @@ ErrorHandling::ErrorHandling(const std::unique_ptr& _r_b r_powersupply[0]->subscribe_all_errors([this](const Everest::error::Error& error) { process_error(); }, [this](const Everest::error::Error& error) { process_error(); }); } + + // Subscribe to powermeter to receive errors from powermeter hardware + if (r_powermeter.size() > 0) { + r_powermeter[0]->subscribe_all_errors([this](const Everest::error::Error& error) { process_error(); }, + [this](const Everest::error::Error& error) { process_error(); }); + } } void ErrorHandling::raise_overcurrent_error(const std::string& description) { @@ -102,7 +111,8 @@ void ErrorHandling::process_error() { const int error_count = p_evse->error_state_monitor->get_active_errors().size() + r_bsp->error_state_monitor->get_active_errors().size() + number_of_active_errors(r_connector_lock) + number_of_active_errors(r_ac_rcd) + - number_of_active_errors(r_imd) + number_of_active_errors(r_powersupply); + number_of_active_errors(r_imd) + number_of_active_errors(r_powersupply) + + number_of_active_errors(r_powermeter); if (error_count == 0) { signal_all_errors_cleared(); @@ -159,6 +169,13 @@ std::optional ErrorHandling::errors_prevent_charging() { } } + if (r_powermeter.size() > 0) { + fatal = is_fatal(r_powermeter[0]->error_state_monitor->get_active_errors(), ignore_errors.powermeter); + if (fatal) { + return fatal; + } + } + return std::nullopt; } diff --git a/modules/EvseManager/ErrorHandling.hpp b/modules/EvseManager/ErrorHandling.hpp index 8db687eaf..056c4a757 100644 --- a/modules/EvseManager/ErrorHandling.hpp +++ b/modules/EvseManager/ErrorHandling.hpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include "Timeout.hpp" @@ -47,7 +48,8 @@ class ErrorHandling { const std::vector>& r_ac_rcd, const std::unique_ptr& _p_evse, const std::vector>& _r_imd, - const std::vector>& _r_powersupply); + const std::vector>& _r_powersupply, + const std::vector>& _r_powermeter); // Signal that error set has changed. Bool argument is true if it is preventing charging at the moment and false if // charging can continue. @@ -77,6 +79,7 @@ class ErrorHandling { const std::unique_ptr& p_evse; const std::vector>& r_imd; const std::vector>& r_powersupply; + const std::vector>& r_powermeter; }; } // namespace module diff --git a/modules/EvseManager/EvseManager.cpp b/modules/EvseManager/EvseManager.cpp index 3a15f2722..19ecfe00f 100644 --- a/modules/EvseManager/EvseManager.cpp +++ b/modules/EvseManager/EvseManager.cpp @@ -161,8 +161,13 @@ void EvseManager::ready() { bsp->set_ev_simplified_mode_evse_limit(true); } + // we provide the powermeter interface to the ErrorHandling only if we need to react to powermeter errors + // otherwise we provide an empty vector of pointers to the powermeter interface + const std::vector> empty; error_handling = std::unique_ptr( - new ErrorHandling(r_bsp, r_hlc, r_connector_lock, r_ac_rcd, p_evse, r_imd, r_powersupply_DC)); + new ErrorHandling(r_bsp, r_hlc, r_connector_lock, r_ac_rcd, p_evse, r_imd, r_powersupply_DC, + config.fail_on_powermeter_errors ? r_powermeter_billing() : empty)); + if (not config.lock_connector_in_state_b) { EVLOG_warning << "Unlock connector in CP state B. This violates IEC61851-1:2019 D.6.5 Table D.9 line 4 and " "should not be used in public environments!"; diff --git a/modules/EvseManager/EvseManager.hpp b/modules/EvseManager/EvseManager.hpp index fc4ba9825..0a2728ff8 100644 --- a/modules/EvseManager/EvseManager.hpp +++ b/modules/EvseManager/EvseManager.hpp @@ -102,6 +102,7 @@ struct Conf { int soft_over_current_timeout_ms; bool lock_connector_in_state_b; int state_F_after_fault_ms; + bool fail_on_powermeter_errors; }; class EvseManager : public Everest::ModuleBase { @@ -136,8 +137,7 @@ class EvseManager : public Everest::ModuleBase { r_imd(std::move(r_imd)), r_powersupply_DC(std::move(r_powersupply_DC)), r_store(std::move(r_store)), - config(config) { - } + config(config){}; Everest::MqttProvider& mqtt; Everest::TelemetryProvider& telemetry; @@ -194,7 +194,7 @@ class EvseManager : public Everest::ModuleBase { const std::vector>& r_powermeter_billing(); - // FIXME: this will be removed with proper intergration of BPT on ISO-20 + // FIXME: this will be removed with proper integration of BPT on ISO-20 // on DIN SPEC and -2 we claim a positive charging current on ISO protocol, // but the power supply switches to discharge if this flag is set. std::atomic_bool is_actually_exporting_to_grid{false}; diff --git a/modules/EvseManager/manifest.yaml b/modules/EvseManager/manifest.yaml index 1c912d700..d51abe96f 100644 --- a/modules/EvseManager/manifest.yaml +++ b/modules/EvseManager/manifest.yaml @@ -192,7 +192,7 @@ config: default: 0.5 hack_fix_hlc_integer_current_requests: description: >- - Some cars request only integer ampere values during DC charging. For low power DC charging that + Some cars request only integer ampere values during DC charging. For low power DC charging that means that they charge a few hundred watts slower then needed. If enabled, this will charge at full power if the difference between EV requested current (integer) and HLC current limit is less then 1.0 type: boolean @@ -257,8 +257,8 @@ config: default: 10 switch_3ph1ph_cp_state: description: >- - CP state to use for switching. - WARNING: Some EVs may be permanently destroyed when switching from 1ph to 3ph. + CP state to use for switching. + WARNING: Some EVs may be permanently destroyed when switching from 1ph to 3ph. It is the responsibiltiy of the evse_board_support implementation to ensure the EV is capable of performing the switch. If it is not, the capabilities must set the supports_changing_phases_during_charging to false. Phase switching is only possible in basic charging mode. @@ -283,7 +283,7 @@ config: description: >- Set state F after any fault that stops charging for the specified time in ms while in Charging mode (CX->F(300ms)->C1/B1). When a fault occurs in state B2, no state F is added (B2->B1 on fault). - Some (especially older hybrid vehicles) may go into a permanent fault mode once they detect state F, + Some (especially older hybrid vehicles) may go into a permanent fault mode once they detect state F, in this case EVerest cannot recover the charging session if the fault is cleared. In this case you can set this parameter to 0, which will avoid to use state F in case of a fault and only disables PWM (C2->C1) while switching off power. This will violate IEC 61851-1:2017 however. @@ -291,6 +291,11 @@ config: This setting is only active in BASIC charging mode. type: integer default: 300 + fail_on_powermeter_errors: + description: >- + Set the EVSE Manager as inoperable if the powermeter is configured and has errors + type: boolean + default: false provides: evse: interface: evse_manager From 1f08b5a514069c43dbc9acdfab083576bc9fc317 Mon Sep 17 00:00:00 2001 From: florinmihut Date: Wed, 18 Dec 2024 17:57:24 +0100 Subject: [PATCH 2/3] Add behavior in the error handling document Signed-off-by: florinmihut --- modules/EvseManager/doc.rst | 125 +++++++++++++++++++----------------- 1 file changed, 65 insertions(+), 60 deletions(-) diff --git a/modules/EvseManager/doc.rst b/modules/EvseManager/doc.rst index 4fb00fc31..08927b586 100644 --- a/modules/EvseManager/doc.rst +++ b/modules/EvseManager/doc.rst @@ -6,20 +6,20 @@ EvseManager See also module's :ref:`auto-generated reference `. -The module ``EvseManager`` is a central module that manages one EVSE +The module ``EvseManager`` is a central module that manages one EVSE (i.e. one connector to charge a car). It may control multiple physical connectors if they are not usable at the same time and share one connector id, -but one EvseManager always shows as one connector in OCPP for example. So in +but one EvseManager always shows as one connector in OCPP for example. So in general each connector should have a dedicated EvseManager module loaded. -The EvseManager contains the high level charging logic (Basic charging and -HLC/SLAC interaction), collects all relevant data for the charging session -(e.g. energy delivered during this charging session) and provides control over -the charging port/session. For HLC it uses two helper protocol modules that it +The EvseManager contains the high level charging logic (Basic charging and +HLC/SLAC interaction), collects all relevant data for the charging session +(e.g. energy delivered during this charging session) and provides control over +the charging port/session. For HLC it uses two helper protocol modules that it controls (SLAC and ISO15118). -Protocol modules such as OCPP or other APIs use EvseManagers to control the +Protocol modules such as OCPP or other APIs use EvseManagers to control the charging session and get all relevant data. The following charge modes are supported: @@ -32,7 +32,7 @@ Additional features: * Autocharge support (PnC coming soon) * Seamlessly integrates into EVerest Energy Management -* The lowest level IEC61851 state machine can be run on a dedicated +* The lowest level IEC61851 state machine can be run on a dedicated microcontroller for improved electrical safety * Support for seperate AC and DC side metering in DC application @@ -47,18 +47,18 @@ AC Configuration DC Configuration ---------------- -In DC applications, the EvseManager still has an AC side that behaves similar -to a normal AC charger. The board_support module therefore still has to report +In DC applications, the EvseManager still has an AC side that behaves similar +to a normal AC charger. The board_support module therefore still has to report AC capabilities which refer to the AC input of the AC/DC power supply. If an AC -side RCD is used it also belongs to the board_support driver. -An AC side power meter can be connected and it will be used for Energy +side RCD is used it also belongs to the board_support driver. +An AC side power meter can be connected and it will be used for Energy management. In addition, on the DC side the following hardware modules can be connected: -* A DC powermeter: This will be used for billing purposes if present. +* A DC powermeter: This will be used for billing purposes if present. If not connected, billing will fall back to the AC side power meter. -* Isolation monitoring: This will be used to monitor isolation during +* Isolation monitoring: This will be used to monitor isolation during CableCheck, PreCharge and CurrentDemand steps. * DC power supply: This is the AC/DC converter that actually charges the car. @@ -68,16 +68,16 @@ Published variables session_events -------------- -EvseManager publishes the session_events variable whenever an event happens. -It does not publish its internal state but merely events that happen that can +EvseManager publishes the session_events variable whenever an event happens. +It does not publish its internal state but merely events that happen that can be used to drive an state machine within another module. -Example: Write a simple module that lights up an LED if the evse is reserved. -This module requires an EvseManager and subscribes to the session_events -variable. Internally it has only two states: Reserved (LED on), NotReserved +Example: Write a simple module that lights up an LED if the evse is reserved. +This module requires an EvseManager and subscribes to the session_events +variable. Internally it has only two states: Reserved (LED on), NotReserved (LED off). -The state machine transitions are driven by the two events from EvseManager: +The state machine transitions are driven by the two events from EvseManager: ReservationStart and ReservationEnd. All other events are ignored in this module as they are not needed. @@ -85,10 +85,10 @@ All other events are ignored in this module as they are not needed. powermeter ---------- -EvseManager republishes the power meter struct that if it has a powermeter -connected. This struct should be used for OCPP and display purposes. It comes -from the power meter that can be used for billing (DC side on DC, AC side on -AC). If no powermeter is connected EvseManager will never publish this +EvseManager republishes the power meter struct that if it has a powermeter +connected. This struct should be used for OCPP and display purposes. It comes +from the power meter that can be used for billing (DC side on DC, AC side on +AC). If no powermeter is connected EvseManager will never publish this variable. @@ -96,9 +96,9 @@ Authentication ============== The Auth modules validates tokens and assignes tokens to EvseManagers, see Auth -documentation. It will call ``Authorize(id_tag, pnc)`` on EvseManager to -indicated that the EvseManager may start the charging session. -Auth module may revoke authorization (``withdraw_authorization`` command) if +documentation. It will call ``Authorize(id_tag, pnc)`` on EvseManager to +indicated that the EvseManager may start the charging session. +Auth module may revoke authorization (``withdraw_authorization`` command) if the charging session has not begun yet (typically due to timeout), but not once charging has started. @@ -107,79 +107,79 @@ Autocharge / PnC ---------------- Autocharge is fully supported, PnC support is coming soon and will use the same -logic. The car itself is a token provider that can provide an auth token to be -validated by the Auth system (see Auth documentation for more details). +logic. The car itself is a token provider that can provide an auth token to be +validated by the Auth system (see Auth documentation for more details). EvseManager provides a ``token_provider`` interface for that purpose. -If external identification (EIM) is used in HLC (no PnC) then Autocharge is +If external identification (EIM) is used in HLC (no PnC) then Autocharge is enabled by connecting the ``token_provider`` interface to Auth module. When the -car sends its EVCCID in the HLC protocol it is converted to Autocharge format +car sends its EVCCID in the HLC protocol it is converted to Autocharge format and published as Auth token. It is based on the following specification: https://github.com/openfastchargingalliance/openfastchargingalliance/blob/master/autocharge-final.pdf -To enable PnC the config option ``payment_enable_contract`` must be set to -true. If the car selects Contract instead of EIM PnC will be used instead of +To enable PnC the config option ``payment_enable_contract`` must be set to +true. If the car selects Contract instead of EIM PnC will be used instead of Autocharge. Reservation ----------- -Reservation handling logic is implemented in the Auth module. If the Auth -module wants to reserve a specific EvseManager (or cancel the reservation) it -needs to call the reserve/cancel_reservation commands. EvseManager does not -check reservation id against the token id when it should start charging, this -must be handled in Auth module. EvseManager only needs to know whether it is +Reservation handling logic is implemented in the Auth module. If the Auth +module wants to reserve a specific EvseManager (or cancel the reservation) it +needs to call the reserve/cancel_reservation commands. EvseManager does not +check reservation id against the token id when it should start charging, this +must be handled in Auth module. EvseManager only needs to know whether it is reserved or not to emit an ReservatonStart/ReservationEnd event to notify other -modules such as OCPP and API or e.g. switch on a specific LED signal on the +modules such as OCPP and API or e.g. switch on a specific LED signal on the charging port. Energy Management ================= -EvseManager seamlessly intergrates into the EVerest Energy Management. +EvseManager seamlessly intergrates into the EVerest Energy Management. For further details refer to the documentation of the EnergyManager module. -EvseManager has a grid facing Energy interface which the energy tree uses to -provide energy for the charging sessions. New energy needs to be provided on -regular intervals (with a timeout). +EvseManager has a grid facing Energy interface which the energy tree uses to +provide energy for the charging sessions. New energy needs to be provided on +regular intervals (with a timeout). If the supplied energy limits time out, EvseManager will stop charging. -This prevents e.g. overload conditions when the network connection drops +This prevents e.g. overload conditions when the network connection drops between the energy tree and EvseManager. -EvseManager will send out its wishes at regular intervals: It sends a -requested energy schedule into the energy tree that is merged from hardware -capabilities (as reported by board_support module), EvseManager module -configuration settings -(max_current, three_phases) and external limts (via ``set_external_limits`` +EvseManager will send out its wishes at regular intervals: It sends a +requested energy schedule into the energy tree that is merged from hardware +capabilities (as reported by board_support module), EvseManager module +configuration settings +(max_current, three_phases) and external limts (via ``set_external_limits`` command) e.g. set by OCPP module. Note that the ``set_external_limits`` should not be used by multiple modules, as the last one always wins. If you have multiple sources of exernal limits -that you want to combine, add extra EnergyNode modules in the chain and +that you want to combine, add extra EnergyNode modules in the chain and feed in limits via those. -The combined schedule sent to the energy tree is the minimum of all energy +The combined schedule sent to the energy tree is the minimum of all energy limits. -After traversing the energy tree the EnergyManager will use this information -to assign limits (and a schedule) -for this EvseManager and will call enforce_limits on the energy interface. +After traversing the energy tree the EnergyManager will use this information +to assign limits (and a schedule) +for this EvseManager and will call enforce_limits on the energy interface. These values will then be used -to configure PWM/DC power supplies to actually charge the car and must not +to configure PWM/DC power supplies to actually charge the car and must not be confused with the original wishes that -were sent to the energy tree. +were sent to the energy tree. -The EvseManager will never assign energy to itself, it always requests energy +The EvseManager will never assign energy to itself, it always requests energy from the energy manager and only charges if the energy manager responds with an assignment. Limits in the energy object can be specified in ampere (per phase) and/or watt. -Currently watt limits are unsupported, but it should behave according to that +Currently watt limits are unsupported, but it should behave according to that logic: -If both are specified also both limits will be applied, whichever is lower. +If both are specified also both limits will be applied, whichever is lower. With DC charging, ampere limits apply to the AC side and watt limits apply to both AC and DC side. @@ -230,12 +230,13 @@ This module subscribes to all errors of the following requirements: * ac_rcd * isolation_monitor * power_supply_DC +* powermeter (if the config option fail_on_powermeter_errors is set true) A raised error can cause the EvseManager to become Inoperative. This means that charging is not possible until the error is cleared. If no charging session is currently running, it will prevent sessions from being started. If a charging session is currently running and an error is raised this will interrupt the charging session. -Almost all errors that are reported from the requirements of this module cause the EvseManager to become Inoperative until the error is cleared. +Almost all errors that are reported from the requirements of this module cause the EvseManager to become Inoperative until the error is cleared. The following sections provide an overview of the errors that do **not** cause the EvseManager to become Inoperative. evse_board_support @@ -265,4 +266,8 @@ power_supply_DC * power_supply_DC/VendorWarning +powermeter +---------- + +* powermeter/CommunicationFault From 03fbac41f2c5d823e6dcbda40fd393e7aeda39d8 Mon Sep 17 00:00:00 2001 From: florinmihut Date: Thu, 19 Dec 2024 09:12:24 +0100 Subject: [PATCH 3/3] Update modules/EvseManager/manifest.yaml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Piet Gömpel <37657534+Pietfried@users.noreply.github.com> Signed-off-by: florinmihut --- modules/EvseManager/manifest.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/EvseManager/manifest.yaml b/modules/EvseManager/manifest.yaml index d51abe96f..ff06a1e91 100644 --- a/modules/EvseManager/manifest.yaml +++ b/modules/EvseManager/manifest.yaml @@ -293,7 +293,7 @@ config: default: 300 fail_on_powermeter_errors: description: >- - Set the EVSE Manager as inoperable if the powermeter is configured and has errors + Set the EVSE Manager to an inoperative state if the powermeter requirement is configured and has reported errors type: boolean default: false provides: