Consensus based SoC trajectory tracking control design for economic-dispatched distributed battery energy storage system.

The state-of-charge (SoC) of an energy storage system (ESS) should be kept in a certain safe range for ensuring its state-of-health (SoH) as well as higher efficiency. This procedure maximizes the power capacity of the ESSs all the times. Furthermore, economic load dispatch (ELD) is implemented to allocate power among various ESSs, with the aim of fully meeting the load demand and reducing the total operating cost. In this research article, a distributed multi-agent consensus based control algorithm is proposed for multiple battery energy storage systems (BESSs), operating in a microgrid (MG), for fulfilling several objectives, including: SoC trajectories tracking control, economic load dispatch, active and reactive power sharing control, and voltage and frequency regulation (using the leader-follower consensus approach). The proposed algorithm considers the hierarchical control structure of the BESSs and the frequency/voltage droop controllers with limited information exchange among the BESSs. It embodies both self and communication time-delays, and achieves its objectives along with offering plug-and-play capability and robustness against communication link failure. Matlab/Simulink platform is used to test and validate the performance of the proposed algorithm under load disturbances through extensive simulations carried out on a modified IEEE 57-bus system. A detailed comparative analysis of the proposed distributed control strategy is carried out with the distributed PI-based conventional control strategy for demonstrating its superior performance.


Introduction
The main trend in electric power system, for the past few decades, has been the modification of conventional power system. This trend was triggered by several aspects including environmental, technological and economic aspects. The idea was to incorporate smaller distributed generating units (DGUs) into existing power system so as to mitigate the climate change concerns and the increasing energy demand. This led to the development of the so-called a1111111111 a1111111111 a1111111111 a1111111111 a1111111111 Distributed cooperative control of multi-agent systems is mainly categorized into the leaderless consensus (or regulator synchronization problem) and the leader-follower consensus (or tracking synchronization problem). In the leaderless consensus, all the nodes of the MG synchronize to a common value that is not prescribed or controllable and depends on initial conditions. While in the leader-follower consensus, a leader or control node (one of the networked nodes) acts as a command generator by dictating the desired value. The rest of the nodes (i.e. followers) synchronize their outputs with that of the leader. The neighboring nodes can communicate with each other. Moreover, the leader node is only connected to a small portion of the total networked nodes [10,11].

Related work
Consensus based control of the BESSs is fairly a new research area introduced in the literature recently. Compared with SoC balancing of the BESSs, as reported in [12][13][14], the modern consensus designs also address other issues of the BESSs, including regulation of frequency and voltage, synchronization of energy levels as well as active and reactive power sharing using exchange of information among the neighboring BESSs [15]. In [16], the authors have proposed a distributed consensus based algorithm for SoC balancing of the grid-connected BESSs consisting of 20 battery packages. However, the convergence speed of the algorithm was too slow, that is, around 2 hours. Furthermore, the droop controllers for frequency and voltage regulation have not been considered. A relatively simple and better linear quadratic regulator (LQR) based consensus algorithm was proposed in [17] for synchronizing the SoC as well as the power levels of the BESSs, with limited information exchange. The proposed design operated effectively both in the islanded and grid-connected mode. However, not only the convergence speed of the algorithm was very slow, that is, around 30 minutes, but also the droop controllers for frequency and voltage regulation have been ignored. Another LQR-based consensus algorithm was proposed in [18], similar to the one proposed in [17], for dynamic energy level balancing of the BESSs in droop controlled MGs. Detailed small signal battery dynamics have been considered in the design, however, the convergence speed was very slow, that is, around 1 hour. In [19], a novel nonlinear sliding mode control (SMC) based multi-agent consensus algorithm was proposed for SoC balancing of the distributed BESSs in a DC MG. This nonlinear consensus based strategy offered some qualitative improvements over the existing linear consensus based SoC balancing strategies in terms of avoiding circulating currents and providing plug-and-play capabilities. However, the algorithm has a very slow convergence speed by developing consensus in around 40 minutes.

