Reliable Dispatch of Active Distribution Networks via a Two-Layer Grid-Aware Model Predictive Control: Theory and Experimental Validation

Dispatching active distribution networks (ADNs) is an energy-intensive application that, if implemented via battery-energy storage systems (BESSs), can require a large capacity of these assets in order to fully balance the uncertainties caused by the stochastic demand and generation. The insufficient capacity of the BESSs often leads to their state-of-charge (SOC) saturation; this results in unreliable dispatch tracking. In this work, we propose and experimentally validate a real-time control scheme that achieves a highly-reliable dispatching of ADNs and ensures that the BESSs’ SOC is not saturated during the daily operation. Our proposed scheme uses a two-layer model predictive control (MPC). The upper-layer MPC, running every 5 minutes, optimizes the BESSs’ SOC trajectories while minimizing the tracking error, considering the prosumption forecast of the whole day. Then, the lower layer MPC, running every 30 seconds, takes the BESSs’ SOC trajectories as constraints while achieving a high-resolution tracking of the dispatch plan over the current 5-minute time horizon. Both layers account for the grid constraints by using the augmented relaxed optimal power-flow (AR-OPF) model; an exact convex relaxation of the original AC-OPF and used in this paper (for the first time in the literature) to solve a real-time constrained control problem for ADNs. Our proposed framework was experimentally validated using a 1.5 MVA/2.5 MWh BESS connected to an actual 24-node medium-voltage (MV) ADN that, in Aigle, Switzerland, hosted an uncontrollable 3.2 MWp distributed photovoltaic generation, 3.4 MVA hydro-power generations, and a 2.8 MW base demand.

