Skip to content

ooleksyuk/CarND-PID-Control-Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PID Controller Project Udacity - Self-Driving Car NanoDegree

Reflections

The main goal of the project is to implement PID controller in C++ to steer the self driving car around the track in a Simulator.

About PID Controller

I have worked on PID Controller with twiddle algorithm inside a state machine to optimize P,I, D parameters.

The actual implementation of the Controller is fairly straight forward. Making the Controller perform well on the track took me a few iterations. I went over Sebastian's lecture about PID over two times. I have implemented the basic PID class with Init, Update, and TotalError functions. The long part was to figure out input params for the PID instance of teh Controller. I have started with only P, by assigning 0 value to Kp. After running a car on the track with only P I have selected the value ov 0.1. After that I have proceeded with D. I have started with 0 value and ran a simulator for a few tracks to narrow it down to Kd be 2.5. It ended up not working after all on the full track. I have written the Twiddle function that was based on the notes from the Sebastian's lecture. I was able to improve my value and ended up selecting 3.9806.

So far everything looked good but I have not been using Integral part and my car was still not stable on the track.

I have added i_error and Pi to the TotalError function. With a help of Twiddle I was able to narrow it down to 0.0001; Also converting Steer_value into decrease with the help of rad2deg() function.

A PID (Proportional, Integral, Derivative) controller is a control loop feedback controller which is widely used in different control systems.

Error is an input variable for the controller: cte = desired_state - measured_state

As for the whole PID Controller project the knowledge about each component is very important. P is to tune present, D is to tune remember past values and I to predict future.

  • The "P" for proportional means that the car will steer in proportion to the cross-track error, or CTE. CTE is essentially how far from the middle line of the road the car is. With the proportional band (P) only, the PID controller output is proportional to the cte. It takes into account only the present value of cte. Thanks to this part of controller, it is able to steer in the correct direction.
  • The "I" for integral sums up all CTEs up to that point, such that too many negative CTEs (in this case, meaning the car has been to the left of the middle of the lane for awhile) will drive up this value, causing the car to turn back toward the middle, preventing the car from driving on one side of the lane the whole time. If the coefficient is too high for I, the car tends to have quicker oscillations, and does not tend to get up to a quick speed. Integral term (I) takes into account the integral of cte over the past time. It is used to reduce systematic bias. From my experianse of PID tuning on real-world systems and some experiments in the simulator, it was found out that we do not need to compute the integral for all time, but calculate it over only last n frames. In other case, we can accumulate errors because of left turns prevalens which can result in different behaviour of the controller during multi lap drive and even going off the track.
  • The "D" for derivative is the change in CTE from one value to the next. With derivative (D) part, the controller output is proportional to the rate of change of cte (its derivative). The parameter is used to reduce overshooting and dump oscillations caused by the P.
  • Video of Simulator and console out put side by side
  • A GIF Video of the full track in Simulator

While the PID controller is easy to implement, but it is not so easy to tune.

How it was tuned

Initially, the controller was tuned with so-called Ziegler–Nichols method. Generally speaking, it requires to set Kd and Ki to 0 and gradually increase Kp before the car runs with stable and consistent oscillations. This value of Kp and the oscillation period can be used to calculate optimal pid controller parameters by the method. Unfortunatly, the controller with resulted parameters was able to drive car around the track but with a lot of wobbling. That is why, parameters were further tuned manually by try-and-error process.

The same process was applied for differnt speed, so different PID parameters were found for different speed. The results were linearized The same process was applied for different speed, so different PID parameters were found for different speed. The results were linearized in order to make the parameters automatically tune with the car speed variation.

The implementation also takes into account different time intervals between data frames.

Dependencies

There's 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.

About

CarND-PID-Control-Project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages