Giter Site home page Giter Site logo

sdcar_t2_p3_pid_controller's Introduction

CarND-Controls-PID

Self-Driving Car Engineer Nanodegree Program


Goals

The goal of this project is to build a PID (proportional, integral, derivative) controller for a car and simulate the car around a track. The car has to stay in lane, use the PID control logic to properly negotiate the turns on the road by turning left and right as requried and complete a complete loop.

Project implementation details

Initial screen of simulator

Simulator_home

The simulator sends the value of cte (cross track error), speed and steering_angle. We only make use of the cte and calculate the value of the steering_angle and throttle using two PID controllers.

The effect each of the P, I, D components had in your implementation.

Kp = 0.3 -> A low value of proportional coefficient was picked because during sharp turns, a small value ensures smoother transition. A large value results in more extreme oscillations.

Ki = 0 -> The integral coefficient just adds up all the CTE values. In this simulator, the CTE goes up a lot during a turn. When the integral control is applied at this stage, the car completely goes out of control due to a large correction in both steer_value and throttle value that are generated by the integral coefficient. So, in this project the integral coefficient was set to 0.

Kd = 0.8 -> A higher value of derivative coefficient was chosen because it helps a lot with smoothing out after making the proportional correction. Because of this, if the vehicle is closer to the center, the steer_value is gradually reduced and the throttle is also reduced.

fabs(throttle_value) has to be used because if there is a negative value, the car can go in reverse.

straight road means low CTE and low steer_value and throttle (speed) values.

In the video, we can see that during a sharp right turn -> stright road -> left turn -> straight scenario, the car velocity goes from 12 mph -> 18 mph -> 10 mph -> 24 mph - 15 mph. This is all due to the CTE feedback from the simualtor.

car_video

Describe how the final hyperparameters were chosen.

The final parameters were mostly chosen by trial and error observing the behavior of the car and going through the lectures to understand the contribution of each of the parameters Kp, Kd and Ki. I was able to determine that the car can be tuned without the use of twiddle for this project. I did try to implement some code that roughly tries to mimic twiddle but was not able to notice the differences of using this.

Behavior of the car PID controller on a straight road

When the road is straight, the CTE is very low and that results in a small steer_value and throttle value. Due to this the car slows down considerably to 2.5 mph.

low cte - straight road

Behavior of the car PID controller at a left curve

The car approaches a left curve with 4 mph and as the curve increases, the CTE goes up and the the resulting PD values increase as well. Due to this the steer_value and throttle value increase. The car steers more and also moves faster to upto 12 mph at the peak of the turn.

left curve 1

left curve 2

left curve 3

Behavior of the car PID controller at a right curve

Similarly for an sharp right turn, the speed increases from 11 mph to 18 mph at the peak and then settles at 16 mph.

right curve 1

right curve 2

right curve 3

Code review

pid.h and pid.cpp classes have the main logic and main.cpp has the code to run the web socket by connecting it to the simulator. In the main class, the pid objects are initialized, a new steering_angle and throttle value is calculated and passed back to the simulator. The initial values used are Kp=0.3, Ki=0, Kd = 0.8 for both the PID controllers (line 77,78 in main.cpp) Kp - proportional coefficient Ki - integral coefficient Kd - derivative coefficient

main.cpp lines 80-84 -> update of steer and throttle values main.cpp lines 93-125 -> commented code for twiddle tests pid.cpp lines 13-26 -> initialization pid.cpp lines 28-33 -> update of proportional, integral and differential errors pid.cpp lines 35-39 -> update of steer and throttle using the Kp, Ki and Kd coeffients and cte pid.cpp lines 41-114 -> commented code for twiddle tests

The program was run from the build directory using the command ./pid and starting the simulator with GPU mode enabled. Here is a sample command line during the run.

command_line

Finally when everything seems to work, it seems like magic but its been a fun project and I learned a lot.

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.

sdcar_t2_p3_pid_controller's People

Contributors

domluna avatar baumanab avatar srini31 avatar mvirgo avatar swwelch avatar davidobando avatar citlaligm 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.