/Udacity-SelfDrivingCar-T2-P4-PIDControl

Implement PID control in C++ to drive a vehicle autonomously at highest speed possible.

Primary LanguageC++

CarND-Controls-PID

Self-Driving Car Engineer Nanodegree Program


This project implements a PID control in C++ to drive a vehicle autonomously at highest speed possible in a computer simulated environment. In addition to driving at highest speed, the program needs to pick an optimal parameters to make the vehicle drive in as straight as posible, which mean minimal sway/swirl left and right.

The program/application receive vehicle's Cross Track Error(CTE), which is the distance between the lane center and the position of thevehicle, and use this error to calculate the values for Proportional, Integral, Derivative (PID). In the end, the program will calculate combine PID error value, which will be sent back to the vehicle as throttle/speed signal.

'P' is the proportional term affect the steering base on the Cross Track Error (CTE), which mean if the vehicle is facing toward the right of the lane, the 'P' value will adjust left, and vice versa.

'I' is integral term that track and calculate a sum of all observed CTE errors, which help the vehicle adjust to drifting issues, such as the vehicle is consistently drifting to the right of the lane, then it will adjust to back left.

The derivative term 'D' evaluate the change in error between the previous error and current error to adjust overshooting of vehicle steering direction and bring the vehicle closer to the reference line.

A manual process was used in selecting value for PID parameters. Initially, I set various values for 'P', while setting zero for 'I' and 'D', and observe the result. This single parameter value setting method is applied to 'I' and 'D' until the vehicle begin to navigate within the lane. All paramereter values are started out at high value and slowly reduced until the vehicle achieve the desire high speed and minimal sway/swirl.

The final values of P, I, and D are set at 0.2, 0.0004, 4.0, which make the vehicle achieve an average speed of 52 mph.


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.

Tips for setting up your environment can be found here

Editor Settings

We've purposefully kept editor configuration files out of this repo in order to keep it as simple and environment agnostic as possible. However, we recommend using the following settings:

  • indent using spaces
  • set tab width to 2 spaces (keeps the matrices in source code aligned)

Code Style

Please (do your best to) stick to Google's C++ style guide.