**7. Conclusion**

In this paper, an optimal PQ control technique for inverter-based DG in the grid-connected microgrid has been presented. A power controller has been optimally designed to control a predefined injected real and reactive powers to the utility. Moreover, the current controller parameters and filter components have been optimized. To improve the microgrid dynamic response, the optimized controller parameters have been adjusted. For microgrid stability enhancement, with the proposed objective function, PSO has been employed for searching the optimal settings of the optimized controller and filter parameters. Two different cases in terms of the microgrid configuration have been considered to inject and share a predefined set real and reactive powers respectively. In both cases, the microgrid performance has been investigated for severe disturbances to clarify how the proposed optimal control improved the microgrid dynamic stability. The proposed controller response has been compared with that given in the literature. The time domain simulations confirm the proposed approach usefulness over the previous controller. For the proposed microgrid, the obtained RTDS results verify the usefulness of the proposed controllers for different disturbances. Additionally, RTDS results demonstrate reasonable performance with effective damping characteristics of the proposed controller.

**Author Contributions:** M.A.H. and M.A.A. initiated the idea, formulated the problem, performed the simulation, and analyzed the results. M.Y.W. participated in paper revision stage, contributed in enhancing the simulation results, and shared in paper writing.

**Funding:** This research was funded by King Fahd University of Petroleum and Minerals through the Power Research Group funded project RG171002 and King Abdullah City for Atomic and Renewable Energy (K.A. CARE).

**Conflicts of Interest:** The authors declare no conflict of interest.
