Engee documentation
Notebook

Optimization of rocket control parameters

Introduction

An urgent task in the field of applied mathematics and control theory is solving nonlinear problems of optimal control of dynamic systems. This example considers a special but illustrative case of such a task — maximizing the final height of the vertical flight of a rocket, taking into account its dynamics.

The purpose of this study is to demonstrate a methodology for the formulation and numerical solution of such problems using modern computational optimization tools.

The presented model takes into account key physical factors: variable mass due to fuel consumption, gravity depending on height, and aerodynamic drag, which makes it suitable for demonstrating the principles of optimal control.

We will attach the necessary libraries.

In [ ]:
using JuMP, Ipopt, Measures

It is necessary to select such optimal parameters to ensure the maximum possible height of a vertically launched rocket.

We can control the thrust of a rocket based on its mass, fuel consumption, gravity, and aerodynamic drag.

Let's look at the basic description of the model.

There are three state variables in our model:

  • Speed:

  • Height:

  • Mass of rocket and remaining fuel:

and one control variable:

  • Traction: .

The dynamics of a rocket is described by three equations:

  • Lifting speed:

  • Acceleration:

  • Rate of mass loss: ,

Where is the resistance is a function of height and speed, gravity — the height function, and — the constant.

These forces are defined as follows:

and

.

We use a time-discretized model with a fixed number of steps. .

Thus, our goal is to maximize .

Initial data

Normalized dimensionless parameters are used in this model.

Initialize the source data.

In [ ]:
h_0 = 1                      # Initial height
v_0 = 0                      # Initial velocity
m_0 = 1.0                    # Initial weight
m_T = 0.6                    # Final weight
g_0 = 1                      # Gravity on the surface
h_c = 500                    # Height parameter for resistance
c = 0.5 * sqrt(g_0 * h_0)    # Specific impulse (fuel consumption thrust)
D_c = 0.5 * 620 * m_0 / g_0  # Resistance coefficient
u_t_max = 3.5 * g_0 * m_0    # Maximum thrust
T_max = 0.2                  # Flight time (in seconds)
T = 1_000                    # Number of time steps
Δt = T_max / T               # Time step duration

Let's create a model and choose an optimization method. Since this is a non-linear task, we need to use a non-linear method such as Ipopt.

In [ ]:
model = Model(Ipopt.Optimizer)
set_silent(model)

Next, we will create variables that describe the state and control of the rocket. They all change over time. In order for the method to find a solution faster, we set each variable to its approximate initial value.

In [ ]:
@variable(model, x_v[1:T] >= 0, start = v_0)           # Speed
@variable(model, x_h[1:T] >= 0, start = h_0)           # Height
@variable(model, x_m[1:T] >= m_T, start = m_0)         # Weight
@variable(model, 0 <= u_t[1:T] <= u_t_max, start = 0); # Thrust

Let's set the initial and final conditions.

In [ ]:
fix(x_v[1], v_0; force = true)
fix(x_h[1], h_0; force = true)
fix(x_m[1], m_0; force = true)
fix(u_t[T], 0.0; force = true)

The optimization goal is to ensure that the rocket reaches the highest possible altitude by the end of the maneuver.

In [ ]:
@objective(model, Max, x_h[T])

The resistance and gravity in the model are set using the functions:

In [ ]:
D(x_h, x_v) = D_c * x_v^2 * exp(-h_c * (x_h - h_0) / h_0)
g(x_h) = g_0 * (h_0 / x_h)^2

Optimization constraints are defined in the form of equations describing the motion of the rocket.

In [ ]:
ddt(x::Vector, t::Int) = (x[t] - x[t-1]) / Δt
@constraint(model, [t in 2:T], ddt(x_h, t) == x_v[t-1])
@constraint(model, [t in 2:T], ddt(x_v, t) == (u_t[t-1] - D(x_h[t-1], x_v[t-1])) / x_m[t-1] - g(x_h[t-1]))
@constraint(model, [t in 2:T], ddt(x_m, t) == -u_t[t-1] / c);

Let's complete the optimization task and check the solution.:

In [ ]:
optimize!(model)
assert_is_solved_and_feasible(model)
solution_summary(model)
******************************************************************************
This program contains Ipopt, a library for large-scale nonlinear optimization.
 Ipopt is released as open source code under the Eclipse Public License (EPL).
         For more information visit https://github.com/coin-or/Ipopt
******************************************************************************

Out[0]:
solution_summary(; result = 1, verbose = false)
├ solver_name          : Ipopt
├ Termination
│ ├ termination_status : LOCALLY_SOLVED
│ ├ result_count       : 1
│ └ raw_status         : Solve_Succeeded
├ Solution (result = 1)
│ ├ primal_status        : FEASIBLE_POINT
│ ├ dual_status          : FEASIBLE_POINT
│ ├ objective_value      : 1.01278e+00
│ └ dual_objective_value : 4.66547e+00
└ Work counters
  ├ solve_time (sec)   : 6.59115e+00
  └ barrier_iterations : 24

Let's define a function for plotting the altitude, mass, speed, and thrust of a rocket with optimal parameters.

In [ ]:
function trajectory(y; kwargs...)
    return Plots.plot(
        (1:T) * Δt,
        value.(y);
        xlabel = "Time in seconds",
        legend = false,
        linewidth = 2,
        kwargs...,
    )
end

Let's plot the altitude of the rocket.

In [ ]:
Plots.plot(траектория(x_h; ylabel = "Height"))
Out[0]:

Let's plot the mass change of the rocket.

In [ ]:
Plots.plot(траектория(x_m; ylabel = "Weight"))
Out[0]:

Let's plot the speed of the rocket.

In [ ]:
Plots.plot(траектория(x_v; ylabel = "Speed"))
Out[0]:

Let's plot the optimal thrust of the rocket.

In [ ]:
Plots.plot(траектория(u_t; ylabel = "Thrust"))
Out[0]:

Conclusion

Within the framework of this study, the problem of nonlinear optimal control for the vertical rocket flight model was successfully solved. The goal of maximizing the final height is achieved by constructing a discrete approximation of the initial continuous problem and its subsequent optimization.

The methodology presented in this paper is universal and can be extended to more complex cases, such as three-dimensional dynamics problems, multistage flights, or systems with additional phase constraints. Thus, the research contributes to the practice of applying nonlinear programming methods to solve optimal control engineering problems.