Particle accelerators play a critical role in modern scientific research. However, existing manual beam control methods heavily rely on experienced operators, leading to significant time consumption and potential challenges in managing next-generation accelerators characterized by higher beam current and stronger nonlinear properties. In this paper, we establish a dynamical foundation for designing the online adaptive controller of accelerators using machine learning. This provides a guarantee for dynamic controllability for a class of scientific instruments whose dynamics are described by spatial-temporal equations of motion but only part variables along the instruments under steady states are available. The necessity of using historical time series of beam diagnostic data is emphasised. Key strategies involve also employing a well-established virtual beamline of accelerators, by which various beam calibration scenarios that actual accelerators may encounter are produced. Then the reinforcement learning algorithm is adopted to train the controller with the interaction to the virtual beamline. Finally, the controller is seamlessly transitioned to real ion accelerators, enabling efficient online adaptive control and maintenance. Notably, the controller demonstrates significant robustness, effectively managing beams with diverse charge mass ratios without requiring retraining. Such a controller allows us to achieve the global control within the entire superconducting section of the China Accelerator Facility for Superheavy Elements.