we propose and validate a dispatching framework on an medium voltage (MV) feeder by using a utility-scale BESS. In the work in [11], we propose and validate a dispatching framework on a micro-grid by using multiple controllable DERs. Both controls were formulated to track the dispatch plan, over a short horizon (i.e., 5 minutes). This makes the control myopic, with respect to prosumers' uncertainties in the forthcoming timesteps. The consequence of such schemes is that the early saturation of the flexibility offered by controllable resources (e.g., BESSs' state-of-charge -SOC) can occur hence can interrupt the reliable tracking of the dispatch plan. A way to solve the problem is proposed, in [11], by optimally curtailing the excess of power from renewable stochastic generation. Another solution is to increase the time-ahead horizon period (e.g., [12]) in the real-time (RT) model predictive control (MPC) of the schemes proposed in [9] and [11]. However, this approach increases the computation time (due to large number of variables) and can exceed the RT actuation-time deadline of the MPC controller. Furthermore, most of the RT controls proposed in the literature assume BESSs to have sufficient capacities. However, this is not always true in real-life setups as different applications have different energy and power requirements. For example, using a BESS for providing primary frequency regulation [13] is a power-intensive application and does not necessarily require a large energy capacity. Two other examples of power-intensive applications are voltage regulation [14], and congestion management [15]. However, dispatching by a BESS (the main focus of this work) is an energy-intensive application, as it needs to compensate for the dispatch energy-errors that occur during the day (or until a sufficient SOC is restored). The previous works in [9] and [11] were validated with sufficiently sized BESSs. An insufficiently sized BESS, however, results in an early saturation of its capacity and will discontinue the dispatching activity for the rest of the day. Additionally, when the above schemes are implemented on a grid with rich stochastic injections, a successful dispatch requires a large BESS capacity. This capacity might be challenging to procure by the DSOs, due to regulatory constraints and (sufficiently low) payback times.
Furthermore, the works in [9] and [12] do not account for the grid constraints, and the work in [11] does consider the grid constraints via a linear power-flow model. Although the linear power-flow model in [11] stands correct for most of the cases, it cannot rigorously guarantee the feasible operation of a generic power distribution grid in correspondence to any possible state. In this respect, the full AC power-flow equations could be considered to properly model the grid constraints. However, this leads to the well-known non-convex optimal power-flow (OPF) problem [16], [17]. OPF problems are usually computationally expensive. Hence, they are often used for offline optimizations schemes such as for the planning of grid reinforcements (e.g., [18]). Several OPF-based optimization schemes are presented in [19], [20], [21], and [22]; however, either they are quite computationally expensive hence cannot be used for real-time controls, or they are not exact (i.e, the OPF solution is not a solution of the AC power-flow equations). To solve this issue, several convexification approaches (for example [11], [23], [24], [25], [26], [27], [28]) are proposed in the literature. These approaches improve the OPF computational performance for real-time controls. They can be broadly categorized into two types. The first one is based on the OPF linearization, for example, in [11], [23], [24], and [25]. These schemes rely on the first (e.g., [11], [24], [25]) or multiple (e.g., [23]) order of Taylor's series expansion of the power-flow equations that are used to express, as a function of the power injections, the nodal voltages, line currents, and the losses. In the works [11] and [25], Authors here implement linearized OPFs-based real-time controllers for real-scale ADNs. The second approach relies on the adoption of a suitable relaxation of the power-flow equations to obtain a convex formulation of the OPF [26], [27], [28]. Semi-definite relaxations as second-order-coneprogram (SOCP) in a bus injection model [27] and in a branch flow model [28] are the most adopted models. These relaxations are referred to as relaxed-OPF (R-OPF) models. However, as shown in [26], R-OPF applies to a subset of distribution networks. Furthermore, these methods ignore the presence of shunt elements, which is not a realistic assumption for MV distribution networks with branches composed by long coaxial cables. Due to inexactness of these methods, they have not been used in actual networks in realtime controllers. To overcome these shortcomings, in [26], the so-called augmented relaxed (AR)-OPF is proposed; this would account for the shunt elements and provide an exact solution of the OPF if specific conditions are met. AR-OPF is based on a SOCP relaxation of the original power-flow equations. Compared to the other SOCP-based relaxations, the AR-OPF guarantees the exactness of the power-flow solutions, given that some conditions (verifiable ex-ante) are met [26]. As it will be described later, the exactness is achieved by including some additional constraints on the SOCP-based relaxation of [28].
Given the above-listed issues, we propose a real-time gridaware MPC scheme that: (i) achieves an accurate dispatch tracking of distribution grid while avoiding BESSs' SOC saturation and (ii) integrates an AC-OPF-based grid-aware real-time control by using the AR-OPF. The proposed scheme inherently restores adequate SOC levels for the subsequent day. This is achieved by a proposed two-layer real-time MPC where the upper layer refines the SOC trajectory of the BESS every 5 minutes, based on updated forecasts of prosumers uncertainties for longer-time horizons. Then, the lower-layer MPC computes the BESS's active and reactive power setpoints by considering the SOC trajectory computed by the upper layer as a constraint. The upper-layer MPC is periodically fed with the updated 5-minute forecasts of the stochastic injections for a longer-time horizon (up to the end of the day of operation). Regarding the forecasts, we adopted an integrated data-driven prediction of the prosumption by relying on the day-ahead predicted scenarios, updated global horizontal-irradiance (GHI) forecasts from a commercial service, and the latest power measurements. Our proposed framework was experimentally validated on an actual 24-node medium voltage (MV) grid (in Aigle, Switzerland), hosted an uncontrollable 3.2 MWp distributed photovoltaic generation, 3.4 MVA hydro generations, and a 2.8 MW base demand. A grid-connected 1.5 MVA/2.5 MWh BESS was the sole controllable resource in this setup. The grid was equipped with a state-of-the-art metering and communication infrastructure to determine the grid state at a high refresh rate (i.e., 50 estimations a second) by using 17 commercial distribution-level phasor-measurement units (PMUs). In summary, our main contributions with respect to the existing literature are the following.
• The formulation of a two-layer MPC scheme. To the best of our knowledge, this is the first work that proposes a two-layer MPC scheme applied for avoiding BESS SOC saturation in dispatching ADNs. Compared to the works in [9] and [12], the proposed two-layer MPC avoids BESS SOC saturation by solving a farsighted MPC (considering a longer horizon till the end of the day), along with a myopic MPC (by a shorter horizon of 5 minutes).
• The formulation accounts for the grid constraints by using an exact convex model of AC-OPF, i.e., the AR-OPF, in contrast to the linearized grid model in [11]. Due to its exactness, the AR-OPF guarantees the feasible operation of the grid, with respect to any possible grid state. Compared to the SOCP-based AC-OPF models of [28], it applies to network models that take into account the shunt parameters.
• The experimental validation. To the best of our knowledge, this is the first real-scale experimental validation of a grid-aware AC-OPF-based real-time MPC on a real MV distribution network. The control is assisted by a dedicated metering and communication infrastructure. The paper is organized as follows. Section II states the problem, Section III describes the day-ahead problem, Section IV introduces the real-time controller, Section V presents the experimental setup, Section VI discusses the experimental results and Section VII summarizes the outcomes and findings.