Motivation and contributions
The authors, in [15], have proposed a novel and very remarkable distributed control design based on consensus theory for proportional active and reactive power sharing, synchronization of energy levels, and frequency and voltage regulation of multiple BESSs. Self and communication time-delays have been explicitly considered in the design. The proposed consensus algorithm has a very fast convergence speed, by developing consensus approximately within 10 seconds, because of independent controls of each of power and energy levels, active and reactive powers, frequency and voltage regulation, with and without time-delays. However, this algorithm has not been tested for plug-and-play capabilities and robustness against communication link failure. This was the main driving force that motivated the authors to undertake this research work and move further in this area by putting their own contributions. The authors, in this research article, have proposed a consensus based SoC trajectory tracking control design for economic-dispatched distributed BESSs in a MG. The MG itself is considered as a multi-agent system with the BESSs serving as agents, where each BESS can communicate with its neighboring BESSs through a sparse communication network. Without requiring any centralized controller, the proposed consensus based distributed algorithm in this article has been applied to multiple BESSs for achieving SoC trajectory tracking control, active and reactive power sharing control, voltage and frequency regulation as well as dispatching the load economically.
In order to efficiently operate the BESSs in a smart grid, this article proposes a time-delay resilient leader-follower consensus based fully distributed control strategy for fulfilling multiple objectives. The significant contributions of this research work, that distinguish it from the current literature, are summarized as follows: control inputs for energy level (SoC), active power, reactive power, frequency and voltage (i.e. E, P, Q, ω and V), respectively, designed in Section 3, and A, B, and C are constant matrices with compatible dimensions, and x 2 R, u 2 R and y 2 R are, respectively, the state, the input and the output.

Droop control
When BESSs are operated in parallel, the droop control mechanism, which is implemented at the primary control level, serves as in charge of both the frequency and voltage regulation. In this mechanism, the frequency and voltage of each BESS is regulated by using the locally measured instantaneous (actual) active and reactive powers, respectively. The droop control mechanism basically mimics the operation of the governor and field exciter of a conventional synchronous generator to regulate the output frequency and voltage magnitude of a microgeneration source, according to the active and reactive power demands at its output terminals, respectively [20].
The frequency and voltage droop control dynamics for an i th BESS can be expressed as follows: In Eqs (2) and (3), ω i and ω nom are the actual and nominal frequencies, |V i | and jV nom i j are the actual and nominal voltage magnitudes, and K P i , K Q i are the active and reactive power droop gains, and P i , Q i represent the measured active and reactive powers, respectively, for an i th BESS.
Note that the primary control provides the active and reactive power sharing, among all the BESSs, according to the following criteria: where j 2 N i represents the neighboring nodes set of node i. For ease of understanding, denoting the active and reactive power sharing for an i th BESS byP In [17], it was assumed that the frequency and voltage deviation was always zero. Moreover, the dynamics of the droop controllers were ignored in the BESS model. However, the BESS model in this article explicitly considers and, hence, integrates the dynamics of the droop controllers into the simplified BESS model expressed in Eq (1). As a result, the final dynamic model of the droop-controlled i th BESS, becomes as follows: It is also important to note that the existing LQR-based consensus control approaches in [17,18] use only one control input u P i for controlling both the energy and active power levels of the i th BESS. In other words, these approaches control the energy levels of the BESSs indirectly through their powers. This strategy leads to a very slow convergence speed. Moreover, the design is not fully distributed. Hence, to increase the convergence speed, and to make the design fully distributed, the energy and active power level of the i th BESS is controlled independently in this work by using two independent control inputs for each purpose (i.e. u E i , u P i ). This is essential when the load demand varies rapidly and the DGs have to respond accordingly.

Consensus based distributed control strategy for BESSs
The consensus control inputs (u for BESSs are designed using the theory of multi-agent system (MAS), where each BESS is regarded as an agent, and the communication lines as edges. The communication/information exchange among various agents is covered using graph theory.

Preliminaries on graph theory
The information exchange among various agents (BESSs in this case) in a MAS, comprising N agents, can be graphically represented by a communication graph, and defined by algebraic graph theory. Such that, this graph is mathematically represented by a Laplacian matrix (or conductance matrix), L = [ℓ ij ], with its diagonal and off-diagonal elements, defined below [21]: In Eq (5), d in i denotes the in-degree of a node i (i.e. the number of neighboring nodes, it is receiving information from) and a ij stands for the weight of the communication link between two nodes i and j. An equivalent method for constructing the Laplacian matrix is using, ] stand for the in-degree matrix and adjacency (or connectivity) matrix, respectively. The adjacency matrix, with its diagonal and off-diagonal elements, can be defined as follows [22]: The in-degree matrix is a diagonal matrix where the diagonal elements denote the in-degree, d in i , of each node. On the other hand, the adjacency matrix is a non-negative matrix with all the diagonal elements equal to zero. The out-degree of a node i, represented by d out i , denotes the number of neighboring nodes, it is sending information to. If the in-degree and out-degree are equal, for all nodes, the communication graph is known as balanced. A communication graph is termed as undirected, if a ij = a ji , that is if there is a bidirectional/two-way communication link between nodes i and j having the same weights in both directions. Otherwise, for a ij 6 ¼ a ji the communication graph is termed as a directed graph or a digraph. A directed graph is known as strongly connected, if there exists a directed path between every two distinct nodes. Similarly, an undirected graph is known as simply connected, if there exists an undirected path between every two distinct nodes (i.e. a directed path from node i to j, and also a directed path from node j to i). The in-degree of a node i equals the i th row sum of the adjacency matrix, whereas, its out-degree equals the i th column sum of the adjacency matrix. For a balanced undirected graph, the adjacency matrix is symmetric (i.e. A = A T ), moreover, its i th row sum equals the i th column sum.
In general, for any Laplacian matrix whether balanced or not, all row sums are equal to zero. Furthermore, for a balanced Laplacian matrix, all the row sums as well as all the column sums are equal to zero. A balanced undirected graph has a symmetric positive semi-definite Laplacian matrix. If the communication graph is connected, it possesses a simple 0 eigenvalue with a corresponding eigenvector 1 (where 1 represents a column vector of ones), while all the other eigenvalues are positive.
The Laplacian matrix of a connected and balanced communication graph satisfies the following condition [17]: and

