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

fix(core): Avoid flickering between charge/discharge due to PID filter #2960

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

parapluplu
Copy link
Contributor

@parapluplu parapluplu commented Jan 8, 2025

Before this change the PID filter implementation eventually caused the behavior to switch from charging to discharing, eventhough the system wanted to (a) charge with a lower value than before (b) set active power to 0. This was due to the fact, that the PID filter overshoots its target.
By detecting if the system wants charge/discharge/no current flow the battery, it now dynamically adjusts the limits of the battery so it does not overshoot in the unwanted area. This reduces stress on the battery. It also improves the controller that are using this filter (e.g. self consumption optimization, peak load shaving). Sometimes they showed behavior where they wildly flicker between charging/discharging.

Examples:
image

self consumption optimization:
image

@parapluplu parapluplu force-pushed the parapluplu/feat/pid_fix branch from 1c683a1 to 2d398f4 Compare January 8, 2025 14:40
Copy link

codecov bot commented Jan 8, 2025

Codecov Report

Attention: Patch coverage is 88.23529% with 2 lines in your changes missing coverage. Please review.

Additional details and impacted files
@@              Coverage Diff              @@
##             develop    #2960      +/-   ##
=============================================
+ Coverage      57.09%   57.23%   +0.14%     
- Complexity      9735     9775      +40     
=============================================
  Files           2266     2267       +1     
  Lines          96819    96823       +4     
  Branches        7163     7164       +1     
=============================================
+ Hits           55270    55407     +137     
+ Misses         39487    39348     -139     
- Partials        2062     2068       +6     

@parapluplu parapluplu force-pushed the parapluplu/feat/pid_fix branch 3 times, most recently from fcbcdfb to b477aca Compare January 8, 2025 19:08
Before this change the PID filter implementation eventually caused the behavior to switch from charging to discharing, eventhough the system wanted to (a) charge with a lower value than before (b) set active power to 0. This was due to the fact, that the PID filter overshoots its target.
By detecting if the system wants charge/discharge/no current flow the battery, it now dynamically adjusts the limits of the battery so it does not overshoot in the unwanted area. This reduces stress on the battery. It also improves the controller that are using this filter (e.g. self consumption optimization, peak load shaving). Sometimes they showed behavior where they wildly flicker between charging/discharging.
@parapluplu parapluplu force-pushed the parapluplu/feat/pid_fix branch from b477aca to c4a0653 Compare January 8, 2025 20:25
@tsicking
Copy link
Contributor

tsicking commented Jan 9, 2025

Looking at your graphs I have some questions:

  1. Is the unit really kW, or is it an error in your Grafana dashboard? Changing from -120kW to 90kW within a few seconds is quite massive.
  2. What does the graph actually show? Is it the active power read from the device (SymmetricEss.ChannelId.ACTIVE_POWER), or the setpoint from OpenEMS (ManagedSymmetricEss.Channeld.DEBUG_SET_ACTIVE_POWER)?
  3. Do you also have "After"-screenshots to see the impact of this PR?

Best regards,
Thomas

@parapluplu
Copy link
Contributor Author

parapluplu commented Jan 9, 2025

Hey,

  1. Yes, it's actually kW.
  2. The graph shows the ActivePower channel of the ess, so SymmetricEss.ChannelId.ACTIVE_POWER, which is the active power of the device.
  3. Partially yes. I have a graph of an inital hot fix I've applied back when I observed the issue.
    The graph ends, as the next datapoint is a 0 again, which is only send 5 minutes later and therefore you don't see it when you zoom in. The second picture shows the overall picture, but you don't see the PID curves as nicely as in the first one.
    image
    image

@parapluplu
Copy link
Contributor Author

I've reproduced the problem on a simulated system now to generate graphs for the fix in this merge request (and not just for my previous hotfix). The graphs are much more beautiful, because they show the pure behavior of the PID controller. In the graphs above the hardware factor made the graphs a bit more noisy. :)

Setup:
Simulated ESS with max 120kW charge/discharge power.
Used self consumption optimization controller.
Simulated energy consumption of 150kW, which then suddenly drops to 0kW
PID controller with p=0.3, i=0.3, d=0.1

Without the fix you get the following (in my opinion beautiful) graph:
image

With the fix you get the following (booooring) graph:
image

@Sn0w3y
Copy link
Contributor

Sn0w3y commented Jan 10, 2025

I can confirm, that i had the same Issues with 0,3 0,3 0,1

@sfeilmeier
Copy link
Contributor

@pooran-c & @huseyinsaht Could you please crosscheck this with our experiences?

@TheSerapher
Copy link

TheSerapher commented Jan 18, 2025

This looks like something I have been seeing in my much smaller system I think. Whenever my system was loaded with a 20kW consumer (Water heater) and the load was suddenly turned off it looked like the system needed some time to balance things out again. When I saw your simulated graph that looked pretty much like something I have been seeing. Not saying it’s the same thing but if it is I can’t wait for this fix being added to FEMS as well. Well done, the after-graph looks great!

@Sn0w3y
Copy link
Contributor

Sn0w3y commented Jan 18, 2025

This looks like something I have been seeing in my much smaller system I think. Whenever my system was loaded with a 20kW consumer (Water heater) and the load was suddenly turned off it looked like the system needed some time to balance things out again. When I saw your simulated graph that looked pretty much like something I have been seeing. Not saying it’s the same thing but if it is I can’t wait for this fix being added to FEMS as well. Well done, the after-graph looks great!

Yes, I also had the same Issues (NO FEMS - native OpenEMS) :)

@sfeilmeier
Copy link
Contributor

Please note that PID is disabled by default for FENECON Home systems, because there we use a specific SMART mode instead, which uses the faster internal reaction time of the inverter.

@TheSerapher
Copy link

Please note that PID is disabled by default for FENECON Home systems, because there we use a specific SMART mode instead, which uses the faster internal reaction time of the inverter.

If that is the case and I am seeing instability when trying to recover from a removed load for a couple of minutes I would assume it’s not working properly? Probably not for this issue then 🙂

@TheSerapher
Copy link

Quickly threw together a Grafana panel since it just happened again. I think this looks very similar to the graphs above. Purple line (Consumer 3) is a load and after the load is gone it takes quite some time to come to an equilibrium again.

IMG_0197

@TheSerapher
Copy link

Even though the PID filter may not apply on FEMS systems, the flicker still exists. Here a better view with lower power consumption overall but visible flicker of Grid/Battery fluctuations.

Not sure this is the right place for it since it’s using a different implementation but figured I append the ticket.

IMG_0209
IMG_0208

@huseyinsaht
Copy link
Contributor

Hi @parapluplu,

We have reviewed your code and noticed that you are manipulating the input of the PID controller.
Instead, this should be implemented as a disturbance within the PID controller.
pid-controller

Rather than altering the feedback power (input), we should take the calculated power value and then decide how to proceed with it.
As we understand, the goal is to observe the output power as shown below (red line).
pid-regel

Apart from that, it is quite difficult to predict the outcome because we do not know the model.
The best approach is to conceptualize and develop a model for our storage systems.
However, this will be discussed with our electrical engineers.

We will give a feedback as soon as possible as we talk to our engineers.

BR,
Huseyin Sahutoglu

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.

6 participants