**3. Proposed Methodology**

Depending on the grid demand, the DG inverter is controlled to inject specific amount of power. An optimal PQ control scheme illustrated in Figure 3 is proposed adopting double loop controls to improve the dynamic performance of the grid-connected microgrid. The proposed PI power controller is firstly implemented to produce the reference current signal based on injected power. Secondly, the current control loop considers several aspects such as providing injected three-phase balanced currents, obtaining high power quality and overcoming the nonlinearities coming from the interaction between inverter switching and external disturbances [21].

**Figure 3.** Proposed microgrid controller.

The proposed methodology can be summarized as follows. Firstly, the optimization process will be initiated where PSO generates random controller parameters. These random parameters are used to calculate the objective function. The minimum objective function and its corresponding optimal parameters will be saved. Secondly, the inverter output voltage and current are measured and converted into *dq* forms. Thirdly, the real and reactive powers are calculated using the output voltage and current. Fourthly, the optimal controller parameters of the power controller are used to generate the reference currents by comparing the calculated powers with reference powers. Finally, the optimal controller parameters of the current controller are employed to generate the reference voltages to fire the inverters by comparing the reference currents with measured currents. These steps will be explained in detail in the next sections.

Firstly, the three-phase output voltage *vo* and current *io* are measured at PCC as shown in Figures 1 and 2. Then the measured output voltage *vo* is converted to the *dq* components using the transformation angle θ as given in Equation (1). Similarly, the *dq* components of the output current *io* can be obtained. The angle θ is obtained using the phase locked loop (PLL) shown in Figure 4a,b. Considered as one of the most common synchronization methods, PLL is used to extract the phase angle θ of the grid voltage and keep the output signal synchronized with the frequency and phase of the reference input signal [31].

$$
\begin{pmatrix} v\_{od} \\ v\_{\alpha q} \\ v\_{\alpha o} \end{pmatrix} = \sqrt{\frac{2}{3}} \begin{pmatrix} \cos\theta & \cos\left(\theta - \frac{2\pi}{3}\right) & \cos\left(\theta + \frac{2\pi}{3}\right) \\ -\sin\theta & -\sin\left(\theta - \frac{2\pi}{3}\right) & -\sin\left(\theta + \frac{2\pi}{3}\right) \\ \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \end{pmatrix} \begin{pmatrix} v\_{od} \\ v\_{ob} \\ v\_{\alpha o} \end{pmatrix} \tag{1}
$$

$$\omega = k\_P^{PLL} (\upsilon\_{\alpha \eta} - \upsilon\_{\alpha \eta}^\*) + k\_I^{PLL} \int (\upsilon\_{\alpha \eta} - \upsilon\_{\alpha \eta}^\*) dt \tag{2}$$

$$\theta = \int \left(\omega - \omega\_{ref}\right) dt + \theta(0) \tag{3}$$

where ω and <sup>ω</sup>*ref* are the nominal and reference frequencies, *voq* and *v\*oq* are the *q* components of the inverter output and reference voltages *vo* and *<sup>v</sup>\*o*, *kPPLL*, *kIPLL* are the PI controller parameters of the PLL.

Secondly, the *dq* components of the output voltage and current are used to calculate the real and reactive powers (*Pcal* and *Qcal*) as given in [3].

$$P\_{\rm cal} = \upsilon\_{\rm od} i\_{\rm od} + \upsilon\_{\rm oq} i\_{\rm oq} \tag{4}$$

$$Q\_{\rm cal} = \upsilon\_{ad} i\_{aq} - \upsilon\_{aq} i\_{\rm ad} \tag{5}$$

where *vod* and *voq* are the *dq* components of the inverter output voltage *vo, iod* and *ioq* are the *dq* components of the inverter output current *io*.

**Figure 4.** Phase locked loop (PLL) model.

Thirdly, by comparing the reference real and reactive powers (*P\** and *Q\**)and the calculated real and reactive powers (*Pcal* and *Qcal*) respectively, the proposed PI power controller is deployed to produce the *dq* components of the output reference currents (*i\*od* and *i\*oq*) as given in Equations (6) and (7). The injected powers to the grid could track the reference power. Note that real and reactive power can be controlled independently because of the decoupling of the reference current (6) and (7) as shown in Figure 5.

