Fast hierarchical coordinated controller for distributed battery energy storage systems to mitigate voltage and frequency deviations

This paper proposes a novel hierarchical optimal control framework to support frequency and voltage in multi-area transmission systems, integrating battery energy storage systems (BESSs). The design is based on the coordinated active and reactive power injection from the BESSs over conventional synchronous generator-based control for fast and timely mitigation of voltage and frequency deviations. The principle of this new idea is to use two hierarchical schemes, one physical and one logical. The objective of the first scheme prioritises the power injection from the BESSs installed in the area where a contingency occurs, consequently reducing the disturbance of the dynamics in the neighbouring areas. In the second scheme, operational rules for aggregated BESSs in each are incorporated, increasing the safety of the asset. The proposed approach exploits the advantages of time-synchronised measurements, the eigensystem realisation algorithm (ERA) identification technique, the optimal linear quadratic Gaussian (LQG) controllers and a new aggregating agent that coordinates the power injection of BESSs in a hierarchical and scalable scheme to precisely regulate frequency and voltage of modern transmission grids, increasing their reliability and stability. The feasibility and robustness of the proposal is demonstrated using simulated scenarios with significant load changes and three-phase, three-cycle faults on a modified Kundur-system with four interconnected areas, mitigating frequency and voltage contingencies in less than 450 ms.


Introduction
Dynamics in traditional power systems are primarily dominated by the actions of synchronous generators (SGs) [1,2].However, the increasing spread of distributed energy resources (DERs), renewable energy systems and the connection of nonlinear loads with fast timeconstants triggers undesired dynamics that droop control and automatic generation control (AGC) systems are unable to handle, impacting the stability and reliability of modern power grids [3][4][5][6].Thus, this fact motivates the suitable combination of both SGs and battery energy storage systems (BESSs) acting synergistically through novel control schemes that prioritise, in an accurate and a fast way, the power dispatch.The BESSs can significantly improve the performance and security of transmission networks, improving the voltage and frequency transient responses [7,8].Likewise, it is also mandatory to bring both responses within the voltage and frequency limits, as shows in Fig. 1, according to the establishment in the standard ANSI [9,10].
Recent contributions highlight the application of BESSs for frequency and voltage support in power transmission networks [11,12].
In [1], a real-time controller that formulates the power command sets as an optimisation problem is experimentally validated, this considers the converter capacity and BESS safety constraints to provide ancillary services towards power grids.In [13,14], closed-loop control systems are proposed leveraging the BESSs to enhance the inertia of the power system even under conditions of high penetration of photovoltaic plants.In [15], an open source tool for dynamic co-simulation of transmission and distribution networks with high penetration of DERs and their influence on frequency and voltage regulation is presented.A scheme based on linear control loops, static compensators and BESSs to improve the voltage and frequency stability and energy transport capacity in an interconnected multi-generator system is investigated in [8].In [5], a central primary controller based on coordinated BESSs is proposed to mitigate voltage and frequency deviations of transmission networks.
In [16], the benefits of a novel method of coordinated control to reduce the secondary frequency droop using a BESS are presented, where the controller allows minimising the BESS utilisation.However, https://doi.org/10.1016/j.apenergy.2022 Initial mechanical power steam turbines  𝐿 Power demand despite the positive results presented, this strategy neglects the regulation of the voltage profile in the network.Similarly, in [17] are reported experimental results verifying the effectiveness of the control method based on frequency and voltage deviations.Although this technique exhibits a response time of less than 30 s, the frequency and voltage regulations present significant deviations with respect to the steadystate control commands.In [18], a hierarchical control method for  frequency and voltage regulation based on the integration of distributed energy resources and indirect measurement of control variables from load flows is proposed.The algorithm is able to mitigate the contingency in 7s, but causes oscillations in the active power injection of some generators and retains a steady-state error in controlled variables until the frequency and voltage deviation computations are updated.
In [19], several strategies to provide frequency support under low grid inertia conditions using BESSs are proposed.The presented techniques consider the simultaneous injection of active and reactive power up to the BESS operating limits.A quantitative analysis of the impact of BESS for frequency regulation in low inertia networks based on stochastic models of demand and production is presented in [20].The results only deal with the hourly estimates, preventing the evaluation of the dynamic response of the control schemes in a short time frame (on a scale of seconds).In addition, this work does not report strategies that consider the operational constraints of the electronic converters and batteries which constitute the BESSs.
Several control schemes for frequency and voltage support by power injection from the BESS are summarised in Table 1.Most of these works address the dynamic analysis from off-line simulations performed in Matlab Simulink™software.All reviewed controllers do not jointly consider the BESS operating constraints, the propagation of contingencies between network areas and the optimal calculation of control set points.From Table 1 it can be observed that all the reviewed controllers present a response time larger than 5s.
Although applications of BESSs in power systems have been widely addressed in previous research [8,[13][14][15]22], two research gaps in the existing literature on real-time control of BESSs can be highlighted: (i) the formulation of optimal control strategies with very fast response time (in the order of milliseconds), which coordinates the injection of power from clustered BESSs in order to provide ancillary services and working cooperatively with the traditional controllers in the transmission network, and (ii) the integration of algorithms that enhance battery utilisation and include the operational constraints of BESS, increasing your operational safety.Addressing these research gaps, the most significant contributions of this work are: 1.This paper proposes a novel real-time, optimal and hierarchical control framework to provide simultaneous voltage and frequency support to transmission networks with very fast response time (less than 450 ms), by exploiting the injection of power from BESSs clustered in each area of the power network.This new controller addresses two hierarchical schemes working in parallel: one physical and one logical.The former is referred to a physical prioritisation, since it reduces the utilisation of the BESSs and locally mitigates the imbalances between supply and demand in the area where the contingency takes place, in turn it reduces the impact of the disturbance in the neighbouring areas.The latter regards the logical architecture for the information flow to compute the power commands for each BESS according to its battery and converter operational constrains.At the same time, this logical architecture allows reducing the latency and computational burden of the conventional central controller, distributing the computations in the controllers and aggregators for each area.2. The proposal includes an aggregating agent acting as an intermediary between the linear quadratic gaussian controller (LQG) and each of the grouped BESSs in a network area.This aggregator can smartly manage those BESSs geographically close, working in a symbiotic cooperation with the transmission system operator (TSO) and aggregators in other areas of the network.This aggregator implements the proposed physical and logical hierarchical schemes to make the controller scalable for networks with a larger number of areas.This aggregator also implements a routine that after overcoming a contingency gradually transfers the power injection task from the BESS to the SGs in a ramp form, allowing enough time for the SGs to assume the power injection.This routine prevents disturbances to neighbouring areas by the abrupt shutdown of the BESSs.
The remaining sections of the paper are structured as follows.The detailed operation of the proposed controller and the BESSs topology with its respective controllers are described in Section 2.Then, the modelling of the system by performing the ERA identification technique is presented in Section 3. The optimal LQG controller design based on Bellman's principle is addressed in Section 4. In Section 5, the results of the tests in different scenarios are addressed.Finally, concluding remarks are pointed out in Section 6.

