Giter Site home page Giter Site logo

carnd-pid-control-project's Introduction

CarND-Controls-PID

Self-Driving Car Engineer Nanodegree Program


Please click on this image to see video of PID controller driving the car for two laps. Two Laps


Reflections

Build Issues with uWS Versions

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

Susceptibility to Simulator's scree size, and graphics quality

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

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

Effect of the Proportional ("P") component

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.
Low P High P
Effect of the Integral ("I") component

Throttle = 0.3

Negative Value Positive Value
P=0, I=-1, D=0 P=0, I=+1, D=0
Car tends to turn right - heavy bias, as -1 is actually pretty high rate of accumulation. Car tends to turn left - heavy bias, as +1 is actually pretty high rate of accumulation.
Negative I Positive I
Effect of the Derivative ("D") component

Throttle = 0.3

Low Value Mid Value High Value
P=0.3, I=0, D=1 P=0.3, I=0, D=5 P=0.3, I=0, D=15
A tuned value of P, but with low D, the car still oscillates. With tuned P and tuned value of D, the car follows the track smoothly. With tuned P and high value of D, the car follows track but the steering oscillates wildly, which can lead to tyre burnout and reduced speed.
Low D Mid D High D
Effect of the vehicle speed on P,I,D components

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.

High Speed

Overall observations

For this exercise: kD >> kP >> kI

Criteria: Describe how the final hyperparameters were chosen.

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.

Adaptive throttle control and hard limits on error to apply breaks

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

Command line usage

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

Further possible improvements

  • 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

Dependencies

Basic Build Instructions

  1. Clone this repo.
  2. Make a build directory: mkdir build && cd build
  3. Compile: cmake .. && make
  4. Run it: ./pid.

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

carnd-pid-control-project's People

Contributors

domluna avatar kswaroop1 avatar htuennermann avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.