  Fishes, cetaceans, and many other aquatic vertebrates undulate their bodies
to propel themselves through water. Swimming requires an intricate interplay
between sensing the environment, making decisions, controlling internal
dynamics, and moving the body in interaction with the external medium. Within
this sequence of actions initiating locomotion, biological and physical laws
manifest complex and nonlinear effects, which does not prevent natural swimmers
to demonstrate efficient movement. This raises two complementary questions: how
to model this intricacy and how to abstract it for practical swimming. In the
context of robotics, the second question is of paramount importance to build
efficient artificial swimmers driven by digital signals and mechanics. In this
study, we tackle these two questions by leveraging a biomimetic robotic swimmer
as a platform for investigating optimal control strategies for thrust
generation. Through a combination of machine learning techniques and intuitive
models, we identify a control signal that maximizes thrust production. Optimum
tail-beat frequency and amplitude result from the subtle interplay between the
swimmer's internal dynamics and its interaction with the surrounding fluid. We
then propose a practical implementation for autonomous robotic swimmers that
requires no prior knowledge of systems or equations. Direct fluid-structure
simulations confirms the effectiveness and reliability of the proposed
approach. Hence, our findings bridge fluid dynamics, robotics, and biology,
providing valuable insights into the physics of aquatic locomotion