Time-delayed consensus design
The consensus development is based on the communication among various BESSs. Therefore, the communication time-delays may potentially deteriorate the convergence and performance of the consensus algorithms, especially when the time-delays are very large. To ensure the smart grid reliability and avoid any potential instability issue, the Institution of Electrical and Electronics Engineers (IEEE) and International Electro-technical Commission (IEC) have clearly defined standards for communication delay requirements. These two well-known standards set the maximum permissible communication delay to be 16 milliseconds for both monitoring and control purposes [23]. The same standard has also been taken into consideration in this article. Two different types of time-delays (i.e self time-delay, T ij > 0, and communication timedelay, τ ij > 0) have been explicitly considered in the proposed work. These time-delays are imposed on the states of a node or agent i (BESS in this case) and the neighboring node j 2 N i . The self time-delay is the delay occurring on the computation or reaction of a node. On the other hand, the communication time-delay is the delay on the communication channel when a state propagates from a node j to a neighboring node i.
In the existing literature, a time-delayed robust consensus design for SoC balancing of ESSs in a microgrid can be found in [24]. However, this approach considers only the communication time delays (τ ij > 0), and not the self time delays (T ij = 0).

Leader-follower based consensus design
Generally, the droop control (primary control) alone may not restore the frequencies and voltage magnitudes of the BESSs back to their nominal values, especially when there is a load change. Hence, a secondary control level is always required, in addition to primary control, for frequencies and voltage magnitudes restoration. In the proposed design, the secondary frequency and voltage support/restoration is accomplished by using a leader-follower consensus approach.
In the leader-follower consensus approach, the frequencies and voltage magnitudes of all the BESSs are regulated by selecting a virtual leader node (BESS) in the system of multiple BESSs. This leader node must be connected to at least one other node. The leader node provides/dictates a reference frequency and voltage magnitude (i.e. ω ref and |V ref |, respectively) to the distributed controller. The distributed controller also receives information from all the neighboring nodes. In this way, the frequencies and voltage magnitudes of all the remaining BESSs (followers) are then tracked through the distributed controller to these references commanded by the leader node, even if there is a load change, provided that the communication graph among the BESSs is connected.
The existence of the leader node is represented by an index α 0i , such that, α 0i = 1 if a node i is connected to the leader (i.e. i 2 N 0 ), otherwise α 0i = 0 (i.e. i= 2N 0 ), where N 0 represents the neighboring set of nodes of the leader node.

Consensus control inputs design
The dynamic closed-loop model of the i th BESS with distributed control feature, and based on time-delayed leader-follower consensus approach, for fulfilling different objectives, is formulated by designing the consensus control inputs given in Eq (4)

PLOS ONE
Consensus based control design for distributed battery energy storage system In Eq (12), ω i (t − T ij ) is given as follows: Þ |ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl {zffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl } In Eq (14), |V i |(t − T ij ) is expressed as follows: Þ |ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl {zffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl ffl } Eq (9) is the SoC trajectory tracking control algorithm, whereas Eqs (10), (11), (12) and (14) are the consensus control algorithms for active power, reactive power, frequency and voltage magnitude regulation, respectively, where E i , P i and Q i represent the actual (or measured) energy level (or SoC), actual active power and actual reactive power of the i th BESS, respectively. Assuming that the BESS energy base equals its capacity, then the BESS (per unit) energy can be taken equal to its SoC (i.e. E i = SoC i ), as reported in [17]. The actual frequency and voltage magnitude at the i th BESS terminals are denoted by ω i and |V i |, respectively. The nominal frequency and voltage magnitude of the i th BESS are designated by o nom i and jV nom i j, respectively. While C 1 , C 2 , and C 3 > 0 correspond to positive scalar coupling/consensus gains.
It should be noted that the consensus algorithms for active power, reactive power and voltage, respectively, expressed in Eqs (10), (11) and (14) are exactly the same as proposed in [15]. However, the algorithms given in Eqs (9) and (12) for energy level (i.e. SoC) and frequency, respectively, have been modified. The reason behind this modification is to achieve the objectives of SoC trajectory tracking control and the ELD for the BESSs. For achieving the objective of the ELD, an additional consensus control input, u Cp i ðtÞ, that also appears in Eq (12), is considered in this research article. It is defined in Eq (16), as follows: In Eq (16), u Cp i is the production cost consensus control input, C 4 > 0 is a positive scalar coupling/consensus gain, C p i and λ i are the production cost and incremental cost of the i th BESS, respectively, and P i;sharing ¼ K P i P i is the power shared by the i th BESS. The detailed closed-loop BESS model with distributed control feature, and based on leaderfollower consensus approach, is depicted in Fig 1. Note that the consensus algorithms, Eqs

