/CarND-P8

PID Controller

Primary LanguageC++MIT LicenseMIT

CarND-Controls-PID

Self-Driving Car Engineer Nanodegree Program


Dependencies

Fellow students have put together a guide to Windows set-up for the project here if the environment you have set up for the Sensor Fusion projects does not work for this project. There's also 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.

Project Instructions and Rubric

Note: regardless of the changes you make, your project must be buildable using cmake and make!

More information is only accessible by people who are already enrolled in Term 2 of CarND. If you are enrolled, see the project page for instructions and the project rubric.

Reflection

1. Describe the effect each of the P, I, D components had in your implementation.

  • P component
kp=0.01;ki=0.0;kd=0.1 kp=0.2;ki=0.0;kd=0.1
Alt Text Alt Text

The effect of P component is to reduce the error between the response and the reference value.

In the above two gifs, the controller with smaller P value kp = 0.01 cannot have large enough steering angle to guide the vehicle back to the center line; the controller with larger P value kp = 0.2 can pull the vehicle back to the center, however have large oscillations.

  • D component
kp=0.2;ki=0.0;kd=0.1 kp=0.2;ki=0.0;kd=2.0
Alt Text Alt Text

The effect of D component is to reduce oscillations.

In the above two gifs, the controller with larger D value kd = 2.0 has much smaller oscillations compared with kd = 0.1.

  • I component

Cross track error controller

kp=0.2;ki=0.0;kd=2.0 kp=0.2;ki=0.01;kd=2.0
Alt Text Alt Text

The effect of I component is to eliminate systematic bias.

As the systematic bias for the cte pid controller is small, adding I component to the controller doesn't have significant influence on the controller's performance, except for the starting stage where the controller with ki = 0.01 has larger oscillations than ki = 0.0.

Speed controller

kp=0.2;ki=0.0;kd=5.0 kp=0.2;ki=0.002;kd=5.0
Alt Text Alt Text

However, the I component is quite effective in the speed pid controller. As the friction applied on the vehicle is a systematic bias that is not negligible, the speed controller with ki = 0.0 cannot reach the reference speed = 30.0 (left gif). Then by setting ki = 0.002, the right gif shows the controller can eliminate the systematic bias and successfully reach the reference speed.

2. Describe how the final hyperparameters were chosen.

I chose to tune the parameters manually. I refered to this post and the strategy I took is the following:

  • Step 1: Increase the P gain until the response is steady oscillation.
  • Step 2: Increase the D gain until the oscillations are reduced to the acceptable level.
  • Step 3: Repeat steps 2 and 3 until increasing the D gain does not stop the oscillations.
  • Step 4: Increase the I gain to eliminate the systematic bias.

Finally, the parameters I chose are:

  • reference speed = 30 mph
  • cte controller: kp = 0.2, ki = 0.001, kd = 2.0
  • speed controller: kp = 0.2, ki = 0.002, kd = 5.0