Nonlinear Model Predictive Control : An
Implementation using CasADi
Santosh Rajkumar
The Ohio State University
Abstract
This project delves into the implementation of Nonlinear Model Predictive Control
(NMPC) using CasADi within the MATLAB environment, leveraging its capabilities in
numerical optimization and automatic differentiation. Theoretical foundations covering
MPC, non-linear programming, and transcription methods are discussed to provide a com-
prehensive understanding. A demonstration of the NMPC scheme is conducted utilizing
a non-linear system featuring an inverted pendulum with a spring-damper setup. The
NMPC implementation for the pendulum system is showcased across various initial condi-
tions. Additionally, the project investigates the robustness of MPC in handling parameter
uncertainties and noise within the pendulum system.
Contents
1 Introduction 1
1.1 Introduction to Model Predictive Control . . . . . . . . . . . . . . . . . . . 1
1.2 Nonlinear Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3 Transcription Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.4 CasADi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2 The System Under Consideration 9
2.1 Modeling of the Pendulum System . . . . . . . . . . . . . . . . . . . . . . 10
3 Direct Multiple Shooting Method 13
3.1 Implementation of Direct Multiple Shooting Method . . . . . . . . . . . . 13
3.2 Solving the NLP and Implementing NMPC . . . . . . . . . . . . . . . . . . 17
4 Results 19
4.1 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.2 MATLAB Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
5 Conclusions 25
List of Figures
1 A block diagram of MPC implementation . . . . . . . . . . . . . . . . . . . 2
2 Reference tracking using MPC (adapted from [2]) . . . . . . . . . . . . . . 3
3 CasADi facilitating solution to OCPs . . . . . . . . . . . . . . . . . . . . . 8
4 The nonlinear system under consideration . . . . . . . . . . . . . . . . . . 9
5 Free body diagram of the pendulum system . . . . . . . . . . . . . . . . . 10
6 The phase portrait of the pendulum system (autonomous case) . . . . . . . 11
7 Pictorial description of continuity constraints in multiple shooting method 15
8 Stabilization of the pendulum with initial conditions θ = 35,
˙
θ = −5.73
o
/sec 19
9 Stabilization of the pendulum with initial conditions θ = −20
o
,
˙
θ = −5.73
o
/sec 20
10 Stabilization of the pendulum with parameter mismatch considering condi-
tions θ = 35
o
,
˙
θ = −5.73
o
/sec . . . . . . . . . . . . . . . . . . . . . . . . . 21
11 the stabilization of the pendulum in the presence of both parameter mis-
match and noisy measurements with initial conditions θ = 35
o
,
˙
θ = −5.73
o
/sec 21