$$
\dot{m}\_{\rm ad}^\* = k\_{\rm pp}(P^\star - P\_{\rm cal}) + k\_{\rm ip} \int \left(P^\star - P\_{\rm cal}\right) dt\tag{6}
$$

$$d\_{\alpha q}^{\*} = k\_{pq}(Q^{\*} - Q\_{\text{cal}}) + k\_{iq} \int (Q^{\*} - Q\_{\text{cal}}) dt \tag{7}$$

where *kpp*, *kip*, *kpq* and *kiq* are the PI power controller parameters.

**Figure 5.** Proposed power controller.

The inverter is controlled to inject the coupling inductor current *iL* not the inverter output current *io* as shown in Figures 1 and 2. Therefore, to obtain the coupling inductor reference current *<sup>i</sup>L* in the *dq* frame, the *dq* components of the output reference currents *i\*o* is added to the *dq* components of the capacitor current *ic* as given in Equations (8) and (9) and shown in Figure 5.

$$\dot{i}\_d^\Sigma = \dot{i}\_{\alpha d}^\* + i\_{\text{cd}} = \dot{i}\_{\alpha d}^\* + (i\_{Ld} - i\_{\text{ad}}) \tag{8}$$

$$i\_q^\Sigma = i\_{aq}^\* + i\_{cq} = i\_{aq}^\* + (i\_{l,q} - i\_{aq}) \tag{9}$$

Then the fundamental reference currents *i\*Ld* and *i\*Lq* can be obtained using a low-pass filter [21].

$$\mathbf{i}\_{Ld}^{\*} = \frac{\alpha\_{\mathcal{E}}^{2}}{s^{2} + \sqrt{2}s\alpha\_{\mathcal{E}} + \alpha\_{\mathcal{E}}^{2}} \mathbf{i}\_{d}^{\Sigma} \tag{10}$$

*Sustainability* **2019**, *11*, 5828

$$\mathbf{i}\_{Lq}^{\*} = \frac{\alpha\_{\mathcal{E}}^{2}}{\mathbf{s}^{2} + \sqrt{2}s\alpha\_{\mathcal{E}} + \alpha\_{\mathcal{E}}^{2}} \mathbf{i}\_{q}^{\Sigma} \tag{11}$$

where ω*c* is the cut-off frequency of the low-pass filter.

Fourthly, the PI current controller shown in Figure 6 is used to obtain the *dq* components of the reference voltage *v\*l* targeting zero steady state error and compensating both inductor non-idealities and inverter switching nonlinearities [21].

$$
\sigma\_{ld}^\* = \upsilon\_{od} - \omega L\_f i\_{Ld} + k\_p^d (i\_{Ld}^\* - i\_{Ld}) + k\_I^d \int (i\_{Ld}^\* - i\_{Ld}) dt \tag{12}
$$

$$
\sigma\_{\rm Lq}^\* = \upsilon\_{\alpha q} + \alpha L\_f i\_{\rm Lq} + k\_P^q (i\_{\rm Lq}^\* - i\_{\rm Lq}) + k\_I^q \int (i\_{\rm Lq}^\* - i\_{\rm Lq}) dt \tag{13}
$$

where *iLd*, *iLq* are *dq* components of the coupling inductor current *iL, <sup>i</sup>\*Ld*, *i\*Lq* are *dq* components of the reference controller current *<sup>i</sup>\*L*, *kP<sup>d</sup>*, *kId, kPq*, *kIq* are PI current controller parameters.

**Figure 6.** Current controller.

Additionally, the relationship between the PCC output voltage *vo* and the inverter voltage *vl* are given by Equations (14), (15), and (16) [32].

$$
\begin{bmatrix} v\_{la} \\ v\_{lb} \\ v\_{lc} \end{bmatrix} = R\_f \begin{bmatrix} i\_{la} \\ i\_{lb} \\ i\_{lc} \end{bmatrix} + L\_f \frac{d}{dt} \begin{bmatrix} i\_{la} \\ i\_{lb} \\ i\_{lc} \end{bmatrix} + \begin{bmatrix} v\_{\alpha a} \\ v\_{\alpha b} \\ v\_{\alpha c} \end{bmatrix} \tag{14}
$$

