PID Control

PID Control Project

Goals

In this project you'll revisit the lake race track from the Behavioral Cloning Project. This time, however, you'll implement 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.

One more thing. The speed limit has been increased from 30 mph to 100 mph. Get ready to channel your inner Vin Diesel and try to drive SAFELY as fast as possible!

NOTE: you don't have to meet a minimum speed to pass.


Dependencies

Environment Setup

  1. Open Eclipse IDE

Linux:

docker run --rm --name pid \
    --net=host -e DISPLAY=$DISPLAY \
    -v $HOME/.Xauthority:/root/.Xauthority \
    dragon7/carnd-pid-control-project

Mac:

socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\"

docker run --rm --name pid \
    -e DISPLAY=[IP_ADDRESS]:0 \
    -p 4567:4567 \
    dragon7/carnd-pid-control-project
  1. Import the project into Eclipse

    1. Open Eclipse.
    2. Import project using Menu File > Import alt text
    3. Select General > Existing projects into workspace alt text
    4. Browse /root/workspace/CarND-PID-Control-Project/build and select the root build tree directory. Keep "Copy projects into workspace" unchecked. alt text
    5. Now you should have a fully functional eclipse project alt text
  2. Code Style

    1. From Eclipse go to Window > Preferences > C/C++ > Code Style > Formatter
    2. Click Import
    3. Select /root/workspace/eclipse-cpp-google-style.xml
    4. Click Ok
  3. Build

    • Select Project -> Build All alt text

    OPTIONAL: Build on command line

    cd /root/workspace/CarND-PID-Control-Project/build
    make
    
  4. Run

    • Right click Project -> Run as -> 1 Local C++ Application alt text

    OPTIONAL: Run on command line

    ./pid

  5. Launch simulator

alt text


Reflection

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

The PID algorithm is implemented in line 24~26 and 33 of PID.cpp as below.

  d_error = cte - p_error;
  p_error = cte;
  i_error += cte;
  -Kp * p_error - Kd * d_error - Ki * i_error;

alt text

  1. P Component

From the formula, we can found that the P component control how the Cross Track Error (CTE), i.e. how far from road middle, affect the steering angle. If we got larger Kp, the steering angle would be more affected by CTE. If the car is far away from middle, this would be helpful. Because it need more steering angle to adjust to return back to center. But if the car is close to the middle. larger Kp would let the car overshoot or oscillate more quickly. However, if Kp is too small, it would not sensitive to land curvature.

alt text

  1. D Component

Besides P component, we added one D, i.e. differential, part to the formula to let the steering angle more smooth. Consider the car gradually leaves the middle, the would cause a positive differential. So we would get more steering angle to return back to center. IF the car is gradually back to middle, we got negative differential, and smaller steering angle. Make sense. But if Kd too large, it would make the steering angle change too rough. However, if the Kd is too small it can't solve the overshoot problem.

alt text

  1. I Component

In this portion, we add an I, i.e. integral, part to the equation. It looks like we compensate all previous error. If Ki is close to 1, the steering angle will sensitive to oscillation and can't go for high speed. If Ki close to 0, the car will tend to drift to one side of the lane for a long period of time.

alt text

P Controller PD Controller PID Controller Twiddle PID Controller
effect marginally stable solve overshoot solve systematic bias parameters (P,I,D) optimization
side effect overshoot, systematic bias systematic bias

alt text

Describe how the final hyperparameters were chosen.

The final hyperparameter were chosen as below. Manually tuned these parameters with the base values gotten from PID Control lesson. Followed the procedure from P to D then I to tune these parameters. During P parameter tuning, I set D and I as zero. During D tuning, fixed P and let I as zero. Finally during I tuning, fixed P and D. Because the values got from the lesson almost already workable. I haven't implemented Twiddle algorithm to find the optimized parameters. I found that the result run from Udacity workspace and Mac is a little different, so I made some modification on these hyperparameters.

coefficient P I D
value 0.2 0.001 3

Result

alt text


Reference