Real-time hierarchical control architecture and BESS topology
The proposed control framework takes advantage of emerging communication technologies and the integration of advanced metering infrastructure in a real-time control scheme with a fast-response time.Optimal and timely regulation of grid frequency and voltage can be achieved by the controlled injection of active and reactive power from several BESSs installed at different geographical locations, but working in a cooperative and coordinated way.
The controller framework comprises two hierarchical categories: (i) a logical hierarchy for information management and (ii) a physical hierarchy with dynamic allocation of power injection points.
The former includes four hierarchical levels to distribute the computations in multiple elements of the system, reducing communication latency, computational burden and optimising the batteries utilisation.Meanwhile, the second hierarchical category reduces the spread of voltage or frequency disturbances towards neighbouring areas, since the proposed scheme initially injects power only from the BESSs in the area where the contingency takes place.If the available capacity of these BESSs is not sufficient to compensate this contingency, a logical signal is sent to the surrounding areas to request support, activating the local BESSs, thus a cooperative compensation is achieved.A detailed description of the system components and their operation is given below.
The overall diagram of the proposed control scheme is depicted in Fig. 2. In this framework, The TSO schedules the grid operation on a 24-hour horizon and the regular execution of the system identification routines.The prioritisation levels, operative limits and slope of the ramp-down process is assigned by the TSO.The LQG controller, hinged on the Bellman's principle, computes the optimal active and reactive power needed to compensate the contingency in each area.The aggregator implements a complete set of rules from the logical and physical hierarchical schemes, adding intelligence to the controller.Moreover, the element is used to compute the active and reactive power set points for each BESSs grouped in the area.
In this application, the BESSs work as actuators allowing to modify the frequency and voltage dynamics in the transmission network by injecting active and reactive power.Each BESS consists of a battery pack, an electronic voltage source converter (VSC), a controllers that regulate battery charge/discharge and reactive power injection, a battery management system (BMS), a phase-locked loop (PLL) synchronisation system and a set of electronic filters.The phasor measurement units (PMUs) allow to remotely sense frequencies (  ) and voltage amplitudes (| |  ), transmitting their information in real time to TSO, LQG controllers and aggregators.
The proposed control structure reflects the scalability for larger transmission networks through the implementation of the layered information flow scheme in which the computational burden is distributed over multiple elements, taking advantage of modern digital communication systems (see Fig. 3).Thus, these computational elements can be implemented in low-cost platforms with real-time communication.Additionally, the proposed physical hierarchy scheme allows the system to control each area through an independent controller that interacts with adjacent areas only in case the contingency spreads to these areas.

