View the Project on GitHub MarkBroerkens/CarND-PID-Control-Project

Udacity - Self-Driving Car NanoDegree

The Project

In this project a PID controller that is used to maneuver the vehicle around the track in the simulator.

The simulator provides the cross track error (CTE) and the velocity (mph) and current steering angle. This data is used to compute the appropriate steering angle and throttle.

Rubric Discussion Points

The P, or “proportional”, component had the most directly observable effect on the car’s behavior. It causes the car to steer proportionally (and opposite) to the car’s distance from the lane center (which is the CTE) - if the car is far to the right it steers hard to the left, if it’s slightly to the left it steers slightly to the right. Bigger values of P result in faster reactions of the steering angle with respect to the CTE. I had to use higher values for higher speed of the car.

The D, or “differential”, component counteracts the P component’s tendency to overshoot the center line. A properly tuned D parameter will cause the car to approach the center line smoothly. Higher values of P also required higher values of D.

The I, or “integral”, component counteracts a bias in the CTE which prevents the P-D controller from reaching the center line. This bias can take several forms, such as a steering drift.

The P, or “proportional”, component had the most directly observable effect on the speed of the car’s behavior. High values of P resulted in quick reactions on changes of the target speed which even allowed the car to brake (negative throttle).

The D, or “differential”, component counteracts the P component’s tendency to overshoot the target speed.

The I, or “integral”, was set to 0 since the target speed is constantly changing and I observed a tendency to not breaking fast enough.

Hyperparameters were tuned manually at first. As an inital configuration I used the values from the lesson (p=0,2, i=0,004, d=3). These parameters worked pretty well for constant throttle of 0.3. The I tried to increase the speed of the car by using higher constant throttle values and figured out that the car frequently left the track. In order to overcome this issue added a PID controller that minimizes the speed of the car in case of high cross track error and high steering angle.

Manual Experiments

With this setup and some additional manual experiments with regards to the Hyperparameters of the PID controllers I ended up with the following result.

steering PID parameters (p=0.14, i=0.00027, d=6). throttle PID parameters (p=0.1, i=0.0, d=1).

Initial Hyperparameters

Twiddle I then implemented the Twiddle algorithm for automated optimization of the Hyperparameters of both controllers. This step is quite time consuming since the car needs to pass all critical locations of the track for each combination of parameters. I ran the car for more than a lap in order to be sure that the critical curve after the bridge is handle correctly.

Using a max throttle of 0.3 a few iterations of the twiddle algorithm resulted in the following hyperparameters.

steering PID parameters (p=0.135, i=0.0015, d=8.51561). throttle PID parameters (p=0.1, i=0.0, d=1).

Twiddled Hyperparameters

Extra Material

The following links to extra material on PID controllers are from the Udacity review. Thanks.


There’s an experimental patch for windows in this PR

Basic Build Instructions

  1. Clone this repo.
  2. Make a build directory: mkdir build && cd build
  3. Compile: cmake .. && make
  4. Run it: ./pid.

Tips for setting up your environment can be found here

Code Style

I tried to stick to the Google’s C++ style guide. In order to check the guidelines I installed cpplint using pip install cpplint