# Modular Model Composition for Rapid Implementations of Embedded Economic Model Predictive Control in Microgrids

^{1}

^{2}

^{*}

## Abstract

**:**

## 1. Introduction

## 2. Materials and Methods

#### 2.1. Generalised Dynamic System Model

#### 2.2. Control Hardware Structure and Commissioning Process

- A measurement of all configured devices is conducted by the PLC and its connected input and output modules.
- The system configuration, the component parameters, and the component measurements are communicated to the EC via field bus (PLC to EC).
- The dynamic system model, depending on the transmitted configuration, is automatically composed in the EC.
- An economic optimisation is conducted based on PV and power demand predictions and the recently sampled system state (EC).
- The optimal device setpoints are communicated via field bus (PLC to EC).
- The device setpoints are applied in the energy system (simulation) by the PLC.

#### 2.3. Programming Implementation of the Configuration and Measurements (PLC)

#### 2.4. Programming Implementation of the Modular Model Composition (Edge Computer)

`instance_no`for every additional component. The parametrisation is read by the EC. The system equations are then instantiated depending on the configured system architecture (number of devices) and the parameters of the corresponding devices. The system equations are composed by using classes for the device types. Figure 4 shows an UML class diagram for the five device types that are used in the modular model composition. The classes for the device types that can occur multiple times (BESS, PV, and EV) contain the class variable

`instances`of type

`list`. The constructor-method of each class registers all invoked instances in the

`instances`variable. Using Pythons’ list comprehension, iterating over instances (derived from the parametrisation) is used to modularly compose the equation system. The assembly of the system of equations is conducted before every computation of the LP-solution (every 15 min), such that the model can be reconfigured on the fly when parameters change or additional devices are commissioned. Again, read-and-write methods for parameters, measurements and optimal setpoints are implemented for each class. The predictors for load and PV are also configured by parametrisation. These prediction methods and their accuracy have already been described in a previous publication, on which this modular model is based [13].

#### 2.5. Extension on Mixed Integer and Nonlinear Problem Formulation

#### 2.6. System Test Conditions of the MPC Controller

`systemd`daemon in order to maintain precise MPC cycles.

## 3. Results

**which**storage unit is charged or discharged, as long as the summary power is scheduled optimally, SOC limits of the EVs and BESSs are considered, and the threshold SOCs of the EVs are reached. There is no mechanism in the cost function that governs the allocation of charging or discharging among the units.

**when**the storage units are charged, because no grid power supply is used during these times, and dynamic supply prices, therefore, have no influence (the feed-in tariff is static). This becomes especially clear, when surplus renewable energy is fed into the grid in the hours 9–13, but the EVs are not charged yet.

## 4. Discussion

- Giving privilege to early charging when excess renewable power is available by adding a cost term to the objective function that penalises the charging power of storage devices and that increases over time. The cost per Watt must be small enough not to significantly alter the objective function value. This privilege can be given under the assumption that the forecast quality decreases over time. Thus, it is intuitive to use surplus renewable generation earlier rather than later, as later surplus generation may not be available anymore if the forecast is wrong. Privileging earlier charging does not have negative influences in case the forecast is right; therefore, there is no trade-off to be taken, as long as the original objective is not substantially changed by the added costs.
- Giving privilege to selected storage devices by adding a device-specific charging cost to the objective function that penalises the charging of storage devices more/less than others. Again, the cost per Watt must be small enough to not significantly alter the objective function value. A privilege sequence can be established by gradually offsetting the cost terms of the storage units.
- The commissioner has the possibility to ignore the device specific charging and discharging of the BESSs. He can use the summary charging and discharging power and share it among the two units. This can be conducted either equally or weighted with the SOCs, capacities, etc. of the storage units. Of course, the equality and inequality constraints have to be met. Nevertheless, this is the case anyway, as the PLC must continuously meet the constraints, because the economic optimisation is conducted only every 15 min and the real PV or load power can differ from the assumed prediction scenarios. This approach, however, is not suitable for the EVs, as their presence and SOC thresholds are device specific, and a summarised power approach is not possible.

## 5. Conclusions

## Author Contributions

## Funding