II. PROBLEM STATEMENT
We consider a power distribution grid that hosts heterogeneous controllable and uncontrollable DERs. The uncontrollable resources comprise stochastic renewable power generators and demand, whereas the controllable resource is a grid-connected BESS. The grid is dispatched at its grid-connection point (GCP) by controlling the BESS via a real-time (RT) controller, according to a pre-determined dispatch plan. The dispatch plan is computed the day ahead, based on the forecasts of stochastic generation and demand, on the status of the controllable resource (i.e., the BESS), and by taking into account the local grid constraints. The dispatch plan has a 5-minute time resolution and is computed at 23:30 local time the day before operation. The RT operation begins at 00:00 local time. The purpose of the RT controller is to achieve a fine tracking of the day-ahead dispatch plan and, during the rest of the daily operation, to avoid the saturation of the BESS SOC. At the end of the day, the framework has to restore a sufficient BESS SOC for dispatching the next day. Existing schemes in [9] and [11] used a RT controller with an MPC look-ahead horizon of 5 minutes. However, this MPC is myopic to the uncertainties of the injections, which eventually leads to BESS SOC saturation, as schematically shown in Fig. 1. In this work, we avoid the BESS SOC saturation by adding a farsighted MPC layer that enforces an SOC budget. This feature is enabled by the proposed two-layered MPC framework, where the upper layer (farsighted) avoids the SOC saturation of the BESS; whereas, the lower layer (myopic) fine tracks the dispatch plan.
• The upper-layer MPC computes the BESS energybudget by using the latest intra-day forecasts and the current states of both the grid and the BESS. It runs every 5 minutes and considers an MPC horizon of the whole day in a shrinking manner, i.e, horizon length reduces as the day advances.
• The lower-layer MPC optimizes the active and reactive power setpoints of the BESS and considers the energy budget restrictions from the upper-layer MPC and grid constraints. It runs every 30 seconds and considers an MPC horizon of 5 minutes, in a shrinking manner. The day-ahead and real-time data flow is shown in Fig. 2. Each stage is described in detail in the following sections.

III. DAY-AHEAD DISPATCH COMPUTATION
The objective of the day-ahead scheduling is to compute the dispatch plan, specifically, the active power-profile that the targeted distribution network should follow at its GCP at a 5-minute resolution, during the next day operation. VOLUME 9, 2022 The dispatch plan is denoted by the sequence P disp y , y = 0, 1, . . . , N − 1, where index y is associated with 5-minute discrete intervals of the day of operation, and where N = 288 is the number of time intervals in 24 hours. The dispatch plan accounts for the stochastic variations of the distributed renewable generations and for the demand by day-ahead scenarios produced according to forecasts.

A. DAY-AHEAD LOAD AND RENEWABLE GENERATION FORECAST
The dispatch computation relies on power-injection forecasts (for each node of the network) modeled by scenarios. We develop a data-driven scheme for generating day-ahead scenarios of demand and renewable-power (in the form of PV and hydro-) generation. We assume that the PV generation is aggregated behind-the-meter (BTM) with the local loads, whereas the hydro-power generation is from stand-alone distributed power plants. Most nodes in this network hosts uncontrollable distributed renewable generation (e.g., PV) and demands (e.g., electrical appliances in residential and commercial buildings). Generally, they are characterized by a high degree of volatility due to the reduced smoothing effect given by the small number of single load units. A survey of forecasting methods accounting for local effects is presented in [29]. Based on these relatively standard approaches, we develop data-driven schemes for stochastic demand and renewable generation forecasts. These schemes are described below.

1) DEMAND FORECAST
It uses nodal historical data-sets updated on a rolling horizon, whenever new data is available. Algorithm 1 shows the key steps: The first one refers to the disaggregation of the true demand from the aggregated nodal power-injections (denoted by P l ), followed by the clustering and multivariate Gaussian fitting of the true demand. These steps are described below.
• Disaggregation separates the true demand from the behind-the-meter (BTM) PV-power generation. We use the unsupervised disaggregation (step 4 in Algorithm 1) process proposed in [30]. In short, the method relies on the net nodal power-injections (P l ), GHI G, and air temperature θ from the same area. It models the PV-power generation as a function of GHI (considering several tilt and azimuth of PV panels), enabling the identification of the patterns of the PV-power generation in the measured data set. Furthermore, it provides the disaggregated (or actual) demand that is used to develop the corresponding day-ahead forecast model.
• Clustering is applied on the estimated demand profiles (P load l ) to group them into N c clusters based on features (such as day-types in step 8, Algorithm 1). We use four clusters (N c = 4): Mondays to Thursdays (C 1 ) are in one day type, Fridays (C 2 ), Saturdays (C 3 ) and Sundays (C 4 ) are in three other separate day-type clusters.
Each day type cluster is fitted to a multivariate-Gaussian model via the following steps: (i) compute the zero mean scenarios for the historical data set (step 11, Algorithm 1), (ii) compute the time cross-correlation matrix (step 12), (iii) sample N sc number of scenarios by using the time-correlated multivariate-Gaussian distribution model with a 95% confidence interval (step 13) and, finally, (iv) generate the demand scenarios by adding the cluster mean (step 14).

2) PV-POWER GENERATION
It is modeled from the day-ahead GHI forecasts provided by a commercial forecasting service, SoDa( 2 ). It provides the present and the next-day forecasts, with a time resolution of 15 minutes and updated every 6 hours. It uses gradientboosting as part of machine-learning scheme, and inputs from historical data-sets of HelioClim-3, McClear clear sky irradiance model [31], and Global Forecast Service (GFS) Numerical Weather Prediction (NWP). 3 It provides point predictions and 5% and 95% confidence intervals that are fundamental to generate scenarios for computing the dispatch plan. The 15-minute forecasts are linearly interpolated to obtain forecasts with 5-minute time samplings. The GHI forecasts are converted to power generation using a physics-based model tool-chain [32], [33] that takes air temperature (θ), tilt, and azimuth angles and the PV-plant's nominal capacity. These parameters are obtained from the PV-config output from step 4, Algorithm 1 as the true configurations of the PV plants are not known a priori.

