Modeling, Stability Analysis, and Control of Distributed Generation in the Context of Microgrids