Model Predictive Control from Scratch: Derivation and Python Implementation-Optimal Control Tutorial

preview_player
Показать описание
#controltheory #mechatronics #systemidentification #machinelearning #datascience #recurrentneuralnetworks #timeseries #timeseriesanalysis #signalprocessing #dynamics #mechanics #statics #mechanicalengineering #controltheory #mechatronics #robotics
If you need help with your professional engineering problem, or you need to develop new skills in the fields of control, signal processing, embedded systems, programming, optimization, machine learning, robotics, etc., we are here to help. We provide engineering services, as well as tutoring and skill development services. We have significant industry, research, and university-level teaching experience. Describe your problem and we will send you a quote for our services.
It takes a significant amount of time and energy to create these free video tutorials. You can support my efforts in this way:
- You Can also press the Thanks YouTube Dollar button

In this control engineering, system identification, and control theory tutorial, we explain:
1) How to derive a model predictive control algorithm from scratch.
2) How to implement the model predictive control algorithm in Python from scratch.

Starting from a state space model, we formulate an optimization problem and explain how to compute the closed form of the model predictive control solution.

The GitHub page with all the codes is given here:

The website tutorial is given here:

The MPC algorithm implementation in C++:

The main challenge was how to make a tutorial that was easy for beginners without going immediately into nonlinear and complex optimization worlds, where students immediately get lost and immediately give up on studying MPC. This comment also applies to modern control theory. A number of control scientists publishing papers in Automatica/IEEE TAC simply do not put effort into explaining things such that everyone can understand the basic concepts. There is a trend to make the control theory as complex as possible and as a pure math discipline. I think that was not the vision of the founders of control theory, who were actually engineers solving real-life problems. In fact, control theory is super applicable and relatively easy. The only issue is that one has to conquer math to be able to apply it. Consequently, I start with the MPC formulation for linear systems and I try to stick as much as possible to basic linear algebra.

We explain how to formulate a least-squares cost function, and how to minimize it. The solution can be expressed in a closed form as a solution of a weighted least-squares problem. The input constraints can be implicitly handled by properly selecting weighting matrices. We then explain how to implement this algorithm in Python from scratch and in a disciplined and clean manner (by using Python classes). We test the algorithm on a classical system consisting of two objects connected by springs and dampers. In the second part of this tutorial series, we will consider constrained linear systems. In the third part, we will consider nonlinear smooth systems (the most general formulation). After we complete the Python model predictive control tutorials, we will start a new tutorial series on how to implement the algorithm in C++ by using the Eigen Library.
Рекомендации по теме
Комментарии
Автор

It takes a significant amount of time and energy to create these free video tutorials. You can support my efforts in this way:
- You Can also press the Thanks YouTube Dollar button

aleksandarhaber
Автор

the best tutorial about MPC! i've been looking such explanation out there until the very detail of MPC and I must say I have finally found it! Thank you very much

krisnaanandakusuma
Автор

Wow, it is amazing explanation and implementation about MPC which I’ve never seen before.

mortezaghodoosi
Автор

One of the best tutorials on MPC. Short, sweet and to the point. Thank you.

faisaltariq_artist
Автор

Probably the best explanation for MPC! Thank you so much for this video.

vatastakoul
Автор

Great video, thanks! In addition, look forward to seeing the explanation of the multi-output problem!

Duang_
Автор

The best tutorial, thank you. Obrigado ! from Brazil ! Brasil 🇧🇷

Trextreks
Автор

It takes a significant amount of time and energy to create these free video tutorials. You can support my efforts in this way:
- You Can also press the Thanks YouTube Dollar button

aleksandarhaber
Автор

I want to express my appreciation for the effort and passion you put into creating your channel, website, and content. Your work is exceptional, and you are a brilliant person with exceptional teaching skills. I wish you the best of luck in all of your endeavors and objectives. Have a fantastic day!

markusbuchholz
Автор

Very good content! Thank you very much for your effort! It helps alot :)

halihammer
Автор

Very precise and easy to understand explanation with implementation. Thanks @Aleksander 🙂

AbhijitBhaktechd
Автор

Hey, there are some written errrors:
in equation(13) the last line of matrix M, the power of A should be {f-1}, {f-2}, {f-3}
the equation(15) has the same problem, and "C\bar{A}_{1, v}B" should be replaced by "C\bar{A}_{v+1, v}B".
By the way, the tutorial is great that helps me a lot, thank you.

YueXu-ym
Автор

Hi,
Your tutorial videos are exactly what I am searching so far but didn't got any, The perfect combination of theory + code implementation from scratch. I am currently a final year engineering bachelor student and learning about Control systems, these video lecture series is noting less than a treasure for me. Thank you so much for helping me. I have a request, can you please make tutorials on the various state estimation techniques also and show how to integrate data from observation, multiple sensor inputs with the state model to get a more accurate state estimate, and a series on controlling non-linear control systems,

AniketRoy-qr
Автор

Great video, thank you for this. Im commenting as Im working through your detailed explanation.
I have 2 questions:
1. For 9:47, from equation (5), is there a B missing from the u_k | k term? Should it be C*(A^2)*B instead of C*(A^2)? I also realised the B term is missing until later on for equation (13) for the u_k|k term.
2. Why is it that we will need to obtain control inputs for time k+2 and later? Wouldn't having just control input at time k and k+1 be sufficient? Is this because we need the future control inputs to obtain the predicted trajectory for time instants k+2 and later?

MeinHerrDreyer
Автор

The website tutorial is given here:
The GitHub page with all the codes is given here:

The MPC algorithm implementation in C++:

aleksandarhaber
Автор

Indeed, the best tutorial, thank you very much, can I ask if the model can be easily modified for a Multiple Input Single Output (MISO) system with 4 inputs and 1 output by changing r=1; m=4 and n= 1 ? or there are more considerations? Thanks for your time!

consuelovega
Автор

Thank you for sharing. However, I have a question, please. I am currently implementing an MPC to control the temperature inside a room. To model the system, I used a neural network that takes as input a window of data (disturbance_w, control_w, output_w) to predict the output over a prediction horizon. Then, I use these predictions to calculate an objective function in order to obtain the first command to apply to my system to get the first output. For this, I use scipy, but the control proposed by this library remains constant regardless of the output values (the output does not follow the reference). Do you have any advice to improve this?

amel
Автор

Would love to see Mpc for boost converter in simulink

emperor