Real-Time Battery Control Method For Microgrid Energy Management