Skip to content

Commit

Permalink
fix set current prev (openWB#2089)
Browse files Browse the repository at this point in the history
  • Loading branch information
LKuemmel authored Dec 19, 2024
1 parent 4f5d4af commit 5b5dea0
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 15 deletions.
6 changes: 3 additions & 3 deletions packages/control/algorithm/surplus_controlled.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ def _set(self,
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:
pv_charging = data.data.general_data.data.chargemode_config.pv_charging
dif_to_old_current = available_for_cp + cp.data.set.target_current - cp.set_current_prev
dif_to_old_current = available_for_cp + cp.data.set.target_current - cp.data.set.current_prev
# Wenn die Differenz zwischen altem und neuem Soll-Strom größer als der Regelbereich ist, trotzdem
# nachregeln, auch wenn der Regelbereich eingehalten wird. Sonst würde zB nicht berücksichtigt werden,
# wenn noch ein Fahrzeug dazu kommmt.
if (pv_charging.control_range[1] - pv_charging.control_range[0]) / 230 < abs(dif_to_old_current):
current = available_for_cp
else:
# Nicht mehr freigeben, wie das Lastmanagement vorgibt
current = min(cp.set_current_prev - cp.data.set.target_current, available_for_cp)
current = min(cp.data.set.current_prev - cp.data.set.target_current, available_for_cp)
else:
current = available_for_cp

Expand Down Expand Up @@ -141,7 +141,7 @@ def _fix_deviating_evse_current(self, chargepoint: Chargepoint) -> float:
man den EVSE-Strom auf, pendelt die Regelung um diesen 1A-Schritt."""
MAX_DEVIATION = 1.1
evse_current = chargepoint.data.get.evse_current
if evse_current and chargepoint.data.set.current != chargepoint.set_current_prev:
if evse_current and chargepoint.data.set.current != chargepoint.data.set.current_prev:
formatted_evse_current = evse_current if evse_current < 32 else evse_current / 100
offset = formatted_evse_current - max(chargepoint.data.get.currents)
if abs(offset) >= MAX_DEVIATION:
Expand Down
12 changes: 5 additions & 7 deletions packages/control/chargepoint/chargepoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ def __init__(self, index: int, event: Optional[threading.Event]):
self.template: CpTemplate = None
self.chargepoint_module: AbstractChargepoint = None
self.num = index
# set current aus dem vorherigen Zyklus, um zu wissen, ob am Ende des Zyklus die Ladung freigegeben wird
# (für Control-Pilot-Unterbrechung)
self.set_current_prev = 0.0
# bestehende Daten auf dem Broker nicht zurücksetzen, daher nicht veröffentlichen
self.data: ChargepointData = ChargepointData()
self.data.set_event(event)
Expand Down Expand Up @@ -304,8 +301,9 @@ 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
self.data.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)
Pub().pub("openWB/set/chargepoint/"+str(self.num)+"/set/current_prev", self.data.set.current_prev)

def reset_log_data_chargemode_switch(self) -> None:
reset_log = Log()
Expand Down Expand Up @@ -337,7 +335,7 @@ def initiate_control_pilot_interruption(self):
if charging_ev.ev_template.data.control_pilot_interruption:
if self.data.config.control_pilot_interruption_hw:
# Wird die Ladung gestartet?
if self.set_current_prev == 0 and self.data.set.current != 0:
if self.data.set.current_prev == 0 and self.data.set.current != 0:
# Die CP-Unterbrechung erfolgt in Threads, da diese länger als ein Zyklus dauert.
if thread_handler(threading.Thread(
target=self.chargepoint_module.interrupt_cp,
Expand Down Expand Up @@ -370,7 +368,7 @@ def _is_phase_switch_required(self) -> bool:
# 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 and self.data.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
Expand Down Expand Up @@ -619,7 +617,7 @@ def set_required_currents(self, required_current: float) -> None:
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:
if self.data.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
Expand Down
5 changes: 3 additions & 2 deletions packages/control/chargepoint/chargepoint_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ class Set:
plug_time: Optional[float] = None
required_power: float = 0
rfid: Optional[str] = None
# set current aus dem vorherigen Zyklus, um zu wissen, ob am Ende des Zyklus die Ladung freigegeben wird
# (für Control-Pilot-Unterbrechung)
current_prev: float = 0.0
target_current: float = 0 # Soll-Strom aus fest vorgegebener Stromstärke
charging_ev_data: Ev = field(default_factory=ev_factory)
ocpp_transaction_id: Optional[int] = None
Expand Down Expand Up @@ -229,6 +232,4 @@ def chargepoint_module(self) -> AbstractChargepoint: ...
@property
def num(self) -> int: ...
@property
def set_current_prev(self) -> float: ...
@property
def data(self) -> ChargepointData: ...
1 change: 0 additions & 1 deletion packages/control/chargepoint/chargepoint_state_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def update(self):
cp = copy.deepcopy(self.chargepoint)
except TypeError:
cp = Chargepoint(self.chargepoint.num, None)
cp.set_current_prev = copy.deepcopy(self.chargepoint.set_current_prev)
cp.data = copy.deepcopy(self.chargepoint.data)
cp.chargepoint_module = self.chargepoint.chargepoint_module
cp.template = copy.deepcopy(self.cp_template_data[f"cpt{self.chargepoint.data.config.template}"])
Expand Down
1 change: 0 additions & 1 deletion packages/control/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ def __copy_cp_data(self) -> None:
except TypeError:
self.cp_data[cp] = Chargepoint(SubData.cp_data[cp].chargepoint.num, None)
self.cp_data[cp].template = copy.deepcopy(SubData.cp_data[cp].chargepoint.template)
self.cp_data[cp].set_current_prev = copy.deepcopy(SubData.cp_data[cp].chargepoint.set_current_prev)
self.cp_data[cp].data = copy.deepcopy(SubData.cp_data[cp].chargepoint.data)
self.cp_data[cp].chargepoint_module = SubData.cp_data[cp].chargepoint.chargepoint_module
self.cp_all_data = copy.deepcopy(SubData.cp_all_data)
Expand Down
3 changes: 2 additions & 1 deletion packages/helpermodules/setdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,8 @@ def process_chargepoint_topic(self, msg: mqtt.MQTTMessage):
if ("/set/charging_ev" in msg.topic or
"/set/charging_ev_prev" in msg.topic):
self._validate_value(msg, int, [(-1, float("inf"))])
elif "/set/current" in msg.topic:
elif ("/set/current" in msg.topic or
"/set/current_prev" in msg.topic):
if hardware_configuration.get_hardware_configuration_setting("dc_charging"):
self._validate_value(msg, float, [(0, 0), (6, 32), (0, 450)])
else:
Expand Down

0 comments on commit 5b5dea0

Please sign in to comment.