Skip to content

Feature negative dc charging - #3795

Draft
AlexanderHa98 wants to merge 8 commits into
openWB:masterfrom
AlexanderHa98:feature_negative_dc_charging
Draft

Feature negative dc charging#3795
AlexanderHa98 wants to merge 8 commits into
openWB:masterfrom
AlexanderHa98:feature_negative_dc_charging

Conversation

@AlexanderHa98

@AlexanderHa98 AlexanderHa98 commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Fürs Debug in _chargepoint.py folgende Zeilen setzen:
pub_to_broker("openWB/set/chargepoint/" + str(self.num) + "/get/max_charge_power", 500000)
pub_to_broker("openWB/set/chargepoint/" + str(self.num) + "/get/max_discharge_power", -500000)
pub_to_broker("openWB/set/chargepoint/" + str(self.num) + "/get/evse_signaling", "HLC")

@AlexanderHa98
AlexanderHa98 requested a lite review from Copilot August 12, 2026 07:45
@AlexanderHa98
AlexanderHa98 requested a lite review from Copilot and removed request for Copilot August 17, 2026 05:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the charging/control logic to support bidirectional operation (negative currents/power), including counter/loadmanagement tracking for “export” limits and updated algorithm behavior/tests for DC discharge scenarios.

Changes:

  • Allow/control negative setpoints for bidirectional (dis)charging across templates and EV current calculation.
  • Add “exported” headroom tracking on counters (power + currents) and use it in loadmanagement limiting.
  • Update BIDI algorithm flow and expand integration test coverage for instant discharging / DC current limits.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/helpermodules/setdata.py Relaxes validation for chargepoint /set/required_power to allow negative values.
packages/control/loadmanagement.py Adds BIDI-specific current availability method and extends current/power limiting to handle negative currents.
packages/control/ev/ev.py Passes bidirectional state into instant-charging template logic.
packages/control/ev/charge_template.py Enables instant-charging discharge behavior (negative current) gated by BidiState.
packages/control/ev/charge_template_test.py Updates unit test to match new instant-charging signature (adds BidiState).
packages/control/counter.py Tracks remaining “exported” power/currents headroom and updates raw-value accounting for discharge scenarios.
packages/control/algorithm/integration_test/bidi_charging_test.py Expands integration tests for BIDI instant discharge (DC current, counter export limits, multi-CP behavior).
packages/control/algorithm/common.py Allows negative diffs (discharge) and updates current monotonicity logic for discharge.
packages/control/algorithm/chargemodes.py Reorders/extends mode tuples and slice definitions to include additional BIDI discharge consideration.
packages/control/algorithm/bidi_charging.py Refactors BIDI handling to use loadmanagement-based limiting and adds instant-discharge handling based on DC current.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/control/loadmanagement.py Outdated
try:
# Am meisten belastete Phase trägt am meisten zur Leistungsreduktion bei.
currents[i] = available_currents[i] / sum(available_currents) * raw_power_left / cp_voltage
currents[i] = available_currents[i] / sum(available_currents) * power_left / cp_voltage
Comment thread packages/helpermodules/setdata.py Outdated
self._validate_value(msg, float, [(float("-inf"), 0), (6, 32), (0, 0)])
elif "/set/required_power" in msg.topic:
self._validate_value(msg, float, [(0, float("inf"))])
self._validate_value(msg, float)
@AlexanderHa98 AlexanderHa98 self-assigned this Aug 17, 2026
@AlexanderHa98
AlexanderHa98 requested a review from LKuemmel August 17, 2026 06:26
Comment on lines +103 to +106
if cp.data.set.charging_ev_data.data.get.soc is None:
raise ValueError(f"LP{cp.num}: Auto-Bat SoC unbekannt, daher keine Entladung möglich.")
if cp.data.set.charging_ev_data.data.get.soc > 0:
# Auto-bat ist nicht leer

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if cp.data.set.charging_ev_data.data.get.soc is None:
raise ValueError(f"LP{cp.num}: Auto-Bat SoC unbekannt, daher keine Entladung möglich.")
if cp.data.set.charging_ev_data.data.get.soc > 0:
# Auto-bat ist nicht leer

Ob das Auto leer ist oder aus anderen Gründen die Entladung verweigert (fast leer, Temperatur, etc.) wird ja dadurch abgefangen, dass nur die tatsächlich entladenen Leistung zum Laden von anderen Fahrzeugen verwendet wird. Dann kann diese Restriktion entfallen.

Comment on lines +41 to +42
counters = data.data.counter_all_data.get_counters_to_check(cp.num)
for counter in counters:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gibt es einen Grund, dass Du nicht die Methode mode_and_counter_generator verwendest, Die auch min_current,.. verwenden, um über die Zähler zu iterieren?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wenn ich mode_and_counter_generator verwende, schlägt der Test test_cp3_cp4_bidi_discharge fehl.
In dem Test wird geprüft, ob bei mehreren Bidi-CPs (im Zielladen) alle gleichmäßig entladen werden und nicht nur einer und die anderen nicht.

-> Deswegen habe ich das so gelöst. Ich brauche eine Liste mit allen CPs, die sich in diesem Mode befinden, um das Entladen entsprechend aufteilen zu können.

Comment on lines +108 to +116
dc_current = cp.data.set.charging_ev_data.charge_template.data.chargemode.instant_charging.dc_current
if dc_current < 0:
# Phasen in use berücksichtigen
missing_currents = [dc_current for i in range(0, cp.data.get.phases_in_use)]
missing_currents += [0] * (3 - len(missing_currents))

for index in range(0, 3):
missing_currents[index] = cp.check_min_max_current(
missing_currents[index], cp.data.get.phases_in_use)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Müsste das nicht control_parameter.required_currents entsprechen?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ja das ist genau der Punkt, denn wir schonmal besprochen haben:
Durch das self.surplus_controlled.set_required_current_to_max()in calc_current() steht im control_parameter.required_currents immer der Maximalwert.
-> Wir brauchen hier aber den im UI eingestellten Wert.

if min(element_current) < 0:
# nur Hausverbraucher ohne Einspeisung
currents_exported_raw = list(map(operator.sub, currents_exported_raw, element_current))
continue

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Müsste hier nicht ein else hin? Die entladenden Fahrzeuge sollen nicht aus dem Zähler herausgerechnet werden, sondern die entladene Leistung als verfügbar auf ladende Fahrzeuge verteilt werden.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants