## 2 Control Method  
Droop control P-\(\omega\) and droop control Q-V have been successfully applied to microgrids [26]. These methods are simple but not very effective when the load changes in different nodes in the microgrid. Therefore, this paper proposes a very useful control strategy for this type of problem. Figure 1 shows the diagram of a single EV and a house connected to a network that uses renewable energies and power inverters.  
The active and reactive power transferred from the inverter to the load are given by Equations (1) and (2). These equations express, respectively, the active and reactive power that is lost through the inductive reactance associated with transmission lines. Herein, the term \(\delta\) represents the phase angle between the voltage generated by the inverters (\(V\)) and the voltage of the AC bus (\(E\)). Furthermore, the impedance \(Z=R+jX\) has an angle \(\theta\) that can be defined as \(R=Z\cos\theta\) and \(X=Z\sin\theta\):  
\[P=\frac{1}{R^{2}+X^{2}}\Big{(}RE^{2}-REV\cos\delta\ +XEV\sin\delta\Big{)}, \tag{1}\]  
\[Q=\frac{1}{R^{2}+X^{2}}\Big{(}XE^{2}-XEV\cos\delta-REV\sin\delta\Big{)}. \tag{2}\]  
A control strategy with virtual impedances is proposed as a method to control the reactive power of the microgrid, considering connections and disconnections of EVs. Figure 2 shows a detailed configuration of a DG unit using the proposed control strategy. The P-\(\omega\) controller is adopted to regulate the frequency and to achieve accurate reactive power sharing by using virtual impedance.  
The controller used with the electrical circuit starts by measuring the current in the inductance of the filter \(i_{abc}\), the output voltage \(V_{abc}\), and the zero-sequence current \(i_{\text{{\em bdc}}}\). Using the Park transform method, the three previous values are transformed to obtain the \(dq\) values, such as \(i_{dq}\), \(V_{dq}\), and \(i_{\text{{\em dof}}}\)  
Figure 1: Diagram of an electric vehicle (EV) connected to the power grid.  
Figure 2: Electrical circuit with the proposed control strategy applied to distributed generation.  
The active power P is calculated by using the output voltage \(V_{dq}\) and the current measured in the output of the system \(i_{0 dq}\), both in \(dq\) coordinates; then, the final signal is passed through the filter and droop controller to obtain \(\theta\).  
A variable virtual impedance \(X_{m}\), related to the line and load impedances considered from each EV to the inverters, is applied to the control. Then, the total virtual impedance \(X_{V}\) is calculated by summing \(X_{m}\) and a fixed virtual impedance \(X_{Vf}\) related to the line and load impedances considered from each house to the inverters, as defined in Equation (3). Reactive power sharing is performed by regulating this total virtual impedance according to the location of EVs in the microgrid.  
\[X_{V}=X_{Vf}\ +X_{m}. \tag{3}\]  
Then, the reference voltage \(V_{ref}\) is calculated by using the \(X_{V}\) and the \(i_{0 dq}\). Next, the reference voltage \(V_{ref}\) and the output voltage \(V_{dq}\) that is measured and transformed to \(dq\) coordinates are used to obtain the voltage error, which is then converted to the reference current using the voltage controller.  
The voltage control loop uses a PR controller to track the voltage reference value, which is given by the controller. The output of the voltage control gives a reference current that is used to calculate the current error with the \(i_{0 dq}\). The current control loop uses a P controller to adjust the output current that is sent to the pulse width modulation (PWM) to make the inverter obtain the desired voltage response.