/PID-Control-Project-SDC-Term2-P4-Udacity

PID Control project is the fourth project of the second term of the Self Driving Car Nanodegree by Udacity

Primary LanguageC++MIT LicenseMIT

CarND-Controls-PID

Self-Driving Car Engineer Nanodegree Program


Overview

In this project, I implemented a PID controller in C++ to maneuver the vehicle around the track. The simulator will provide you the cross track error (CTE) and the velocity (mph) in order to compute the appropriate steering angle.

Dependencies

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.

Simulator

You can download the simualtor here. Then, choose "Project 4: PID Controller" Project 4: PID Controller

Reflection

The effect of the P, I, D component of the PID algorithm

  • The proportional component depends only on the difference between the set point and the process variable. This difference is referred to as the Error term. The proportional gain (Kc) determines the ratio of output response to the error signal. In general, increasing the proportional gain will increase the speed of the control system response. However, if the proportional gain is too large, the process variable will begin to oscillate. If Kc is increased further, the oscillations will become larger and the system will become unstable and may even oscillate out of control.
  • The integral component sums the error term over time. The result is that even a small error term will cause the integral component to increase slowly. The integral response will continually increase over time unless the error is zero, so the effect is to drive the Steady-State error to zero. Steady-State error is the final difference between the process variable and set point. A phenomenon called integral windup results when integral action saturates a controller without the controller driving the error signal toward zero.
  • The derivative component causes the output to decrease if the process variable is increasing rapidly. The derivative response is proportional to the rate of change of the process variable. Increasing the derivative parameter will cause the control system to react more strongly to changes in the error term and will increase the speed of the overall control system response. Most practical control systems use very small derivative parameter, because the Derivative Response is highly sensitive to noise in the process variable signal. If the sensor feedback signal is noisy or if the control loop rate is too slow, the derivative response can make the control system unstable

Source: http://www.ni.com/white-paper/3782/en/

Video of the car

Video sample
This video has been made with a previous version of my code. There are some minor changes in respect to my final code (max_steer and throttle in the main.cpp file).

Final hyperparameters

I decided to manually tune the hyperparameters. I first tried to implement twiddle, but it was difficult to implement and didn't give me a good result. Watching what other students did, I decided to discard the twiddle implementation and I focus my effort on optimizing manually the hyperparameters. I choose to set P to 0.35, I to 0.00005 and D to 18. I first tried with all the three hyperparameters close to 1, but the car went off road. I had to drastically diminish I to make the car stay on track. To optimize driving I had to drastically increase D to make the car stay on track recovering from errors. I, then, played a little with throttle and steer_value to increase the speed of the car and increasing its performance. You can read the code in the main.cpp file (lines 70:88). The car reached the speed of 60 mph.