PLOS ONE
Consensus based control design for distributed battery energy storage system (9)- (12) and (14), work on the basis of integral control. This integral control is assumed to be installed at each battery converter. It receives both local information (from i th BESSs) and the neighbors information (from j th BESSs), to fulfill the following control objectives: 1. Frequencies and voltage magnitudes of all the BESSs must track their desired reference values, that is, 2. SoCs of all the BESSs must track their reference trajectories, that is, . Equal active and reactive power sharing among BESSs must be guaranteed, that is,

Stability analysis
In this section, stability analysis of different algorithms proposed in Section 3.4 is presented. It is evident from Eqs (10), (11) and (16) that the active power, reactive power and the production cost consensus control inputs of the i th BESS have been expressed in the same form. Hence, stability proof for active power sharing will be provided only, while for reactive power sharing and production cost, it can be derived in the same manner.
To transform these algorithms from the time-domain into the Laplace domain, the delaydependent adjacency, the in-degree and the Laplacian matrices of the communication graph, discussed in Section 3.1, are, respectively, expressed as follows: (9) can be re-written as follows:

Stability proof for SoC trajectory tracking control of the BESSs
Eq (20) represents a closed-loop equation for SoC trajectory tracking control of the BESSs. If (20), in time-domain, takes the following generalized form: Re-writing Eq (21) in Laplace domain as follows: Eq (22) can also be expressed as follows: Rearranging and simplifying Eq (23), it can be expressed as follows: where C 1 ; C E 0 > 0. Hence, SoC trajectory tracking control is achieved only, if the communication graph is connected. Moreover, the characteristic equation of the closed-loop system, that is, ¼ 0 has no roots in the right-half of the complex plane. (10) can be re-written as follows:

Consensus proof for active power sharing control of the BESSs
Eq (25) represents a closed-loop equation for active power sharing control of the BESSs. If (25), in time-domain, takes the following generalized form: Re-writing Eq (26) in Laplace domain as follows: Rearranging and simplifying Eq (27), it can be expressed as follows: where C 2 > 0. Therefore, the active power sharing consensus is achieved only, if the communication graph is connected. Furthermore, the characteristic equation of the closed-loop BESSs, that is, DðsÞ ¼ detðsI þ C 2 D À 1 L d ðsÞÞ ¼ 0 has no roots in the right-half of the s-plane.

Consensus proof for frequency tracking/regulation of the BESSs
Taking time derivative of Eq (13), it can be re-written as follows: Also, letô Rearranging and taking time derivative of Eq (30), it yields:  (16) and _ P i ðtÞ from Eq (25) into Eq (29), the following equation is obtained: Simplifying Eq (32) using o nom it can be expressed as follows: Using can be further simplified as follows: Ifô ¼ô 1 ;ô 2 ; . . . ;ô N � T � and P � = [λ 1 P 1 , λ 2 P 2 . . ., λ N P N ] T then Eq (34), in time-domain, takes the following generalized form: where D 0 = diag{α 0i }. Re-writing Eq (35) in Laplace domain as follows: Rearranging and simplifying Eq (36), it reduces to the following form: where C 2 ; C o 0 ; C 4 > 0. Therefore, the frequency consensus is achieved only, if the communication graph is connected. Furthermore, the characteristic equation of the closed-loop system, that is, ¼ 0 has no roots in the right-half of the splane.

