DEV Community

Farzon Lotfi
Farzon Lotfi

Posted on • Originally published at blog.farzon.org on

To the Moon and Back: How a fundamental Algorithm is Navigating the Artemis Missions

I have been so energized with all the cool space news in 2026. It has been one of the few things keeping me sane 🤣. So today I'm going to walk through a paper I just read as I try to consume as much space news as possible.

Have you ever wondered how a spacecraft, hurtling through the vacuum of space at thousands of miles per hour, knows exactly where it is? Well NASA answered that question in 2023 in the paper Extended Kalman Filter Performance on the Artemis-1 Mission.

Orion Shuttle in space

The secret is the Kalman Filter, specifially the Extended Kalman Filter (EKF). During the historic Artemis missions, this algorithm was the silent pilot, running from the moment the engines ignited until the capsule splashed down in the Pacific. In this post, we’re going to peel back the curtain on how NASA used this algorithm to navigate and how you can build one yourself.

What is a Kalman Filter and How does it work?

Imagine trying to track a car in a tunnel. You have a math model (the car’s speed) and noisy data (a fuzzy GPS signal). A Kalman Filter is like a super-smart judge that looks at both and decides: "The GPS is a bit jumpy right now, so I'll trust the math model more," or "The car just hit a speed bump, I should trust the GPS."

In our Python Notebook, we simulate this exact sceanrio with a vehicle moving in 1D. While the Artemis mission used 3D vectors and complex gravity models, the core logic is identical to this snippet. Let’s break down the two-step dance of the Kalman Filter.

1D Kalman filter

Phase 1: State Propagation (The Guess)

Before looking at any sensors, the filter uses physics to predict where the spacecraft should be. In the NASA paper, this is called "propagating the state."

# x_pred: New Position estimate
# p_pred: New Uncertainty (Covariance)
x_pred = x + v * dtp_pred = p + q
Enter fullscreen mode Exit fullscreen mode

NASA Fun Fact: Artemis-1 used IMU data to drive this prediction at 40Hz, ensuring the spacecraft never "stopped" navigating.

Phase 2: The Measurement Update (The Correction)

Now we compare our guess to the sensor (GPS or Optical Nav). The difference between them is the Residual. The Kalman Gain (k) decides how much we trust that error.

# Calculate how much to trust the sensor vs. the math
k_gain = p_pred / (p_pred + r)
# Correct the position using the measurement residual
x = x_pred + k_gain * (measurement - x_pred)
# Update our confidence for the next loop
p = (1 - k_gain) * p_pred
Enter fullscreen mode Exit fullscreen mode

NASA Fun Fact: The Artemis paper highlights "Measurement Underweighting." If the measurement is too far from the prediction, the filter "dampens" the gain so the spacecraft doesn't make jerky, dangerous movements.

NASA's Ultimate "Guess and Check" System

The last time humanity went to the moon was the Apollo missions back in the 1960s. The computers were less powerful than a Casio calculator. Navigation often required ground crews to "beam" coordinates up to the astronauts. This is the first time we have a space craft with he power to do navigation on its own and Orion does not disappoint.

The Artemis-1 Orion spacecraft used this exact "Predict-Update" cycle, but on a massive scale. As detailed in the mission architecture, Orion ran four specialized filters:

  1. Atmospheric Filter (ATMEKF): Handled the shaky, high-stakes launch and re-entry.
  2. Earth Orbit Filter (EOEKF): Used GPS satellites to stay on track near home.
  3. Cislunar Filter (CLEKF): Took over when GPS faded, using Optical Navigation (taking photos of the Earth and Moon) to find its way.
  4. Attitude Filter (ATTEKF): Used the stars to ensure the craft was always pointing in the right direction.

Breaking this down into our Predict update cycle

  • The Prediction: Instead of the simple linear motion in our Python script, Orion used high-fidelity gravity models and IMU data.
  • The Update: When near Earth, it used GPS. When near the Moon, it used Optical Navigation (OpNav) which is literally taking photos of the Moon’s horizon to calculate its position.

What makes an Extended Kalman Filter (EKF)?

If you look at the Python notebook, we used a "Standard" Kalman Filter. But the NASA paper explains that for a Moon mission, standard isn't enough. They used two critical upgrades:

  1. UDU Factorization: In our code, we calculate the "Uncertainty Matrix" (P). In space, rounding errors in a computer can make that math "break." NASA uses UDU Factorization to break the matrix into pieces that are mathematically impossible to break, ensuring the navigation never "diverges."

  2. The Multiplicative EKF: While our notebook handles 1D motion, Orion has to track 3D rotation. NASA uses a "Multiplicative" approach for attitude, meaning they track the error in rotation and "rectify" it after every measurement.

From Your Laptop to the Lunar Surface

The code in our Python notebook is the "Hello World" of the same system that just returned humanity to the lunar vicinity. By understanding how to balance a "prediction" with a "measurement," you are using the same logic that NASA engineers used to certify Orion for crewed flight.

Artemis blasting off

Whether it’s a simple simulation on your screen or a multi-billion dollar mission to the Moon, the Kalman Filter is the tool that turns the "noise" of the universe into a clear path forward.

Try out the tutorial here: Open In Colab


References:

Top comments (0)