GithubHelp home page GithubHelp logo

jasonzhangxz / carnd-mpc-project Goto Github PK

View Code? Open in Web Editor NEW

This project forked from udacity/carnd-mpc-project

0.0 1.0 0.0 63.6 MB

CarND Term 2 Model Predictive Control (MPC) Project

License: MIT License

CMake 1.84% Dockerfile 0.01% Shell 0.19% Ruby 0.12% C++ 83.01% C 2.03% Cuda 1.14% Fortran 11.48% Python 0.08% JavaScript 0.07% CSS 0.05%

carnd-mpc-project's Introduction

CarND-Controls-MPC

Self-Driving Car Engineer Nanodegree Program


Overview

This project is to build a MPC controller and make the vehicle drive successfully around the track without going out of the track.

Implementation

The MPC controller is implemented in ./src/MPC.cpp. It utilizes the IPOPT and CppAD libraries to calculate the optimal trajectory and the corresponding actuation commands i.e. the throttle/brake and steering angle, to minimize the cost function of cross track error, steering angle error and penalization of roughness .

The Model

The MPC model uses a kinematic model without taking into account of the complex road and tire interactions. The model equations are below:

Equations

The model has 6 state variables:

  • x : car's position x
  • y : car's position y
  • psi : car's heading angle
  • v : car's velocity
  • cte : cross track error
  • epsi : heading angle error

*Note:The variable Lf is the length from front to center of gravity, it is given by Udacity sample code.

The model has two outputs:

  • a : acceleration/deceleration value
  • delta: steering angle

The objective is to find the best acceleration/deceleration (a) and steering angle (delta) values to minimize the cost function which includes multiple factors:

  • cross track error and heading angle error
  • penalization of uses of actuations
  • penalization of rapid changes

Timestep Length and Elapsed Duration (N & dt)

Number of points (N) and time interval (dt) together define the prediction horizon. With too many points, the model will become slower easily. However, too less points will not predict a good curve. This project uses the Udacity suggested values: N = 10; dt = 0.1;

Polynomial Fitting and MPC Preprocessing

In this project, the provided waypoints are transformed to the vehicle coordinates first, then fitted a 3rd order polynomial.

Model Predictive Control with Latency

To take care of the actuator latency, this project calculates and uses the delayed states to feed into the MPC solver, instead of using the initial values.

Simulation

Here is a video shows the car successfully drove one lap using the implemented MPC controller: ./videos/mpc.mp4

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. The MPC is recommended to be tested on examples to see if implementation behaves as desired. One possible example is the vehicle offset of a straight line (reference). If the MPC implementation is correct, it tracks the reference line after some timesteps(not too many).
  2. The lake_track_waypoints.csv file has waypoints of the lake track. This could 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

carnd-mpc-project's People

Contributors

awbrown90 avatar baumanab avatar domluna avatar huynguyen avatar ianboyanzhang avatar jasonzhangxz avatar kaixunyao avatar moisesvw avatar mvirgo avatar swwelch avatar tawnkramer 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.