Consensus proof for voltage tracking/regulation of the BESSs
Taking time derivative of Eq (15), it can be re-written as follows: where, Also, let Rearranging and taking time derivative of Eq (40), it yields: Now substituting the values of _ V i ðtÞ from Eq (41), _ V nom i ðtÞ from Eq (14), and _ Q i ðtÞ from Eq (39) into Eq (38), it yields the following equation: Simplifying Eq (42) using jV nom i ðt À T ij Þj ÀQ i ðt À T ij Þ ¼ jV i ðt À T ij Þj and jV nom j ðt À t ij Þj À Q j ðt À t ij Þ ¼ jV j ðt À t ij Þj from Eq (15), it can be expressed as follows: Using (43) can be further simplified as follows: If jV j ¼ jV 1 j; jV 2 j; . . . ; jV N j� T h , then Eq (44), in time-domain, takes the following generalized form: where D 0 = diag{α 0i }. Re-writing Eq (45) in Laplace domain as follows: Rearranging and simplifying Eq (46), it reduces to the following form: where C 3 ; C V 0 > 0. Therefore, the voltage consensus is achieved only, if the communication graph is connected. Furthermore, the characteristic equation of the closed-loop system, that is, ¼ 0 has no roots in the right-half of the complex plane.

Simulation results and discussion
In this section, performance of the various algorithms, described in Section 3.4, have been tested in Matlab/Simulink, through extensive simulations carried out on a modified IEEE 57-bus system with generators replaced by BESSs, as shown in Fig 2. That is, the original IEEE 57-bus system (comprising 7 generators and 42 loads) has been modified by replacing generators with BESSs. The communication graph for these 7 BESSs, that is N = 7 and i = {1, 2, 3, 4, 5, 6, 7}, with two-way communication links (represented by double-headed dotted arrows) considered in this research, is depicted in Fig 3, where BESS2 is serving as the virtual leader node to provide frequency and voltage references to other BESSs (followers). All the 7 BESSs are forced to track their (frequency and voltage) references dictated by the virtual leader node, provided that the communication graph among the BESSs is connected.
Based on the graph theory explanation given in Section 3.1, it can be seen that the communication graph, depicted in Fig 3, is undirected. The corresponding laplacian matrix for the communication graph depicted in Fig 3 (under normal conditions), is given as follows: The performance of the proposed control strategy is tested under four different cases, described below:

Case 1: Analysis without plug-and-play and communication link failure events
In case 1, SoC trajectory tracking control, frequency and voltage regulation, proportional active and reactive power sharing and ELD have been tested under normal conditions, that is, without plug-and-play and communication link failure events. An intentional self time-delay (of T ij = 5 ms) and a communication time-delay (of τ ij = 15 ms) have been considered, while carrying out analysis under case 1, to validate the robustness of the proposed strategy to communication latency. SoC trajectory tracking control of the BESSs under case 1. Among different techniques for energy management, ToU-based pricing is one of the most effective method. In this method, the load users adjust their electricity consumption behaviors in response to ToU-

PLOS ONE
based pricing during both peak and off-peak hours. Such that, the users are encouraged to store more energy, by charging the ESS, during off-peak hours. On the other hand, they are urged to release the stored energy, by discharging the ESS, during peak hours. Hence, these behaviors can not only reduce the overall electricity cost, but they also smooth out the demand curve [8].
To accomplish ToU-price based SoC trajectory tracking control for BESSs, first, a ToUbased price, p ToU , is defined. Then, a threshold price is defined with its upper and lower limits, that is, p th up;i and p th low;i , respectively. Now, if the ToU-based price, is greater than or equal to the upper limit of the threshold price, the SoC of each BESS is maintained at its lowest level. However, if the ToU-based price is less than or equal to the lower limit of the threshold price, the SoC of each BESS is maintained at its highest level. If none of the stated conditions apply, the SoC of each BESS is maintained at the preferred/actual level. This concept is explained in Eq (48), as follows:  Table 1, whereas the dynamic ToU-based electricity pricing curve for 24 hours period is illustrated in Fig 4. As depicted in Fig 4, the peak electricity price occurs during the time interval 18:00-22:00 hours, whereas, the minimum price occurs during 0:00-02:00 and 22:00-24:00 hours. The initial/present SoC values, assumed and set in the integral controllers, are indicated by SoC i (0) in Table 1. The SoC trajectory tracking controller parameters, expressed in Eq (9), are given in Table 1.

Using Eq (48), a unique reference SoC (i.e. E i ref or SoC i ref ) is generated for an i th BESS, based on
ToU-pricing, which is then tracked by the actual SoC of the i th BESS, using Eq (9). It should be noted, however, that in this particular case each BESS has its own virtual leader dictating a reference SoC, that is, E i ref or SoC i ref , to be tracked by the actual SoC of the corresponding BESS, that is, E i or SoC i . The SoC tracking for each BESS is illustrated in Fig 5, where each BESS starts tracking its reference/desired SoC in less than 1 hour. The zoomed-in portions of the figure validate the accurate SoC tracking with negligible steady-state error. Fig 6 shows the SoC errors, e SoC i , that is, the difference between the actual SoC and the reference SoC of an i th BESS. Mathematically, it can be described as follows: Once, all the 7 BESSs start tracking their reference SoCs, the corresponding control efforts converge to zero, implying that the system becomes stable.