$$
\omega\_{ld} = \upsilon\_{od} + \mathcal{R}\_f i\_{od} + L\_f \frac{d i\_{od}}{dt} - \omega L\_f i\_{\alpha q} \tag{15}
$$

$$
\omega\_{lq} = v\_{\alpha q} + R\_f i\_{\alpha q} + L\_f \frac{di\_{\alpha q}}{dt} + \omega L\_f i\_{\alpha d} \tag{16}
$$

To reduce the inverter switching frequency ripple, a low-pass filter is used. Additionally, a damping resistance is added to evade the possible resonance between this filter and the coupling inductance shown in Figure 1 [21]. Their models are given as follows:

$$
\upsilon v\_{\rm la} = i\_{\rm La} R\_f + L\_f \frac{di\_{\rm La}}{dt} + \upsilon\_{\rm Ca} + i\_{\rm Ca} R\_d \tag{17}
$$

$$
\omega\_{\rm bu} = -i\_{\rm cu}R\_{\rm c} - L\_{\rm c}\frac{di\_{\rm co}}{dt} + \upsilon\_{\rm Ca} + i\_{\rm Ca}R\_{\rm d} \tag{18}
$$

$$\frac{dv\_{\rm Ca}}{dt} = \frac{1}{C\_f}(i\_{La} - i\_{\rm ca})\tag{19}$$

where *vLa*, *vLb*, *vLc* are inverter output voltages.

#### **4. Optimal Controller Design**

Based on time domain simulation, the control problem is designed and formulated as an optimization problem where PSO is employed to minimize the proposed objective function *J* aiming to obtain the optimal controller and filter parameters [3].

$$J = \int\_{t=0}^{t=t\_{\rm sim}} (P\_{cal} - P^\*)^2 \, t \, dt \tag{20}$$

where *t* is added to ensure minimum settling time, *tsim* the simulation time, and Pcal and P\* are the calculated and reference real power of the inverter-based DG respectively.

The problem constraints are the controller and filter parameters K= [*kpp kipkpqkiqkp<sup>d</sup> kidkpqkiqLfCf, Rd*] T bounded as follows:

$$\mathcal{K}^{\min} \le \mathcal{K} \le \mathcal{K}^{\max} \tag{21}$$

where *kpp kipkpq* and *kiq* are the PI controller parameters of the proposed power controller while *kpd kidkpq* and *kiq* are the PI controller parameters of the current controller. *Lf*a and *Cf* are the filter inductance and capacitance respectively. *Rd* is the damping resistance.

In 1995, PSO is a population based stochastic optimization method developed by Eberhart and Kennedy inspired by social behavior of bird flocking or fish schooling [33]. It is worth mentioning that PSO is used as an efficient tool for optimization that gives a balance between local and global search techniques. PSO advantages—like computational efficiency, simplicity, and robustness—will enhance the microgrid transient performance [3]. Using PSO, the best solution (candidate) of the population could be obtained by starting random particles selection and updating the generations inside this population. Ensuring the optimal solution convergence, the particles are moving in the search space trying to follow the optimum particles. In the minimization problem, at a given position, the highest fitness corresponds to the lowest value of the objective function at that position. At iteration (n + 1), the new position of each particle is obtained by Equation (22) as follows:

$$k\_{n+1}^i = k\_n^i + v\_{n+1}^i \tag{22}$$

where *<sup>k</sup>in*+*<sup>1</sup>* is the position of particle *i* at iteration *n* + *1*; *kin* is the position of particle *i* at iteration *n*; and *<sup>v</sup>in*+*<sup>1</sup>* is the corresponding velocity vector.

At each time step, the velocity of each particle is modified depending on both current velocity and current distance from the personal and global best positions as follows:

$$w\_{n+1}^i = wv\_n^i + c\_1 r\_1 p\_{\text{best}} - k\_n^i + c\_2 r\_2 (g\_{\text{best}} - k\_n^i) \tag{23}$$

