PID Control Project
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.
- 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
-
Import the project into Eclipse
- Open Eclipse.
- Import project using Menu
File > Import
- Select
General > Existing projects into workspace
- Browse
/root/workspace/CarND-PID-Control-Project/build
and select the root build tree directory. Keep "Copy projects into workspace" unchecked. - Now you should have a fully functional eclipse project
-
Code Style
- From Eclipse go to
Window > Preferences > C/C++ > Code Style > Formatter
- Click Import
- Select
/root/workspace/eclipse-cpp-google-style.xml
- Click Ok
- From Eclipse go to
-
Build
OPTIONAL: Build on command line
cd /root/workspace/CarND-PID-Control-Project/build make
-
Run
OPTIONAL: Run on command line
./pid
-
Launch simulator
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;
- 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.
- 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.
- 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.
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 |
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 |