SlideShare a Scribd company logo
1 of 16
Implementation of
Linear MPC
By: Kandai Watanabe
Problem with LQR Controller
LQR Controller MPC Controller
Only consider current state at step t*
• Unable to track the reference trajectory
Correctly
Consider states from t to t+T
*To be more specific, LQR does consider infinite steps in the future, but solves the optimization problem before running the simulation
What is Linear Quadratic Regulator (LQR)
• Objective:
• minimize the quadratic cost for Infinite Time
Model
Analytically computes a
stationary feedback gain
Solution should be optimal for infinite time horizon
Analytically computes a
stationary feedback gain
Disadvantages:
• Cannot consider reference trajectory into account
• Input is only dependent on current state at step t
What is Model Preditive Controller (MPC)?
• Objective:
• minimize the quadratic cost for Finite Time
This allows for the controller to take future steps in account at every step t
Model
Only Optimize Input in a finite time
LQR vs. MPC
• Standard Controller (PID, LQR) • Model Predictive Controller
Infinite Time Optimal Control
→ Stationary Policy
Finite Time Optimal Control
→ non-Stationary Policy
Current
Error
Use Model to “Predict” future
states and compute error over
time
MPC Objective
• Future states can be predicted using model dynamics
• Future states
Rollouts
Derive a Dynamical Model from
Newton’s second law
Minimize Error between predicted and reference states & inputs
Rewriting Objective wrt U
• Objective
• Sub Y
MPC Formulization
• Discrete System
• Model
• Augmented Model
• Objective
State
Input
Disturbance
Observed
State
Weight
Matrix
Here, I added gravity vector
as a disturbance
For now
Everything is measurable
Formulate Linear MPC as a Quadratic Programming Problem
• Quadratic Programming
where
Constraints
• Input Constraints
ex) Let Force be limited within 10 [N]
Constraints
• State Constraints
ex) Let max velocity be limited within 10 [m/s]
Rewrite the constraints only with input U
Simulation
LQR Controller MPC Controller
Simulation Model
Nonlinear Model
Constraints
Angles are constrained within
±0.15 rad
Python Package: pycontroller
https://github.com/watakandai/pycontroller
Framework
DQN
DDPG
TD3
Rainbow
PPO
LQR PID
MPC DDP
iLQR CEM
I am adding more features
* This is just for running with an optimized agent. RL Agent has a train function separately.
Add your own policy, controller, environment
Just inherit from the base classes

More Related Content

What's hot

Maneuverable Target Tracking using Linear Kalman Filter
Maneuverable Target Tracking  using Linear Kalman FilterManeuverable Target Tracking  using Linear Kalman Filter
Maneuverable Target Tracking using Linear Kalman Filter
Annwesh Barik
 
Kalman filter - Applications in Image processing
Kalman filter - Applications in Image processingKalman filter - Applications in Image processing
Kalman filter - Applications in Image processing
Ravi Teja
 

What's hot (19)

Maneuverable Target Tracking using Linear Kalman Filter
Maneuverable Target Tracking  using Linear Kalman FilterManeuverable Target Tracking  using Linear Kalman Filter
Maneuverable Target Tracking using Linear Kalman Filter
 
Sensor Fusion Study - Ch13. Nonlinear Kalman Filtering [Ahn Min Sung]
Sensor Fusion Study - Ch13. Nonlinear Kalman Filtering [Ahn Min Sung]Sensor Fusion Study - Ch13. Nonlinear Kalman Filtering [Ahn Min Sung]
Sensor Fusion Study - Ch13. Nonlinear Kalman Filtering [Ahn Min Sung]
 
199 Final Report
199 Final Report 199 Final Report
199 Final Report
 
Pid controller
Pid controllerPid controller
Pid controller
 
6. steady state error
6. steady state error6. steady state error
6. steady state error
 
Different prr per link in contiki cooja simulation
Different prr per link in contiki cooja simulationDifferent prr per link in contiki cooja simulation
Different prr per link in contiki cooja simulation
 
Integration schemes in Molecular Dynamics
Integration schemes in Molecular DynamicsIntegration schemes in Molecular Dynamics
Integration schemes in Molecular Dynamics
 
[01] Quantum Error Correction for Beginners
[01] Quantum Error Correction for Beginners [01] Quantum Error Correction for Beginners
[01] Quantum Error Correction for Beginners
 
Ps1
Ps1Ps1
Ps1
 
