Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/bsp interface #379

Merged
merged 3 commits into from
Dec 22, 2023
Merged

Refactor/bsp interface #379

merged 3 commits into from
Dec 22, 2023

Conversation

corneliusclaussen
Copy link
Contributor

No description provided.

@corneliusclaussen corneliusclaussen force-pushed the refactor/bsp_interface branch 2 times, most recently from 243fe8d to 1072f72 Compare October 9, 2023 21:05
@lategoodbye
Copy link

Hi @corneliusclaussen
thanks for sharing this pull request. Could you please elaborate the motivation of this pull request? Is it to move as much as possible IEC 61851 specific stuff out of the BSP?

@corneliusclaussen
Copy link
Contributor Author

This is a refactoring that was planned for quite some time. As it breaks the BSP interfaces in an incompatible way, all BSP drivers will need to be changed. It should be relatively easy though.
Main motivations:

  1. board_support_AC was used for DC as well for a while now but some things were missing for proper DC support. Also naming was wrong

  2. To synchronize with the charging state machine in evsemanager abstract events were used (such as CarPluggedIn). This proved to be complex to use as the hardware typically knows states ABCDEF and the translation was non-trivial. To simplify BSP development, remove complexity from BSP drivers and avoid code duplication this code was moved into EvseManager. We decided to still use those abstract events internally in EvseManager as they hide some nasty details of IEC61851-1 (such as simplified charging mode). Now the BSP needs to report only the states ABCDEF. Most BSP drivers now only contain protocol translation code to the MCU and no logic anymore.

  3. Factor out AC RCD. The RCD was in the board_support_AC interface before, in order to make the design a little cleaner it was moved to a separate interface (just like the IMD for DC charging)

In addition a lot of small improvements were made.

As this breaks code for many users we will also announce this on the mailing list as well as in todays community dev meeting

@corneliusclaussen
Copy link
Contributor Author

Another note: EvseManager itself will need internal refactoring as well at some point as it got quite complex, but for now this is more about improving the interfaces to the outside so that we hopefully do not need to break BSP compatibility soon again.

@corneliusclaussen
Copy link
Contributor Author

Please especially review the following:

interfaces/evse_board_support.yaml
types/board_support_common.yaml
types/evse_board_support.yaml

Copy link
Contributor

@mooraby mooraby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General notes:

  • Not sure what guidelines do you follow, but what about using "this" to improve readability?
  • Code documentation

interfaces/evse_board_support.yaml Outdated Show resolved Hide resolved
types/board_support_common.yaml Outdated Show resolved Hide resolved
modules/EvseManager/BspStateMachine.cpp Outdated Show resolved Hide resolved
modules/EvseManager/BspStateMachine.hpp Outdated Show resolved Hide resolved
modules/EvseManager/BspStateMachine.cpp Outdated Show resolved Hide resolved
modules/EvseManager/BspStateMachine.cpp Outdated Show resolved Hide resolved
types/board_support_common.yaml Show resolved Hide resolved
types/evse_board_support.yaml Show resolved Hide resolved
modules/EvseManager/BspStateMachine.cpp Outdated Show resolved Hide resolved
modules/EvseManager/BspStateMachine.cpp Outdated Show resolved Hide resolved
types/board_support_common.yaml Show resolved Hide resolved
types/board_support_common.yaml Outdated Show resolved Hide resolved
interfaces/evse_board_support.yaml Show resolved Hide resolved
@mooraby
Copy link
Contributor

mooraby commented Oct 11, 2023

I will need to do another round of review, but at least I can confirm that the SIL is working now, also in multiple subsequent charging sessions.

@lategoodbye
Copy link

Hi,
on our website there is a detailed list (chapter 3.3.4 ff) of all error codes from our old charging stack. If i ignore all persistence related errors there are still some errors which are not available (e.g. lock capacitor not charged) above.

How should we handle these? Add them on demand later?

@corneliusclaussen
Copy link
Contributor Author

About the BspEvent error codes: I'm trying to collect all useful error codes in this enum at the moment. I'll have a look at your list as well and will include them, I think it is a good moment as we are breaking things anyway right now. Of course also more can be added later on.
Before this PR gets undrafted, we want to also port it over to the new error handling framework, see PR #284. So the error list collected in the BspEvent enum is just a temporary list to collect all error codes that we want to be able to report.

@corneliusclaussen
Copy link
Contributor Author

I looked through the ChargeControl C documentation and added the lock motor failure details. I renamed them a bit to align better with the wording used in MREC codes. The other error codes such as RCD and powermeter do not belong to this interface, they should go into the ac_rcd and powermeter interfaces. Those will become reportable errors as well soon with the new error handling framework.