## Institutional Review Board Statement

## Informed Consent Statement

## Data Availability Statement

## Acknowledgments

## Conflicts of Interest

## Abbreviations

A | Set of PV power plants |

B | Set of BESSs |

$\mathsf{\Gamma}$ | Set of EVs |

$\alpha $ | PV index |

$\beta $ | BESS index |

$\gamma $ | EV index |

${P}_{\mathrm{g},\mathrm{s}}$ | Grid supply power |

${P}_{\mathrm{g},\mathrm{f}}$ | Grid feed-in power |

${P}_{\alpha}$ | Supply power of PV power plant $\alpha $ |

${P}_{\mathrm{A}}$ | Summarised supply power of all PV plants |

${P}_{\beta ,\mathrm{ch}}$ | Charge power of BESS $\beta $ |

${P}_{\beta ,\mathrm{dc}}$ | Discharge power of BESS $\beta $ |

${E}_{\beta}$ | Energy content of BESS $\beta $ |

${E}_{\mathrm{B}}$ | Summarised energy content of all BESSs |

${P}_{\gamma ,\mathrm{ch}}$ | Charge power of EV $\gamma $ |

${P}_{\gamma ,\mathrm{dc}}$ | Discharge power of EV $\gamma $ |

${P}_{\gamma ,\mathrm{a}}$ | Discharge power of EV $\gamma $ by driving |

${P}_{\mathsf{\Gamma},\mathrm{ch}}$ | Summarised charge power of all EVs |

${P}_{\mathsf{\Gamma},\mathrm{dc}}$ | Summarised discharge power of all EVs |

${E}_{\gamma}$ | Energy content of EV $\gamma $ |

${E}_{\mathsf{\Gamma}}$ | Summarised energy content of all EVs |

k | Discretisation timestep |

${t}_{\mathrm{k}}$ | Time at step k |

i | Generalised index of the components |

$\Delta t$ | Sampling interval |

N | Number of timesteps |

${\eta}_{\beta ,\mathrm{ch}}$ | Charging efficiency of BESS $\beta $ |

${\eta}_{\gamma ,\mathrm{ch}}$ | Charging efficiency of EV $\gamma $ |

${\eta}_{\beta ,\mathrm{dc}}$ | Discharging efficiency of BESS $\beta $ |

${\eta}_{\gamma ,\mathrm{dc}}$ | Discharging efficiency of EV $\gamma $ |

${P}_{\alpha ,\mathrm{f}}$ | Power forecast of PV plant $\alpha $ |

${P}_{\mathrm{l},\mathrm{f}}$ | Power forecast of load |

${P}_{i,\mathrm{max}}$ | Maximum power of general component i |

${P}_{i}^{k}={P}_{i}(t={t}_{k})$ | Power of general component i at timestep k |

${E}_{i}^{k}={E}_{i}(t={t}_{k})$ | Energy content of general component i at timestep k |

$SO{C}_{\beta}$ | State of charge of BESS $\beta $ |

$SO{C}_{\gamma}$ | State of charge of EV $\gamma $ |

${C}_{\beta}$ | Capacity of BESS $\beta $ |

${C}_{\gamma}$ | Capacity of EV $\gamma $ |

${c}_{\mathrm{f}}$ | Feed-in tariff |

${c}_{\mathrm{s}}^{k}$ | Dynamic electricity tariff at timestep k |

${c}_{\mathrm{f},\beta}$ | Feed-in tariff of PV plant $\beta $ |

${P}_{\beta ,\mathrm{inst}}$ | Installed power of PV plant $\beta $ |

${P}_{\mathrm{B},\mathrm{inst}}$ | Installed power of all PV plants |

${\mathbf{P}}_{\mathbf{i}}$ | Power vector of general component i |

${\mathbf{E}}_{\mathbf{i}}$ | Energy vector of general component i |

$\mathbf{x}$ | State vector |

$\mathbf{c}$ | Cost vector |

${A}_{\mathrm{eq}}$ | Equality constraint matrix |

${A}_{\mathrm{ub}}$ | Upper bound inequality constraint matrix |

${\mathbf{b}}_{\mathrm{eq}}$ | Equality constraint vector |

