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

: Economic model predictive control in microgrids combined with dynamic pricing of grid electricity is a promising technique to make the power system more ﬂexible. However, to date, each individual microgrid requires major efforts for the mathematical modelling, the implementation on embedded devices, and the qualiﬁcation of the control. In this work, a ﬁeld-suitable generalised linear microgrid model is presented. This scalable model is instantiated on ﬁeld-typical hardware and in a modular way, so that a class of various microgrids can be easily controlled. This signiﬁcantly reduces the modelling effort during commissioning, decreases the necessary qualiﬁcation of commissioning staff, and allows for the easy integration of additional microgrid devices during operation. An exemplary model, derived from an existing production facility microgrid, is instantiated, and the characteristics of the results are analysed.


Introduction
Economic model predictive control (MPC) in smart grids and microgrids is a topical field of research, and many successful applications have already been demonstrated, even if often only in simulation studies. One of these applications is unit commitment, dispatch, and demand-side optimisation in microgrids, based on dynamic pricing at the electricity exchange [1]. In this application, the optimal energy or power scheduling of microgrid components is computed based on predictions of weather, electrical, or thermal load, electricity prices, etc. The optimal schedule is used as the setpoint for the microgrid components. This optimisation of the schedule is repeated periodically with a receding horizon. The implementation of such optimisation methods on embedded hardware for industrial control is a still developing but expanding research field [2][3][4].
A critical requirement of MPC implementations is the availability of accurate and detailed mathematical models of the controlled systems. The high modelling effort can pose a significant hurdle to a widespread application of MPC in microgrids due to the time and qualification needed for the generation and identification of suitable controloriented models [5]. A large number of models for a variety of systems are described in the literature, but they are usually designed for one specific system to be controlled, major effort is spent on the implementation of these unique models, and often, they are implemented in desktop software such as Simulink or Modelica [6]. Depending on the grid regulatory framework, the cost of the modeling effort and control implementation may exceed the potential benefits from implementing MPC in microgrids. As stated by Forbes et al. [7], "many industries do not necessarily need better [MPC] algorithms, but rather improved usability of existing technologies to allow a limited workforce of varying expertise to easily commission, use, and maintain these valued applications".
The goal of this work is to reduce the modelling effort that is required to implement MPC in a class of microgrids with various configurations and to enable rapid commis-sioning of MPC on field-typical hardware. The focus is on commercial microgrids in small and medium enterprises (SMEs), using industrial information and communication technology (ICT).
One approach to rapidly implement MPC on embedded hardware is to develop the control solution in desktop software such as Matlab or Modelica and then use automatic code generation for the real-time implementation on the target embedded hardware, as presented by Krupa et al. [3]. While providing comfortable high-level engineering tools, this approach also has disadvantages. The engineering process still requires personnel who have in-depth knowledge of MPC and microgrid modelling. The automatically generated code can cause a major effort for long-term maintenance or even the need for redesign when the system architecture changes, e.g., when new components such as photovoltaic power plants or electric vehicles are put into operation. The difficulties of rapid development of MPC solutions were also addressed by Lucia et al. [8], who reduced the effort of going from simulation to an online application by providing a modular software system with standardised interfaces for simulator, model, estimator, and optimiser. An experimental validation was conducted on a laboratory reactor, where optimal control was computed on a desktop computer, and hardware was interfaced with laboratory communication equipment. Verschueren et al. [9] presented a software package for model predictive control, avoiding a separate code generation phase for prototyping and embedded applications and trying to reduce the high price to pay in flexibility, maintainability, and extensibility of code generation. Validation was conducted numerically with an inverted pendulum model on a notebook computer. Another approach to reduce modelling and system identification effort is to replace traditional physics-based models with black box models, obtained by learning techniques. However, these data-driven approaches often use highly nonlinear models resulting in high computational complexity of the MPC problem. It is not yet clear, if such data-driven methods provide significant advantages, as most studies lack benchmarking, model validation, and the proof of scalability or generalisation when applied to other buildings or systems [10].
The main aim of this work is to reduce the modelling effort needed to implement economic MPC on field devices for a wide range of microgrids and to reduce the qualification needed by the commissioning staff. We achieve this by developing a generalised model that can be easily assembled in a modular fashion when concrete microgrids are commissioned. Commissioning is carried out in IEC 61131 programming languages, which are commonly known in the automation industry [11,12]. The presented solution provides a major complexity reduction for the commissioners, who need to be trained but do not need to be MPC experts. Moreover, we investigate the effects of the generalisation and its scalability. This paper presents a generalisation of our research on field-ready implementations of economic MPC in small and medium enterprises (SMEs) [13].