Kalman filter - Applications in Image processing
Kalman filter - Applications in Image processingKalman filter - Applications in Image processing
Kalman filter - Applications in Image processing
 
Kalman filters
Kalman filtersKalman filters
Kalman filters
 
Data fusion with kalman filtering
Data fusion with kalman filteringData fusion with kalman filtering
Data fusion with kalman filtering
 
Understanding kalman filter for soc estimation.
Understanding kalman filter for soc estimation.Understanding kalman filter for soc estimation.
Understanding kalman filter for soc estimation.
 
QUANTUM COMP 22
QUANTUM COMP 22QUANTUM COMP 22
QUANTUM COMP 22
 
ppt on Time Domain and Frequency Domain Analysis
ppt on Time Domain and Frequency Domain Analysisppt on Time Domain and Frequency Domain Analysis
ppt on Time Domain and Frequency Domain Analysis
 
The extended kalman filter
The extended kalman filterThe extended kalman filter
The extended kalman filter
 
Thesis1
Thesis1Thesis1
Thesis1
 
Sensor Fusion Study - Ch7. Kalman Filter Generalizations [김영범]
Sensor Fusion Study - Ch7. Kalman Filter Generalizations [김영범]Sensor Fusion Study - Ch7. Kalman Filter Generalizations [김영범]
Sensor Fusion Study - Ch7. Kalman Filter Generalizations [김영범]
 
Pid controller
Pid controllerPid controller
Pid controller
 

Similar to Implementation of Model Predictive Controller for a drone

Presentation FOPID Boost DC-DC Converter.pptx
Presentation FOPID Boost DC-DC Converter.pptxPresentation FOPID Boost DC-DC Converter.pptx
Presentation FOPID Boost DC-DC Converter.pptx
SherAli260123
 
APznzabA8g23RgxiR6fP-ozZy3sPtXBejAWXnpOk2IAUSf8MhKCcj9HvCFizojknFBbbouRLn8EtY...
APznzabA8g23RgxiR6fP-ozZy3sPtXBejAWXnpOk2IAUSf8MhKCcj9HvCFizojknFBbbouRLn8EtY...APznzabA8g23RgxiR6fP-ozZy3sPtXBejAWXnpOk2IAUSf8MhKCcj9HvCFizojknFBbbouRLn8EtY...
APznzabA8g23RgxiR6fP-ozZy3sPtXBejAWXnpOk2IAUSf8MhKCcj9HvCFizojknFBbbouRLn8EtY...
AdeelShaikh28
 
Power System Dynamics & Stability Overview & Electromagnetic Transients
Power System Dynamics & Stability Overview  &  Electromagnetic TransientsPower System Dynamics & Stability Overview  &  Electromagnetic Transients
Power System Dynamics & Stability Overview & Electromagnetic Transients
Power System Operation
 

Similar to Implementation of Model Predictive Controller for a drone (20)

Application of a merit function based interior point method to linear model p...
Application of a merit function based interior point method to linear model p...Application of a merit function based interior point method to linear model p...
Application of a merit function based interior point method to linear model p...
 
Application of a merit function based interior point method to linear model p...
Application of a merit function based interior point method to linear model p...Application of a merit function based interior point method to linear model p...
Application of a merit function based interior point method to linear model p...
 
Start MPC
Start MPC Start MPC
Start MPC
 
IEEE APE
IEEE APEIEEE APE
IEEE APE
 
Presentation FOPID Boost DC-DC Converter.pptx
Presentation FOPID Boost DC-DC Converter.pptxPresentation FOPID Boost DC-DC Converter.pptx
Presentation FOPID Boost DC-DC Converter.pptx
 
A framework for nonlinear model predictive control
A framework for nonlinear model predictive controlA framework for nonlinear model predictive control
A framework for nonlinear model predictive control
 
Design of Speed and Current Controller for Two Quadrant DC Motor Drive
Design of Speed and Current Controller for Two Quadrant DC Motor DriveDesign of Speed and Current Controller for Two Quadrant DC Motor Drive
Design of Speed and Current Controller for Two Quadrant DC Motor Drive
 
1578385.ppt
1578385.ppt1578385.ppt
1578385.ppt
 
predictive current control of a 3-phase inverter
predictive current control of a 3-phase inverterpredictive current control of a 3-phase inverter
predictive current control of a 3-phase inverter
 
P1111214158
P1111214158P1111214158
P1111214158
 