3) HYDRO-POWER GENERATION
In our forecast model, the hydro-power plants are operated at a given power setpoint and do not have significant intra-day variation, hence we model them as constant power-injection sources.
A validation of the predicted scenarios by using above forecasting methods are presented in Sec VI.

B. DAY-AHEAD PROBLEM FORMULATION
We use the dispatch computation algorithm from [34], a stochastic-based optimization problem accounting for the uncertainty of the nodal powers (modeled by day-ahead scenarios) and the grid constraints by co-dist-flow 4 [34]. The problem minimizes the dispatch error that considers all the day-ahead scenarios and the flexibility offered by the controllable resource. The dispatch plan is computed such that the power regulation made by the controllable resources (BESS in this case) does not violate the grid and its constraints; and the power factor at the GCP remains within a pre-defined range. As our main contribution in this work is on a real-time control scheme, we omit the dispatch formulation.

IV. REAL-TIME OPERATION
The purpose of real-time control is to track the day-ahead dispatch plan, during the day of operation by using a BESS. As stated earlier, the real-time control scheme comprises two layers operating at 5-minute and 30-second time resolutions. The control problems of both layers are formulated as MPC and require forecasts of the nodal power injections. The upper layer MPC uses forecasts of the nodal power-injections at 5-minute time resolutions, whereas the lower layer MPC uses forecasts at 30-second time resolutions. We use data-driven schemes for intra-day and short-term forecasting for upper and lower MPCs respectively. They are described below.

A. INTRA-DAY AND SHORT-TERM FORECASTING
A data-driven intra-day forecasting scheme is developed to forecast nodal power-injections during the day by using the latest power measurements (p meas l ) (provided by PMUs), the updated GHI forecasts (from SoDa), and the day-ahead scenarios. The scheme in described in Algorithm 2. Intraday forecastsp load l are obtained as the weighted sum of the day-ahead scenarios of nodal injections (P l from Algorithm 1). The weights are computed every 5 minutes, based on recent realizations (from the measurements). The weights are computed by finding the similarity (by norm-2) between the realization and day-ahead scenarios as in step 5, Algorithm 2. In step 7-12, the updated GHI and air temperature forecasts are obtained from the SoDA service then used to compute PV generation (p pv l ). Intra-day forecasts are updated every 5 minutes.

Algorithm 2 Intra-Day Forecasting
Require: Day-ahead load scenarios (P l = [p load l,1 , . . . , p load l,N sc ]), PVconfig (from Algorithm 1) 1: procedure IntraDayForecast 2: for l = 1:|L| do 3: Get realizations (p meas l ) till the last 5-minutes slot. 4: if node l contains a PV plant then  Short-term forecasts are obtained by linearly interpolating the latest intra-day forecasts with the time-resolution of 30 seconds; then we use a persistent predictor 5 to correct the forecasts of current timesteps by using the last observations. The short-term forecasts are updated every 30 seconds.

B. GRID MODEL
Both MPC layers account for the grid constraints by using the AR-OPF [26] model, an exact convexification of the non-linear AC power-flow equations. To introduce the AR-OPF nomenclature, we refer to generic two-port equivalent −model of the network branches shown Fig. 3. As anticipated, we consider a radial grid configuration.
Let index 0 refer to the slack bus. Buses other than the slack are denoted by 1, . . . , L and are in the set L. The upstream and downstream buses to bus l are denoted, respectively, by symbol up(l) and l. The symbol H refers to adjacency matrix, as defined in [26]. Let k be the time index in the set l,k be the complex power that enters the line l from top and bottom, respectively; and let f l be the square of the current in line l flowing through z l (see Fig. 3). z l = r l + ix l and 2b l be the longitudinal impedance and shunt capacitance of line l. z * According to [26], the AR-OPF constraints are composed of the SOCP relaxations of the power-flow equation (referred to as relaxed (R)-OPF). The R-OPF equations are For the exactness, the AR-OPF [26] introduces auxiliary variables in order to add security constraints on the upper bounds of the nodal voltage-and current-magnitudes. This is done such that these security constraints do not depend on original variable f , but rather on an upper boundf . Let symbolsf ,Ŝ,S are auxiliary variables for lines of the grid andv for the buses. The AR-OPF equations are as follows.    Fig. 4, and they can be represented by piecewise-linear functions as follows.
Here, v dc is the DC bus voltage and v ac t is the magnitude of the direct sequence voltage on the AC side of the converter. They can be obtained from measurements.
We model the BESS losses by adding an equivalent resistance in the power-flow equations, as proposed in [34]. The approach integrates the equivalent resistance into the grid's admittance matrix by adding a extra line (l ) for each BESS. It enables the retention of the convexity of the AR-OPF problem, without the need of any auxiliary variables. Fig. 4(b) 470 VOLUME 9, 2022 shows the equivalent resistance with an ideal voltage source and series resistance (R bess l ). Due to this simplification (i.e., adding equivalent resistance to the grid's admittance matrix) the BESS state-of-energy (SOE) (SOE l = SOC l E bess l ) evolution with sampling time T s is now expressed simply by SOE l,k+1 = SOE l,k + T s p B l,k , ∀l ∈ L, ∀k ∈ K. (2b) We constrain the SOE by safety margin of 0.1 per unit of the extremes saturation/depletion of the battery. It is 0.1 E bess l ≤ SOE l,k ≤ 0.9 E bess l , ∀l ∈ L, ∀k ∈ K, (2c) Also, to account for the degradation of the BESS caused by its operation, we include the following constraint that limits the active power by a pre-defined threshold: where N e is rated number of cycles for the battery.

