A Multi-phase nonlinear Optimal control problem solver using Pseudo-spectral collocation
Project description
MPOPT
MPOPT is an open-source, extensible, customizable and easy to use python package that includes a collection of modules to solve multi-stage non-linear optimal control problems(OCP) using pseudo-spectral collocation methods.
The package uses collocation methods to construct a Nonlinear programming problem (NLP) representation of OCP. The resulting NLP is then solved by algorithmic differentiation based CasADi nlpsolver ( NLP solver supports multiple solver plugins including IPOPT, SNOPT, sqpmethod, scpgen).
Main features of the package are :
- Customizable collocation approximation, compatible with Legendre-Gauss-Radau (LGR), Legendre-Gauss-Lobatto (LGL), Chebyshev-Gauss-Lobatto (CGL) roots.
- Intuitive definition of single/multi-phase OCP.
- Supports Differential-Algebraic Equations (DAEs).
- Customized adaptive grid refinement schemes (Extendable)
- Gaussian quadrature and differentiation matrices are evaluated using algorithmic differentiation, thus, supporting arbitrarily high number of collocation points limited only by the computational resources.
- Intuitive post-processing module to retrieve and visualize the solution
- Good test coverage of the overall package
- Active development
Quick start
- Install from the Python Package Index repository using the following terminal command, then copy paste the code from example below in a file (test.py) and run (python3 test.py) to confirm the installation.
pip install mpopt
- (OR) Build directly from source (Terminal). Finally,
make run
to solve the moon-lander example described below.
git clone https://github.com/mpopt/mpopt.git --branch master
cd mpopt
make build
make run
source env/bin/activate
A sample code to solve moon-lander OCP (2D) under 10 lines
OCP :
Find optimal path, i.e Height ( $x_0$ ), Velocity ( $x_1$ ) and Throttle ( $u$ ) to reach the surface: Height (0m), Velocity (0m/s) from: Height (10m) and velocity(-2m/s) with: minimum fuel (u).
$$\begin{aligned} &\min_{x, u} & \qquad & J = 0 + \int_{t_0}^{t_f}u\ dt\ &\text{subject to} & & \dot{x_0} = x_1; \dot{x_1} = u - 1.5\ & & & x_0(t_f) = 0; \ x_1(t_f) = 0\ & & & x_0(t_0) = 10; \ x_1(t_0) = -2\ & & & x_0 \geq 0; 0 \leq u \leq 3\ & & & t_0 = 0.0; t_f = \text{free variable} \end{aligned}$$
# Moon lander OCP direct collocation/multi-segment collocation
# from context import mpopt # (Uncomment if running from source)
from mpopt import mp
# Define OCP
ocp = mp.OCP(n_states=2, n_controls=1)
ocp.dynamics[0] = lambda x, u, t: [x[1], u[0] - 1.5]
ocp.running_costs[0] = lambda x, u, t: u[0]
ocp.terminal_constraints[0] = lambda xf, tf, x0, t0: [xf[0], xf[1]]
ocp.x00[0] = [10.0, -2.0]
ocp.lbu[0], ocp.ubu[0] = 0, 3
ocp.lbx[0][0] = 0
# Create optimizer(mpo), solve and post process(post) the solution
mpo, post = mp.solve(ocp, n_segments=20, poly_orders=3, scheme="LGR", plot=True)
x, u, t, _ = post.get_data()
mp.plt.show()
Resources
- Detailed implementation aspects of MPOPT are part of the master thesis.
- Quick introduction presentation.
- List of solved examples
- Features of MPOPT in Jupyter Notebooks
A pdf version of this documentation can be downloaded from PDF document
A must read Jupyter notebook on MPOPT features Getting Started
Case studies
- Quick demo of the solver using simple moon-lander fuel minimization OCP (bang-bang type control), refer Quick features demo notebook for more details. The image below shows the optimal altitude and the velocity profile (states) along with the optimal throttle (controls) to get minimum fuel trajectory to land on the Moon.
- A complex real-world example of The SpaceX falcon9 rocket orbital launch with the booster recovery results are shown below. OCP is defined to find the optimal trajectory and the thrust profile for booster return, refer SpaceX Falcon9 booster recovery notebook for more details. The first image below is the MPOPT solution using adaptive mesh and the second one is the real-time data of the SpaceX Falcon9 launch of NROL76 mission. The ballistic altitude profile of the booster is evident in both MPOPT solution and the real-time telemetry. Further, the MPOPT velocity solution compares well with the real-time data even though the formulation is only a first order representation of the actual booster recovery problem.
Features and Limitations
While MPOPT is able to solve any Optimal control problem formulation in the Bolza form, the present limitations of MPOPT are,
- Only continuous functions and derivatives are supported
- Dynamics and constraints are to be written in CasADi variables (Familiarity with casadi variables and expressions is expected)
- The adaptive grid though successful in generating robust solutions for simple problems, doesn't have a concrete proof on convergence.
Authors
- Devakumar THAMMISETTY
- Prof. Colin Jones (Co-author)
License
This project is licensed under the GNU LGPL v3 - see the LICENSE file for details
Acknowledgements
- Petr Listov
Cite
- D. Thammisetty, “Development of a multi-phase optimal control software for aerospace applications (mpopt),” Master’s thesis, Lausanne, EPFL, 2020.
BibTex entry:
@mastersthesis{thammisetty2020development,
title={Development of a multi-phase optimal control software for aerospace applications (mpopt)},
author={Thammisetty, Devakumar},
year={2020},
school={Master’s thesis, Lausanne, EPFL}}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file mpopt-1.0.tar.gz
.
File metadata
- Download URL: mpopt-1.0.tar.gz
- Upload date:
- Size: 53.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b71ee2ee37fa9c5044e61f106749231dab824e424f787f0d447baa2c8da942c5 |
|
MD5 | 8995cf0a7fb280fdd9c8ea058ca394fb |
|
BLAKE2b-256 | ec65c1be27d1548c40fb5cfa4d8f3e586da0a6a6d3b7fcf79685271c1a0570a7 |
Provenance
File details
Details for the file mpopt-1.0-py3-none-any.whl
.
File metadata
- Download URL: mpopt-1.0-py3-none-any.whl
- Upload date:
- Size: 62.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86cd9ad7244f03abe44f2244a81b8583ccc4f079140216ec819545712ca9e24c |
|
MD5 | e43613badaabf9585000db076be4889a |
|
BLAKE2b-256 | 3569e39319bf876b628d16de1e15e1c1459797ff16debc966ebd8c679e43b039 |