${\mathbf{b}}_{\mathrm{ub}}$ | Upper bound inequality constraint vector |

$\mathbf{l}$ | Lower bounds |

$\mathbf{u}$ | Upper bounds |

BESS | Battery electric storage system |

EC | Edge computer |

EV | Electric vehicle |

FB | Functional block |

FBD | Functional block diagram language |

ICT | Information and communication technology |

MPC | Model predictive control |

PLC | Programmable logic controller |

PV | Photovoltaic |

SME | Small and medium enterprise |

SOC | State of charge |

UML | Unified modeling language |

## References

- Garcia-Torres, F.; Zafra-Cabeza, A.; Silva, C.; Grieu, S.; Darure, T.; Estanqueiro, A. Model Predictive Control for Microgrid Functionalities: Review and Future Challenges. Energies
**2021**, 14, 1296. [Google Scholar] [CrossRef] - Ferreau, H.; Almér, S.; Verschueren, R.; Diehl, M.; Frick, D.; Domahidi, A.; Jerez, J.; Stathopoulos, G.; Jones, C. Embedded Optimization Methods for Industrial Automatic Control. IFAC-PapersOnLine
**2017**, 50, 13194–13209. [Google Scholar] [CrossRef] - Krupa, P.; Limon, D.; Alamo, T. Implementation of Model Predictive Control in Programmable Logic Controllers. IEEE Trans. Control Syst. Technol.
**2021**, 29, 1117–1130. [Google Scholar] [CrossRef] - Johansen, T.A. Toward Dependable Embedded Model Predictive Control. IEEE Syst. J.
**2017**, 11, 1208–1219. [Google Scholar] [CrossRef][Green Version] - Thieblemont, H.; Haghighat, F.; Ooka, R.; Moreau, A. Predictive control strategies based on weather forecast in buildings with energy storage system: A review of the state-of-the art. Energy Build.
**2017**, 153, 485–500. [Google Scholar] [CrossRef][Green Version] - Drgoňa, J.; Arroyo, J.; Figueroa, I.C.; Blum, D.; Arendt, K.; Kim, D.; Ollé, E.P.; Oravec, J.; Wetter, M.; Vrabie, D.L.; et al. All you need to know about model predictive control for buildings. Annu. Rev. Control
**2020**, 50, 190–232. [Google Scholar] [CrossRef] - Forbes, M.G.; Patwardhan, R.S.; Hamadah, H.; Gopaluni, R.B. Model Predictive Control in Industry: Challenges and Opportunities. IFAC-PapersOnLine
**2015**, 48, 531–538. [Google Scholar] [CrossRef] - Lucia, S.; Tătulea-Codrean, A.; Schoppmeyer, C.; Engell, S. Rapid development of modular and sustainable nonlinear model predictive control solutions. Control Eng. Pract.
**2017**, 60, 51–62. [Google Scholar] [CrossRef] - Verschueren, R.; Frison, G.; Kouzoupis, D.; van Duijkeren, N.; Zanelli, A.; Quirynen, R.; Diehl, M. Towards a modular software package for embedded optimization. IFAC-PapersOnLine
**2018**, 51, 374–380. [Google Scholar] [CrossRef] - Kathirgamanathan, A.; Rosa, M.D.; Mangina, E.; Finn, D.P. Data-driven predictive control for unlocking building energy flexibility: A review. Renew. Sustain. Energy Rev.
**2021**, 135, 110120. [Google Scholar] [CrossRef] - IEC 61131-3:2013. Programmable Controllers—Part 3: Programming Languages; Standard, International Organisation for Standardization: Geneva, Switzerland, 2013. [Google Scholar]
- Sehr, M.A.; Lohstroh, M.; Weber, M.; Ugalde, I.; Witte, M.; Neidig, J.; Hoeme, S.; Niknami, M.; Lee, E.A. Programmable Logic Controllers in the Context of Industry 4.0. IEEE Trans. Ind. Inform.
**2021**, 17, 3523–3533. [Google Scholar] [CrossRef] - Kull, T.; Zeilmann, B.; Fischerauer, G. Field-Ready Implementation of Linear Economic Model Predictive Control for Microgrid Dispatch in Small and Medium Enterprises. Energies
**2021**, 14, 3921. [Google Scholar] [CrossRef] - VDE-AR-N 4100. Technische Anschlussregeln Niederspannung; Standard, VDE Verlag: Berlin, Germany, 2019. [Google Scholar]
- Commission Regulation (EU) 2016/631. Establishing a network code on requirements for grid connection of generators. Off. J. Eur. Union
**2016**, 631, 1–68. [Google Scholar] - Han, X.; Lu, L.; Zheng, Y.; Feng, X.; Li, Z.; Li, J.; Ouyang, M. A review on the key issues of the lithium ion battery degradation among the whole life cycle. eTransportation
**2019**, 1, 100005. [Google Scholar] [CrossRef] - Boyd, S.P.; Vandenberghe, L. Convex Optimization; Cambridge University Press: Cambridge, UK, 2004. [Google Scholar]
- Jin, X.; Vora, A.; Hoshing, V.; Saha, T.; Shaver, G.; Wasynczuk, O.; Varigonda, S. Applicability of available Li-ion battery degradation models for system and control algorithm design. Control. Eng. Pract.
**2018**, 71, 1–9. [Google Scholar] [CrossRef] - WAGO. 750-8212 Controller PFC200, 2nd Generation; Datasheet; WAGO Kontakttechnik GmbH & Co. KG: Minden, Germany, 2021; Available online: https://www.wago.com/global/plcs-%E2%80%93-controllers/controller-pfc200/p/750-8212 (accessed on 25 October 2021).
- WAGO. 752-9400 Edge Computer; Datasheet; WAGO Kontakttechnik GmbH & Co. KG: Minden, Germany, 2021; Available online: https://www.wago.com/global/plcs-%E2%80%93-controllers/edge-computer/p/752-9400 (accessed on 25 October 2021).
- Python Software Foundation. Python Language Reference, Version 3.8.8. Available online: https://docs.python.org (accessed on 5 August 2021).
- Mitchell, S.; Peschiera, F.; Duquesne, C.M.; O’Neil, R.J.; Usher, W.; Hsueh, F.Y.; Prypin, O.; Detha, U.; Feng, J.; Marvin, A.; et al. Coin-or/Pulp: Version 2.4. 2020. Available online: https://zenodo.org/record/4326970#.YYy4froxVjU (accessed on 25 October 2021).
- Forrest, J.; Vigerske, S.; Ralphs, T.; Hafer, L.; Fasano, J.; Santos, H.G.; Saltzman, M.; Gassmann, H.; Kristjansson, B.; King, A. Coin-or/Clp: Version 1.17.6. 2020. Available online: https://zenodo.org/record/3748677#.YYy4k7oxVjU (accessed on 25 October 2021).
- Forrest, J.; Vigerske, S.; Santos, H.G.; Ralphs, T.; Hafer, L.; Kristjansson, B.; Fasano, J.; Straver, E.; Lubin, M.; Lougee, R.; et al. Coin-or/Cbc: Version 2.10.5. 2020. Available online: https://zenodo.org/record/3700700#.YYy4rroxVjU (accessed on 25 October 2021).
- Littlewood, B. Complexity is the enemy of dependability—Can diversity provide a defence? In Proceedings of the Eighth IEEE International Conference on Engineering of Complex Computer Systems, Greenbelt, MD, USA, 2–4 December 2002. [Google Scholar]
- Sangi, R.; Kümpel, A.; Müller, D. Real-life implementation of a linear model predictive control in a building energy system. J. Build. Eng.
**2019**, 22, 451–463. [Google Scholar] [CrossRef] - Bolzoni, A.; Parisio, A.; Todd, R.; Forsyth, A. Model Predictive Control for optimizing the flexibility of sustainable energy assets: An experimental case study. Int. J. Electr. Power Energy Syst.
**2021**, 129, 106822. [Google Scholar] [CrossRef]

