← back to projects

ML Digital Twin of a Drone

Teaching machine learning models to imitate a quadrotor's flight dynamics. LSTM vs Neural ODE vs XGBoost, trained on flight data collected in simulation through ROS 2.

PyTorch · Neural ODE · LSTM · XGBoost · ROS 2 · Gazebo view on github ↗

A digital twin is only as good as its dynamics model. Instead of deriving a quadrotor’s equations of motion by hand, I wanted to see whether a machine learning model could learn those dynamics from flight data alone, and which type of model does it best.

LSTM predicted vs actual state trajectories
LSTM predictions against the true state across several held-out test flights.

Collecting the data

A ROS 2 node flies a simulated quadrotor in Gazebo and logs synchronized state and command pairs: position, attitude (converted from quaternions), linear velocities, and the velocity commands that produced them. That gives a clean time-series record of what the drone was doing and what it was told to do, which is the raw material for learning the dynamics.

Three models, one question

Each model gets the same job: given the current state and command, predict the next state.

  • LSTM — the classic sequence model; learns temporal patterns in how the drone behaves.
  • Neural ODE — models the dynamics as a continuous-time differential equation learned by a neural network, which is conceptually closest to how the physics actually works.
  • XGBoost — gradient-boosted trees as a fast tabular baseline that ignores time entirely.
XGBoost predicted vs true scatter plot
The XGBoost baseline: predicted vs. true values across the state variables.

Why it matters

A learned dynamics model gives you a simulator that runs much faster than full physics. That opens the door to rapid control prototyping, model-predictive control, and anomaly detection, where the drone isn’t responding the way the twin predicts. It’s the same idea behind EdgeSense, applied to a different machine.