Materials and Methods
This section describes a generic linear microgrid model, its modular composition, the implementation specifics on field-typical hardware, and its commissioning process. Finally, the conditions and scenarios of system tests are specified. The tests are performed in a hardware-in-the-loop test environment, which is a digital twin of an exemplary microgrid of a production facility in Germany, that is to be controlled.

Generalised Dynamic System Model
For the configurable and modular model composition, a generalised microgrid model was developed. The microgrid can consist of photovoltaic power plants (PV), electric vehicles (EV), battery electric storage systems (BESS), a single immutable load representing the total aggregated power demand of a generic production facility (LOAD), and the utility grid connection (GRID). The device types PV, BESS, and EV are not limited to single devices, as usually more than one of these can be found in SMEs and commercial microgrids. These devices are organised in sets A, B, and Γ. The utility grid connection is modelled as single instance, as multiple-grid connections are uncommon. The aggregated power demand of the production facility is also modelled as a single instance, as considering the power demand of all electrical loads separately brings no benefit in this modelling approach. The typical system architecture, in which all devices are connected to a common bus, is depicted in Figure 1. The utility grid can be used as an energy source with the supply power P g,s or as an energy sink for surplus renewable generation with the feed-in power P g,f . The aggregated power demand of the production facility is modelled as load power P l . Each PV power plant α ∈ A feeds into the common bus (main node) with a power P α , resulting in the summarised PV power Each BESS β ∈ B has a charging power P β,ch and a discharging power P β,dc , resulting in summarised charging and discharging powers The energy content of each BESS is E β , and the summarised energy content of all BESSs is Each EV γ ∈ Γ has a charging power P γ,ch and a discharging power P γ,dc with summarised powers P Γ,ch = ∑ γ∈Γ P γ,ch and P Γ,dc = ∑ γ∈Γ P γ,dc .
Each EV is discharged by driving during its absence with P γ,a . The summarised EV energy content is The equality constraints of the MPC controller model, given in explicit discrete state space representation, are P k A + P k B,dc + P k Γ,dc + P k g,s = P k l + P k B,ch, + P k Γ,ch + P k where denotes the active power of component i ∈ I = {A, B, Γ, l, g} at timestep k, and are the energy contents of the component i at timestep k. The time interval ∆t is the time difference between discretisation steps (sampling interval). This was chosen to be 15 min, which is a common billing period in energy economics, and the MPC prediction horizon was chosen to be 48 h, resulting in N = 192 timesteps, allowing a reasonably foresighted microgrid scheduling. The equality constraints in Equations (6)-(10) express the following system interrelationships: Energy conservation is required at the bus (main node) at all timesteps and includes all summarised incoming and outgoing powers. Moreover, there is energy conservation in all BESSs β ∈ B and EVs γ ∈ Γ, where η β,ch and η γ,ch are the charging efficiencies and η β,dc and η γ,dc are the discharging efficiencies, which are simplified to be constant and independent of cell temperature, power, etc. The generated power P k α of every PV plant α ∈ A is assumed to equal a plant-specific PV power forecast P k α,f . The power demand of the aggregated loads in the production facility P k l is assumed to equal a load power forecast P k l,f . In this generalised model, devices of the category BESS, EV, or PV can be modularly added to the system of equations. By adding devices to the microgrid, corresponding terms are added to the summary powers in Equation (6) and sets of N equations of type (7)-(9) are added to the equality constraints. The same principle applies to the following inequalities and bounds.
Feed-in from BESSs or EVs into the utility grid is typically regulated by region-specific rules. In Germany, grid regulation allows compensated feed-in from storage units into the utility grid only if these components are exclusively charged from on-site renewable generation [14]. However, this makes the exploitation of dynamic grid electricity pricing with these storage units impossible. To exploit time-variable energy tariffs by predictively charging BESSs and EVs and to satisfy the abovementioned grid regulation, feed-in from BESS or EV into the utility grid must therefore be prohibited by the inequality constraint.
The EU Network Code Requirements for Generators (RfG) [15], which is the underlying European regulation, is not specific on this topic and leaves room for individual regulatory design in the member states, such that the inequality of Equation (13) is not directly applicable to other European member states. However, similar national regulations have been passed in other states.
In order not to charge the EVs from the BESSs, the inequality constraint applies. Further constraints result from the limited rated power of the components and cabling.
The energy contents of the BESSs with the capacities C β and the EVs with the capacities C γ are limited with their respective minimum and maximum permitted state of charge (SOC).
The SOC operating window can be a subset of [0, 1], in order to increase battery life [16] or to guarantee minimum battery uptime for uninterruptible power supply during grid faults. The vehicle's feed into the local grid can be (temporarily or constantly) limited by the inequality constraint.
To guarantee a desired range within the EV's planned operation, their minimum SOC thresholds to be achieved at one or multiple scheduled timesteps, deviating from Equation (17) The predicted SOCs of arriving EVs at timestep k are Transmission losses due to cabling, etc., are omitted for simplicity because it would require unreasonable efforts to determine them in practical commissioning situations.
The linear cost function represents the sum of grid supply cost and feed-in revenue for all timesteps in the prediction horizon. This function is to be minimised. The feed-in revenue at timestep k equals the product of a fixed feed-in tariff c f and surplus feed-in of renewable energy into the utility grid P k g,f . The grid supply cost at timestep k equals the product of the dynamic grid electricity price c k s and grid electricity supply P k g,s . In many European countries, different PV power plants are subject to different feed-in tariffs, depending on their size and their year of commissioning. In this case, the overall feed-in tariff c f is the sum of the individual feed-in tariffs c f,β , weighted with the share of the individual installed power P β,inst in the total installed PV power P B,inst : Depending on the device type, we define one to three power vectors of type and, if applicable, one energy vector of type for each device i ∈ {A, B, Γ, l, g}. A state vector x is defined, containing all power and energy content vectors P i and E i of all devices, arranged by device type x := (E BESS , E EV , P GRID , P LOAD , P PV , P BESS , P EV ), (25) where these device class vectors are concatenations of the respective power and energy vectors P BESS = ((P 1,ch , . . . , P |B|,ch ), (P 1,dc , . . . , P |B|,dc ), P EV = ((P 1,ch , . . . , P |Γ|,ch ), (P 1,dc , . . . , P |Γ|,dc ), (P 1,a , . . . , P |Γ|,a )), and their size depends on the number of devices in each class (the cardinality of the sets).
The linear optimisation problem can then be written in general form as A ub x ≤ b ub , and (35) where c is a cost vector, which contains the cost of grid energy supply and revenue from feed-in at the corresponding indices of P g,s and P g,f and otherwise equals the zero vector. A eq and A ub are the equality and upper-bound inequality constraint matrices and b eq and b ub are the corresponding constraint vectors. Equation (34) represents the equality constraints in Equations (6)- (10), and the inequality in Equation (35) represents the constraints in Equations (13) and (14). The state vector x is constrained by the lower and upper bounds l and u. The inequality in Equation (36) represents the power and energy bounds of Equations (15)- (20). Thus, the problem is formulated in general form, and standard linear optimisation procedures such as simplex or interior-point algorithms can be used [17]. The number of rows and columns of the constraint matrices each scale linearly with additional components: where The presented modular modelling approach aims at deployment in several different plants with a simplified commissioning routine. Since BESS degradation and cycle life are quite device specific, these are not included in the optimisation model. To consider degradation, it is sufficient to (automatically) adjust the BESS parameters that change over time (e.g., capacity or efficiency) in the field hardware implementation (see Section 2.2). These parameters are usually given by the battery management system of industrial BESSs via field-bus and can be retrieved automatically. If the BESS manufacturer does not perform condition monitoring, a general model from the literature can be used. The chosen degradation model should generalise well across operating conditions and should be computationally efficient and simple enough to be used in model-based system design [18]. The cost function in Equation (21) does not consider the cost of battery degradation. However, the degradation cost could be easily included by adding a specific charging or discharging cost to the cost function where c deg is calculated from the levelised cost of storage of the specific BESS device. This preserves linearity and does not obstruct modular assembly. Due to the now high cycle stability of typical stationary BESS and the low expected number of cycles in this application, degradation costs are not considered further, and the cost function in Equation (21) is used in the presented evaluation.

Control Hardware Structure and Commissioning Process
The generalised controller model was used to implement MPC on industrial-level control hardware, which is a programmable logic controller (PLC) and an edge computer (EC). Both embedded components are mounted on DIN-rails and are suitable for switchboard cabinets. The PLC is responsible for the system sampling (measurements of the devices, e.g., PV power generation) and for the application of optimal setpoints to underlying control circuits (e.g., battery charge controller). Moreover, the specifications of the concrete controller model (the individual device parameters and the number of devices, i.e., the cardinality of the sets) are defined by a commissioning staff in the PLC in IEC 61131 languages. These specifications are communicated via field bus to the EC, where the modular model composition and the embedded optimisation take place. The hardware structure is depicted schematically in Figure 2. The device separation is conducted for reasons of commissioning, reliability, maintainability, and IT-security as explained in [13].
After the system is specified in the PLC, the optimisation, which is performed every 15 min, works as follows:

1.
A measurement of all configured devices is conducted by the PLC and its connected input and output modules. 2.
The system configuration, the component parameters, and the component measurements are communicated to the EC via field bus (PLC to EC). 3.
The dynamic system model, depending on the transmitted configuration, is automatically composed in the EC.

4.
An economic optimisation is conducted based on PV and power demand predictions and the recently sampled system state (EC). 5.
The optimal device setpoints are communicated via field bus (PLC to EC). 6.
The device setpoints are applied in the energy system (simulation) by the PLC.

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.

Programming Implementation of the Configuration and Measurements (PLC)
For a widespread application of economic MPC in power systems, it is crucial to not only reduce the modelling effort but as well to reduce the commissioning time and the training needs of commissioning staff. In the presented implementation, the commissioners do not need to be trained MPC experts, because the system configuration is conducted entirely on the PLC within the widely used IEC 61131 programming style using the Codesys V3 runtime system [11]. Since 2013, the third and current edition of the standard (IEC 61131-3) allows for object-oriented programming. A PLC program contains function blocks (FBs) that can be linked together in graphical programming languages such as the function block diagram language (FBD). These FBs correspond to classes in the object-oriented programming paradigm.
The developed program contains preconfigured FBs for all component types. Figure 3 shows the FBs (classes) of the PLC program. For every device in the power system, one instance of a corresponding FB has to be instantiated by the commissioner. All device parameters, that describe the corresponding device (e.g., maximum charge power, minimum and maximum SOC/energy content of a BESS, etc.), must be passed to the FB instance. Furthermore, the measurements from the power system are passed from I/O components of the PLC to the FB instances. All FBs contain methods for the publication of parameters and measurements on the communication bus, which can then be accessed by the edge computer in order to assemble the equation system, depending on the system configuration and parametrisation. The IEC standard allows extensions of function blocks, a concept that is similar to inheritance. This allows commissioning engineers to extend function blocks in order to incorporate functionalities, that are additional to the presented core properties and methods and add to the flexibility that is required to adapt the general model in concrete microgrids. This includes device-specific battery degradation models.

Programming Implementation of the Modular Model Composition (Edge Computer)
After receiving the configuration, parametrisation, and measurements on the communication bus from the PLC, the concrete model is automatically composed in the EC, and the economic optimisation is computed as follows: The model composition and economic optimisation is implemented in Python [21] using the coin-or/pulp modelling language [22] and the coin-or/clp solver [23]. The parametrisation in the PLC is communicated via Modbus to the EC. The bus address of each device is composed of class-specific addressoffsets together with sequential numbers 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]. . 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).

