Implement Linear Quadratic Regulator (LQR) Control Algorithm in C++ From Scratch Using Newton Method

preview_player
Показать описание
#controltheory #mechatronics #systemidentification #machinelearning #datascience #recurrentneuralnetworks #timeseries #timeseriesanalysis #signalprocessing #dynamics #mechanics #mechanicalengineering #controltheory #mechatronics #robotics #astrodynamics #astrophysics #physics #chaos #apphysics #apmaths #mathematics #mathematicians #calculus #electricalengineering #mechanicalengineering #engineering #leastsquares #nonlinearsystems #modelpredictivecontrol #optimalcontrol #controlengineering #controltheory

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

Video tutorial for installing VS Code Editor and C++ Compiler:

Video tutorial for installing the Eigen C++ library in VS Code Editor:

MPC implementation in Python:

Here is how to implement the popular linear quadratic regulator optimal control algorithm (LQR) from scratch in C++: I created a video tutorial (together with GitHub and tutorial pages) on how to implement the Linear Quadratic Regulator (LQR) Optimal Control Algorithm in C++ from scratch. I explained how to compute the solution of the LQR problem by using the Newton method for solving the Riccati equation. the Newton method solves the Riccati equation by solving a series of the Lyapunov equations. I implemented the Newton and Lyapunov solvers from scratch by using the Eigen matrix library to perform matrix-vector multiplications and to compute the eigenvalues. I explained how to compute the initial stabilizing guess of the solution of the Riccati equation. I explained how to simulate the control algorithm in C++. Finally, I compared my implementation with the LQR implementation available in the Python control system toolbox. There is almost a perfect match!

My emphasis is on explaining how to create C++ code in a disciplined and object-oriented way. That is why I created a class-based implementation of the LQR algorithm. The computed results are saved in csv files such that they can be imported in other programs or used for comparison.
Here is the motivation for creating this video tutorial. Namely, most control engineering classes and teachers focus on MATLAB/Simulink without providing the students and engineers with the necessary knowledge on how to implement control algorithms in C++ or Python. That is, students rarely have the opportunity to learn real-life implementation of control/estimation algorithms. There is a huge gap between what people learn in undergraduate and graduate programs with what the industry needs and wants. Also, graduate students studying control are focused too much on advanced mathematics and theorem proofs and they rarely have a chance to learn C++ and how to implement algorithms. On the other hand, computer science students have good coding skills. However, they often do not study advanced mathematical concepts necessary to understand control theory and engineering. That is, there is a huge knowledge gap that students need to fill. To be a successful model-based control engineer who will be able to tackle advanced problems one needs to be proficient in control theory and math on one side and in coding on the other side. The free tutorials I am creating aim to fill this knowledge gap. Also, I do not think that automatic code generation is the solution. If you want to become a solid control/estimation/perception/signal processing engineer, you need to know how to implement the algorithms from scratch.
Рекомендации по теме
Комментарии
Автор

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
Автор

Control theory and C++. This is awesome tutorial! Thank you very much.

nguyenbahuy