APznzabA8g23RgxiR6fP-ozZy3sPtXBejAWXnpOk2IAUSf8MhKCcj9HvCFizojknFBbbouRLn8EtY...
APznzabA8g23RgxiR6fP-ozZy3sPtXBejAWXnpOk2IAUSf8MhKCcj9HvCFizojknFBbbouRLn8EtY...APznzabA8g23RgxiR6fP-ozZy3sPtXBejAWXnpOk2IAUSf8MhKCcj9HvCFizojknFBbbouRLn8EtY...
APznzabA8g23RgxiR6fP-ozZy3sPtXBejAWXnpOk2IAUSf8MhKCcj9HvCFizojknFBbbouRLn8EtY...
 
Model Predictive Control For Integrating Processes
Model Predictive Control For Integrating ProcessesModel Predictive Control For Integrating Processes
Model Predictive Control For Integrating Processes
 
Small Signal Modelling and Controller Design of Boost Converter using MATLAB
Small Signal Modelling and Controller Design of Boost Converter using MATLABSmall Signal Modelling and Controller Design of Boost Converter using MATLAB
Small Signal Modelling and Controller Design of Boost Converter using MATLAB
 
Power System Dynamics & Stability Overview & Electromagnetic Transients
Power System Dynamics & Stability Overview  &  Electromagnetic TransientsPower System Dynamics & Stability Overview  &  Electromagnetic Transients
Power System Dynamics & Stability Overview & Electromagnetic Transients
 
05 tuning.pid.controllers
05 tuning.pid.controllers05 tuning.pid.controllers
05 tuning.pid.controllers
 
Trajectory Control With MPC For A Robot Manipülatör Using ANN Model
Trajectory Control With MPC For A Robot Manipülatör Using  ANN ModelTrajectory Control With MPC For A Robot Manipülatör Using  ANN Model
Trajectory Control With MPC For A Robot Manipülatör Using ANN Model
 
Nonlinear predictive control of a boiler turbine unit
Nonlinear predictive control of a boiler turbine unitNonlinear predictive control of a boiler turbine unit
Nonlinear predictive control of a boiler turbine unit
 
Self tuning, Optimal MPC, DMC.pptx
Self tuning, Optimal MPC, DMC.pptxSelf tuning, Optimal MPC, DMC.pptx
Self tuning, Optimal MPC, DMC.pptx
 
Dynamic Matrix Control (DMC) on jacket tank heater - Rishikesh Bagwe
Dynamic Matrix Control (DMC) on jacket tank heater - Rishikesh BagweDynamic Matrix Control (DMC) on jacket tank heater - Rishikesh Bagwe
Dynamic Matrix Control (DMC) on jacket tank heater - Rishikesh Bagwe
 
MPC Tuning Based On Desired Frequency Domain Closed Loop Response
MPC Tuning Based On Desired Frequency Domain Closed Loop ResponseMPC Tuning Based On Desired Frequency Domain Closed Loop Response
MPC Tuning Based On Desired Frequency Domain Closed Loop Response
 

Recently uploaded

1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
MayuraD1
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
Kamal Acharya
 

Recently uploaded (20)

Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
Electromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptxElectromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptx
 
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesLinux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdf
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 

Implementation of Model Predictive Controller for a drone

  • 2. Problem with LQR Controller LQR Controller MPC Controller Only consider current state at step t* • Unable to track the reference trajectory Correctly Consider states from t to t+T *To be more specific, LQR does consider infinite steps in the future, but solves the optimization problem before running the simulation
  • 3. What is Linear Quadratic Regulator (LQR) • Objective: • minimize the quadratic cost for Infinite Time Model Analytically computes a stationary feedback gain Solution should be optimal for infinite time horizon Analytically computes a stationary feedback gain Disadvantages: • Cannot consider reference trajectory into account • Input is only dependent on current state at step t
  • 4. What is Model Preditive Controller (MPC)? • Objective: • minimize the quadratic cost for Finite Time This allows for the controller to take future steps in account at every step t Model Only Optimize Input in a finite time
  • 5. LQR vs. MPC • Standard Controller (PID, LQR) • Model Predictive Controller Infinite Time Optimal Control → Stationary Policy Finite Time Optimal Control → non-Stationary Policy Current Error Use Model to “Predict” future states and compute error over time
  • 6. MPC Objective • Future states can be predicted using model dynamics • Future states Rollouts Derive a Dynamical Model from Newton’s second law Minimize Error between predicted and reference states & inputs
  • 7. Rewriting Objective wrt U • Objective • Sub Y
  • 8. MPC Formulization • Discrete System • Model • Augmented Model • Objective State Input Disturbance Observed State Weight Matrix Here, I added gravity vector as a disturbance For now Everything is measurable
  • 9. Formulate Linear MPC as a Quadratic Programming Problem • Quadratic Programming where
  • 10. Constraints • Input Constraints ex) Let Force be limited within 10 [N]
  • 11. Constraints • State Constraints ex) Let max velocity be limited within 10 [m/s] Rewrite the constraints only with input U
  • 12. Simulation LQR Controller MPC Controller Simulation Model Nonlinear Model
  • 15. Framework DQN DDPG TD3 Rainbow PPO LQR PID MPC DDP iLQR CEM I am adding more features * This is just for running with an optimized agent. RL Agent has a train function separately.
  • 16. Add your own policy, controller, environment Just inherit from the base classes