**Figure 1.**Block diagram of the controller system model containing multiple devices. The device types PV, EV, and BESS are modelled individually and occur in sets A, B, and $\mathsf{\Gamma}$. The grid connection (GRID) and the aggregated power demand (LOAD) are each modelled as a single instance.

**Figure 2.**Block diagram of the control system structure: measurements of the energy system (or a digital twin energy system simulation) are taken by the PLC (Wago PFC200 [19]) and are forwarded to the edge computer (Wago Edge Computer [20]) together with configuration data from commissioning. In the edge computer, the system model is composed, and optimal setpoints are calculated, which are then applied to the energy system by the PLC.

**Figure 3.**UML class diagram of the system configuration in the PLC. Exemplary system configuration (fbCFG) and parametrisation: one component each for the load (fbAggregatedDemand) and the utility grid (fbUtilityGrid), two PV Plants (fbpvCarport, fbpvWorkshop), two EVs (fbID4, fbID4), and two battery storages (fbBYD, fbCommeo).

**Figure 5.**Flow chart of the scalable MPC implementation on PLC and EC. Initial configuration steps by the commissioning staff are highlighted green. Cyclic behaviour of the control components is highlighted blue. Dashed lines mark field-bus communication.

**Figure 6.**Results of an exemplary optimisation. The number of modular components (PVs, BESSs, and EVs) is two per category. The predicted PV power of the two plants is depicted in (

**a**,

**b**). Subplot (

**c**) shows the predicted power demand ${P}_{l}$. The charging power (blue) and discharging power (orange) of the two BESSs are shown in subplot (

**d**,

**e**). Subplot (

**f**) shows the summary charging power (blue) and discharging power (orange) of both BESSs. The resulting SOC is shown in (

**g**,

**h**). The grid supply price is plotted in (

**i**). The background of all subplots is color-coded with the grid supply price (

**i**), green meaning low prices, and red meaning high prices. The charging power (solid line) and availability (dashed line) of the EVs are plotted in (

**j**,

**k**). Subplot (

**l**) shows the summary charging power of the EVs. The resulting SOCs are shown in (

**m**,

**n**). Finally, the grid residual power (supply: blue, feed-in: orange) is shown in subplot (

**o**).

