Memuat
Memuat
Want to go deeper?
Join one of our courses or ask us directly on WhatsApp.
Picked from the software, topic, and level of “Class Autonomous Car MPC Path Tracking #4: MPC Formulation: Linearization, Horizon, Cost Function, Steering Constraints”.
Other ways we can help with Python.
Learn with a mentor
Scheduled Simulation & Engineering courses with live guidance and a certificate.

Course/Training Ansys ~ Heat Transfer and Heat Flux Analysis
★ 5.0 (10)

Course/Training MATLAB — MATLAB App Design: The Ultimate Guide to MATLAB Apps
★ 5.0 (10)

Course/Training Ansys — Airflow Simulation of a Car Radiator with ANSYS
★ 5.0 (9)
Have it built for you
No time to learn Python? Our team can do the project for you.

Matlab Development Service — Complete Neural Signal Processing and Analysis Zero to Hero
★ 5.0 (59)

Ansys Maxwell Development Service
★ 5.0 (50)

Petrel Development Service
★ 5.0 (14)
Get notified about new Python classes
At most one email a week. Unfollow anytime with one click.
The full narration of this video. The current sentence is highlighted while the video plays; click any sentence to jump there.
This is the final result, the linear vehicle model for MPC prediction. Standard Euler linearization deviates by 75 cm in 1.2 seconds at 15 meters per second, while the numerical Jacobian Runge-Kutta is much more accurate. Then we formulate the MPC. Let's start. Hello, welcome to episode four of the autonomous vehicle MPC Path Tracking series. Model predictive control works by predicting the vehicle's motion several steps ahead, then selecting the best sequence of steering and acceleration through optimization, while respecting physical limits. To make the optimization fast, we need a linear model. Today we build that model and formulate the optimization problem.
Create a file named linearisasi.py The classic approach is analytical Jacobian, derive the motion equations with respect to heading, velocity, and steering, then discretize with Euler, so that the next Z equals AZ plus BU plus C. The second method, Runge-Kutta 4 linearization, calculates the Jacobian numerically from the same Runge-Kutta step function used in simulation, by perturbing each state and adding a small amount. The result is a linear model consistent with the simulation. The reference function builds a reference along the horizon.
The vehicle's position is projected onto the path to get a continuous S distance, then the reference advances by velocity times dt per step, and position, heading, and curvature are interpolated to avoid jumping between points. The velocity profile is made realistic, approaching the target velocity with a maximum acceleration of 3 meters per second squared. Then the reference is calculated from curvature, art tangent L kappa, and the equal direction function ensures the vehicle's angle is proportional to the unwrapped path angle.
Create a file named test_underscore_linearisasi_dot_py and run it. We create a curved reference path at 15 meters per second, then a vehicle that slightly deviates with different inputs, and predict its motion with both linear models. After 0.6 seconds, the Euler model deviates by 0.42 meters, while the Runge-Kutta 4 model only deviates by 0.12 meters. After 1.2 seconds, Euler deviates by 0.75 meters and Runge-Kutta 4 by 0.5 meters. A more accurate model means a more reliable MPC prediction.
Let's see the graph. The RK4 prediction points stick to the non-linear curve longer, while Euler quickly diverges, because Euler uses the heading at the start of the step for the entire step, leading to increasing errors at high speeds and sharp turns.
Now formulate the MPC in the file mpc.py. The variables are the state during the 12-step horizon, which is 1.2 seconds, and the input during 11 steps. Matrices A, B, C, initial state, and reference are created as CVXPy parameters, so the problem is built once and only the parameter values are changed at each step. The cost function is the sum of squared errors relative to the reference with weight Q, plus the squared input with weight R, plus the squared change in input with weight RD to ensure smooth steering. The constraints are linear, maximum acceleration and steering angle, steering rate, and speed limits. All of this forms a convex quadratic program.
Done! We have linearized the bicycle model in two ways, built a continuous reference horizon, and formulated MPC as a parameterized quadratic program in CVXPy. In the next episode, we will solve MPC at each step, run it on icy turns, and create the animation. Currently working on a thesis, dissertation, or research in the field of autonomous vehicles and control systems? Cerdas Inovasi Digital helps implement vehicle control systems, from bicycle models, reference paths, pure pursuit and Stanley, up to model predictive control with CVXPy, and also opens Python programming courses for electrical and mechatronics engineering. Want to master the entire series, from vehicle models to circuit tests with various speeds? All six episodes, complete with PDF step-by-step guides and source code, are available to premium tutorial subscribers. Subscribe starting at Rp69.000 per month, save 28% with the 12-month package, or pay once Rp999.000 for lifetime access. Want just one class? Buy the single class with lifetime access. Subscribe now at the premium page cerdas inovasi digital.com. Contact us via WhatsApp, or visit cerdas inovasi digital.com. Thank you for watching, see you in the next episode.
Type a question or keyword; we find the part of this episode that explains it and jump the video there.
Notes are saved with the current video time and are only visible to you.
Stuck on a step? Ask here; the instructor and other learners can answer.
No questions yet.

Cerdas Inovasi Digital Team
Software developers, BIM & 3D engineers, and AI practitioners
We build software, BIM models, games and AI automations for clients every day, and turn that hands-on work into step-by-step classes: every step is shown on screen and comes with a PDF guide you can keep.
See our clients →