Logical hierarchical structure
The advocated logic controller consists of four levels of information flow, as detailed in Figs. 3 and 4. In this scheme, the computational tasks are distributed to be executed on multiple aggregators and controllers.Thus, it reduces the computational burden, decreases the risk of total controller failure and increases the scalability of the control scheme for multi-area networks.

First logical level
Here, the operation is scheduled on a 24-hour horizon by the TSO at the central controller, where the operating limits and the target values for frequency and voltage are defined as   =1pu,   =60 Hz, respectively.additionally, the TSO sets maximum operating temperature (  ), SOC limits (  and   ) and the weighting factor    for each BESS, depending on the injection capacity and chemistry of the batteries and electronic converter of each BESS.Furthermore, this controller is responsible for issuing the binary command   for the aggregator to execute the system identification routine.

Second logical level
In this level, the LQG MIMO controller optimises the calculation of control actions (   and    ), minimising the error and the energy needed to drive the controlled variables to the desired values in each area.At this level, the LQG control system compares the frequency (  ) and voltage amplitude (| |  ) measurements of each PMU with the set point signals provided by TSO (  and   ).The design of the LQG controllers are detailed in Sections Section 4.

Third logical level
In this level, the aggregating agents behave as intermediaries between each of the LQG controller and the total number of aggregated BESSs per area, reducing the computational burden of the TSO and adding intelligence to the controller in each area via Algorithm 1.The optimal control actions computed by the corresponding LQG controller and the security constraints of the BESSs are also incorporated into the algorithm running in the aggregator.
In this proposed scheme, the aggregator requests more power from the BESSs whose SOC is closer to the optimal level shown in Fig. 5, maximising the utilisation of the batteries in their optimum zone and balancing the capacity of BESSs per area according to their    and their current   .Thus, the TSO can prioritise the use of  max  or   through the proper choice of the weighting factor   (0 ≤   ≤ 1), depending on the chemistry of the batteries and the operative limits of the power converter.The magnitude of active power to be injected for each BESS is determined according to (1).
Previous research has demonstrated that the SOC limits set for charging and discharging processes reduce batteries' service life and increase the risk of accidents for BESS operators [21,23].Manufacturers usually recommend the use of lithium batteries within the range 10%≤SOC≤90%.However, recent studies propose more moderate limits for their application in BESSs, e.g.30%≤SOC≤70% [21,23].Thus, this concept is exploited in this work to assign optimal limits for the SOC at each BESS (  and   , respectively).
where    denotes the active power required for each BESSs and    is the optimum active power estimated by the LQG controller for the th area.This logical control structure also prioritises the injection of active power towards the grid (   > 0) from BESSs with high SOC and the absorption of power from the grid (   ≤ 0) towards the BESS batteries with low SOC, encouraging the charging or discharging of the batteries to keep the SOC in the optimal zone (Fig. 5), while simultaneously BESSs provide frequency and voltage support to the transmission network.
On the other hand, the total available capacity of the BESSs per area to inject reactive power can be expressed as follows The requested reactive power (   ) of each BESS is proportionally calculated based on the available capacity, such that The aggregator also incorporates a routine that shifts the power injection commitment from the BESSs to the SGs, reducing the battery usage.The operation of the ramp is shown in Fig. 6.When the contingency occurs, deviations of frequency and voltage of the power system outside the established operating limits are detected, as is depicted at time  1 in Fig. 6(a).In response to the contingency, the proposed hierarchical control system requests power from the BESSs and the AGC system requests power from the SGs, as shows in Figs. 6 (b) and  (c), respectively.Due to the high inertia of SGs, the most significant power injection between  2 and  3 is provided by the BESSs.When the frequency and voltage return within the admissible operating limits at  3 , the BESS starts a reduction of power injection in ramp-down, whose slope is assigned by the TSO.Between  3 and  4 , the batteries usage is gradually reduced until their power injections reach zero at  4 , giving enough time for the SGs to assume the power injection required to support the change in demand with their turbine control systems [24], as is depicted in Fig. 7.In this scheme, the conventional speed controller is enhanced by incorporating a linear control (highlighted in green in Fig. 7) to reduce the error between the machine angular frequency (  ) and the expected angular frequency (  = 2  ).Where  0 and   stand for the initial mechanical power output of the steam turbines and power demand, respectively.The time constants of the SGs (  ,   and   ) and the inertia constant of the system (  ) determine the inertial behaviour and the primary frequency response of each synchronous generator.
As additional safety precaution against short-circuits, the proposed controller waits for 6 cycles of the fundamental frequency of the grid (between  1 and  2 ) and continuously checks the voltage amplitude to prevent the injection of active power that may aggravate this type of contingency.If the short-circuit is ruled out, then the process of network support through the BESSs can continue.
In addition, the aggregator has the ability to run the model identification algorithm of the power system.The design of the identification routine and the LQG MIMO controller is detailed in Sections 3 and 4, respectively.