Proportional active and reactive power sharing of the BESSs under case 1.
For achieving proportional active power and reactive power sharing from the BESSs, the active and reactive power consensus controller parameters, expressed in Eqs (10) and (11), respectively, are given in Table 2, where P i (0) and Q i (0) indicate the initial values of powers set in the integral controllers.
It is evident from Figs 8 and 9 that the consensus of active and reactive power sharing is achieved in around 2 seconds. Both active and reactive power sharing remain synchronized until there is a sudden load change (increase) of (1 + j1 pu)/BESS at the 16th second. After the load change event, both the active and reactive power sharing are successfully re-synchronized to a new (higher) value. This proves that the proposed strategy is effective for offering active and reactive power sharing control.

Remark 1 An important feature of the consensus control scheme is that the sum of the individual control inputs of all the BESSs is always zero. It means that the sum of the power orders of all the BESSs should be constant. The main function of the consensus control is to adjust the power output of each BESS while maintaining the total power constant. This function can also be combined with the secondary frequency and voltage control. Such that, whenever there is a load change, the secondary frequency control will handle it by adjusting the active power order of each BESS. In this way, the consensus control maintains the sum of the active power orders by adjusting the individual active power orders of the BESSs for achieving consensus. The same is true for the secondary voltage control by adjusting the reactive power orders of the BESSs.
Figs 10 and 11 illustrate the active and reactive power consensus control efforts, respectively. The load change event appears as transient disturbances in the control efforts. Once the active and reactive powers are synchronized, before and after the load change, the control efforts converge to zero. Thus, guaranteeing the stability of the system.

Frequency and voltage regulation of the BESSs under case 1.
The proposed work also supports frequency and voltage regulation of the BESSs using the leader-follower consensus approach. The frequency and voltage consensus controller parameters, expressed in Eqs https://doi.org/10.1371/journal.pone.0232638.g009 (12) and (14), respectively, are given in Table 2 The corresponding control efforts for frequency and voltage regulation are depicted in Figs 14 and 15, respectively. Since, both are converging to zero, once the consensuses on reference values are achieved, it implies the system is becoming stable eventually.

PLOS ONE
Consensus based control design for distributed battery energy storage system A slight oscillation in the vicinity of the vertical axis, depicted in the zoomed-in views, in both the frequency and voltage plots in Figs 12 and 13, respectively, is due to the communication delays. In the proposed strategy, the system is successfully tolerating a communication latency, τ ij , of upto 15 ms.

Economic load dispatch under case 1.
On generation side, the ELD is an optimization problem that aims to allocate power generation among various generating units, subject to several physical constraints, so that the system may be able to supply its load fully and most economically (with the minimum operating/generation cost) [25].
Assume C i (P i,sharing ) to be a quadratic generation cost function for an i th BESS, expressed as follows: where a i , b i > 0 are the cost parameters/coefficients. The corresponding incremental cost, λ i , for an i th BESS can be expressed as follows: Now, the total production cost, C p i , for an i th BESS can be given as follows: To achieve ELD, first of all the incremental cost, λ i , is computed using Eq (51) for an i th BESS. Different values of a i and b i , and the lower and upper limits of the active power sharing (i.e. P i;sharing and � P i;sharing , respectively, for an i th BESS) and the total power demand from the system, P T D , are given in Table 3.
The ELD is ensured using Eq (16), such that, all the 7 BESSs develop consensus by synchronizing their production costs, as shown in Fig 16. Despite the load change (increase) event at the 16th hour, the production costs consensus is re-established at a new (higher) value, thus guaranteeing the effectiveness of the proposed approach. The convergence of production cost consensus control effort to zero, illustrated in Fig 17, implies the system is becoming stable.  A slight oscillation is observed in the vicinity of the vertical axis, as depicted in the zoomedin views, in Figs 16 and 17, respectively. This is due to the communication delays. However, the system is resilient to withstand a communication latency of upto 15 ms.
The active power sharing mismatch, ΔP i,sharing , for an i th BESS, can be expressed as follows: The power mismatch as well as the power balance are demonstrated in Figs 18 and 19, respectively. It can be seen that the system accurately fulfills the active load demand, that's why the power mismatch converges to almost zero.

