UDACITY SDCE Nanodegree Term 2: PID Controller for Self-Driving Vehicles

Implementation of a PID controller for self-driving vehicles. The goals / steps of this project is to implement a PID controller in C++ to maneuver the vehicle around the track! The vehicle successfully drives a lap around the track!

PID Control

PID controllers are a class of algorithms that can be used not only to steer self-driving vehicles but also have many other applications. The general equation of a PID controlled for steering can be given by (Note that the steering angle needs to be normalized):

steering_angle = -tau_p * prop_CTE -tau_d * diff_CTE - tau_i * int_CTE

It encompasses of three controllable parameters and if tuned properly can be incredibly effective and accurate. The three parameters are proportional gain (P), integral gain (I), and derivative gain (D), hence the name PID. The P parameter attempts to control a vehicle in proportion to the error from a reference trajectory. The D parameter helps control oscillations and how smooth the vehicle will approach the reference trajectory. Finally, the I parameter measures large errors that manifest due to biases (e.g., steering drift). By tuning these three parameters it is possible to implement controllers for a variety of applications including autonomous vehicles.

In this project a PID controller is implemented in C++ in order to maneuver a vehicle around a track. A major part of this project was to tune the parameters.

Effect of P,I,D parameters

Choosing the PID parameters too low resulted in the car not able to correct its trajectory in time. On the other hand, setting the P and I components high resulted in large oscillations, in the case of the P parameter the car was able to just barely stay on the road. Setting the I parameter high, resulted in the car almost immediately exiting the track due to the large impact of the error being accumulated. Finally, with regards to the D parameter, setting it too high results in the car never actually going straight but constantly doing an oscillating motion even if it is capable of going through the track.

Final Hyper-parameters

The parameters where chosen empirically. By starting with large values and halving then until somewhat stable performance could be achieved. From there the parameters where optimized manually one by one. First, by analyzing the oscillations of the car and the rate of steering adjustment I was able to infer which parameters needed to be optimized further. In addition, the throttle is adjusted based on the steering angle in order to slow down when the angle resulting in a smoother drive. The final parameters that I have chosen are [0.1,0.005,3.8] for P,I, and D respectively.

Video Demonstration

PhD in Computer Engineering, Self-Driving Car Engineering Nanodegree, Computer Vision, Visual Perception and Computing

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store