modules/EvseManager/IECStateMachine.cpp Show resolved Hide resolved
modules/EvseManager/IECStateMachine.cpp Outdated Show resolved Hide resolved
modules/EvseManager/IECStateMachine.cpp Outdated Show resolved Hide resolved
types/evse_manager.yaml Outdated Show resolved Hide resolved
types/board_support_common.yaml Outdated Show resolved Hide resolved
@lategoodbye
Copy link

@corneliusclaussen I have a question regarding the detection of an EV. It's possible to implement this via different approaches (only CP, only PP, mixed CP/PP).

Is it up to the implementor of the board support package to decide if an EV is connected or is there some kind of EVerest policy how to detected this?

@mhei
Copy link
Contributor

mhei commented Oct 19, 2023

@corneliusclaussen: Would it be an option for you to cut the plug lock stuff out into a dedicated interface? This would make the bsp interface even more generic and minimalistic. BSPs with plug lock capabilities could easily implement both interfaces in a single module (e.g. Yeti if I'm right) and boards with no hardware support at all could easily just skip it. On platform like our Tarragon, we have for example two hardware plug lock interfaces. Our plan would be to create a module which cares about a single one, but customers could use another module instance for the second plug lock (e.g. for locking a fixed cable while a socket is in use...).

@corneliusclaussen
Copy link
Contributor Author

@corneliusclaussen I have a question regarding the detection of an EV. It's possible to implement this via different approaches (only CP, only PP, mixed CP/PP).

Is it up to the implementor of the board support package to decide if an EV is connected or is there some kind of EVerest policy how to detected this?

No, the BSP just sends the states etc, it does not need to find out if a car is connected or not. The norm leaves that as a choice for the implementation afaik.

EvseManager always uses CP to detect a plugin. If configured for Socket (non tethered) it will use PP afterwards to determine the current limit (and set it to 0 if PP value is invalid).

This means: attached cable: CP only (nothing else is possible)
Socket: CP+PP needs to be correct

I do not see an application where PP only makes sense?

@corneliusclaussen
Copy link
Contributor Author

@corneliusclaussen: Would it be an option for you to cut the plug lock stuff out into a dedicated interface? This would make the bsp interface even more generic and minimalistic. BSPs with plug lock capabilities could easily implement both interfaces in a single module (e.g. Yeti if I'm right) and boards with no hardware support at all could easily just skip it. On platform like our Tarragon, we have for example two hardware plug lock interfaces. Our plan would be to create a module which cares about a single one, but customers could use another module instance for the second plug lock (e.g. for locking a fixed cable while a socket is in use...).

In this case EvseManager would need to decide when to lock/unlock. In all HW that we have here this is actually done by an MCU (which ensures proper unlocking in case of Linux fails etc). It could be done though as the MCU can still do it on its own and not use the evsemanager supplied information. I factored out the RCD for the same reason of . I can make a draft, but probably after charin testival

@corneliusclaussen
Copy link
Contributor Author

@corneliusclaussen: Would it be an option for you to cut the plug lock stuff out into a dedicated interface? This would make the bsp interface even more generic and minimalistic. BSPs with plug lock capabilities could easily implement both interfaces in a single module (e.g. Yeti if I'm right) and boards with no hardware support at all could easily just skip it. On platform like our Tarragon, we have for example two hardware plug lock interfaces. Our plan would be to create a module which cares about a single one, but customers could use another module instance for the second plug lock (e.g. for locking a fixed cable while a socket is in use...).

@mhei : Another though on this: If we refactor out all motor lock things into a separate interface, would it make sense to also move all PP related things to this motor lock interface? If there is a socket it also requires a lock and only with a socket PP is useful?

If there is a fixed attached cable you don't need motor lock but you also don't need PP. What do you think?

@mhei
Copy link
Contributor

mhei commented Oct 20, 2023

In this case EvseManager would need to decide when to lock/unlock. In all HW that we have here this is actually done
by an MCU (which ensures proper unlocking in case of Linux fails etc). It could be done though as the MCU can still do it
on its own and not use the evsemanager supplied information. I factored out the RCD for the same reason of .

I like this idea. Reason is that when we factor out RCD stuff, then IMHO the EvseManager is in charge to control whether the plug should be pull-able from the socket or not and not the BSP (since it does not have the information about the tripped RCD/RCM). (I such an error case, this could then e.g. require explicit force-removal trigger via OCPP...)

@mhei : Another though on this: If we refactor out all motor lock things into a separate interface, would it make sense to
also move all PP related things to this motor lock interface? If there is a socket it also requires a lock and only with
a socket PP is useful?
If there is a fixed attached cable you don't need motor lock but you also don't need PP. What do you think?

I agree that this is usually related, but as I mentioned, I'd like to (re-)use the lock motor interface for other purposes as well. Having then a stray PP interface in this interface would make things more complex on this side.

@corneliusclaussen
Copy link
Contributor Author

I agree that this is usually related, but as I mentioned, I'd like to (re-)use the lock motor interface for other purposes as well. Having then a stray PP interface in this interface would make things more complex on this side.

Agreed. Then we leave PP in the bsp interface and create a new one with just the lock/unlock commands and error reports for the lock

@corneliusclaussen
Copy link
Contributor Author

I agree that this is usually related, but as I mentioned, I'd like to (re-)use the lock motor interface for other purposes as well. Having then a stray PP interface in this interface would make things more complex on this side.

Agreed. Then we leave PP in the bsp interface and create a new one with just the lock/unlock commands and error reports for the lock

I pushed a draft for the interfaces/connector_lock.yaml, pls have a look. It is not used that, I'll implement in evsemanager once the interface is agreed

@mhei
Copy link
Contributor

mhei commented Oct 20, 2023

@corneliusclaussen : connector lock interface (aka motor lock interface) LGTM, thanks for addressing this topic so quickly 👍

@FaHaGit
Copy link
Contributor

FaHaGit commented Nov 9, 2023

Hello together,

We at chargebyte would like to give you a brief update on the current draft of the BSP interface. We have tested the new interface for CP/PP and contactor handling with our hardware platform for the AC path. Everything seems to work as expected with the EvseManager. Some comments are still open from the code review, but once these are answered we see no problems to create a pull request from it.

Also the reported bug with resuming of the charging session by the EV (CP B -> C -> B -> C transition) works now after we updated everest framework.

We know that it will probably take a lot of effort on your side to prepare everything that it can be merged into erverest-core, but we are looking forward to working with the new interface soon :-).

Are there already plans when the new interface will be available?

Thank you and best regards

@FaHaGit
Copy link
Contributor

FaHaGit commented Nov 9, 2023

One additional note to the CP B -> C -> B -> C transition scenario. There is still 100% duty cycle for a short time after the second switch from B to C. I think this not expected.

@corneliusclaussen
Copy link
Contributor Author

Will look into the comments. Apart from that I would like to move all error logic over to the new error handling in framework. After that I will undraft the PR

@corneliusclaussen corneliusclaussen force-pushed the refactor/bsp_interface branch 2 times, most recently from b2f68eb to c2e57a7 Compare November 22, 2023 16:27
@corneliusclaussen corneliusclaussen force-pushed the refactor/bsp_interface branch 4 times, most recently from 853ef93 to dea0de0 Compare December 13, 2023 12:58
@corneliusclaussen corneliusclaussen force-pushed the refactor/bsp_interface branch 2 times, most recently from 5d48b56 to 0eb2a50 Compare December 20, 2023 16:08
@corneliusclaussen
Copy link
Contributor Author

All comments should be addressed now. It was tested both in SIL as well as on real hardware.

@corneliusclaussen corneliusclaussen marked this pull request as ready for review December 20, 2023 16:14
@corneliusclaussen corneliusclaussen force-pushed the refactor/bsp_interface branch 3 times, most recently from bded59b to 0c61816 Compare December 20, 2023 16:51
- The new evse_board_support interface replaces the old board_support_AC interface both for AC and DC.
- Move from abstract events (e.g. CarPluggedIn) to CP states A/B/C/D/E/F to simplify BSP drivers
- This moves the complete IEC61851-1 state machine into EvseManager
- create new interfaces for AC_RCD and connector_lock
- Charging subsystem is now using the new error framework
- Added most MREC error types that relate to charging
- Yeti and umwc driver will need MCU firmware updates that will come soon
- Added most MREC fault codes to NodeRed SIL UI

Signed-off-by: Cornelius Claussen <[email protected]>
corneliusclaussen and others added 2 commits December 21, 2023 15:22
Add {} to if

Co-authored-by: Kai Hermann <[email protected]>
Signed-off-by: corneliusclaussen <[email protected]>
Signed-off-by: Cornelius Claussen <[email protected]>
Comment on lines +126 to +127
if (caps_received)
break;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (caps_received)
break;
if (caps_received) {
break;
}

@corneliusclaussen corneliusclaussen merged commit d24b64f into main Dec 22, 2023
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants