Use a PID controller to control the steering angle and throttle for driving a car in a car game simulator.

View the Project on GitHub

Autonomous driving with PID controllers

1. Objective

This project is to use PID controllers to control the steering angle and the throttle for driving a car in a game simulator. The simulator provides cross-track error (CTE) via websocket. The PID (proportional-integral-differential) controllers give steering and throttle commands to drive the car reliably around the simulator track.

Demo 1: Steady drive with constant throttle (click to see the full video)


2. Parameters of PID controller

Description of PID values in PID control

Finally parameters

How to tune the parameters

The parameters are tuned manually with the order of: p, d, i. The d and i are first setted to be zeros, and 0.2 is used for the p value. I adjust the p value up and down till it could drive around the first corner and hard to imporve more. Then I keep the p value as it is, and increase the d value. Use the same approach for d value and i value.

In order to automatically fine tune the parameters, an optimization algorithm twiddle can be used, which is exampled as follows:

Demo 2: speedy drive, which is targeting for dirivng the car as fast as possible, but as a side effect, the car starts to swing. In order to make the car drive fast as well as steady, further joint parameter tuning for both PID controllers need to be carried out.

Code & Files

1. Dependencies & environment

2. How to run the code

  1. Clone this repo.
  2. Clean the project: $./
  3. Build the project: $./
  4. Run the project: $./
  5. Start the simulator v1.45, select the PID Controller.

3. My project files

4. Code Style

5. Release History