Skip to content
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: 2 additions & 1 deletion packages/control/algorithm/bidi_charging.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from control import data
from control.algorithm.chargemodes import CONSIDERED_CHARGE_MODES_BIDI_DISCHARGE
from control.algorithm.filter_chargepoints import get_chargepoints_by_mode
from helpermodules.phase_handling import voltages_mean

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -39,7 +40,7 @@ def set_bidi(self):
for index in range(0, 3):
missing_currents[index] = cp.check_min_max_current(missing_currents[index],
cp.data.get.phases_in_use)
grid_counter.update_surplus_values_left(missing_currents, cp.data.get.voltages)
grid_counter.update_surplus_values_left(missing_currents, voltages_mean(cp.data.get.voltages))
cp.data.set.current = missing_currents[0]
log.info(f"LP{cp.num}: Stromstärke {missing_currents}A")
preferenced_cps.pop(0)
15 changes: 11 additions & 4 deletions packages/control/algorithm/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from control.algorithm.utils import get_medium_charging_current
from control.chargepoint.chargepoint import Chargepoint
from control.counter import Counter
from helpermodules.phase_handling import voltages_mean
from helpermodules.timecheck import check_timestamp
from modules.common.component_type import ComponentType

Expand Down Expand Up @@ -74,9 +75,13 @@ def set_current_counterdiff(diff_current: float,
counters = data.data.counter_all_data.get_counters_to_check(chargepoint.num)
for counter in counters:
if surplus:
data.data.counter_data[counter].update_surplus_values_left(diffs, chargepoint.data.get.voltages)
data.data.counter_data[counter].update_surplus_values_left(
diffs,
voltages_mean(chargepoint.data.get.voltages))
else:
data.data.counter_data[counter].update_values_left(diffs, chargepoint.data.get.voltages)
data.data.counter_data[counter].update_values_left(
diffs,
voltages_mean(chargepoint.data.get.voltages))
data.data.io_actions.dimming_set_import_power_left({"type": "cp", "id": chargepoint.num}, sum(diffs)*230)

chargepoint.data.set.current = current
Expand Down Expand Up @@ -146,9 +151,11 @@ def update_raw_data(preferenced_chargepoints: List[Chargepoint],
counters = data.data.counter_all_data.get_counters_to_check(chargepoint.num)
for counter in counters:
if surplus:
data.data.counter_data[counter].update_surplus_values_left(diffs, chargepoint.data.get.voltages)
data.data.counter_data[counter].update_surplus_values_left(
diffs,
voltages_mean(chargepoint.data.get.voltages))
else:
data.data.counter_data[counter].update_values_left(diffs, chargepoint.data.get.voltages)
data.data.counter_data[counter].update_values_left(diffs, voltages_mean(chargepoint.data.get.voltages))
data.data.io_actions.dimming_set_import_power_left({"type": "cp", "id": chargepoint.num}, sum(diffs)*230)


Expand Down
13 changes: 8 additions & 5 deletions packages/control/algorithm/surplus_controlled.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from control.counter import ControlRangeState, Counter
from control.limiting_value import LoadmanagementLimit
from control.loadmanagement import LimitingValue, Loadmanagement
from helpermodules.phase_handling import voltages_mean


log = logging.getLogger(__name__)
Expand Down Expand Up @@ -53,11 +54,13 @@ def _set(self,
while len(chargepoints):
cp = chargepoints[0]
missing_currents, counts = common.get_missing_currents_left(chargepoints)
available_currents, limit = Loadmanagement().get_available_currents_surplus(missing_currents,
cp.data.get.voltages,
counter,
cp,
feed_in=feed_in_yield)
available_currents, limit = Loadmanagement().get_available_currents_surplus(
missing_currents,
voltages_mean(cp.data.get.voltages),
counter,
cp,
feed_in=feed_in_yield
)
cp.data.control_parameter.limit = limit
available_for_cp = common.available_current_for_cp(cp, counts, available_currents, missing_currents)
if counter.get_control_range_state(feed_in_yield) == ControlRangeState.MIDDLE:
Expand Down
2 changes: 1 addition & 1 deletion packages/control/chargepoint/chargepoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from control import phase_switch
from control.chargepoint.chargepoint_state import CHARGING_STATES, ChargepointState
from control.text import BidiState
from helpermodules.phase_mapping import convert_single_evu_phase_to_cp_phase
from helpermodules.phase_handling import convert_single_evu_phase_to_cp_phase
from helpermodules.pub import Pub
from helpermodules import timecheck
from helpermodules.utils import thread_handler
Expand Down
12 changes: 7 additions & 5 deletions packages/control/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from dataclass_utils.factories import currents_list_factory, voltages_list_factory
from helpermodules import timecheck
from helpermodules.constants import NO_ERROR
from helpermodules.phase_mapping import convert_cp_currents_to_evu_currents
from helpermodules.phase_handling import convert_cp_currents_to_evu_currents
from modules.common.fault_state import FaultStateLevel
from modules.common.utils.component_parser import get_component_name_by_id

Expand Down Expand Up @@ -194,17 +194,19 @@ def _set_power_left(self, loadmanagement_available: bool) -> None:
else:
self.data.set.raw_power_left = None

def update_values_left(self, diffs, cp_voltages: List[float]) -> None:
def update_values_left(self, diffs, cp_voltage: float) -> None:
# Mittelwert der Spannungen verwenden, um Phasenverdrehung zu kompensieren
# (Probleme bei einphasig angeschlossenen Wallboxen)
self.data.set.raw_currents_left = list(map(operator.sub, self.data.set.raw_currents_left, diffs))
if self.data.set.raw_power_left:
self.data.set.raw_power_left -= sum([c * v for c, v in zip(diffs, cp_voltages)])
self.data.set.raw_power_left -= sum([c * cp_voltage for c in diffs])
log.debug(f'Zähler {self.num}: {self.data.set.raw_currents_left}A verbleibende Ströme, '
f'{self.data.set.raw_power_left}W verbleibende Leistung')

def update_surplus_values_left(self, diffs, cp_voltages: List[float]) -> None:
def update_surplus_values_left(self, diffs, cp_voltage: float) -> None:
self.data.set.raw_currents_left = list(map(operator.sub, self.data.set.raw_currents_left, diffs))
if self.data.set.surplus_power_left:
self.data.set.surplus_power_left -= sum([c * v for c, v in zip(diffs, cp_voltages)])
self.data.set.surplus_power_left -= sum([c * cp_voltage for c in diffs])
log.debug(f'Zähler {self.num}: {self.data.set.raw_currents_left}A verbleibende Ströme, '
f'{self.data.set.surplus_power_left}W verbleibender Überschuss')

Expand Down
15 changes: 9 additions & 6 deletions packages/control/loadmanagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from control.chargepoint.chargepoint import Chargepoint
from control.counter import Counter
from control.limiting_value import LimitingValue, LoadmanagementLimit
from helpermodules.phase_handling import voltages_mean
from modules.common.utils.component_parser import get_component_name_by_id


Expand Down Expand Up @@ -35,7 +36,7 @@ def get_available_currents(self,
limit = new_limit if new_limit.limiting_value is not None else limit

available_currents, new_limit = self._limit_by_power(
counter, available_currents, cp.data.get.voltages, counter.data.set.raw_power_left, feed_in)
counter, available_currents, voltages_mean(cp.data.get.voltages), counter.data.set.raw_power_left, feed_in)
limit = new_limit if new_limit.limiting_value is not None else limit

if f"counter{counter.num}" == data.data.counter_all_data.get_evu_counter_str():
Expand All @@ -47,7 +48,7 @@ def get_available_currents(self,

def get_available_currents_surplus(self,
missing_currents: List[float],
cp_voltages: List[float],
cp_voltage: float,
counter: Counter,
cp: Chargepoint,
feed_in: int = 0) -> Tuple[List[float], LoadmanagementLimit]:
Expand All @@ -61,7 +62,7 @@ def get_available_currents_surplus(self,
limit = new_limit if new_limit.limiting_value is not None else limit

available_currents, new_limit = self._limit_by_power(
counter, available_currents, cp_voltages, counter.data.set.surplus_power_left, feed_in)
counter, available_currents, cp_voltage, counter.data.set.surplus_power_left, feed_in)
limit = new_limit if new_limit.limiting_value is not None else limit

if f"counter{counter.num}" == data.data.counter_all_data.get_evu_counter_str():
Expand Down Expand Up @@ -94,20 +95,22 @@ def _limit_by_unbalanced_load(self,
def _limit_by_power(self,
counter: Counter,
available_currents: List[float],
cp_voltages: List[float],
cp_voltage: float,
raw_power_left: Optional[float],
feed_in: Optional[float]) -> Tuple[List[float], LoadmanagementLimit]:
# Mittelwert der Spannungen verwenden, um Phasenverdrehung zu kompensieren
# (Probleme bei einphasig angeschlossenen Wallboxen)
currents = available_currents.copy()
limit = LoadmanagementLimit(None, None)
if raw_power_left:
if feed_in:
raw_power_left = raw_power_left - feed_in
log.debug(f"Verbleibende Leistung unter Berücksichtigung der Einspeisegrenze: {raw_power_left}W")
if sum([c * v for c, v in zip(available_currents, cp_voltages)]) > raw_power_left:
if sum([c * cp_voltage for c in available_currents]) > raw_power_left:
for i in range(0, 3):
try:
# Am meisten belastete Phase trägt am meisten zur Leistungsreduktion bei.
currents[i] = available_currents[i] / sum(available_currents) * raw_power_left / cp_voltages[i]
currents[i] = available_currents[i] / sum(available_currents) * raw_power_left / cp_voltage
except ZeroDivisionError:
# bei einphasig angeschlossenen Wallboxen ist die Spannung der anderen Phasen 0V
currents[i] = 0.0
Expand Down
2 changes: 1 addition & 1 deletion packages/control/loadmanagement_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_limit_by_power(available_currents: List[float],
counter_name_mock = Mock(return_value=COUNTER_NAME)
monkeypatch.setattr(loadmanagement, "get_component_name_by_id", counter_name_mock)
# evaluation
currents = Loadmanagement()._limit_by_power(Counter(0), available_currents, [230]*3, raw_power_left, None)
currents = Loadmanagement()._limit_by_power(Counter(0), available_currents, 230, raw_power_left, None)

# assertion
assert currents == expected_currents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ def convert_single_cp_phase_to_evu_phase(phase_1: int, cp_phase: int) -> int:

def convert_single_evu_phase_to_cp_phase(phase_1: int, evu_phase: int) -> int:
return EVU_TO_CP_PHASE_MAPPING[phase_1][evu_phase]


def voltages_mean(voltages: List[float]) -> float:
# Zoes erzeugen bei einphasiger Ladung 140V auf Phase 2
filtered_voltages = [v for v in voltages if v > 200]
if not filtered_voltages:
return 0.0
return sum(filtered_voltages) / len(filtered_voltages)
2 changes: 1 addition & 1 deletion packages/modules/common/store/_counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from control import data
from helpermodules import compatibility
from helpermodules.phase_mapping import convert_cp_currents_to_evu_currents
from helpermodules.phase_handling import convert_cp_currents_to_evu_currents
from modules.common.component_state import CounterState
from modules.common.component_type import ComponentType
from modules.common.fault_state import FaultState
Expand Down