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
1 change: 1 addition & 0 deletions packages/control/algorithm/common_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def test_set_current_counterdiff(diff: float,
cp.data.control_parameter.required_currents = required_currents
cp.data.set.charging_ev_data = ev
cp.data.set.current = 6
cp.data.get.currents = [10]*3
get_counters_to_check_mock = Mock(return_value=["cp0", "cp6"])
monkeypatch.setattr(CounterAll, "get_counters_to_check", get_counters_to_check_mock)
data.data.counter_data = {"cp0": Mock(spec=Counter), "cp6": Mock(spec=Counter)}
Expand Down
4 changes: 2 additions & 2 deletions packages/control/auto_phase_switch_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def __init__(self,
timestamp_auto_phase_switch=1652682772.0, phases_to_use=1, required_current=6,
evu_surplus=1640, get_currents=[15.6, 0, 0], get_power=3450,
state=ChargepointState.PHASE_SWITCH_DELAY,
expected_phases_to_use=3, expected_current=6, expected_state=ChargepointState.PHASE_SWITCH_DELAY_EXPIRED),
expected_phases_to_use=3, expected_current=6, expected_state=ChargepointState.PHASE_SWITCH_AWAITED),

Params("3to1, not enough power, start timer", max_current_single_phase=16, timestamp_auto_phase_switch=None,
phases_to_use=3, required_current=6, evu_surplus=0,
Expand Down Expand Up @@ -116,7 +116,7 @@ def __init__(self,
timestamp_auto_phase_switch=1652682592.0, phases_to_use=3, required_current=6,
evu_surplus=-460, get_currents=[4.5, 4.4, 5.8],
get_power=3381, state=ChargepointState.PHASE_SWITCH_DELAY, expected_phases_to_use=1, expected_current=16,
expected_state=ChargepointState.PHASE_SWITCH_DELAY_EXPIRED),
expected_state=ChargepointState.PHASE_SWITCH_AWAITED),
]


Expand Down
54 changes: 25 additions & 29 deletions packages/control/chargepoint/chargepoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from helpermodules import timecheck
from helpermodules.utils import thread_handler
from modules.common.abstract_chargepoint import AbstractChargepoint
from helpermodules.timecheck import create_timestamp
from helpermodules.timecheck import check_timestamp, create_timestamp


def get_chargepoint_config_default() -> dict:
Expand Down Expand Up @@ -304,6 +304,7 @@ def _set_values_at_start(self):

def remember_previous_values(self):
self.data.set.plug_state_prev = self.data.get.plug_state
self.set_current_prev = self.data.set.current
Pub().pub("openWB/set/chargepoint/"+str(self.num)+"/set/plug_state_prev", self.data.set.plug_state_prev)