2) MODEL PREDICTIVE CONTROL (MPC) PROBLEM
As stated earlier, the real-time control scheme comprises two layers, both formulated as MPCs but with different horizon lengths. The upper layer considers intra-day prosumption forecast during the whole day, via a subsequent shrinking horizon, and it computes successive BESS SOC trajectories. The lower layer considers a forecast of 5-minute intervals with a shrinking horizon and computes power setpoints for the BESS and accounts for the SOC trajectory (provided by the upper layer) as a hard constraint. This two-layered structure enables full visibility of the uncertainties during the real-time operations, thus ensuring that the control does not saturate the BESS SOC. , where . refers to the floor function. The first and the last 30-second indexes in current 5-minute intervals are denoted, respectively, by k andk, i.e., k = k 10 ×10 andk = k +10−1. The power measurements at the GCP denoted by P meas 0,k is obtained. UsingP disp k , P meas 0,k and SOE k , the lower-lyaer MPC computes BESS setpoints p B k at time resolutions of 30 seconds with indices k = 0, 1, . . . , K − 1 ∈ K with K = 2880 (for 24 hours) during the day of operation.

a: UPPER-LAYER MPC
The objective is to minimize the tracking error between the dispatch plan P disp and power at the GCP P t 0 . Note that P t 0 is a dependent variable related to the uncontrollable power injections, the controllable BESS injections and the grid losses derived from AR-OPF (Eq.(1)). The decision variables are the BESS active and reactive powers for compensating for the uncertainties in the nodal injections, the latter modeled by intra-day point forecasts. The objective function to minimize is the weighted 6 sum of the tracking error for the whole day and for the grid losses 7 : A bound on the final SOE such that it is restored to comfortable SOC by the day's operation is also added. (3c) The state of energy budget SOE l is computed using the first element of the BESS setpoint vector from upper-layer MPC: As stated before, the upper-layer MPC is solved every 5 minutes in a shrinking manner, with updated prosumption forecasts until the end of the day. Once it is solved, index y is updated to the next 5-minute index.

b: LOWER-LAYER MPC
The problem is formulated as an MPC and the objective is to minimize the energy error incurred over a 5-minute horizon length with power set-points actuated every 30 seconds. The dispatch-energy error at time k comprises (i) uncoveredenergy errors from time index k to k − 1,ˆ k = k−1 j=k (P disp j − P meas 0,j ) and (ii) the predicted error from k tok given as k = k j=k (P disp j − P t 0,j ). The MPC is fromulated as a multi-objective function that comprises the dispatch energy Additionally, the energy budget from the upper-layer MPCs are added as constraint on the BESS SOE as The constraints in (4c) sets a threshold SOC to be attained by the end of the current 5-minute duration. This ensures that the BESS is used judiciously by the lower MPC to avoid its saturation hence restore a comfortable SOC value by the end of the daily operation. Due to the convex reformulation of the AC power-flow equations that use the AR-OPF, the control problems in (3) and (4) are convex and can be solved by standard solvers (eg., Mosek [35]).

V. EXPERIMENTAL SETUP A. MEDIUM-VOLTAGE DISTRIBUTION GRID IN AIGLE, SWITZERLAND
We validate the proposed control scheme on a real MV grid situated in Aigle, Switzerland (a mixed rural/urban system operated by Romande Energie, 8 one of the main Swiss DSOs). We consider a radial feeder composed of 24 nodes. The topology and locations of various connected resources are shown in Fig. 6a-6b. It is a three-phase 21 kV/20 MVA balanced (seen in the observations) system. The grid accommodates peak power consumption (at the feeder) of 4.3 MWp and 2.9 MWp, respectively, during the winter and summer. It hosts an aggregated PV-power generation capacity of 3.2 MWp, including a single plant of 1.8 MWp. The grid also hosts a distributed hydro-power generation of 3.4 MVA that is allocated to four plants. The placement of these generations are shown in Fig. 6a. The grid is connected with a 1.5 MW/2.5 MWh BESS at node 11. Figure 6c(2-3) shows the exterior and interior of the BESS. The cells are lithiumnickel-manganese-cobalt-oxide (Li-NMCo) based and are 8 https://www.romande-energie.ch/ rated for 4000 equivalent full cycles. The grid comprises 30 racks in parallel, with 11 modules per rack in series (each module composed by 1p22s cell pack) connected to a four-quadrant power converter. The whole setup is installed in a temperature controlled container, as shown in Fig. 6c.

