Skip to content

Latest commit

 

History

History
175 lines (93 loc) · 8.63 KB

README.md

File metadata and controls

175 lines (93 loc) · 8.63 KB

Introduction



Take me to the MATLAB Simulation Code for the Self Driving Car!



Development of autonomous vehicles has accelerated in the past decade due to advances in computing speed, sensor technology, and popular interest. This article explores the Software Architecture for the Self-Driving Car shown below. The controller uses a Model Predictive Control (MPC) algorithm to anticipate the car's future position, knowing the car's Vehicle Dynamics equations and measured position (current state).



Car-Sensor



The algorithm should work on any Drive-By-Wire car which has electronically controlled steering wheel, gas, and brake pedals. You can read sensor values (Camera, Radar, Lidar, GPS) and control the car directly from the car's CAN Bus, check with the manufacturer to confirm.





Model Predictive Control (MPC) Algorithm



This architecture lets you control the vehicle acceleration, brake, and steering using Model Predictive Control (MPC). The software architecture shown above has been tested on the Self-Driving Hyundai Sonata shown in the above picture. It has been successfully tested in highway speeds and city driving conditions.



Control-System



At each sampling time step, beginning at the current state, an open loop optimal control problem is solved over a finite horizon. For each consecutive time step, time step a new optimal control problem based on new measurements is solved over a shifted horizon.



The optimal solution relies on a dynamic model of the process with respects to input constraints, output constraints, and minimizing a performance index (cost). The cost equation for this model is the simple distance formula, this keeps the car at the center of the lane by minimizing cost error which is the car's center position coordinate minus lane center coordinate.



MPC





Vehicle Dynamics



Here is a description of a car's Vehicle Dynamics. You can find the constants for your car with some simple research or taking measurements. The simulated vehicle in this project tracks a circular trajectory, but the algorithm can follow any trajectory. Your real-world trajectory comes from lane detection which is generated by your camera sensor's Computer Vision (CV) system.



Vehicle-Dynamics



Vehicle-Equations



Vehicle-Constants



The only input considered is the vehicle steering angle (steering wheel) and acceleration (gas and brake pedal). Some constraints are implemented to smooth out driving commands like a limited steering angle range, and limited rate of change for steering angle which reduces jerk in steering.



The Vehicle Model equations need to be linearized which is like finding the next position of a point given its initial position and slope. Linearized equations are MUCH easier to calculate from a computer's perspective.



Vehicle-Linear





Bicycle Model



Bicycle models are not as computationally expensive as car models, and also less prone to errors due to their simplicity. It's highly recommended to use a Bicycle Model for the real Self-Driving Car. Check out this research paper which compares Vehicle versus Bicycle Models for Autonomous Vehicles. Also read this research paper on Autonomous Drifting.



Bicycle-Model



Bicycle-Equations



Bicycle-Symbols





Autonomous Drifting!



The tire model equation is not necessary for normal driving. It's only included for fun to simulate drifting. It forces tire friction to saturate (no traction) and get the car to drift! Remove the tire equations and friction saturation constraints to simulate regular driving.



Drifting



Tire-Model





Results



The following images are made in MATLAB, they show the lane (Red lines), the car and steering wheel angle (Black box), and the covered trajectory (Blue line).

Normal Driving



Result-Car

Drifting



Drifting-Result





Robot Operating System (ROS)



The Robot Operating System (ROS) is an open source platform that's quickly becoming an industry standard in the Robotics field. ROS let's you quickly prototype and reuse code through their robust publisher-subscriber (pub-sub) architecture. You can also use different languages to create your nodes which is a huge bonus for modular design.



ROS applies a Soft Real-Time system to your code which is fine for single projects but becomes problematic when implemented at scale. There are workarounds for getting Hard Real-Time performance, but that's a topic for another post. Follow along with these ROS Tutorials to get you started, section 1.1 steps 1-13 are the most important tutorials. The following Self-Driving Car visualization was made in ROS using the Rviz package.



ROS





Code



This repository only contains the MATLAB simulation for this project. However in the real world, this project was implemented on the Self-Driving Car using Robot Operating System (ROS). Find the MATLAB simulation in the 'Code' folder of this repository.



$ git clone https://github.com/AMoazeni/Self-Driving-Car.git
$ cd Self-Driving-Car