diff --git a/.ipynb_checkpoints/README-checkpoint.md b/.ipynb_checkpoints/README-checkpoint.md index 217e39a..bc6c2b7 100644 --- a/.ipynb_checkpoints/README-checkpoint.md +++ b/.ipynb_checkpoints/README-checkpoint.md @@ -1,36 +1,53 @@ # mpc_python -Python implementation of mpc controller for path tracking. +Python implementation of a mpc controller for path tracking using **[CVXPY](https://www.cvxpy.org/)**. ## About -The MPC is a model predictive path following controller which does follow a predefined reference path Xref and Yref by solving an optimization problem. The resulting optimization problem is shown in the following equation: +The MPC is a model predictive path following controller which does follow a predefined reference by solving an optimization problem. The resulting optimization problem is shown in the following equation: -![](img/quicklatex1.png) +![](img/quicklatex_equation.png) -The vehicle dynamics are described by the differential drive model: +The terns of the cost function are the sum of the **reference tracking error**, **heading effort** and **actuaction rate of change**. + +Where R,P,Q are the cost matrices used to tune the response. + +The vehicle model is described by the bicycle kinematics model using the state space matrices A and B: ![](img/quicklatex2.png) -The state variables of the model are: +The state variables **(x)** of the model are: * **x** coordinate of the robot * **y** coordinate of the robot +* **v** velocuty of the robot * **theta** heading of the robot -The inputs of the model are: +The inputs **(u)** of the model are: -* **v** linear velocity of the robot -* **w** angular velocity of the robot +* **a** linear acceleration of the robot +* **delta** steering angle of the robot ## Demo +The MPC implementation is tested using **[bullet](https://pybullet.org/wordpress/)** physics simulator. Racing car model is from: *https://github.com/erwincoumans/pybullet_robots*. + +![](img/f10.png) + +Results: + ![](img/demo.gif) -To run the demo: +To run the pybullet demo: ```bash -python3 mpc_demo/main.py +python3 mpc_demo/mpc_demo_pybullet.py +``` + +To run the simulation-less demo: + +```bash +python3 mpc_demo/mpc_demo_pybullet.py ``` ## Requirements @@ -38,3 +55,8 @@ python3 mpc_demo/main.py ```bash pip3 install --user --requirement requirements.txt ``` + +## References +* [mpc paper](https://borrelli.me.berkeley.edu/pdfpub/IV_KinematicMPC_jason.pdf) +* [pythonrobotics](https://github.com/AtsushiSakai/PythonRobotics/) +* [pybullet](https://pybullet.org/wordpress/) \ No newline at end of file diff --git a/README.md b/README.md index 36418b6..bc6c2b7 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,11 @@ Python implementation of a mpc controller for path tracking using **[CVXPY](http The MPC is a model predictive path following controller which does follow a predefined reference by solving an optimization problem. The resulting optimization problem is shown in the following equation: -![](img/quicklatex1.png) +![](img/quicklatex_equation.png) -The terns of the cost function are the sum of the **cross-track error**, **heading error**, **velocity error** and **actuaction effort**. +The terns of the cost function are the sum of the **reference tracking error**, **heading effort** and **actuaction rate of change**. -Where R,P,K,Q are the cost matrices used to tune the response. +Where R,P,Q are the cost matrices used to tune the response. The vehicle model is described by the bicycle kinematics model using the state space matrices A and B: @@ -55,3 +55,8 @@ python3 mpc_demo/mpc_demo_pybullet.py ```bash pip3 install --user --requirement requirements.txt ``` + +## References +* [mpc paper](https://borrelli.me.berkeley.edu/pdfpub/IV_KinematicMPC_jason.pdf) +* [pythonrobotics](https://github.com/AtsushiSakai/PythonRobotics/) +* [pybullet](https://pybullet.org/wordpress/) \ No newline at end of file diff --git a/img/quicklatex_equation.png b/img/quicklatex_equation.png new file mode 100644 index 0000000..74eb6f9 Binary files /dev/null and b/img/quicklatex_equation.png differ diff --git a/img/quicklatex_equation_white.png b/img/quicklatex_equation_white.png new file mode 100644 index 0000000..e1f6b8e Binary files /dev/null and b/img/quicklatex_equation_white.png differ diff --git a/notebooks/MPC_racecar_tracking.ipynb b/notebooks/MPC_racecar_tracking.ipynb index 5b94dce..c5cb2a0 100644 --- a/notebooks/MPC_racecar_tracking.ipynb +++ b/notebooks/MPC_racecar_tracking.ipynb @@ -634,7 +634,7 @@ "$\n", "\\begin{equation}\n", "\\begin{aligned}\n", - "\\min_{} \\quad & \\sum^{t+T-1}_{j=t} (x_{j} - x_{j,ref})^TQ(x_{j} - x_{j,ref}) + \\sum^{t+T-1}_{j=t+1} u^T_{j}Ru_{j} + (u_{j} - u_{j-1})^T(u_{j} - u_{j-1}) \\\\\n", + "\\min_{} \\quad & \\sum^{t+T-1}_{j=t} (x_{j} - x_{j,ref})^TQ(x_{j} - x_{j,ref}) + \\sum^{t+T-1}_{j=t+1} u^T_{j}Ru_{j} + (u_{j} - u_{j-1})^TP(u_{j} - u_{j-1}) \\\\\n", "\\textrm{s.t.} \\quad & x(0) = x0\\\\\n", " & x_{j+1} = Ax_{j}+Bu_{j} \\quad \\textrm{for} \\quad t