B. METERING AND IT INFRASTRUCTURE 1) PHASOR MEASUREMENT UNITS
The RT-MPC algorithm relies on the grid awareness provided by a cluster of distributed metering units that provide up-todate relevant measurements such that they can be accounted as initial conditions, (in the RT-MPC problem in (3) and (4)) ensuring a safe and secure operation of the grid. In this respect, the MV-distribution grid is equipped with the stateof-the-art monitoring solution SynchroGuard 9 that provides real-time situational awareness of the grid. The setup contains 17 PMUs distributed across the grid, the locations are shown in Fig. 6a. Fig 7a shows an example of an installed PMU and its components at a substation. The PMUs provide synchronised and time-tagged phasors that are sent to a central server through a phasor data concentrator (PDC). As described later, the PDC is hosted in a local server and is compliant with the IEEE Guide C37.244-2013 [36]. The PDC is responsible for the data aggregation and data pushing of the PMU measurements. The measured characteristics of this setup, especially the network latency and packet losses, are given in the Appendix VII-B. As shown in Fig. 16, the average and maximum latencies of most PMUs are below 60 and 180 milliseconds, respectively; this is much lower than the control actuation time of 30 seconds. We also show the packet losses in Table 4. As observed, the mean packet losses are below 0.02%. Therefore, the installed measuring and communication infrastructure can be considered reliable for the experimental validation of the RT-MPC [37].
A real-time state estimator (RTSE) accurately estimates nodal voltage and nodal/branch current and powers of the whole grid, every 20 ms using only the PMU data. The performance analysis of the RTSE is detailed in [38].
Note that the metering system is also a source of historical measurements used to predict day-ahead scenarios, intra and short-term forecasts of the uncontrollable injections.

2) GHI AND TEMPERATURE MEASUREMENT BOX
For the modelling of the PV generation, we use the historical data of GHI and air temperature from the same region where the PV plants are located. We installed GHI and temperature sensing boxes (Meteobox) to measure the GHI, airand PV-panel-temperatures. These meteoboxes are installed at three locations 10 in the grid. They provide in real-time measurements with sampling of 500 ms (including communication latency). Fig 7b shows the installed meteobox at the site; each one consists of a pyranometer to sense the GHI, two temperature sensors, and a power supply. They each also contain a modem to stream the measured data, by using the public 4G network, to the local data server. The meteobox code is implemented in National Instruments-Comapct-RIO. Fig. 8 shows the schematic of the communication and server infrastructure that enables the day-ahead and real-time control operations. A centralised local server hosts five different virtual machines (VMs) to implement a PDC, RTSE, data- 10 As distribution networks generally have limited geographical expansion and the substations are close to each other, a few GHI sensors are sufficient to represent GHI variation over the whole distribution network. logging, day-ahead dispatch, real-time MPC, a BESS setpoint actuator, and a router. PMU measurements are streamed to the VM1 through the public network. In the VM1, a dedicated PDC is implemented. It is responsible for PMU data aggregation and alignment. Once data aggregation is finished, it is sent to the real-time state estimation (RTSE) (running on the same VM1). After the estimation is done, the measurements and the estimated states are sent, and stored, in the local server database (by VM2). The real-time controls, day-ahead dispatcher and forecasting algorithms are implemented in VM3. VM4 hosts the BESS actuator responsible to measure the BESS state and send actuation messages (e.g., BESS setpoints). To facilitate communication among the VMs, BESS's BMS and its converter, PMUs and Meteoboxes, we equip them with a dedicated IPv4 communication network by using Ethernet cables, as shown in Fig. 8. The communication network links all the monitoring units (PMUs and Meteoboxes), the controllable resources (BESS' BMS and its converter), and the local server. The PMUs and the Meteoboxes use public telecom networks (4G), whereas the BESS BMSs and converters use Ethernet cables. As shown in Fig. 8, all the elements are connected to the local substation switch that is physically connected to a DSO control centre by the DSOowned optical-fibre network. The BESS operator connects to the server, remotely through a secure VPN client provided by the DSO control centre. Fig. 9 shows the sequence of the operations and communication flows at the day-ahead and real-time stages. In the dayahead scheduler (first step), the dispatch plan is computed and stored in the database. It is run once a day at 23:30 local time. The input to the day-ahead stage are the forecast scenarios of the load and generation of different nodes (Sec. III-A) and the estimated state of the BESS. The real-time stage (second step onward) shows the steps during the real-time operations. At the beginning of each 5-minute time interval, the energy budget is computed by the upper-layer MPC, based on latest intra-day forecasts and current SOCs. Then, the lower-layer MPC loops every 30 seconds to compute the BESS active and reactive setpoints, based on short-term forecasts and the BESS SOC. This cycle is repeated until 23:59:30 local time.

