Mitigation of vibrations in adaptive optics by minimization of closed-loop residuals