where *w* is the inertia weight; *vin* is the velocity of particle *i* at iteration *n*; *r1* and *r2* are random numbers between 0 and 1; *pbest* is the best position found by particle *i*; *gbest* is the best position in the swarm at time *n*; and *c1* and *c2* are the "trust" parameters. Figure 7 shows the proposed PSO computational flow chart. The PSO steps are summarized in [7].

**Figure 7.** Proposed particle swarm optimization (PSO) computational flow chart.

#### **5. Simulation Results and Discussion**

In this work, to verify the effectiveness of the PQ control in the grid-connected microgrid, two cases have been simulated. Firstly, 5 kVA inverter-based DG is controlled to deliver a predefined real and reactive powers to the grid. Secondly, two different rated inverter-based DG units (5 kVA and 10 kVA) are sharing their injected controlled powers with the grid. Assuming an ideal source from the DG side, the DC bus dynamics is neglected. With the realization of high switching frequencies (4–10 kHz), the switching process of the inverter may also be neglected [14]. A simulation model for the proposed microgrid cases is built in a MATLAB based on the control strategy. The proportional gain *kp* and

integral gain *ki* of the power and current controllers have been optimally tuned using PSO. Using the time domain simulation, the microgrid dynamic stability has been investigated and the proposed controller effectiveness has been evaluated under the following different disturbances:


The optimal parameters for both cases are given respectively in Tables 1 and 2.



#### *5.1. One Inverter-Based DG Case*

The proposed controller has been tested when a 5 kVA inverter-based DG connected to the grid. Firstly, the reference real power has been stepped down from 5 kW to 3 kW at t = 0.1 sec. Figure 8 shows the calculated and reference real and reactive powers for this disturbance. Both injected real and reactive powers are mostly following the reference powers. While Figure 9 depicts the calculated and reference real and reactive powers when the injected reactive power has been stepped down from 5 kVAR to 3 kVAR without any change in the injected real power. Both injected real and reactive powers are almost tracking the reference powers. It could be observed from the results that the controller has quick responses and track the references effectively. Additionally, the results show a reasonable steady state response at the beginning and even after clearing disturbance. (show as Tables 1 and 2).

**Figure 8.** (**a**) Active power response at real power step down change. (**b**) Reactive power response at real power step down change.

**Figure 9.** (**a**) Active power response at real power step down change. (**b**) Reactive power response at real power step down change.

Secondly, Figure 10 shows the microgrid dynamic response with step changes in real and reactive powers. Both active and reactive powers have been simultaneously stepped down from 5 kW to 3 kW and from 5 kVAR to 3 kVAR respectively at t = 0.1 sec. The results show how the proposed controller is working perfectly making the calculated powers track the reference powers perfectly.

**Figure 10.** (**a**) Active power response at real and reactive powers step down changes. (**b**) Reactive power response at real and reactive powers step down changes.

Thirdly for further testing of the controller robustness, a three-phase fault disturbance has been applied at the PCC at t = 0.1 sec. Fault has been cleared at t = 0.4 sec. Figure 11 shows the dynamic responses of the three-phase output currents and their *dq* components where the system has been recovered from the fault. The proposed controller shows a very good transient performance. The calculated real and reactive powers are following the reference real and reactive powers in a good way under this fault disturbance.

Finally, to confirm the superiority of the proposed controller, a comparison between the proposed controller and the existing control scheme (power calculator presented in [21]) has been carried out. As it was mentioned before, the reference currents were calculated using the reference powers and measured output voltage in [21] while in the proposed method, an optimal power PI controller has been implemented to obtain the reference currents where the calculated powers were compared with the reference powers. Figures 12 and 13 show the dynamic response of the *dq* components of the inverter currents, and real and reactive powers when the injected real power stepped down from 5 kW to 3 kW at t = 0.1 sec. It can be shown from the results that the proposed controller shows better performance in terms of tracking the reference powers and steady state response. Figures 14 and 15 illustrate the dynamic response of the real and reactive powers for stepping up the injected reactive power from 3 kVAR to 5 kVAR and stepping down the injected real power from 5 kW to 3 kW at t = 0.1 sec. The results illustrate how the calculated powers follow perfectly the reference

