Adaptive and real-time optimal control for adaptive optics systems