Skip to main content

Rapid Optimal Control Kit

Project description


pipeline status coverage report html docs pdf docs


Rockit logo

Rockit (Rapid Optimal Control kit) is a software framework to quickly prototype optimal control problems (aka dynamic optimization) that may arise in engineering: iterative learning (ILC), model predictive control (NMPC), motion planning.

Notably, the software allows free end-time problems and multi-stage optimal problems. The software is currently focused on direct methods and relies heavily on CasADi. The software is developed by the KU Leuven MECO research team.


Install using pip: pip install rockit-meco

Hello world

(Taken from the example gallery)

You may try it live in your browser: Binder.

Import the project:

from rockit import *

Start an optimal control environment with a time horizon of 10 seconds (free time problems can be configured with FreeTime(initial_guess)):

ocp = Ocp(T=10)

Define two scalar states (vectors and matrices also supported):

x1 = ocp.state()
x2 = ocp.state()

Define one piece-wise constant control input (use order=1 for piecewise linear):

u = ocp.control()

Specify differential equations for states (time dependency supported with ocp.t, DAEs also supported with ocp.algebraic and add_alg):

ocp.set_der(x1, (1 - x2**2) * x1 - x2 + u)
ocp.set_der(x2, x1)

Lagrange objective term:

ocp.add_objective(ocp.integral(x1**2 + x2**2 + u**2))

Path constraints (must be valid on the whole time domain running from t0 to tf=t0+T, grid options available):

ocp.subject_to(x1 >= -0.25)
ocp.subject_to(-1 <= (u <= 1 ))

Boundary constraints:

ocp.subject_to(ocp.at_t0(x1) == 0)
ocp.subject_to(ocp.at_t0(x2) == 1)

Pick an NLP solver backend (CasADi nlpsol plugin):


Pick a solution method: N -- number of control intervals M -- number of integration steps per control interval

method = MultipleShooting(N=10, M=2, intg='rk')
#method = DirectCollocation(N=10, M=2)


sol = ocp.solve()

Show structure:


Structure of optimization problem


tsa, x1a = sol.sample(x1, grid='control')
tsb, x1b = sol.sample(x1, grid='integrator')
tsc, x1c = sol.sample(x1, grid='integrator', refine=100)
plot(tsa, x1a, '-')
plot(tsb, x1b, 'o')
plot(tsc, x1c, '.')

Solution trajectory of states

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for rockit-meco, version 0.1.7
Filename, size File type Python version Upload date Hashes
Filename, size rockit-meco-0.1.7.tar.gz (30.9 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page