Fourth logical level
In the fourth level, all BESSs aggregated per area provide simultaneous injection of active and reactive power into the grid, responding to the power commands sent by the aggregator located on the second level.Meanwhile, the BMS of each BESSs transmits to the aggregator To execute the ERA identification routine (Algorithm 2).36: end if the operating temperature information (  ), the maximum apparent power injection capacity (   ), the state of charge (  ) and the fault report per BESS.Nowadays, the maximum capacity of BESSs is hundreds of MVAr [25].However, the combined action of several BESSs working in coordination allows reaching a capacity of GVA [21], which is harnessed in our proposal.
Our hierarchical and smart controller is able to recognise a contingency when the measured values for frequency or voltage are outside the permissible deadbands (  and   stand for frequency and voltage deviations respectively).Note that these deadbands are primarily necessary for two purposes, which are: (i) to establish the requirements of the grid code [9,10]; and (ii) to reduce unnecessary control actions and battery usage and in turn, increasing its operational safety.

Physical hierarchical structure
At this level, the proposed control scheme considers a finite set of non-overlapping control areas.These areas could be the same as the operator defined for the automatic generation control.Each area contains synchronous generators, BESSs and metering devices such as PMUs.
When a contingency is sensed in any area, the first hierarchical physical level is assigned to this area, the adjacent neighbouring areas sharing direct interconnection lines are mapped to the second hierarchical physical level, the areas that share tie-lines with the second hierarchical level are referred to as the third hierarchical physical level and so on, as shown in Fig. 8. Active and reactive power injections from the BESSs are prioritised in the area where the contingency is detected, i.e. at the lower hierarchical level.
If the power injection capacity of the BESSs grouped in the contingency area is less than the requested power by the LQG controller and the contingency is spreading to the adjacent areas, then all BESSs belonging to the next hierarchical level are activated contributing symbiotically to the regulation.This strategy first mitigates power imbalances locally inside the contingency area with minimal disturbance to the dynamics of the rest of the system.

BESS topology and circuit level control
Power electronic converters are the primary technology for the integration of BESS into power grids [26,27].Their principal role is interfacing the batteries with the grid, controlling the active and reactive power flow.At the same time, they must ensure a safe battery operation and compliance with grid codes.The literature reports many topologies, among them, the simplicity and high efficiency of the 2-level voltage source converter (VSC) presented in Fig. 9(a), stands out [26].This topology operates in the four quadrants of the  −  plane, allowing bidirectional power flow.Its key components are the battery pack, the VSC, the filters at DC and AC terminals, the protection circuits and the step-up transformer.The transformer is used to boost the voltage from hundreds of volts in the output of the VSC up to thousands of volts at the point of common coupling (PCC) of the power network.The DC low-pass filter reduces voltage and current ripples, improving battery operation.The AC filter, consisting of 3 inductors (  x3), minimises the high frequency harmonics caused by the commutation of the power switches [28].
The control system detailed in Fig. 9(b) is implemented using PI controllers tuned with the pole-localisation method.The small-signal average model of the VSC is defined in (4) [7,29].The regulation of the direct current (  ) and current (  ) facilitates the power flow control in the BESS through the instantaneous power calculation.The synchronisation of the VSC with the grid is achieved thanks to the PLL.where   and   respectively symbolise the direct and quadrature voltage in the synchronous reference frame.  is the angular speed estimated by the PLL system.

Eigensystem realisation model via chirp modulations
In contrast to the phenomenological derivation of the power system model based on its physical parameters, this work presents an identification approach based solely on measurements of the network inputs and outputs.The inputs are represented by the active and reactive power injections from the BESSs and the outputs are represented by the frequency and voltage amplitude sensed for all PMUs.Due to a black-box model identification approach is conducted, a detailed knowledge of the internal parameters and the physical laws that relate the variables in the network can be obviated, making this methodology suitable for the identification of multi-area networks.
This work takes advantage of the ERA-based system identification technique to estimate the state-space representation of the linear model for each one of the network areas to be controlled.This modelling routine performs an automatic execution, where the system is stimulated with a known sequence input that is represented by chirp modulations (  ()) in the set points of active and reactive powers (   and    ) for each BESS.To prevent triggering nonlinearities of the power system, this excited with low-level linear inputs.In this investigation, exponential chirp functions of the form in (6), where  is the index of the selected inputs to modulate,   is the amplitude,  is the lasting signal time,   and   are the lower and upper bounds corresponding to the frequency band of the chirp signal [30].
where the chirp parameters are set as   = 25 6 ,  =10s,   = 1 Hz and   = 1 kHz.Then, the system measured response to such perturbation is observed using voltage amplitudes (|  |  ) and frequencies (  ) of different PMUs, generating a set of  output sequences (  ∈ ℜ × ), that is, the th column array corresponds to single channel, as follows: Notice that each channel  {} can be represented by the following output sequence {(0) (1) ⋯ ( − 1)}, which are samples of the voltage and frequency signals at the same sampling frequency.
Once both input and output sequences are available, a generalisation of the form (9) can be established for each single channel with  samples.