Editor's Notes

  1. LQR controller is often compared with MPC because they have similar formulations. Both controllers compute an optimal input u with respect to an objective function. These controllers are called Optimal Controllers. Here throughout this implementation, I used a drone as an example model. In such case, input u is a force and torques applied to a drone. Drone uses 4 rotors to control its upward force and torques. On the left, we have a LQR controller. LQR only considers state at current time t. Therefore, it fails to plan ahead, so it is unable to track to the planned trajectory. However, the MPC controller considers future steps from current t to timestep T in the future. Therefore, it can plan ahead and compute an optimal policy so that it can track the reference trajectory. Now I will talk about the
  2. Linear Quadratic Regulator’s objective is to minimize the linear quadratic state cost and input cost for infinite time horizon. State is system’s state who’s motion is governed by its physical model. From this, solution should be optimal for infinite time horizon. However, it is difficult to consider all reference states in the future. Thus, by setting the reference state and solve it as a linear quadratic regulator problem, an optimal solution can be computed analytically. This feedback gain is stationary and is optimal under this assumption. The disadvantages are 1. 2.
  3. Opposed to LQR Controller, Model Predictive Controller minimizes ... In a graph, it can be illustrated as follows. It only optimizes inputs in a finite time at every time step t. This allows ...
  4. To conclude, the lqr is a stionary policy and the mpc is a non-stationary policy, in other word, it changes over time. Also, it can be stated that MPC can take future steps into consideration.
  5. The objective is to minimize error between predicted and reference states & inputs. The predicted states can be computed by rolling out the dynamics model. The dynamics model can be derived from the newton’s second law and rewrite it in the similar manner as on the right. One should be careful since this is a continuous state. You need to discretize based on the sample time. Once Dynamic Model is derived, the future states can be predicted by rolling out. Then the model can be augmented as on the equation on the bottom left. The final model then would look like the one on the bottom right.
  6. Sub Y=HX in to the original objective function, we can rewritten the equation. At the end, we get a linear quadratic cost.
  7. Wrap up. Disrete System Model can be written as the first equtation. Since, we have the model, we can predict its future state by inputting random inputs The augmented model can be rewritten as similar way. Thus we get the predicted measured states Y. In Linaer Quadratic Problem, our objective is to minimize the quadratic cost of states and inputs. As we can comptue Y with respect to U, it can be rewritten everything wrt U.
  8. This is clearly a quadratic problem. Since this is a quadratic problem, we can add linear constraints.
  9. For example, constraint on inputs can easily be added. For example, if you want the force to be in a range of 10N, you can set a constraint like this. Likewise, you can add constraints to the inputs very easily.
  10. Constraints on the state can also be added, but need some tweak. Since all objectives are written in regard of U, we need to rewrite the constraint. For example, If the velocity has a limit of 10 m/s, one can write like this. But since, X can be written wrt to U, We can sub X into the constraint.
  11. LQR controller is often compared with MPC because they have similar formulations. Both controllers compute an optimal input u with respect to an objective function. These controllers are called Optimal Controllers. Here throughout this implementation, I used a drone as an example model. In such case, input u is a force and torques applied to a drone. Drone uses 4 rotors to control its upward force and torques. On the left, we have a LQR controller. LQR only considers state at current time t. Therefore, it fails to plan ahead, so it is unable to track to the planned trajectory. However, the MPC controller considers future steps from current t to timestep T in the future. Therefore, it can plan ahead and compute an optimal policy so that it can track the reference trajectory. Now I will talk about the