/CarND-PID

C++ PID controller implementation in a vehicle simulation environment

Primary LanguageC++MIT LicenseMIT

CarND-Controls-PID

Self-Driving Car Engineer Nanodegree Program


Solution Description

I tried a few methods to tune this controller. My first attempt was to use the python simulator with the 'twiddle' algorithm to optimize the parameters. The parameters that were generated from the lesson created a system that overcorrected into a state of instability. Parameters like driving speed and max steering angle could be adjusted to better replicate the conditions in the simulator. I realized that, while twiddle reduces total error, the solution is likely not ideal as a passenger. It results in steep, underdamped oscillations that would be highly uncomfortable and unnecessary in most scenarios. From the previous trajectory generation project, it is likely that this path would void the curvature and jerk constraints. Ideally, we could set some constraints on the path during 'twiddle' to prefer overdamped paths that are smooth rather than underdamped paths that oscillate and are uncomfortable.

The other method I used to tune was simply by manual (not twiddle) trial and error. I followed steps described here that instruct to first build a stable PD controller before introducing the integral component. During this process, I found that a minimum proportional value is needed to properly steer around the corners on the track at a given speed. If this value is too small, the vehicle doesn't correct enough and drives off the outside edge of the turn. If its too large, it oscillates once it enters the turn and eventually crashes. I found reducing the speed was helpful to maintain stability around tight corners (I reduced the set speed to 0.13). Although this is not ideal in a scenario where speed is prioritized, considering comfortable driving conditions is necessary in an autonomous vehicle carrying humans, and therefore it is natural to reduce speed in sharp corners. Ideally the trajectory would reduce speed on high curvature areas automatically. Once the PD controller was smooth and strong enough to corner at the set speed, I introduced a relatively small integral coefficient to correct for constant error. Too strong of an integral component and the vehicle will oscillate, but reducing this value provided just enough pull to bring the car back to the lane center.

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.