Skip to content

Commit a9be341

Browse files
committed
integration test bidi charging
1 parent b305fec commit a9be341

4 files changed

Lines changed: 58 additions & 2 deletions

File tree

packages/control/algorithm/chargemodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@
3131
CONSIDERED_CHARGE_MODES_SURPLUS = CHARGEMODES[0:4] + CHARGEMODES[8:20]
3232
CONSIDERED_CHARGE_MODES_PV_ONLY = CHARGEMODES[12:20]
3333
CONSIDERED_CHARGE_MODES_ADDITIONAL_CURRENT = CHARGEMODES[0:12]
34-
CONSIDERED_CHARGE_MODES_MIN_CURRENT = CHARGEMODES[0:-1]
34+
CONSIDERED_CHARGE_MODES_MIN_CURRENT = CHARGEMODES[0:-4]
3535
CONSIDERED_CHARGE_MODES_NO_CURRENT = CHARGEMODES[22:24]
3636
CONSIDERED_CHARGE_MODES_BIDI_DISCHARGE = CHARGEMODES[20:22]
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import pytest
2+
from control import data
3+
from control.algorithm.algorithm import Algorithm
4+
from control.chargemode import Chargemode
5+
6+
7+
@pytest.fixture()
8+
def bidi_cps():
9+
def _setup(*cps):
10+
for cp in cps:
11+
data.data.cp_data[cp].data.get.max_discharge_power = -11000
12+
data.data.cp_data[cp].data.get.max_charge_power = 11000
13+
data.data.cp_data[cp].data.get.phases_in_use = 3
14+
control_parameter = data.data.cp_data[cp].data.control_parameter
15+
control_parameter.min_current = data.data.cp_data[cp].data.set.charging_ev_data.ev_template.data.min_current
16+
control_parameter.phases = 3
17+
control_parameter.required_currents = [16]*3
18+
control_parameter.required_current = 16
19+
control_parameter.chargemode = Chargemode.BIDI_CHARGING
20+
control_parameter.submode = Chargemode.BIDI_CHARGING
21+
return _setup
22+
23+
24+
@pytest.mark.parametrize("grid_power, expected_current",
25+
[pytest.param(-2000, 2.898550724637681, id="bidi charge"),
26+
pytest.param(2000, -2.898550724637681, id="bidi discharge")])
27+
def test_cp3_bidi(grid_power: float, expected_current: float, bidi_cps, all_cp_not_charging, monkeypatch):
28+
# setup
29+
bidi_cps("cp3")
30+
data.data.counter_data["counter0"].data.get.power = grid_power
31+
32+
# execution
33+
Algorithm().calc_current()
34+
35+
# evaluation
36+
assert data.data.cp_data["cp3"].data.set.current == expected_current
37+
assert data.data.cp_data["cp4"].data.set.current == 0
38+
assert data.data.cp_data["cp5"].data.set.current == 0
39+
assert data.data.counter_data["counter0"].data.set.surplus_power_left == 0
40+
41+
42+
def test_cp3_cp4_bidi_discharge(bidi_cps, all_cp_not_charging, monkeypatch):
43+
# setup
44+
bidi_cps("cp3", "cp4")
45+
data.data.counter_data["counter0"].data.get.power = 4000
46+
47+
# execution
48+
Algorithm().calc_current()
49+
50+
# evaluation
51+
assert data.data.cp_data["cp3"].data.set.current == -2.898550724637681
52+
assert data.data.cp_data["cp4"].data.set.current == -2.898550724637681
53+
assert data.data.cp_data["cp5"].data.set.current == 0
54+
assert data.data.counter_data["counter0"].data.set.surplus_power_left == 0

packages/control/algorithm/integration_test/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from control.bat import Bat
88
from control.bat_all import BatAll
99
from control.chargepoint.chargepoint import Chargepoint
10+
from control.chargepoint.chargepoint_template import CpTemplate
1011
from control.counter_all import CounterAll
1112
from control.counter import Counter
1213
from control.ev.ev import Ev
@@ -24,6 +25,7 @@ def data_() -> None:
2425
"cp4": Chargepoint(4, None),
2526
"cp5": Chargepoint(5, None)}
2627
for i in range(3, 6):
28+
data.data.cp_data[f"cp{i}"].template = CpTemplate()
2729
data.data.cp_data[f"cp{i}"].data.config.phase_1 = i-2
2830
data.data.cp_data[f"cp{i}"].data.set.charging_ev = i
2931
data.data.cp_data[f"cp{i}"].data.set.charging_ev_data = Ev(i)

packages/control/chargepoint/chargepoint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ def check_min_max_current(self, required_current: float, phases: int) -> float:
600600
if required_current < 0:
601601
required_current = max(self.data.get.max_discharge_power / phases / 230, required_current)
602602
else:
603-
required_current = max(self.data.get.max_charge_power / phases / 230, required_current)
603+
required_current = min(self.data.get.max_charge_power / phases / 230, required_current)
604604
required_current = self.check_cp_min_max_current(abs(required_current), phases) * -1
605605
else:
606606
required_current, msg = self.data.set.charging_ev_data.check_min_max_current(

0 commit comments

Comments
 (0)