This tutorial explains how to setup a basic MPC controller. Again, we consider a simple actively damped quarter car model.
Let x denote the states, u the control input, p a time-constant parameter, and T the time horizon of an MPC optimization problem. We are interested in tracking MPC problems, which are of the general form:
Here, the function f represents the model equations, s the path constraints and r the terminal constraints. Note that in the online context, the above problem must be solved iteratively for changing x0 and t0 . Moreover, we assume here that the objective is given in least square form. Most of the tracking problems that arise in practice can be formulated in this form with η and μ denoting the tracking and terminal reference.
The following piece of code shows how to implement an MPC controller based on this quarter car model. It comprises six main steps:
The file "ref.txt" contains the data of the (trivial) reference trajectory:
If we run the above piece of code in ACADO, the corresponding Gnuplot output should be as follows:
We end this tutorial with providing lists comprising the most common options that can be set when defining a RealTimeAlgorithm:
Option Name: | Option Value: | Short Description: |
MAX_NUM_ITERATIONS | int | maximum number of SQP iterations (by default, only one SQP iteration is performed) |
USE_REALTIME_ITERATIONS | YES NO | specifying whether real-time iterations shall be used or not |
USE_IMMEDIATE_FEEDBACK | YES NO | specifying whether immediate feedback shall be given or not |
KKT_TOLERANCE | double | termination tolerance for the optimal control algorithm |
HESSIAN_APPROXIMATION | CONSTANT_HESSIAN FULL_BFGS_UPDATE BLOCK_BFGS_UPDATE GAUSS_NEWTON EXACT_HESSIAN | constant hessian (generalized gradient method) BFGS update of the whole hessian structure-exploiting BFGS update (default) Gauss-Newton Hessian approximation (only for LSQ) exact Hessian computation |
DISCRETIZATION_TYPE | SINGLE_SHOOTING MULTIPLE_SHOOTING COLLOCATION | single shooting discretization multiple shooting discretization (default) collocation (will be implemented soon) |
INTEGRATOR_TYPE | INT_RK12 INT_RK23 INT_RK45 INT_RK78 INT_BDF | Runge Kutta integrator (adaptive Euler method) Runge Kutta integrator (order 2/3, RKF ) Runge Kutta integrator (order 4/5, Dormand Prince) Runge Kutta integrator (order 7/8, Dormand Prince) BDF (backward differentiation formula) integrator |
INTEGRATOR_TOLERANCE | double | the relative tolerance of the integrator |
ABSOLUTE_TOLERANCE | double | the absolute tolerance of the integrator ("ATOL") |
LEVENBERG_MARQUARDT | double | value for Levenberg-Marquardt regularization |
PLOT_RESOLUTION | LOW MEDIUM HIGH | specifying screen resolution when plotting |
Next example: Setting-Up More Classical Feedback Controllers