## 3 Controller Design
### Control during Grid-Connected Mode of AC Sub-Grid  
In Section 2.4, the global model during the grid-connected mode of AC sub-grid is presented. VSI side is utilized during this mode and hybrid renewable energy sources contribute with the main grid to provide the necessary power to the utility grid. The battery will be kept in idle mode due to the availability of the grid. The following equation can express the tracking errors to make sure the stable operation of the AC sub-grid as:  
\[\left\{\begin{array}{c}e_{4}\\ e_{5}\\ e_{6}\end{array}\right\}=\left\{\begin{array}{c}x_{5}-V_{dref}\\ x_{6}-I_{dref}\\ x_{7}-\;I_{qref}\end{array}\right\} \tag{62}\]  
where \(I_{dref}\) and \(I_{qref}\) are the reference values of VSI dq axis currents. Errors for wind and PV systems are already defined. The grid-connected mode of the microgrid is activated when switch \(S_{L}\) is ON as shown in Figure 6. Assuming the time derivative in Equation (62) will give the following expressions:  
\[e_{4}=\;(1-\;\mu_{1})\frac{x_{1}}{C_{dc}}+(\;1-\mu_{2})\frac{x_{3}}{C_{dc}}\;- \frac{I_{o}}{C_{dc}}-\dot{V_{dref}}+\dot{\theta}_{4}\;-\frac{3}{2C_{dc}x_{4}} (x_{9}x_{7}+x_{6}x_{8}) \tag{63}\]  
Figure 6: AC/DC configuration of proposed MG.  
\[e_{5} =\ -\frac{x_{8}}{L_{f}}-\frac{R_{f}x_{6}}{L_{f}}+\omega_{0}x_{7}+\frac{ U_{d}x_{5}}{L_{f}}-I_{dref}^{\cdot}+\theta_{5} \tag{64}\] \[e_{6} =\ -\frac{x_{9}}{L_{f}}-\frac{R_{f}x_{7}}{L_{f}}-\omega_{0}x_{6}+ \frac{U_{d}x_{5}}{L_{f}}-I_{qref}^{\cdot}+\theta_{6} \tag{65}\]  
where \(\theta_{4},\theta_{5}\) and \(\theta_{6}\) are the unknown bounds and uncertain dynamics and the accuracy of the controller tends to remove these parameters adaptively. From Equations (64) and (65), the control laws can be derived as:  
\[U_{d}=\frac{L_{f}}{x_{5}}(e_{5}+\frac{x_{8}}{L_{f}}+\frac{R_{f}x_{6}}{L_{f}}- \omega_{0}x_{7}+\ I_{dref}^{\cdot}) \tag{66}\]  
\[U_{q}=\frac{L_{f}}{x_{5}}(e_{6}+\frac{x_{9}}{L_{f}}+\ \frac{R_{f}x_{7}}{L_{f}}+ \omega_{0}x_{6}+\ I_{qref}^{\cdot}) \tag{67}\]  
For the error convergence towards zero, barrier functions for \(e_{5}\) and \(e_{6}\) are illustrated below considering the Equation (43) as:  
\[e_{5} =-K_{5}|e_{5}|\ sgn\ (e_{5}) \tag{68}\] \[e_{6} =\ -K_{6}|e_{6}|\ sgn\ (e_{6}) \tag{69}\]  
where \(K_{5}\) and \(K_{6}\) are the adaptive gains, whose values can be determined by using. Equations (44) and (45) as:  
\[K_{\beta}(t)=\left\{\begin{array}{c}K_{PB}(t),K_{PB}^{\cdot}(t)=F|e_{\beta} (t)|,\qquad if\ (0<t<\bar{t})\\ K_{PSB}|e_{\beta}(t)|,\qquad if\ (t>\bar{t})\end{array}\right. \tag{70}\]  
where \(\beta\) = 5, 6, and \(\bar{F}\) is a positive arbitrary number. Control laws for WES and PV system will remain the same as given in Equations (59) and (60). Hence, control laws for AC-grid side can be expressed by the following equations as:  
\[U_{d} =\frac{L_{f}}{x_{5}}(\ -K_{5}|e_{5}|\ sgn\ (e_{5})\ +\frac{x_{8}}{L_{f}}+ \frac{R_{f}x_{6}}{L_{f}}-\omega_{0}x_{7}+\ I_{dref}^{\cdot}) \tag{71}\] \[U_{q} =\frac{L_{f}}{x_{5}}(-K_{6}|e_{6}|\ sgn\ (e_{6})+\frac{x_{9}}{L_{f}}+ \ \frac{R_{f}x_{7}}{L_{f}}+\omega_{0}x_{6}+\ I_{qref}^{\cdot}) \tag{72}\]  
The active power reference generation during the grid-connected mode can be determined by solving the Equation (63).  
\[I_{d}^{*}=x_{6}^{*}=\frac{2C_{dc}x_{5}}{3x_{8}}\bigg{(}\frac{(1-\mu_{1})x_{1} }{C_{dc}}+\frac{(1-\mu_{2})x_{3}}{C_{dc}}-\frac{I_{o}}{C_{dc}}-x_{5}\ +K_{4}|e_{4}|\ sgn\ (e_{4}) \bigg{)} \tag{73}\]  
where \(c_{2}\) is a constant having a positive value to ensure the convergence of the error \(e_{4}\) towards zero. Equation (63) ensures the stability of DC and AC bus voltages by regulating the flow of active power between AC and DC sides of the microgrid.