Self-Driving Car Engineer Nanodegree Program
Please click on this image to see video of PID controller driving the car for two laps.
- Windows build required changes and uWS version available is v0.14.2 which is source incompatible with v0.13. ** NB Reviewers: please use v0.14+ of uWS **
- After initial tests, produced a build on Ubuntu as well using uWS v0.13; however on the Ubuntu hosted in VirtualBox on Windows 10, the simulator runs painfully slow and results are extremely unstable.
- Decided to test and submit final version from Windows 10 with uWS v0.14.2
- I acknowledge the information provided in help forums and slack channels to get the initial version of project compiling, and also for "restart" code snippet that helps with Twidle.
- Different screen size and graphics quality result in different frame rates.
- The configuration of computer running the simulator will also impact frame rates.
- Due to the PID controller actually not having the delta time component, the change of frame rates result in different values of the error coefficients. Hence the values used after tuning on my PC are not easily reproducible on other PCs.
- Even for recording the video, I had to reduce throttle.
Throttle = 0.3
Low Value | High Value |
---|---|
P=0, I=0, D=0 | P=10, I=0, D=0 |
Car goes straight rather than track the road. | Even with a very small tracking error, car starts oscillating due to overshoots. |
Throttle = 0.3
Throttle = 0.3
We take the same values (P=0.3, D=5) that seemed well tuned for throttle value of 0.3 and increase the throttle to 0.7.
The car now begins to oscillate and eventually crash. Given same steering angle, the car turn more at higher speeds than at lower speeds.
For this exercise: kD >> kP >> kI
I have an implementation of the Twidle algorithm in the PID controller. Since the CTE from simulator is dependent on PID output from intermediate stages, simple mean-squared-root error minimization didn't work well. I had tried training it with a couple of variations of error function,
- maximise the number of frames (iterations or steps) run before car went off track
- maxmiise the combination of number of iterations and standard deviation of CTE (steps/stdev) Both of these did not converge, and it may have been my choice of initial dP values.
Eventually I resorted to manual tuning following suggestions in slack forum that getting parameters for 50 mph drive was easy to do manually. For throttle value of 0.3:
- use a low value of kP, keeping kI and kD at 0, and increase (double) kP until car is somewhat able to follow to tracks and starts oscillating.
- next use a low value of kD, keeping kI at 0, and increase kD until it dampens the oscillations to make the car progress on more of the track.
- repeat steps above until car is able to follow turns safely.
I then increased throttle values to .6 and tuned kP and kD down a bit from the values for throttle .3, as at higher speeds, same steering angle will cause car to turn more than at lower speed. I kept the kI value at 0, as I have tweaked the PID to ignore very small CTE.
With higher throttle values, I started observing some instabilities. My implementation has optional parameters to specify maximum CTE beyond which negative throttle is applied.
However, I had much better success with using a different mechanism for adapting the throttle. I tried using another PID controller, but tuning it was becoming difficult given the time. Hence I have used "moving" variance of the last 40 CTE values and a threshold to adapt the throttle value. When variance of CTE is high, throttle is reduced. At low variance (below 0.01), the throttle applied boosted! The size of "moving" variance history (cteWindowSize
) is also configurable on command line.
throttle_value = throttle_specified + (0.01 - CTE_variance)
NB: When I ported the code to Ubuntu VM hosted on my PC, these results didn't work. That when I also discovered the susceptibility to frame rates of simulator.
I have hard coded the paramenters for my Windows PC's configuration, but these parameters can be overridden on command line. My values are:
Param | Value |
---|---|
P | 0.0880 |
I | 0.000 |
D | 2.875 |
----- | ----- |
throttle_specified |
1.0 |
cteWindowSize |
40 |
Usage: pid [[Kp] [Ki] [Kd] [throttle]] [a [cteWindowSize]] [b [highCte]] [t [[dKp] [dKi] [dKd] [tolerance]] Eg: # no arguments, uses built-in defaults pid
# Kp=.3, Ki=0, Kd=.4, throttle=.4; enable adaptive throttle, with window size of 50; enable break on CTE higher than .7
pid .3 0 5 .4 a 50 b .7
# Kp=0, Ki=0, Kd=0, throttle=.4; twiddle starting with dKp=.1, dKi=0, dKd=5, tolerance=.2
pid 0 0 0 .4 t .1 0 5 .2
- Allow for time duration between telemetry readings (delta t), and make the controller frame rate independent.
- Scale P,I,D sensitivity with speed (lower the values for higher throttle specified)
- Better error function for Twidle, such that the parameters can be learnt automatically
- cmake >= 3.5
- All OSes: click here for installation instructions
- make >= 4.1
- Linux: make is installed by default on most Linux distros
- Mac: install Xcode command line tools to get make
- Windows: Click here for installation instructions
- gcc/g++ >= 5.4
- Linux: gcc / g++ is installed by default on most Linux distros
- Mac: same deal as make - [install Xcode command line tools]((https://developer.apple.com/xcode/features/)
- Windows: recommend using MinGW
- uWebSockets == 0.14, but the master branch will probably work just fine NB: orginal project specified v0.13 which is difficult to install on Windows.
- Follow the instructions in the uWebSockets README to get setup for your platform. You can download the zip of the appropriate version from the releases page. Here's a link to the v0.14.2 zip.
- If you run OSX and have homebrew installed you can just run the ./install-mac.sh script to install this
- Simulator. You can download these from the project intro page in the classroom.
- Clone this repo.
- Make a build directory:
mkdir build && cd build
- Compile:
cmake .. && make
- Run it:
./pid
.
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)
Please (do your best to) stick to Google's C++ style guide.
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.
- You don't have to follow this directory structure, but if you do, your work will span all of the .cpp files here. Keep an eye out for TODOs.
Help your fellow students!
We decided to create Makefiles with cmake to keep this project as platform agnostic as possible. Similarly, we omitted IDE profiles in order to we ensure that students don't feel pressured to use one IDE or another.
However! I'd love to help people get up and running with their IDEs of choice. If you've created a profile for an IDE that you think other students would appreciate, we'd love to have you add the requisite profile files and instructions to ide_profiles/. For example if you wanted to add a VS Code profile, you'd add:
- /ide_profiles/vscode/.vscode
- /ide_profiles/vscode/README.md
The README should explain what the profile does, how to take advantage of it, and how to install it.
Frankly, I've never been involved in a project with multiple IDE profiles before. I believe the best way to handle this would be to keep them out of the repo root to avoid clutter. My expectation is that most profiles will include instructions to copy files to a new location to get picked up by the IDE, but that's just a guess.
One last note here: regardless of the IDE used, every submitted project must still be compilable with cmake and make./