Eigensystem realisation algorithm: Single channel
This identification method algorithm is also widely used to reduce linear systems.The ERA applies the singular value decomposition (SVD) to the Hankel matrix  0 that contains the system response [31].This decomposition is useful to assemble a state-space representation of the linear model enclosing the power system dynamics.To derive the linear model for a single channel system response to a known sequence input, a pseudo-code for the ERA method is listed in Algorithm 2. Due to this investigation takes advantage of this framework to identify the most relevant dynamics of the plant represented by the transmission network.Then, this state-space linear model representation is utilised to design the optimal LQG controller.

Eigensystem realisation algorithm: Multiple-channel
For multiple outputs channels, the Hankel matrix can be also derived using submatrices Hankel that are constructed by each signal.This is called a block Hankel matrix and is given by Thus, this block Hankel matrix and its shifted Hankel matrix H1 are replaced in Step 1 of the pseudo-code in Algorithm 2, extending for multiple channels the ERA method.Besides, ERA technique allows to reduce the order of the identified model, decreasing the complexity of the equations and the computational resources needed for the simulation.
For implementation purposes, this system identification routine takes less than 10 s and is only executed when structural changes take place in the network.Since the system is operating when this routine is running, voltage amplitudes experiment a maximum amplitude variation of less than 3%.This means that the short duration of the identification process and the reduced variations of inputs do not significantly disturb the network operation.

Linear quadratic Gaussian controller
To develop the voltage and frequency regulator based on the ERA identification method and Bellman's principle, a controller structure driven by a LQG controller is adopted in terms of its two typical stages: the linear quadratic regulator (LQR) and the linear quadratic estimator (LQE).Due to the flexibility of adapting to the state-space system, a linear quadratic regulator (LQR) is proposed to perform the optimal controller in each area taking into consideration the power system linear model drawn by the ERA method.Thus, the foundations of the optimal control theory that makes up the LQR design are tackled in the following.Afterwards, the relationship between the LQR and the LQE are formally reported to establish a design of the LQG controller [32].In the sequel, both LQR and LQE are briefly discussed.

Linear quadratic regulator
Bellman's principle yields a solution to minimise error and effort by optimising control actions that modify the dynamics of the power network by reducing the deviations of the state variables (x) [33][34][35].Thus, the quadratic cost function   is proposed to balance the aggressive regulation of x with the cost of control actions u.
where, Q  and R  determine the dynamic behaviour of the controller, weighting the cost of the deviations of the state variables with respect to zero and the cost of the actuation signals.R  is defined as a positive (R  > 0); meanwhile, Q  is defined as a semi-positive matrix (Q  ≥ 0).Q  and R  are constant, symmetric, real and diagonal matrices.The setting of the diagonal elements of these matrices balances the importance between error reduction and actuation effort, prioritising accuracy or energy savings.These weighting matrices also guarantee a unique optimal solution for the control loop [35].
Accordingly, the approach in cost function (18) computes the optimal command u, regulating the plant outputs (y) to approximate it to the desired values (y * ).If the system in 16 is controllable, then it is possible to design a proportional controller to arbitrarily place the eigenvalues of the closed loop system [35], such that This methodology is intended to develop a control strategy that minimises lim →+∞   .The cost function in (18) and the constraints in the power system model in 16 are considered to solve the optimisation problem through the scalar Hamiltonian function (H) [3,34,35].
where  is the Lagrange operator.
Thus, the optimal control gain K  that minimises ( 18) is defined as follows Where P  is the solution of the algebraic Riccati equation (ARE) defined in (22).ARE is derived from (19) and (20) and it is unique symmetric and defined semi-positive.
The closed-loop system is stable when the resulting u in ( 19) is substituted into the state-space representation of the power system 16.The closed loop is expressed by

