Modeling and control for microgrids