  Tracking a magnetic field in real-time with an atomic magnetometer presents
significant challenges, primarily due to sensor non-linearity, the presence of
noise, and the need for one-shot estimation. To address these challenges, we
propose a comprehensive approach that integrates measurement, estimation and
control strategies. Specifically, this involves implementing a quantum
non-demolition measurement based on continuous light-probing of the atomic
ensemble. The resulting photocurrent is then directed into an Extended Kalman
Filter to produce instantaneous estimates of the system's dynamical parameters.
These estimates, in turn, are utilised by a Linear Quadratic Regulator, whose
output is applied back to the system through a feedback loop. This procedure
automatically steers the atomic ensemble into a spin-squeezed state, yielding a
quantum enhancement in precision. Furthermore, thanks to the feedback proposed,
the atoms exhibit entanglement even when the measurement data is discarded. To
prove that our approach constitutes the optimal strategy in realistic
scenarios, we derive ultimate bounds on the estimation error applicable in the
presence of both local and collective decoherence, and show that these are
indeed attained. Additionally, we demonstrate for large ensembles that the EKF
not only reliably predicts its own estimation error in real time, but also
accurately estimates spin-squeezing at short timescales.