Extension on Mixed Integer and Nonlinear Problem Formulation
The basic idea of the linear model assembly is that any additional linear constraint preserves the inherent convexity. This is not the case for mixed-integer linear programs (MILP), since integer problems are inherently nonconvex. On the other hand, solution methods for MILP are typically based on LP relaxation; therefore, the modular methodology is in principle transferable. The used modelling language Pulp [22] allows integer modelling and the integration of the MILP solver CBC [24].
However, complexity is the enemy of dependability [25]. This is especially true in unsupervised embedded implementations such as the presented one, in contrast to supervised MILP implementations on workstation PCs and control rooms that are common in the recent literature [26,27]. MILP formulation of the energy system model can be avoided, as explained in [13]. As a consequence, the linear formulation avoids the necessity of solving NP-hard MILP problems and avoids the necessity of computationally and eventually economically expensive solvers such as CPLEX or Gurobi that can endanger the overall economic feasibility of an MPC implementation in the field.
The approach is in principle transferable to nonlinear modelling, as long as convexity is preserved. However, the convexity of all possible model assemblies should be rigorously assessed. The necessity of expensive solvers can again endanger the economic feasibility of an MPC implementation in the field.

System Test Conditions of the MPC Controller
Together, the PLC and EC form the MPC controller. A flow chart of the two components and their tasks is shown in Figure 5. The PLC tasks are executed cyclically with cycle times of 10-100 milliseconds, i.e., virtually continuously compared to the discrete optimisation intervals of the EC every 15 min. Optimisation in the EC is triggered by Linux' systemd daemon in order to maintain precise MPC cycles.
The implementation was tested with a system model in which the number of modular components (PVs, BESSs, and EVs) is two per category. For the tests, the measurement data and predictions from an existing production facility were used as scenarios. The configured device parameters for BESSs and EVs, used for the system tests, are shown in Table 1. The static feed-in tariff of c f = 0.14 €/kWh is taken from German grid regulation and corresponds to the installed PV power plants at the facility. The dynamic electricity tariffs were taken from a German utility, which provides tariffs based on European electricity exchange prices. The price and scenario data were taken from 18 September 2020 and 19 September 2020.