**Table 1.**Device parameters of EVs and BESSs in an exemplary production facility, which were used for the model composition in the system tests.

Device Parameter | Unit | EV1 | EV2 | BESS1 | BESS2 |
---|---|---|---|---|---|

${P}_{ch,max}$ | kW | 11 | 13 | 2 | 2 |

${P}_{dc,max}$ | kW | 0 | 0 | 2 | 2 |

C | kWh | 77 | 77 | 16 | 11.04 |

${\eta}_{\mathrm{ch}}={\eta}_{\mathrm{dc}}$ | % | 99 | 99 | 98 | 95 |

$SO{C}_{\gamma ,arr}^{24}=SO{C}_{\gamma ,arr}^{24+192}$ | % | 10 | 30 | n/a | n/a |

$SO{C}_{\gamma ,tar}^{68}=SO{C}_{\gamma ,tar}^{68+192}$ | % | 90 | 70 | n/a | n/a |

$SO{C}_{\beta ,min}$ | % | n/a | n/a | 10 | 90 |

$SO{C}_{\beta ,max}$ | % | n/a | n/a | 10 | 90 |

Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations. |

© 2021 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).

## Share and Cite

**MDPI and ACS Style**

Kull, T.; Zeilmann, B.; Fischerauer, G. Modular Model Composition for Rapid Implementations of Embedded Economic Model Predictive Control in Microgrids. *Appl. Sci.* **2021**, *11*, 10602.
https://doi.org/10.3390/app112210602

**AMA Style**

Kull T, Zeilmann B, Fischerauer G. Modular Model Composition for Rapid Implementations of Embedded Economic Model Predictive Control in Microgrids. *Applied Sciences*. 2021; 11(22):10602.
https://doi.org/10.3390/app112210602

**Chicago/Turabian Style**

Kull, Tobias, Bernd Zeilmann, and Gerhard Fischerauer. 2021. "Modular Model Composition for Rapid Implementations of Embedded Economic Model Predictive Control in Microgrids" *Applied Sciences* 11, no. 22: 10602.
https://doi.org/10.3390/app112210602