A. EXPERIMENTAL VALIDATION
In this section, we present the experimental results obtained by dispatching the MV grid described in Sec. V. First, to represent different characteristics in terms of power injection patterns, we show results for two typical days. On the first day, the MV grid imports the net power into the grid, whereas on the second day, it exports the net power (during the middle of the day), due to generations from hydro-power and PVpower plants. Then, we show the control performance for a week-long experiment. The control performance of the proposed two-layer MPC scheme is compared against other two cases: (i) Without control, where no compensation from the BESS is performed, and (ii) a single-layer MPC, where lower-layer MPC problem (eq. 4) is solved, but without SOE budget from the upper-layer MPC. As the experiments were performed with the two-layer MPC, and the same experimental conditions cannot be reproduced, we perform numerical simulations with a single-layer MPC under the same conditions as the day of operation for this comparison.

1) DAY 1
It corresponds to a clear-sky weekday, where the demand is relatively higher than the net generations. The main source of uncertainty is the demand. The experimental results are described below.
a: DAY-AHEAD OPERATION It begins at 23:30 local time the day before. It computes the dispatch plan, based on predicted scenarios. We show the day-ahead scenarios (lineplots in different colors) at the GCP 11 in Fig. 10a. The computed dispatch plan is shown in Fig. 10b, along with the power at the GCP with contribution from the BESS. As observed, the dispatch plan still has some uncovered errors due to the insufficient size of the BESS. In Fig. 10c, the SOC plot shows that, in many scenarios, the BESS reaches its saturation limits. The initial SOC is 50 %; this is also the SOC of the battery before the start of the realtime operation.
b: REAL-TIME OPERATION It starts at 00:00 hrs. Fig 11a shows the dispatch plan (in gray area), the power at the GCP for different control schemes. Fig. 11b shows the SOC evolution with different control schemes. Fig 11c shows the plot of tracking-error cumulativedistribution function (CDF) as a result of different real-time controls. The single-layer MPC lets the BESS saturate at 11 Due to space constraints, the day-ahead scenarios for the all the nodes of Aigle grid are not shown. The day ahead scenarios at the GCP is a by-product of the day-ahead scenarios at all the nodes accounting for the grid losses.  around 8:00 hrs, hence the BESS could not be used for the whole day. As a result, the dispatch fails. In contrast, the two-layer MPC ensures that the BESS never saturates, due to the energy budget constraints computed by the upperlayer MPC. The CDF plot of the tracking error in Fig. 11c shows that two-layer MPC, on the one hand, achieves a better tracking of the dispatch plan with a lower probability of high tracking error. On the other hand, it maintains the BESS SOC within a flexible range. Table 1 reports the maximumabsolute-error (MAE), net absolute-energy-error (AEE), and the root-mean-square-error (RMSE) of the dispatch error by using different controls. The two-layer MPC outperforms, respectively, the single-layer MPC in RMSE by 40%, the MAE by 67%, and the AEE by 35%. Therefore, we conclude that the control based on two-layer MPC performs the best.

2) DAY 2
It corresponds to a day with higher variation in the power injection due to higher uncertainty with next export due to high PV and hydro generations. The results are below. This day exhibits more variations in power injections that result in a higher uncertainty in the day-ahead scenarios of the GCP. Also, during the middle of the day, the net power at the GCP is negative (producing), as hydro-power plants (at different nodes) are generate power. Fig 12b shows the computed dispatch plan and compressed scenarios of the active powers at the GCP, due to the compensations from BESS. However, again the BESS capacity is insufficient to cover the uncertainty of all the day-ahead scenarios, which results in spread of the optimized power at the GCP, even with contribution of the BESS. From the BESS SOC plot in Fig. 12c, it is also evident that BESS saturates for several dayahead scenarios.  Fig. 13b and 13c. The two-layer MPC achieves fine tracking of the dispatch plan, compared to the other two cases. Moreover, the two-layer MPC restores the BESS SOC to 47% at the end of the day's operation, whereas the single-layer MPC lets  the BESS saturate to the upper limit (90%), from 7.00 hrs to 14.00 hrs and again from 20.00 hrs to 24.00 hrs. As a result, it fails the dispatch during this period. The CDF plot in Fig. 13c shows that two-layer MPC achieves a lower tracking error with high probability. The metrics reported in Table 1 show that the two-layer MPC scores on RMSE and MAE, respectively, 31% and 65% better than the single-layer MPC, however similar AEE.