Linear quadratic estimator
Acquisition and processing of full-state measurements of power systems are technologically inviable or prohibitively expensive.In practical applications, the measurements (y) are also affected by electrical noise that must be considered in the estimation of the full state of the power system (x).The Kalman filter theory can be leveraged for the development of a stable estimator that converges to an expected full state ( x).This Kalman-based estimator is applied in conjunction with the previously presented LQR optimal control law to obtain the LQG controller design [35].
Let us now consider a full state estimator that yields an estimate x for the full state  using only knowledge of the measurements , the actuation input u, and a model of the process dynamics in 16.If the system is observable, it is feasible to compute an estimator with a filter gain () [35], as follows where ŷ is the prediction of the expected output from the full state estimation x.For the observable system in its state-space representation in 16, it is feasible to arbitrarily place the eigenvalues of the dynamics of the estimator  − G, guaranteeing the stable convergence of the estimate x to the actual state .Thus, the estimation error e =  − x is introduced.The dynamic error ė is described by The Kalman filter is the full-state optimal estimator that minimises the cost function given by where E is the expectation operator.The optimal Kalman filter gain  is given by where P o is the solution of another ARE represented in (28).V n is a diagonal matrix whose entries contain the variance of the noise terms in the measurements.
V d contains the variance of the disturbance terms.Thus, if the Kalman gain  is chosen such that the system (−G) is asymptotically stable, then  will tend to .

Implementation and simulation results
To validate the effectiveness of the proposed hierarchical control system for frequency and voltage support in transmission networks, a modified Kundur's system with four interconnected areas is simulated (see Fig. 10).Dynamic time-domain simulations are performed in the Matlab Simulink™ environment.The modified Kundur's system contains twenty-two buses and eight generators, each having a rating of 900 MVA, 20 kV and working with a fundamental frequency of 60 Hz.Detailed parameters of each SG are listed in Table 2.The four areas are interconnected with weak tie-lines of 100 km between buses 9, 10, 11 and 12. Four loads and four shunt capacitors are applied to the system at same buses.Each SG is equipped with controllers for the governors and power system stabilisers (PSS).The Kundur's transmission grid is widely used for studies on dynamic stability, power exchange, oscillation damping, among others.The detailed model of the grid is introduced in the textbook of Prabha Kundur [36].The test network is equipped with 7 BESSs, as shown in Fig. 10.Each BESS has the topology diagram shown in Fig. 9 and the rated parameters detailed in Tables 3 and 4.

Definition of test scenarios
The proposed control scheme can be practically applied for the rapid mitigation of voltage and frequency deviations resulting from the connection or disconnection of large loads, temporary failures of the power system, among other contingencies that modify the balance between generation and consumption.Attending to this set of contingencies, the proposed controller is tested in the following four scenarios: Scenario 1.In this case, the performance of the power grid in response to a load increase of 1000MW and 50MVAr at load  1 is presented.The simulations are carried out with the proposed optimal hierarchical controller acting in open loop (Fig. 11), compared to the closed loop system response (Fig. 12).In both simulations, the governor's controller and PSS of each SG are acting.
Scenario 2. This case simulates a three-cycle three-phase fault at node 15.The optimal hierarchical controller, governor's controllers and PSSs of each SG are working in closed loop.In this case, all loads and capacitor banks are maintained at their rated values.Scenario 3. A simultaneously three-cycle three-phase fault at node 15 and node 20 is simulated in this scenario.The optimal hierarchical controller and the conventional controllers of SGs are working in closed loop.The capacitor banks and loads are established at rated values.
Scenario 4. This case presents the behaviour of the optimal hierarchical controller when the maximum BESSs capacity of the area 1 is reached, in presence of a load increase contingency of 1000MW and 50MVAr at load  1 .These simulations showcase the coordinated power contribution provided by the BESSs of the neighbouring areas.In this simulation the capacities of BESSs 1 and 2, located in area 1, are reduced to 150MVA, with respect to the parameters reported in Table 4.   measured in all SGs, which remains above its nominal values, as drawn in Fig. 11(d).Under these conditions, conventional network controllers are unable to timely compensate for abrupt load changes.In contrast, when the power grid is driven by the hierarchical closed-loop controller and a contingency is detected in area 1 (close-up area in Figs.12(a) and 12(b)), the aggregator holds for 6 cycles of the fundamental frequency of the network, verifying that the contingency does not correspond to a sustained short-circuit.Subsequently, it send the power commands for activate the BESSs installed in this area (BESS 1 and BESS 2 ).The fast injection of power from the BESS allows to compensate the voltage and frequency deviations, bringing them back within the limits of the dead bands (DB  and DB  ) and close to the reference values (  =1pu and   =60 Hz), in less than 450 ms.

