Skip to content

Commit

Permalink
Simulate soc in -2, -20 and din. (#393)
Browse files Browse the repository at this point in the history
* Move contactor close check to be after cable check is complete.

* Added display params to AC/DC charge requests in -20

* Fixed formatting errors

* Removed contactor status related changes

* Fixed contactor status check in DIN

* set ev_ress_soc to _soc in simulator

* considered missed chargeLoopCycle

* Fixed mypy issues

* simple guard against 0 charging loop cycles
  • Loading branch information
shalinnijel2 authored Apr 17, 2024
1 parent e661df8 commit 868f704
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
14 changes: 13 additions & 1 deletion iso15118/evcc/controller/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@
SelectedEnergyService,
SelectedVAS,
)
from iso15118.shared.messages.iso15118_20.common_types import RationalNumber
from iso15118.shared.messages.iso15118_20.common_types import (
DisplayParameters,
RationalNumber,
)
from iso15118.shared.messages.iso15118_20.dc import (
BPTDCChargeParameterDiscoveryReqParams,
BPTDynamicDCChargeLoopReqParams,
Expand Down Expand Up @@ -670,3 +673,12 @@ async def enable_charging(self, enabled: bool) -> None:
- ISO 15118-2
- ISO 15118-20
"""

@abstractmethod
async def get_display_params(self) -> DisplayParameters:
"""
Enables charging for the EVCC.
Can be used as an indication to go to state C
Relevant for:
- ISO 15118-20
"""
20 changes: 16 additions & 4 deletions iso15118/evcc/controller/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@
SelectedEnergyService,
SelectedVAS,
)
from iso15118.shared.messages.iso15118_20.common_types import RationalNumber
from iso15118.shared.messages.iso15118_20.common_types import (
DisplayParameters,
RationalNumber,
)
from iso15118.shared.messages.iso15118_20.dc import (
BPTDCChargeParameterDiscoveryReqParams,
BPTDynamicDCChargeLoopReqParams,
Expand All @@ -114,7 +117,8 @@ class SimEVController(EVControllerInterface):

def __init__(self, evcc_config: EVCCConfig):
self.config = evcc_config
self.charging_loop_cycles: int = evcc_config.charge_loop_cycle
self.charging_loop_cycles: int = max(evcc_config.charge_loop_cycle, 1)
self.increment = (1 / self.charging_loop_cycles) * 100
self.precharge_loop_cycles: int = 0
self.welding_detection_cycles: int = 0
self._charging_is_completed = False
Expand Down Expand Up @@ -532,6 +536,7 @@ async def continue_charging(self) -> bool:
return False
else:
self.charging_loop_cycles -= 1
self._soc = min(int(self._soc + self.increment), 100)
# The line below can just be called once process_message in all states
# are converted to async calls
# await asyncio.sleep(0.5)
Expand Down Expand Up @@ -659,14 +664,14 @@ async def get_dc_ev_status_dinspec(self) -> DCEVStatusDINSPEC:
return DCEVStatusDINSPEC(
ev_ready=True,
ev_error_code=DCEVErrorCode.NO_ERROR,
ev_ress_soc=60,
ev_ress_soc=self._soc,
)

async def get_dc_ev_status(self) -> DCEVStatus:
return DCEVStatus(
ev_ready=True,
ev_error_code=DCEVErrorCode.NO_ERROR,
ev_ress_soc=60,
ev_ress_soc=self._soc,
)

async def get_scheduled_dc_charge_loop_params(
Expand Down Expand Up @@ -727,3 +732,10 @@ async def get_target_voltage(self) -> RationalNumber:
async def enable_charging(self, enabled: bool) -> None:
"""Overrides EVControllerInterface.enable_charging()."""
pass

async def get_display_params(self) -> DisplayParameters:
"""Overrides EVControllerInterface.get_display_params()."""
return DisplayParameters(
present_soc=self._soc,
charging_complete=await self.is_charging_complete(),
)
4 changes: 4 additions & 0 deletions iso15118/evcc/states/iso15118_20_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,7 @@ async def process_message(
session_id=self.comm_session.session_id,
timestamp=time.time(),
),
display_parameters=await self.comm_session.ev_controller.get_display_params(), # noqa
scheduled_params=scheduled_params,
dynamic_params=dynamic_params,
bpt_scheduled_params=bpt_scheduled_params,
Expand Down Expand Up @@ -1040,6 +1041,7 @@ async def process_message(
session_id=self.comm_session.session_id,
timestamp=time.time(),
),
display_parameters=await ev_controller.get_display_params(),
ev_present_voltage=await ev_controller.get_present_voltage(),
scheduled_params=scheduled_params,
dynamic_params=dynamic_params,
Expand Down Expand Up @@ -1322,6 +1324,7 @@ async def process_message(
session_id=self.comm_session.session_id,
timestamp=time.time(),
),
display_parameters=await self.comm_session.ev_controller.get_display_params(), # noqa
scheduled_params=scheduled_params,
dynamic_params=dynamic_params,
bpt_scheduled_params=bpt_scheduled_params,
Expand Down Expand Up @@ -1695,6 +1698,7 @@ async def build_current_demand_data(self):
session_id=self.comm_session.session_id,
timestamp=time.time(),
),
display_parameters=await self.comm_session.ev_controller.get_display_params(), # noqa
ev_present_voltage=await self.comm_session.ev_controller.get_present_voltage(), # noqa
scheduled_params=scheduled_params,
dynamic_params=dynamic_params,
Expand Down

0 comments on commit 868f704

Please sign in to comment.