powers without any delay in the proposed controller while in the existing control scheme [21], there is a small delay when the calculated powers try to track the reference powers. Figures 16 and 17 depict the dynamic response of the *dq* components of the inverter currents, real and reactive powers for simultaneous step changes in both real and reactive powers from 3 kW to 5 kW and from 3 kVAR to 5 kVAR respectively at t = 0.1 sec. The system response due to a three-phase fault applied at the PCC is depicted in Figure 18. The results illustrate the superiority of the proposed controller. The response of the microgrid equipped with the proposed controller keep better and fast reference tracking in a good way.

**Figure 11.** (**a**) D-axis current response at three-phase fault disturbance at PCC. (**b**) Q-axis current response at three-phase fault disturbance at PCC. (**c**) Three-phase current response at three-phase fault disturbance at PCC.

**Figure 12.** (**a**) Active power response at step down change in real power. (**b**) Reactive power response at step down change in real power.

**Figure 13.** (**a**) D-axis current responses at step down change in real power. (**b**) Q-axis current responses at step down change in real power.

**Figure 14.** (**a**) Active power response at step up change in reactive power. (**b**) Reactive power response at step up change in reactive power.

**Figure 15.** (a) Active power response at step down change in reactive power. (**b**) Reactive power response at step down change in reactive power.

**Figure 16.** (**a**) Active power response with simultaneous step up change in real and reactive powers. (**b**) Reactive power response with simultaneous step up change in real and reactive powers.

**Figure 17.** (**a**) D-axis current responses with simultaneous step change. (**b**) Q-axis current responses with simultaneous step change.

**Figure 18.** (**a**) D-axis current responses for two controllers at the fault disturbance. (**b**) Q-axis current responses for two controllers at the fault disturbance.

#### *5.2. Two DGs Cases*

In the second case, two different rated (5 KVA and 10 KVA) inverter-based DG units are controlled to bring their real and reactive powers with the grid as shown in Figure 2. Both units are tied together to share the injected powers to the grid. The proposed controller has been examined for different disturbances. Figure 19 shows the dynamic response of the calculated and reference real powers with different step changes for the two different DGs at different times. Firstly, the injected real powers of DG1 and DG2 have been stepped up from 7.5 kW to 10 kW at t = 0.1 sec and from 2.5 kW to 5 kW at t = 0.3 sec respectively. Figure 20 illustrates the dynamic response of the *dq* components of the inverter output currents related to this disturbance. Both injected real and reactive powers are mostly following the reference powers. It could be observed from the results that the controller has quick responses and track the references effectively. Secondly, Figure 21 depicts the dynamic response of the real and reactive powers with simultaneous step change in the injected real powers of DG1 and DG2. For DG1, the real power has been stepped down from 10 kW to 6 kW at t=0.1 sec then it has been stepped up from 6 kW to 10 kW at t = 0.4 sec. While for DG2, the real power has been stepped down from 5 kW to 2 kW at t = 0.3 sec then it has been stepped up from2 kW to 5 kW at t = 0.5 sec. With the proposed controllers, it is obvious that the response overshoot is not significant. The response of the microgrid equipped with the proposed controller keep better and fast reference tracking in a good way.

A severe disturbance has been applied to check the controller capability for such disturbance. At t = 0.1 sec, the microgrid lost DG1 and restore it again at t = 0.4 sec. Meanwhile, the real power of DG2 has been stepped down from 5 kW to 3 kW between t = 0.3 sec and t = 0.5 sec. Figure 22 shows the real and reactive power responses of DG1 and DG2 at this disturbance. While, Figure 23 shows the responses of the *dq* components of the inductor current of DG1 and DG2 at this disturbance. It can be concluded from this disturbance that the proposed controller keeps the microgrid operation in a better shape. Additionally, the proposed controller has a fast response tracking the reference and in a good way.

**Figure 19.** (**a**) Active power responses at stepped up active power disturbances at different times. (**b**) Reactive power responses at stepped up active power disturbances at different times.