3) WEEK-LONG EXPERIMENT
To demonstrate the effectiveness of the dispatching scheme, we ran the control of the BESS for an entire week. Fig 14a  shows the dispatch plan and the measured GCP power with and without two-layer MPC scheme. In Fig. 14b, we show the SOC evolution during the week. The power at the GCP follows the dispatch plan and keeps the BESS SOC within a comfortable SOC so that dispatching is continued the next day.

B. FURTHER ANALYSIS 1) VALIDATION OF THE GRID MODEL
We compare the modelled grid quantities by AR-OPF with the measurements to validate that the grid constraints are accounted correctly with minimum error. Fig. 15 shows comparison, in the form of CDFs, for the difference between (modelled vs. state estimated) the voltage, current and the losses. The CDF plots, on the voltages and currents, correspond to a particular bus/line. The modeled voltages and currents achieve high accuracy. The errors on the voltage and current modelling are less than 0.01 pu, and the errors on the losses are less than 0.2 kW for 99 % of the time. This  comparison validates that the OPF model used, in real-time MPC, to model the grid constraints are realistic.

2) COMPUTATIONAL PERFORMANCE
As stated earlier, the RT-MPC stage is solved on VM3 (Fig. 8). VM3 is configured with the Windows 10 operating system with specification 64-bit, 8 GB memory and 3.3 GHz CPU. It uses the Mosek [35] solver to solve the real-time optimization problem. Using this setup, in Table 2, we list the minimum, mean, and maximum computation times for to solving upper-and lower-layer MPCs. As it can be seen, the computation time is within 30 seconds, the time deadline of real-time actuation.

VII. CONCLUSION
In this work, we have provided a solution to the issue of BESS SOC saturation in dispatching ADNs, where a day-ahead dispatch plan is tracked by controlling a grid-connected BESS, during the day's operation. The solution relied on a two-layer real-time MPC scheme, where a slow and farsighted MPC constrain, every 5 minutes, an energy budget based on latest whole day forecasts, on the real-time fast MPC that runs every 30 seconds. The two-layer scheme ensures that the BESS SOC is not saturated during the day and that it is restored to a comfortable SOC for the subsequent day's dispatch operation. This is useful for reliable and continuous dispatching of ADNs by a BESS. The MPCs are fed by data-driven forecasts of the power demand and generations. The real-time control scheme accounts for the grid constraints by using a convex AC-OPF model. The optimization problem is convex, thus achieving optimality and enhanced-level tractability and being efficient to solve.
The control framework is validated on a real MV grid that is located in Aigle Switzerland and that hosts 3.2 MWp of photovoltaic generation, 3.4 MVA hydro-power generation, and a 2.8 MW of base demand. The MV grid is connected with a 1.5 MVA/2.5 MWh BESS that is controlled by the real-time controller and that is monitored by 17 PMUs. The experimental results, performed over a week (including clearsky, cloudy, weekday, and weekend days), show that the proposed two-layer MPC scheme always keeps the BESS SOC within flexible region and achieves better tracking, compared to myopic single-layer MPC scheme. The proposed two-layer MPC scheme reduces by half the absolute-energy tracking error (AEE), MAE, and the RMSE, compared to the myopic single-layer MPC scheme. We have also validated the grid model by comparing the modeled versus estimated states, and by concluding the error below 0.01 per unit in the nodal voltages/lines currents and below 0.2 kW in the grid losses.

A. COMPUTATION TIME WITH INCREASING NUMBER OF BESS UNITS
We perform a sensitivity analysis of the RT-MPC computation time with multiple distributed BESS units. It provides insight into how the computational performance scales with an increasing number of controllable variables. For this analysis, the BESS energy capacities are split equally at different locations, and power capacity remains the same (as in the experimental setup). The additional BESS units are placed at nodes 1, 2, 5, 7, 9, 10, and 20, respectively. The MPC was simulated for real-time operation of day 2. Table 3 reports the corresponding computation times for both the upper and lower-layer MPCs. It shows the minimum, average, and maximum time. As it can be observed, the computation time of the upper-and lower-layer MPC scale linearly with an increase in the number of BESS. When the computation time exceeds the actuation time-deadline of 30 seconds, the latter can be increased to accommodate more controllable units (or adopt a more computational-performing hardware).

B. STATISTICS ON PDC REPORTING LATENCY AND PACKET LOSSES
To verify the reliability of the communication infrastructure (mainly related to public internet networks), we look at the time latency and packet losses by each PMU. We present statistics on the delays and packet losses per PMUs. Boxplots show the latency of each PMU in Fig. 16, and the packet-data loss is shown in Table 4. The statistics are shown for the experiments conducted on day 2 (22-Mar-2022). As observed, the delays are in tens of milliseconds which is much below the control actuation time deadline. Also, the packet losses are below 0.02 % (on average) and 1.67 % (with 99 % probability). The reported statistics coincide with those reported in [37]. Therefore, we can rely on the developed communication infrastructure for the experimental validation of the proposed RT-MPC.