Case 2: Analysis under plug-and-play and communication link failure events
In case 2, SoC trajectory tracking control, frequency and voltage regulation, proportional active and reactive power sharing and ELD have been tested under plug-and-play and communication link failure events. The self time-delay and the communication time-delay have been kept the same, as discussed in case 1 (i.e. T = 5 ms and τ = 15 ms). Moreover, all the system parameters are the same as given in Tables 1, 2 and 3. An advantage of the MAS based control architecture is to support the plug-and-play feature of the agents. To realize the plug-and-play feature, the system must be able to reconfigure/ adapt itself to the alteration of communication topology (i.e. either due to disconnection/ removal of an existing agent from the system, or due to integration/addition of a new agent to the system) for maintaining a seamless operation [26].
For testing the plug-and-play feature, the BESS4 has been plugged-out at the 3rd hour and plugged-in again at the 5th hour. Similarly, for testing the robustness against communication link failure, the two-way communication link between BESS2 and BESS5 is interrupted from 10th to 12th hour. The updated communication graphs, when BESS4 is taken out of service, and communication link between BESS2 and BESS5 is interrupted, are illustrated in Figs 20 and 21, respectively.

SoC trajectory tracking control of the BESSs under case 2.
In case 2, the SoC trajectory tracking control performance is illustrated in Fig 22 for each BESS. It is evident that the SoC of the BESS4, after disconnection at the 3rd hour, remains unchanged (remains at the reference SoC value tracked before the initiation of the 3rd hour). Because, it is no more fulfilling its active and reactive load demands between the 3rd and the 5th hour. During this stated time, the active and reactive load demand of the BESS4 is shared, and hence fulfilled, by the remaining 6 BESSs. The disconnection of the BESS4 has no effect on the remaining 6 BESSs  and they still tend to track their reference SoCs. When the BESS4 is reconnected at the 5th hour, it again starts tracking its most recent reference SoC.
The effect of communication link failure event between the BESS2 and the BESS5, from 10th to 12th hour, on the SoC tracking performance is depicted in Fig 22, in the form of very small excursions, especially in the vicinity of the 12th hour. However, the proposed algorithm has the ability to fast correct the SoC values. This implies that the system is also robust against two-way communication link failure between the BESSs. The plug-and-play event is almost unnoticeable in the SoC tracking control efforts, illustrated in Fig 23. However, minor disturbances can be seen for the communication link failure event.

Proportional active and reactive power sharing of the BESSs under case 2.
In case 2, the active and reactive power sharing controls have also been tested. Taking the BESS4 out of service at the 3rd second, makes their active and reactive power sharing (i.e. P 4,sharing and Q 4,sharing , respectively) equal to zero, as illustrated in Figs 24 and 25, respectively. Because, it is neither dispatching nor absorbing any power. However, during this time, the active and reactive load demand of the BESS4 is still fulfilled by the remaining 6 BESSs. For this purpose, the   In other words, the proposed algorithm has the capability of fast correcting the frequency and voltage magnitude. Both the plugand-play and communication link failure events are reflected as minor transient disturbances on the frequency and voltage regulation of the system. It can easily be concluded that the system is not only providing a good plug-and-play capability, but also robustness against communication link failure.

Economic load dispatch for the BESSs under case 2.
The ELD for the BESSs is also tested in case 2 and the results for production cost consensus and the corresponding control efforts are plotted in Figs 32 and 33, respectively. When the BESS4 is plugged-out at the 3rd hour, production cost of the BESS4 goes to zero. Because, it is not dispatching any active power. However, the load demand of the BESS4 is shared and supported by the remaining 6 BESSs, which results in a higher production cost value (due to the increase in load of the remaining 6 BESSs). Re-plugging BESS4 at the 5th hour brings the production cost of the system back to its normal value after a sharp transient. On the other hand, there is a negligible effect of the communication link failure event between BESS2 and BESS5, from 10th to 12th hour, on the production cost consensus of the system. Hence, it can easily be concluded that the system possesses both plug-and-play capability and robustness against communication link failure.
The corresponding power mismatch as well as the power balance, in case 2, are illustrated in Figs 34 and 35, respectively. It can be seen that the system accurately fulfills the active load demand, that's why, the power mismatch converges to almost zero.

Case 3: Switching between leader-follower and leaderless consensus without plug-and-play and communication link failure events
In this case study the proposed algorithm is tested when switching between leader-follower and leaderless consensus occurs without plug-and-play and communication link failure events. For this purpose, the leadership status of node 2 is deactivated from 15th to 20th second by setting α 0i = 0 in Eqs (12) and (14), while for rest of the simulation time it still acts as the leader node. The communication graph is the same as illustrated in Fig 3. The frequency and voltage consensus plots are depicted in Figs 36 and 37, respectively. It can be seen that even if the leader node 2 loses its leadership status at the onset of 15th second, the frequency and voltage magnitude still remain synchronized to ω ref , |V ref | = 1 pu, respectively, previously dictated by the leader node till 16th second, as long as the load remains constant. But once the load changes (increases) at 16th second, both the frequency and voltage It means that the proposed algorithm can equally be applied for developing a leader-follower and leaderless consensus.