**Figure 20.** (**a**) D-axis current responses at stepped up active power disturbance. (**b**) Q-axis current responses at stepped up active power disturbance.

**Figure 21.** Power responses with stepped up and down real powers at different times.

**Figure 22.** (**a**) Active power responses when the microgrid lost DG1 for 0.3 sec. (**b**) Reactive power responses when the microgrid lost DG1 for 0.3 sec.

**Figure 23.** (**a**) D-axis current responses when the microgrid lost DG1 for 0.3 sec (**b**) Q-axis current responses when the microgrid lost DG1 for 0.3 sec.

## **6. Real-Time Implementation**

The considered inverter-based DG with its proposed controller has been implemented on real-time digital simulator (RTDS) as shown in Figure 24 [34–36]. For verifying the theoretical simulation, the proposed microgrid is implemented and simulated in RTDS. RTDS works in real-time to provide solutions to power system equations quickly enough to accurately represent conditions in the real world [26]. RTDS offers superior accuracy over analogue systems. It allows for comprehensive product and/or configuration tests. RTDS provides a variety of transient study possibilities. With detailed models of power system components, a model resembles closely the real system setup in the RTDS. As RTDS works in continuous sustained real-time, the simulation is performed fast. With standard library blocks, using their physical representation, components such as grid, LC filter, inverter bridge and coupling inductor are modeled. The RTDS model of the grid-connected microgrid includes the models of the inverter, LC filter, the coupling impedance and the grid is given in Figure 24. The firing pulse generator and triangle wave generator blocks used for generating the firing pulses of the inverter gates are also included in Figure 24.

Additionally, the RTDS models of the power and current controllers are illustrated in Figure 25. The optimal controller parameters are engaged with the implemented RTDS model. Firstly, with stepping up the injected real and reactive powers from 3 kW to 5 kW and from 3 kVAR to 5 kVAR respectively, the dynamic response of the *dq* currents components, real and reactive powers are shown in Figures 26–29. Secondly, Figures 30 and 31 show the dynamic response of the real and reactive powers when a single-phase fault occurs at PCC. Finally, real and reactive powers have been stepped for the proposed system and for the work done previously in [21]. A comparison between the new and old controllers has been presented to prove the superiority of the proposed one. Figures 32 and 33 depict the dynamic response of the real and reactive powers for the previous and proposed controllers. As shown in the RTDS results, during the step changes, the controller has a reasonable capability to track the reference signal without significant overshoots. The proposed controller effectiveness under these disturbances is confirmed in RTDS. The given results illustrate the superiority of the proposed controller. The response of the microgrid equipped with the proposed controller keep better reference tracking in a good way. The results show the controller effectiveness under different disturbances.

**Figure 24.** Laboratory setup for real-time digital simulation.

**Figure 25.** (**a**) Power controller on real-time digital simulation. (**b**) Current controller on real-time digital simulation.

responses at stepped up real power

**Figure 26.** (**a**) Active power responses at stepped up real power disturbance. (**b**) Reactive power

disturbance.

(**b**)

**Figure 27.** (**a**) D-axis inductor current response at stepped up real power disturbance. (**b**) Q-axis inductor current response at stepped up real power disturbance.

**Figure 28.** (**a**) Active power responses at stepped up reactive power disturbance. (**b**) Reactive power responses at stepped up reactive power disturbance.

**Figure 29.** (**a**) D-axis inductor current response at stepped up reactive power disturbance. (**b**) Q-axis inductor current response at stepped up reactive power disturbance.

**Figure 30.** (**a**) Active power responses at fault disturbance at PCC. (**b**) Reactive power responses at fault disturbance at PCC.

**Figure 31.** (**a**) D-axis inductor current response at fault disturbance at PCC. (**b**) Q-axis inductor current response at fault disturbance at PCC.

**Figure 32.** (**a**) Active power responses at stepped up active power disturbance. (**b**) Reactive power responses at stepped up active power disturbance.

**Figure 33.** *Cont*.

**Figure 33.** (**a**) Active power responses at stepped up reactive power disturbance. (**b**) Reactive power responses at stepped up reactive power disturbance.
