Lunar Lander Optimal Control Using Dash

Disclaimer: Plotly paid me to both make a dash app, as well as this post. Even before this I was a fan of Plotly’s products and used them in posts about missed thrust events  and visualizing periodic orbits. In those projects,  I used Plotly because they make some great visualization tools. You should check their stuff out.

Landing a Lunar Lander without a Gimballing Engine

When the Apollo Lunar Module landed on the moon, it oriented itself using a reaction control system made up of small thrusters located about the lander. The main engine, located at the bottom, was fixed in place and only used to slow the spacecraft down. This restriction makes designing a lunar landing trajectory more difficult, so let’s explore the trade space of optimal control trajectories. Note: If you want to try the interactive Dash app directly, without going through all the math, you can find that here

If we restrict it to 2 dimensions, we would obtain the following equations of motion

\ddot{x} = \frac{c_1 *  u * sin(\theta)}{m}

\ddot{y}=\frac{c_1 * u * cos(\theta)}{m} - g

\dot{\theta}=c_3 B

\dot{m} = -\frac{c_1}{c_2}u

In these equations of motion, which come from this paper, where u is the spacecraft’s thrust fraction, B is its pitch rate, c1 its max thrust, c2 the engines efficinecy, and c3 its max pitch rate.

Solving the Optimal Control Problem using Casadei

We’re going to solve two separate optimal control problems in this post, a mass optimal control problem, given by the following equation

min J = -m_f

and a time otpimal control function

min J = t_t

In order to solve the optimal control problem, we are going to use a direct method, which we’ve discussed generally here.

In this problem we’re going to have the following boundary conditions

\vec{X}_0 =\vec{IC}

t_0=0

and

\vec{X}_f=\vec{0}

with the exception of the final mass and final time, which we’re going to leave free. We’re going to enforce the following path constraints

|u|\le 1

as well as a one-step Runge-Kutta 4 constraint on the dynamics

k_1 = f(\vec{X},\vec{U})

k_2 = f(\vec{X} + (.5*dt*k_1),\vec{U})

k_3 = f(\vec{X}+ (.5*dt*k_1),\vec{U})

k_4 = f(\vec{X}+k_3,\vec{U})

\delta_n = \vec{X}_{n+1}- \vec{X}_{n+1} + \bigg(\frac{dt}{6}(k_1+2k_2+2k_3+k_4)\bigg)

Now that we have turned our out optimal control problem into a nonlinear programming, we are going to use CasADi, an “open-source tool for nonlinear optimization”. Here’s a good tutorial about how to use CasADI

Exploring the trade space with a dash app

Instead of exploring the tradespace through images I encourage you to interact with the dash app yourself, you can find it here with the source code here.

Places to learn more about dash apps

If you want to learn more about Dash apps, this is a great resource for getting started, and there’s a forum that I went to for more advanced questions.

Additionally, if you want to see some other creative uses of Dash, they have a Dash gallery.

Want More Gereshes?

If you want to receive the weekly Gereshes blog post directly to your email every Monday morning, you can sign up for the newsletter here! Don’t want another email? That’s ok, Gereshes also has a twitter account and subreddit!