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 #2: Creating Reference Path and Vehicle Simulation”.
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.
Here is the final result, three test tracks: lane change, S-curve, and winding circuit, built from a series of waypoints using cubic spline, complete with curvature and simulation framework. We also see why driving without feedback will inevitably drift. Let's get started. Hello, welcome to episode two of the autonomous vehicle MPC Path Tracking series. Autonomous vehicles receive a path from the path planning, usually in the form of waypoints or path points. The controller needs a smooth path, complete with direction and curvature, as well as a way to measure how far the vehicle has drifted. Today we are building everything from scratch.
Create a file called path.py There are three test tracks: lane change for 3.5 meters, S-curve, and winding circuit. The function create_path connects waypoints with cubic spline based on arc length, then samples points every half meter. From the first derivative of the spline, we can get the direction of the path PSI, and from the second derivative, we can get the curvature, which is 1 over the radius of the turn.
The nearest point function finds the closest point on the path to the vehicle, only within the previous index window to prevent jumping to another part of the path. The error function calculates the lateral error, the perpendicular distance of the vehicle to the path, positive if the vehicle is on the left, as well as the heading error. The simulation function runs the vehicle from the start of the path with any controller, limits the steering rate to 30 degrees per second, and records time, state, inputs, and both errors.
Create a file called test_path.py and run it. The lane change track is 90 meters long with a minimum turning radius of 36.2 meters, the S-curve is 122.5 meters with a minimum turning radius of 21.5 meters, and a 332-meter circuit with the sharpest turns having a radius of 10.7 meters. Then we try the most naive controller, feed-forward. Steering angle is only calculated from the path curvature, without considering the error. As a result, the lateral error accumulates up to 0.55 meters and is never corrected.
Let's look at the graph. The spline passes through all waypoints smoothly. The curvature graph shows the circuit has sharp left and right turns. The right graph shows the feed-forward vehicle slowly drifting off the path. The lesson is, every controller for path tracking needs feedback from the error, and that is what we will do in the next episode.
Done. We have built a reference path using cubic spline, calculated direction and curvature, lateral and angular error, as well as the simulation framework. In the next episode, we create two classic controller benchmarks, Pure Pursuit and Stanley. 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 model, reference path, Pure Pursuit and Stanley, up to model predictive control with CVXPy, as well as offering Python programming courses for electrical and mechatronic engineering. Want to master the entire series, from vehicle models to testing on winding circuits 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 a single class? Buy individual classes with lifetime access. Subscribe now at the premium page cerdasinovasidigital.com Contact our WhatsApp, or visit cerdasinovasidigital.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 →