Results
Results of an exemplary optimisation are shown in Figure 6, where PV, load, and grid supply price scenarios are plotted, as well as planned BESS and EV power, the resulting SOCs, and the resulting grid residual power. This exemplary optimisation was carried out in a system that had been assembled as described above.
The summary power of the storage units (EVs and BESSs) is plausible and scheduled as expected. Charging is scheduled when prices are low (e.g., EV-charging from the grid in the hours 37-40) or when excess PV energy is available (e.g., EV-charging from PV in the hours [11][12][13][14][15][16][17]. Discharging is scheduled when prices are high (e.g., in the hours 6-9 and 19-25). However, the allocation of the total power to the individual storage units seems erratic as it shows randomly appearing on-off behaviour. This is especially visible during the discharging of the BESSs in the hours 19-26 and 43-48. The summarised BESS power during these hours is equal to the power demand of the load, while the two units are alternately operated at their maximum discharge power. The erratic behaviour is also visible during charging of the EVs. The summary power follows the PV scenario power after hour 11, while the allocation to the units is random. This solution of the optimal control problem is indeed erratic since multiple optimal solutions exist, which is a common characteristic of LPs. Multiple optimal solutions can occur when a hyperplane of the constraint polytope is perpendicular to the cost vector. Translated to the application, two sources for the occurrence of multiple optimal solutions were identified.
First, for the economic optimisation under the given cost function, it does not matter 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. Secondly, when excess renewable power is available during a longer time period, it does not matter 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.
The computation time for the two main software modules in the EC (i.e., assembler and solver) was measured for energy systems containing one device per class up to six devices per class (a total number of 3-18 modular devices). The computation time of both software modules scales linearly with additional energy system components. This contributes to the practical applicability of the solution for larger systems, especially in the light of the fact that solution algorithms for LPs in general are polynomially or exponentially bounded algorithms.

Discussion
The demonstrated simplification of microgrid modelling on embedded devices is a novel and major contribution to the accelerated deployment of economic MPC application in the power system. It has the potential to increase the penetration of this advanced control technique in the power system, as the effort for the implementation in existing and new systems is significantly reduced. Unique modelling for every concrete microgrid is no longer a main hurdle, and expert knowledge is no longer required for each commissioning process. In addition, extending the control model with new components does not require a complete redesign, as the system assembly is conducted in every optimisation step. New components can easily be configured and included in the control system. This is especially important, as commercial microgrids tend to change over time, when companies grow. In light of small intraday price spreads of real-world dynamic electricity tariffs [13], the proposed simplification of the commissioning process is a necessity in order to make the application of economic MPC in a variety of SME microgrids economically feasible.
It has been shown that the solutions to the optimal control problem can also be ambiguous. With the described cost function, which represents the actual cost of supplying energy from the power grid, several optimal solutions may exist. While the behaviour shown in Section 3 is perfectly acceptable with respect to the objective function, it may not be perceived as intuitive by the user. In this context, three possible improvements are conceivable:

1.
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.

2.
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.

3.
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.
The presented modular model composition avoids data-driven modelling approaches, which might not be feasible in a practical context. If a company decides to implement advanced control techniques such as MPC, a long-lasting period of data acquisition and model training might not be practicable. This is even more the case for changes in the system architecture. It is not viable to retrain models with every additional device (one might think about the dynamic development of a commercial vehicle fleet).
However, the presented solution is limited to linear modelling and the five device types power grid, loads, PVs, BESSs, and EVs. This linear approach was chosen as the result of a trade-off between performance and dependability. The integration of other devices might make nonlinear modelling or mixed logical dynamic system modelling necessary, in order to represent nonlinear or discrete behaviour of these components. The presented approach is in principle transferable to MILP or NLP formulations, but in the context of reliable unsupervised operation, this requires an ex ante study and rigorous proof of convexity and feasibility of the problem formulation and of reachability of the global optimum, which is comparatively straightforward in linear optimisation.

Conclusions
In this article, a way to decrease modelling and commissioning effort for the application of economic MPC in microgrids on field-typical hardware is presented. This was achieved by the concept of a generalised model, which can be composed for a class of microgrids in a modular fashion on embedded devices. The modular composition is limited to a linear model and the components grid, aggregated power demand, photovoltaic power plants, electric vehicles, and battery electric storage systems. No expert knowledge of economic MPC is required during commissioning, as the model assembly is fully automated and the necessary configuration is performed on a PLC in the IEC 61131 languages, which are widely used in the automation industry. This can help to significantly increase the use of this advanced control method in microgrids, which is undoubtedly necessary to make the power grid more flexible. Future research should aim to replicate these results in field studies. In addition, the extension to mixed integer, mixed logical dynamic systems or nonlinear systems might prove an important subject for future research to include other device types that show nonlinear or discrete behaviour.
Author Contributions: Conceptualization, methodology, software, visualisation, and writingoriginal draft preparation, T.K.; investigation, validation and data curation, T.K. and B.Z.; writingreview and editing, B.Z. and G.F.; resources and supervision, G.F.; project administration and funding acquisition, T.K., B.Z. and G.F. All authors have read and agreed to the published version of the manuscript.

Abbreviations
The following symbols and abbreviations are used in this manuscript: