Code Monkey home page Code Monkey logo

carnd-mpc-project's Introduction

Model Predictive Control

The goal of this project is to track the generated trajectory from the path planning module using model predictive control algorithm to steer and accelerate the vehicle on a simulator track. CppAD and Ipopt packages are used to solve the model predictive control problem.

Output Video Link

Sample Output screenshot of the simulator. alt-txt

Model

Vehicle model used in the project is kinematic bicycle model. The equations for the model are shown below.

alt text

The state [x,y,psi,v,cte,epsi] consist of x-y position, heading angle, cross track error, and error in heading direction respectively. Actuator [delta, a] are steering angle and throttle values with constraints [-25,25] degrees and [-1,1] respectively.

Time step Length and duration

N time step Length and dt time step duration allows to predict till t = Ndt sec ahead with N points. In this project N = 10 and dt = 0.1 were optimal enough for prediction with less computations when compared to N = 25 and dt = 0.05 which had twice the computations for the same time t.

Preprocessing and polynomial fitting

Before polynomial fitting the trajectory waypoints needed to be converted to the vehicles co-ordinate system(refer main.cpp line 120). Velocity is converted to meter/s from miles/h to make sure the units of co-ordinate system match. Third degree polynomial is used to fit transformed waypoints.

Latency

To include the latency effect, the next state of the vehicle for the period of latency is predicted with the current actuator values and used to solve the model predictive control problem (refer main.cpp line 137).

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.

Code Style

Please (do your best to) stick to Google's C++ style guide.

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.