After
In this case, the active power injection is prioritised by the aggregator according to (1), computing the reactive power to be injected as the remaining apparent power according to (2).In this scenario, the active power injected by BESS 2 is higher than that injected by BESS 1 ; due to the fact that, the initial SOC of BESS 2 is 60% compared to the initial SOC of BESS 1 , which is 40%.Thus, the aggregator prioritises the discharge of the batteries of the BESSs with larger initial charge, attempting to dynamically balance the charge level of all BESSs involved in the compensation strategy.When the voltage and frequency return to the DB  and DB  limits, the power injection of all BESSs starts to ramp down, giving enough time for all SGs handling the power injection, which is completed in 32 s (see Figs.  network under the conditions described in Scenario 2. At  1 , a 3cycle three-phase fault event begins abruptly in node 15, disturbing the voltage and frequency levels at all monitored points in the grid.Besides, the hierarchical control system starts the verification of 6-cycle to discard a sustained short-circuit, avoiding injecting power from the BESSs and exacerbating the effect of the fault.Between  1 and  2 , the voltage and frequency detected in the SGs located in areas 1 and 2 reach values up to 60.07 Hz and 0.92pu (outside the admissible limits).Measurements exhibit significantly higher disturbance at nodes close to the point of failure.
At  2 , the fault is cleared, causing additional frequency and voltage deviations.At  3 , the short-circuit verification period is finished and the BESSs in areas 1 and 2 (BESS 1 , BESS 2 and BESS 3 ) react to quickly inject active and reactive powers to compensate the frequency and voltage deviations, by bringing them to the admissible limits given by DB  and DB  in the less than 0.5s.The effects of the fault are totally mitigated and the steady state is reached in less than 1.5s.Subsequently, all power injected by the BESSs is ramped down.
The dynamic response of the system in the presence of a simultaneous three-phase faults at nodes 15 and 20 is analysed in Fig. 14 to verify the robustness of the proposed controller.The operating conditions of the system are exposed in Scenario 3.Both faults occur at  1 , causing significant variations in the voltage, frequency, and power of the entire system.The closed-loop control scheme detects the deviation in frequency and voltage at  1 caused by the faults and initiates the 6-cycle check to discard a sustained short circuit.When the fault ends at  2 , the voltage and frequency exhibits significant oscillations in all measurement points.The short-circuit verification done by aggregator finishes at  3 , starting the injection of power from all BESSs installed in the network to compensate the frequency and voltage deviations as is shown in the zoomed area in Figs.14(c) and 14(d).The magnitude of the power injection in each BESS depends on its apparent power capacity, the initial SOC of its batteries and the requested power quantity by the optimal controller, according to (1).When the frequency and voltage return within the limits set by DB  and DB  , the power injected by all the BESSs begins to ramp down and the steady state is reached in less than 1.5s.Fig. 15 displays the operation of the hierarchical control system in Scenario 4. At  1 , a frequency and voltage contingency is triggered by a load variation at node 9.The most significant voltage and frequency variations are in the area where the contingency takes place, i.e.Area 1, as is depicted in Figs.15(a) and 15(b).The hierarchical control system initiates the 6-cycle check, expiring the verification period in  2 .The optimal LQG controller calculates    and    to request the injection of active and reactive powers from the BESSs in the Area 1.Likewise, the hierarchical controller (according to Algorithm 1) determines that the maximum capacity of the BESSs in Area 1 is less than the amount of power requested by the LQG controller and activates the power injection from the neighbouring areas (Areas 2 and 3), according to the physical hierarchical scheme presented in Section 2.2.
At  3 , the power requested by the LQG controller is reached from the BESSs.Between  3 and  4 , the power injection remains constant and below the maximum operating limits of the BESSs.In this period, the frequency and voltage variations are reduced, getting closer to   and   , respectively.At the instant  4 , the contingency disappears and all frequency and voltage measurements are within DB  and DB  .At this instant, the ramp for the gradual reduction of the power injection from the BESSs starts.Under the conditions simulated in this scenario, the time required to compensate the contingency (from  1 to  4 ) is equal to 1.4s.

Conclusions, future works and prospects applications
In this paper, a novel real-time optimal and hierarchical control framework is presented to provide frequency and voltage support for transmission networks very fast, with a millisecond response time, powered by the coordinated injection of active and reactive powers from BESSs.This proposed control structure includes an aggregating agent that formulates the active and reactive power commands according to the operating constraints of each BESS and the optimal control action estimated by the LQG controller.Simulations results demonstrate that the proposed controller is effective for frequency and voltage support in less than 450 ms, even in the presence of a load increase at node 9 of up to 125%.The dynamic performance and stability of the proposed hierarchical optimal controller is maintained despite events such as three-phase faults and significant load changes take place.This behaviour under extreme operating conditions demonstrates the reliability and robustness of the proposed approach, even considering that the system identification and controllers are tuned at rated operating conditions.
The results show that the proposed control structure prioritises power injection from all BESSs installed in the area where the contingency takes place, mitigating power imbalances locally with minimal disturbance to the dynamics of the rest of the power grid.When the capacity of the BESSs in the area is exceeded, the proposed controller activates the power injection of the BESSs installed in the neighbouring areas of defined in the next hierarchical level, symbiotically contributing to overcome the contingency faster than using traditional controllers.
The proposed hierarchical approach can be extended to control additional distributed inverter-based resources present in the grid, such as solar and wind power plants.The proposed aggregator can be modified to take advantage of the remaining power injection capacity of these inverters to inject reactive power, providing ancillary services to the grid in a coordinated and synergistic strategy with optimal control schemes.
In the next stage of this research can be considered the inclusion of experimental tests in a real time environment with power hardware integrated in the simulation loop.These tests will allow to demonstrate the effectiveness of the proposed control approach to regulate the frequency and voltage of the transmission network in the presence of noise and latency in the measurement and control signals and the effect of other distributed generation resources in the control loop.

Declaration of competing interest
The authors declare that they have no known competing financial interests or personal relationships that could have appeared to influence the work reported in this paper.

Fig. 2 .
Fig. 2. Overall diagram of the high-level controller for frequency and voltage support.

Fig. 3 .
Fig. 3. Proposed logical control architecture for information flow management.

Fig. 4 .
Fig. 4. Logical architecture of the hierarchical control system.

Fig. 5 .
Fig. 5. Logical architecture of the hierarchical control system.

Fig. 6 .
Fig. 6.Ramp to transfer voltage and frequency support from BESSs to SGs.
running scenario 1, a comprehensive comparison between the voltage and frequency responses of the grid operating in open-loop and closed-loop are depicted in Figs.11 and 12, respectively.At 10 s, the load change contingency takes place causing frequency and voltage excursions throughout the entire network.In the open loop response (Fig. 11), the frequency and voltage measurements at all nodes indicate values below the established lower limits for DB  and DB  , as points out the red dotted line in Figs.11(a) and 11(b).The contingency triggers a transient increase of the active power measured in all SGs which then returns to its nominal value as shown in Fig. 11(c).In addition, this contingency causes a sudden boost of the reactive power
12(c) and 12(d)).Fig. 13 details the dynamic responses of the proposed hierarchical control system by operating in closed loop with the modified Kundur

