CarND-Controls-PID

Self-Driving Car Engineer Nanodegree Program


Work summary

I started by adding method NextSteeringValue() in PID.cpp, which provides steering value by PID control. Then I add Twiddling capability by adding InitTwiddle() and Twiddle() in PID.cpp.

On top of these, I tuned PID and twiddle parameters below, with fiding how each parameter works.

P controller

I tuned P only controller with throttle 0.2 because it easily goes off the track with much speed.The final parameter for P was finalized to 0.5.

While tries and erros are like below:

  • P: 0.1
    • Easily went off the track by under steer in recovering to center.
  • P: 0.5
    • Though sometimes went off the track, it ran 1 complete lap. It always overshoot the center line in recovering to center of the lane.
  • P: 1.0
    • Same as 0.5 case. But it is bit more likely to went off by over steer. Espcecially onece it gets away from the center, the steering value becomes much hard so easiliy overshoot the center of the lane much.

P only controller still works in slow speed though, it's not reasonalbe to use this as a controller. We need additional coefficients definitely.

PD controller

The final parameter for PD was finalized to P: 0.5 and D: 9.2.

Tries and errors are:

  • P: 0.5 and D: 1.2
    • In throttle 0.2, it worked fine(make 1 complete lap) but with throttle 0.4, it did not.
  • P: 0.5 and D: 3.2
    • It worked fine with throttle 0.4.
  • P: 0.5 and D: 9.2
    • It worked fine with throttle 0.6. (Sometimes it fails though)
    • Also worked fine with throttle 0.4. Too high D gain should prevents quick lane change, however in this situation we only have single lane so it did not matter.

So far, we can say that PD pramaters are affect by speed of vehicle. At very high level, higer speed requires higher gains.

Twiddle

In throttle 0.6 situation, I tested twiddle as below

  • P: 0.5 and D: 9.2 with Twiddle every 300 frames
  • P: 0.5 and D: 9.2 with Twiddle every 50 frames
  • P: 0.5 and D: 9.2 with Twiddle every 10 frames

Slightly it did better than no-twiddle case, because parameters could catch up speed that changes overtime. I assumed more frequent twiddle does betther for more quick catch up. However I could not find significant different.

Anyway, adding D coefficinet significantly helps stabilizing the vehicle from overshooting again and again situation.

PID controller

The final parameter is P:0.5, D:9.2 and I: 0.01. or 0.0. In this situation we don't have any wind, slippy road those prevent vehicle from goes straing with wheels. So when I applied rather large value like 0.1, the vehicle easily went off the track right after it started running.

Still we can assume adding I coefficient help in case of wheels drifs with running in much speed. However I could not find significant different by adding I:0.01.

Twiddle

  • P: 0.5, D: 9.2 and I: 0.01 with Twiddle every 50 frames

As above, adding I coefficient did not significantly help, so adding twiddle did not bring big difference.

Final Parameter

  • P: 0.5
  • I: 0.01
  • D: 9.2
  • Twiddle
    • Tolerance: 3.0e-8
    • P: 0.05(1/10 of initial P)
    • I: 0.001(1/10 of initial I)
    • D: 0.092(1/10 of initial D)
    • Interval: 50frames

Recorded Youtube Video with the parameters above.

Finalized

Also you can find video of optimizing proccess.(4x speed)

in optimizing

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.

Hints!

  • 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.

Call for IDE Profiles Pull Requests

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./

How to write a README

A well written README file can enhance your project and portfolio. Develop your abilities to create professional README files by completing this free course.