Case 4: Switching between leader-follower and leaderless consensus under plug-and-play and communication link failure events
In this case study the proposed algorithm is further tested when switching between leader-follower and leaderless consensus occurs in the presence of plug-and-play and communication link failure events. The communication graphs are the same as those illustrated in Figs 20 and 21.
The frequency and voltage consensus plots are depicted in Figs 38 and 39, respectively. It is evident that even in the presence of plug-and-play (from 3rd to 5th second) and communication link failure (from 10th to 12th second), the proposed algorithm successfully supports both the leaderless (from 15th to 20th second) and leader-follower consensus (from 0 to 15th second and 20th to 24th second).

Case 5: Distributed PI-based conventional control scheme without plug-and-play and communication link failure events [27]
In this section, the proposed distributed control scheme is tested against the distributed PIbased conventional control scheme, formulated in [27], without plug-and-play and communication link failure events as described in case 1.
In this stated conventional strategy, the authors have shown that for a large class of systems, the decentralized PI-control is not a feasible control strategy. Instead, they have formulated a distributed controller that mimics a decentralized P-controller with a centralized I-controller by distributed averaging. Although the proportional part of this controller is decentralized, the overall controller is distributed due to the communication needs of the distributed integral part. Under distributed PI-based control scheme, the frequency and active power sharing control can be expressed as follows: where γ, β > 0, k P i , k I i > 0 are the proportional and integral gains, respectively, and a ij is the entry of the adjacency matrix.
Similarly, under distributed PI-based control scheme, the voltage and reactive power sharing control can be expressed as follows: where Γ, z > 0. Under distributed PI-based control scheme, SoC trajectory tracking along with corresponding errors are illustrated in Figs 40 and 41, respectively. When compared with their proposed counterparts, as shown in Figs 5 and 6, one can easily conclude that the proposed scheme offers superior SoC tracking with lesser error. The frequency and corresponding active power sharing regulation under distributed PI-based control scheme are depicted in Figs 42 and 43, respectively. It is evident that the consensus development/convergence is slow (around 5 seconds) when compared with the proposed scheme (around 2 seconds), as depicted in Figs 8 and 12. Similarly, the voltage and corresponding reactive power sharing regulation under distributed PI-based control scheme are illustrated in Figs 44 and 45, respectively. Again, it can be seen that the consensus development/convergence is slow (around 5 seconds) when compared with the proposed scheme (around 2 seconds), as depicted in Figs 9 and 13. Furthermore, another major drawback of the distributed PI-based conventional control strategy is Consequently, the proposed distributed control strategy is superior to the conventional PIbased distributed control strategy in terms of offering faster convergence and minor error.

Case 6: Distributed PI-based conventional control scheme under plugand-play and communication link failure events [27]
In this section, the proposed distributed control scheme is further tested against the distributed PI-based conventional control scheme under plug-and-play and communication link failure events as discussed in case 2.
Various results under conventional distributed PI-based control strategy are shown in Figs 47-53. This scheme is also supporting the plug-and-play operation. Such that, unplugging BESS4 makes it frequency and voltage constant, having no role towards consensus  development. Moreover, the active and reactive power sharing and production cost of the BESS4 become zero. One can easily observe that the convergence is slow when compared with their proposed counterparts, as depicted in 28, 29 and 32. Moreover, in this case again, the frequencies and voltages of the BESSs are not exactly regulated to their reference values. However, in the conventional scheme, the link failure and restoration event is seamless.
As a result, the proposed distributed control scheme offers a superior performance to the conventional PI-based distributed control strategy in terms of having faster convergence and lesser error.

Conclusions
In this research article, a multi-agent consensus based distributed control algorithm is proposed for fulfilling multiple objectives, simultaneously, in a microgrid. The proposed algorithm considers the hierarchical control structure of the BESSs and the frequency/voltage droop controllers. It successfully tracks the the SoC reference trajectories of multiple BESSs, generated on time of use based pricing, for 24 hours varying load. Furthermore, it dispatches the load economically, realizes the active and reactive power synchronization, and frequency and voltage regulation (using leader-follower consensus approach), simultaneously. Each BESS only requires its own (local) information and information from the neighboring BESSs through a sparse communication network. Plug-and-play and robustness against communication link failure features are embodied in the proposed algorithm. Moreover, it is resilient to communication latency of upto 15 ms. The effectiveness of the proposed algorithm is tested and validated through extensive simulations carried out in Matlab/Simulink on a modified IEEE 57-bus system, where it has been found to have a very fast convergence and negligible steady-state error. The superior performance of the proposed distributed control strategy is demonstrated by comparing is performance with the distributed PI-based conventional control strategy.