What is Optimal Control?

Lots of problems we encounter in the real world can be boiled down to “what is the best way to get from point A to Point B while minimizing a certain cost”. For a quadcopter, it’s how can I stay in my location while minimizing my battery usage. For a spacecraft, it’s how can I get from Earth to the Moon in the minimum amount of time to protect astronauts from radiation damage. In the GIF below, it’s how can I swing this pendulum on a cart upright using the minimum force squared. These problems are called optimal control problems and there are two main families of techniques for solving them, direct methods, and indirect methods. This post will go over the basics of setting up a direct method.

What are Direct Methods in Optimal Control?

Direct methods in optimal control convert the optimal control problem into an optimization problem of a standard form and then using a nonlinear program to solve that optimization problem. The standard form that I will be using in this post is

A more general introductory tesxt to all optimal control can be found here

Discretizing the Trajectory

Let’s say we have some trajectory. The first task we have to do to put the trajectory in the standard form is to discretize it. I’m going to break the trajectory below into 3 distinct points.

At each of these points there’s a state X, a time t, and a control, U. We can stack them all together in several ways, but for this post, I’m going to choose the following.

for this example, let’s pretend that each state vector is made up of 3 states

and each control vector is made up of 2 controls

There’s no set reason why I stacked the state and the time together and clumped all the controls at the bottom. We could have done it differently, we just need to keep track of where everything is. Additionally, to discretize problems in the real world we often need to discretize the trajectory into tens to even thousands of points depending on the difficulty of the problem.

Enforcing Boundry Constraints

For our trajectory, we don’t know what the path is going to be, but we do know where we want it to start, and where we want it to end. We can write these conditions for our 3 point discritization as

If we also have a set initial and final time, we can then write our boundary constraints as

where

and I(n) is the square identity matrix of size n, and 0(m,n) is a zero matrix of shape m rows and n columns.

Note: There’s no reason why we have to specify all these boundary conditions. For example with the pendulum swing up case shown in the gif in the top, we specified all the initial and final states, but we only care that at the end the pendulum is inverted. We could drop our final location requirement for the cart and this would also be a completely acceptable optimal control problem. It would, however, produce a different solution.

Enforcing The Forward Flow of Time

In this problem, we are enforcing an initial and final time, but let’s also enforce that time must flow forward. This constraint can be written generally as

or in the form of our nonlinear program

where

Note: we don’t always need to enforce forward time. Sometimes the best solutions are gotten by running the problem backward in time, but in most problems, it’s an unwritten constraint that we expect the final time to come after the initial time.

Note 2: In our problem, we specify both the initial and final times, but in problems where we allow the final time to vary, nonlinear programming solvers often want to run backward in time.

Enforcing Path Constraints

We can enforce simple path constraints on the states or the controls directly by imposing hard bounds on them.

This is extremely useful because control in our optimal control problem is often bounded in real life. For example, spacecraft thrusters have hard limits on how much they can thrust.

Defects

Now we need to including the dynamics. Let’s jump back to differential equations and remember the following fact.

All this says, is that by integrating the derivative of the state vector over some time and combining it with the state vector at the start of that time period, we get the state vector at the next time period. But we already have a state at the next time period, so we call the difference between that, and what we get from integrating, the defect .

By ensuring these defects are 0, we can ensure that all our different points are valid solutions to the dynamical system. We can do that using the nonlinear equality constraints

Bringing it all Together

In 2-body orbital dynamics, we can describe the relative motion of two close objects, where one is in a circular orbit using the Clohessy-Wiltshire equations, which are as follows

where mu is the gravitational parameter, and a is the radius of the target. This is extremely useful for final rendezvous with objects like the space station, which has almost no eccentricity. I’ve set up and then solved an optimal control problem of one satellite intercepting another satellite using the direct methods described in this post. The code for that can be found here (templateInit.m is the main script), and is mainly a wrapper around Matlab’s fmincon. Here’s a gif of the results.

Want more Gereshes?

If you want to receive new Gereshes blog post directly to your email when they come out, you can sign up for that here!

Don’t want another email? That’s ok, Gereshes also has a twitter account and subreddit!

Share this: Facebook

Reddit

Twitter

Pocket

More

Print

LinkedIn



Tumblr

Pinterest



Telegram

WhatsApp



Skype