def reset_log_data_chargemode_switch(self) -> None:
Expand Down Expand Up @@ -358,21 +359,20 @@ def _is_phase_switch_required(self) -> bool:
phase_switch_required = False
# Manche EVs brauchen nach der Umschaltung mehrere Zyklen, bis sie mit den drei Phasen laden. Dann darf
# nicht zwischendurch eine neue Umschaltung getriggert werden.
if (self.data.control_parameter.state == ChargepointState.CHARGING_ALLOWED or
self.data.control_parameter.state == ChargepointState.PHASE_SWITCH_DELAY_EXPIRED or
self.data.control_parameter.state == ChargepointState.SWITCH_OFF_DELAY):
if (((self.data.control_parameter.state == ChargepointState.PHASE_SWITCH_AWAITED or
self.data.control_parameter.state == ChargepointState.SWITCH_OFF_DELAY) and
# Nach Ablauf der Laden aktiv halten Zeit, sollte mit der vorgegebenen Phasenzahl geladen werden.
if ((self.check_deviating_contactor_states(self.data.set.phases_to_use, self.data.get.phases_in_use) or
self.check_deviating_contactor_states(self.data.set.phases_to_use, self.data.get.phases_in_use)) or
# Vorgegebene Phasenzahl hat sich geändert
self.check_deviating_contactor_states(self.data.set.phases_to_use,
self.data.control_parameter.phases)) and
self.check_deviating_contactor_states(self.data.set.phases_to_use,
self.data.control_parameter.phases) and
# Wenn ein Soll-Strom vorgegeben ist, muss das Auto auch laden, damit umgeschaltet wird, sonst
# wird zB bei automatischer Umschaltung ständig versucht auf 1 Phase zurück zu schalten, wenn
# das Auto bei 3 Phasen voll ist.
((self.data.set.current != 0 and self.data.get.charge_state) or
(self.data.set.current != 0 and self.set_current_prev == 0) or
self.data.set.current == 0)):
phase_switch_required = True
((self.data.set.current != 0 and self.data.get.charge_state) or
(self.data.set.current != 0 and self.set_current_prev == 0) or
self.data.set.current == 0)):
phase_switch_required = True
if (self.data.control_parameter.state == ChargepointState.NO_CHARGING_ALLOWED and
(self.check_deviating_contactor_states(self.data.set.phases_to_use, self.data.get.phases_in_use) or
# Vorgegebene Phasenzahl hat sich geändert
Expand Down Expand Up @@ -440,8 +440,12 @@ def check_phase_switch_completed(self):
self.set_state_and_log(message)
return
if self.data.control_parameter.state == ChargepointState.WAIT_FOR_USING_PHASES:
if phase_switch.phase_switch_thread_alive(self.num) is False:
self.data.control_parameter.state = ChargepointState.CHARGING_ALLOWED
if (phase_switch.phase_switch_thread_alive(self.num) is False and
check_timestamp(self.data.control_parameter.timestamp_charge_start,
charging_ev.ev_template.data.keep_charge_active_duration) is False):
self.data.control_parameter.state = ChargepointState.PHASE_SWITCH_AWAITED
if self._is_phase_switch_required() is False:
self.data.control_parameter.state = ChargepointState.CHARGING_ALLOWED
except Exception:
log.exception("Fehler in der Ladepunkt-Klasse von "+str(self.num))

Expand Down Expand Up @@ -494,7 +498,7 @@ def initiate_phase_switch(self):
else:
log.error("Phasenumschaltung an Ladepunkt" + str(self.num) +
" nicht möglich, da gerade eine Umschaltung im Gange ist.")
elif self.data.control_parameter.state == ChargepointState.PHASE_SWITCH_DELAY_EXPIRED:
elif self.data.control_parameter.state == ChargepointState.PHASE_SWITCH_AWAITED:
# Wenn keine Phasenumschaltung durchgeführt wird, Status auf CHARGING_ALLOWED setzen, sonst
# bleibt PHASE_SWITCH_DELAY_EXPIRED stehen.
self.data.control_parameter.state = ChargepointState.CHARGING_ALLOWED
Expand Down Expand Up @@ -613,21 +617,15 @@ def set_required_currents(self, required_current: float) -> None:
"was ggf eine unnötige Reduktion der Ladeleistung zur Folge hat.")
self.data.set.required_power = sum(control_parameter.required_currents) * 230

def handle_less_power(self):
if self.data.set.current != 0 and self.data.control_parameter.state == ChargepointState.CHARGING_ALLOWED:
nominal_difference = self.data.set.charging_ev_data.ev_template.data.nominal_difference
if self.data.set.current - nominal_difference > max(self.data.get.currents):
if self.data.control_parameter.timestamp_charge_start is None:
self.data.control_parameter.timestamp_charge_start = create_timestamp()
else:
self.data.control_parameter.timestamp_charge_start = None
else:
# Beim Ladestart Timer laufen lassen, manche Fahrzeuge brauchen sehr lange.
def set_timestamp_charge_start(self):
# Beim Ladestart Timer laufen lassen, manche Fahrzeuge brauchen sehr lange.
if self.data.control_parameter.timestamp_charge_start is None:
if self.set_current_prev == 0 and self.data.set.current != 0:
self.data.control_parameter.timestamp_charge_start = create_timestamp()
elif self.data.set.current == 0:
self.data.control_parameter.timestamp_charge_start = None

def update_ev(self, ev_list: Dict[str, Ev]) -> None:
# Für Control-Pilot-Unterbrechung set current merken.
self.set_current_prev = self.data.set.current
self._validate_rfid()
charging_possible = self.is_charging_possible()[0]
if charging_possible:
Expand All @@ -642,8 +640,6 @@ def update_ev(self, ev_list: Dict[str, Ev]) -> None:

def update(self, ev_list: Dict[str, Ev]) -> None:
try:
# Für Control-Pilot-Unterbrechung set current merken.
self.set_current_prev = self.data.set.current
self._validate_rfid()
charging_possible, message = self.is_charging_possible()
if self.data.get.rfid is not None and self.data.get.plug_state:
Expand Down Expand Up @@ -677,7 +673,7 @@ def update(self, ev_list: Dict[str, Ev]) -> None:
charging_ev.set_submode_changed(self.data.control_parameter, submode)
self.set_control_parameter(submode, required_current)
self.set_required_currents(required_current)
self.handle_less_power()
self.set_timestamp_charge_start()
self.check_phase_switch_completed()

if charging_ev.chargemode_changed:
Expand Down
4 changes: 2 additions & 2 deletions packages/control/chargepoint/chargepoint_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ class ChargepointState(IntEnum):
CHARGING_ALLOWED = 4
SWITCH_OFF_DELAY = 5
SWITCH_ON_DELAY = 6
PHASE_SWITCH_DELAY_EXPIRED = 7
PHASE_SWITCH_AWAITED = 7


CHARGING_STATES = (ChargepointState.PHASE_SWITCH_DELAY,
ChargepointState.WAIT_FOR_USING_PHASES,
ChargepointState.CHARGING_ALLOWED,
ChargepointState.SWITCH_OFF_DELAY,
ChargepointState.PHASE_SWITCH_DELAY_EXPIRED)
ChargepointState.PHASE_SWITCH_AWAITED)

PHASE_SWITCH_STATES = (ChargepointState.PHASE_SWITCH_DELAY,
ChargepointState.PERFORMING_PHASE_SWITCH,
Expand Down
2 changes: 1 addition & 1 deletion packages/control/ev.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ def auto_phase_switch(self,
phases_to_use = new_phase
current = new_current
log.debug("Phasenumschaltung kann nun durchgeführt werden.")
control_parameter.state = ChargepointState.PHASE_SWITCH_DELAY_EXPIRED
control_parameter.state = ChargepointState.PHASE_SWITCH_AWAITED
else:
timestamp_auto_phase_switch = None
data.data.counter_all_data.get_evu_counter(
Expand Down
2 changes: 1 addition & 1 deletion packages/control/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def process_algorithm_results(self) -> None:
cp.initiate_control_pilot_interruption()
cp.initiate_phase_switch()
if control_parameter.state == ChargepointState.NO_CHARGING_ALLOWED and cp.data.set.current != 0:
control_parameter.state = ChargepointState.CHARGING_ALLOWED
control_parameter.state = ChargepointState.WAIT_FOR_USING_PHASES
self._update_state(cp)
else:
# LP, an denen nicht geladen werden darf
Expand Down