GithubHelp home page GithubHelp logo

sandeeppaulraj / carnd-mpc-project Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 2.53 MB

License: MIT License

CMake 1.84% Shell 0.18% C++ 83.02% C 2.03% Cuda 1.14% Fortran 11.48% Python 0.08% JavaScript 0.07% CSS 0.05% Ruby 0.12%
mpc model-predictive-control cpp udacity udacity-self-driving-car self-driving-car

carnd-mpc-project's Introduction

CarND-Controls-MPC

Self-Driving Car Engineer Nanodegree Program


Dependencies

Basic Build Instructions

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

Tips

  1. It's recommended to test the MPC on basic examples to see if your implementation behaves as desired. One possible example is the vehicle starting offset of a straight line (reference). If the MPC implementation is correct, after some number of timesteps (not too many) it should find and track the reference line.
  2. The lake_track_waypoints.csv file has the waypoints of the lake track. You could use this to fit polynomials and points and see of how well your model tracks curve. NOTE: This file might be not completely in sync with the simulator so your solution should NOT depend on it.
  3. For visualization this C++ matplotlib wrapper could be helpful.)
  4. Tips for setting up your environment are available here
  5. VM Latency: Some students have reported differences in behavior using VM's ostensibly a result of latency. Please let us know if issues arise as a result of a VM environment.

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.

Reflection

I essentially followed the 3 main steps below to accomplish this

Example Mind the Line Quiz

I leveraged a lot of the template code from this quiz. Infact most of my project MPC.cpp is for all practical purposes the same as what was used in the quiz.

Project Q&A in Google Hangout.

The Google hangout video gave a lot of hints/information on how to code the main.cpp. After following the instructions and NOT incorporating latency into the model, i had issues with the car going of the track. I realized that based on the project lesson and the project helper video that i had to modify the co-efficients of the cost function. I had to experiment with several values to reach a stage where the car was able to lap the circuit without going off. The co-efficients in the project Q7A video did not work for me.

Add Latency

I consulted the forum to read up on how to add latency. After going through various discussion threads, i settled on how to add latency to the model.

I chose a value of N = 10 and dt = 0.1

These values were based on suggestions given in the helper videos. I will note however, that model is very sensitive to the co-efficients to minimize the value gap between sequential actuations. For steering a value of 300 worked well for me; however a value of 100 and even 200 gave very poor results.

    for (unsigned int t = 0; t < N; t++) {
      fg[0] += 2000*CppAD::pow(vars[cte_start + t] - ref_cte, 2);
      fg[0] += 2000*CppAD::pow(vars[epsi_start + t] - ref_epsi, 2);
      fg[0] += CppAD::pow(vars[v_start + t] - ref_v, 2);
    }

    // Minimize the use of actuators.
    for (unsigned int t = 0; t < N - 1; t++) {
      fg[0] += 20*CppAD::pow(vars[delta_start + t], 2);
      fg[0] += 20*CppAD::pow(vars[a_start + t], 2);
    }

    // Minimize the value gap between sequential actuations.
    for (unsigned int t = 0; t < N - 2; t++) {
      fg[0] += 300*CppAD::pow(vars[delta_start + t + 1] - vars[delta_start + t], 2);
      fg[0] += 15*CppAD::pow(vars[a_start + t + 1] - vars[a_start + t], 2);
    }

For adding latency, i did the following simple update. I decided to add code for latency only after my car able to go around the lap without going off the circuit.

The update i made for latency is as follows. I used the kinematic equations.

	px = px + v * cos(psi) * dt;
	py = py + v * sin(psi) * dt;
	psi = psi - v * delta / Lf * dt;
	v = v + a * dt;

I also made small modifications as suggested in the projects tips and tricks section to modify the psi update.

These are the snippets were the relevant updates were reflected.

	psi = psi - v * delta / Lf * dt;
	// VVIMP: From Lesson update the sign of the equation below.
	// Refer TIPS and Tricks section
	fg[1 + psi_start + t] = psi1 - (psi0 - v0 * delta0 / Lf * dt);

	// VVIMP: From Lesson update the sign of the equation below.
	// Refer TIPS and Tricks section
	fg[1 + epsi_start + t] = epsi1 - ((psi0 - psides0) - v0 * delta0 / Lf * dt);

carnd-mpc-project's People

Contributors

awbrown90 avatar baumanab avatar domluna avatar ianboyanzhang avatar mvirgo avatar sandeeppaulraj avatar swwelch avatar

Watchers

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