Fig. 12 .
Fig. 12. Simulation results for the closed loop with the power grid in (Scenario 1).(a) Frequency response.(b) Voltage response.(c) Active power.(d) Reactive power.

Fig. 15 .
Fig. 15.Power contribution provided by all BESSs of neighbouring areas in the presence of a contingency caused by a load change at node 9 (Scenario 4).(a) Frequency response.(b) Voltage response.(c) Active power.(d) Reactive power.
.119622 Received 9 February 2022; Received in revised form 31 May 2022; Accepted 2 July 2022 Weighting factor per each BESS  Lagrange operator , , ,  Power system model matrices by ERA   Binary command for requesting help from adjacent areas   Amplitude of Chirp signal   ,   Permissible frequency and voltage deadbands E Expectation operator   ,   Frequency bands limits of the chirp signal   , |  |  Remotely measurement of frequency and voltage amplitude in the k-th area  Kalman gain H Scalar Hamiltonian function  0 ,  1 Hankel matrix and shifted Hankel matrix   Inertia constant of the system  Control actions  0 Hankel matrix   ,   Direct and quadrature current  i-th BESS index   Quadratic cost function of LQR controller   Quadratic cost function of LQE estimator  k-th area controlled index Q  , R  Weighting matrices of the LQG controller K  Optimal control gain   Binary command to execute the ERA identification routine  Total number of BESSs grouped per area ,  Unitary matrices used in ERA P  Solution algebraic Riccati equation (ARE)  0

Table 1
Comparison of battery energy storage systems to mitigate voltage and frequency deviations.

Algorithm 2
Eigensystem Realisation Algorithm.Require: Input sequence (  ) corresponding to the chirp stimulation for each BESS and output sequence () corresponding to voltage amplitude and frequency.Both sequences with  samples.Ensure:  =  2 − 1. ⊳  defines the dimension of the Hankel matrix and ensures that it is greater than the number of non-zero singular values in  0 1: To apply Fourier spectra to both input and output sequences, such that ⊳ and  respectively stand for left and right singular vectors in matrix form, satisfying   =  and   = .4: To separate  0 into two components, a  large (nonzero in the case of noiseless measurements) and  small (zero in the case of noiseless measurements) singular values ⊳ 5: To approximate the high-rank Hankel matrix  0 by a reduced-rank  matrix ⊳  0 ≈        (15) 6: To compute the state-space model in discrete-time formed by matrices , , ,  as

Table 2
SGs parameters.All parameters in p.u.