Rocket

Rocket

This problem can be found here.

Packages that will be used

using NLOptControl

Constants

# Note that all parameters in the model have been normalized
# to be dimensionless. See the COPS3 paper for more info.
h_0 = 1    # Initial height
v_0 = 0    # Initial velocity
m_0 = 1    # Initial mass
g_0 = 1    # Gravity at the surface

# Parameters
T_c = 3.5  # Used for thrust
h_c = 500  # Used for drag
v_c = 620  # Used for drag
m_c = 0.6  # Fraction of initial mass left at end

# Derived parameters
c     = 0.5*sqrt(g_0*h_0)  # Thrust-to-fuel mass
m_f   = m_c*m_0            # Final mass
D_c   = 0.5*v_c*m_0/g_0    # Drag scaling
T_max = T_c*g_0*m_0        # Maximum thrust

Define the Problem:

n=define(numStates=3,numControls=1,X0=[h_0,v_0,m_0],XF=[NaN,NaN,m_f],XL=[h_0,v_0,m_f],XU=[NaN,NaN,m_0],CL=[0.0],CU=[T_max]);

State and Control Names

states!(n,[:h,:v,:m],descriptions=["height (t)","velocity (t)","mass (t)"]);
controls!(n,[:T],descriptions=["thrust (t)"]);

Differential Equations

Drag=:($D_c*v[j]^2*exp(-$h_c*(h[j]-$h_0)/$h_0));
Grav=:($g_0*($h_0/h[j])^2);
dx=Array{Expr}(3,);
dx[1]=:(v[j]);
dx[2]=:((T[j]-$Drag)/m[j]-$Grav)
dx[3]=:(-T[j]/$c);

Then add the differential equations to the model:

dynamics!(n,dx)

Configure the Problem:

configure!(n;(:finalTimeDV=>true));

Objective Function

@NLobjective(n.ocp.mdl,Max,n.r.ocp.x[end,1]);

Optimize

optimize!(n);

Post Process

allPlots(n)
0.00 0.05 0.10 0.15 0.950 0.975 1.000 1.025 1.050 time (s) height (t) min mpc 0.00 0.05 0.10 0.15 0.00 0.02 0.04 0.06 0.08 0.10 0.12 time (s) velocity (t) min mpc 0.00 0.05 0.10 0.15 0.6 0.7 0.8 0.9 1.0 time (s) mass (t) max min mpc 0.00 0.05 0.10 0.15 0 1 2 3 time (s) thrust (t) max min mpc