Git Product home page Git Product logo

carnd-term2-p5-mpc-project's Introduction

CarND-Term2-P5-Model-Predictive-Control

Overview

In this project you'll implement model predictive controller to drive the car around the track. You will need to extract the data and calculate the cross track error then compute the appropriate steering angle and acceleration and feed them back to the simulator to drive the vehicle around the track. Besides that, you can also plot your predicted trajectory in front of the vehicle to see how well your model is working. Remember, there is a 100 millisecond latency between actuations commands on top of the connection latency so you will need to handle that latency in your code.
There is a simulator provided by Udacity (Term 2 Simulator Release) which will generate the state and actuator data. And you will be using those data to calculate the cross track error (CTE) then compute the appropriate control inputs then feed them back to the simulator to drive the vehicle.
Here is the link to the orginal repository provided by Udaciy. This repository contains all the code needed to complete the final project for the Model Predictive Control course in Udacity's Self-Driving Car Nanodegree.

Prerequisites/Dependencies

There's an experimental patch for windows in this PR

  • Ipopt and CppAD: Please refer to this document for installation instructions.
  • Eigen. This is already part of the repo so you shouldn't have to worry about it.
  • Simulator. You can download these from the releases tab.
  • Not a dependency but read the DATA.md for a description of the data sent back from the simulator.

Setup Instructions (abbreviated)

  1. Meet the Prerequisites/Dependencies
  2. Intall uWebSocketIO on your system
    2.1 Windows Installation
    2.1.1 Use latest version of Ubuntu Bash 16.04 on Windows 10, here is the step-by-step guide for setting up the utility.
    2.1.2 (Optional) Check your version of Ubuntu Bash here.
  3. Open Ubuntu Bash and clone the project repository
  4. On the command line execute ./install-ubuntu.sh
  5. Build and run your code.
    Tips for setting up your environment can be found here

Project Description

  • main.cpp:Reads in data, calls a function to initialize and run the model predictive controller on steering angle, acceleration pedal and brake. Besides that, it will also handle the 100 millisecond connection latency and retrieve the predicted trajectory from the model predictive controller and propagate the line in front of the vehicle.
  • MPC.cpp: Initializes the model predictive controller, define the cost calculation, set the contraints, process data and return actuator commands and predicted trajectory. Defines FG_eval() and Solve().
  • README.md: Writeup for this project, including setup, running instructions and project rubric addressing.
  • CMakeLists.txt: CMakeLists.txt file that will be used when compiling your code (you do not need to change this file)

Run the project

  • Clone this respository
  • At the top level of the project repository, create a build directory: mkdir build && cd build
  • In /build directory, compile yoru code with cmake .. && make
  • Launch the simulator from Windows
  • Execute the run command for the project ./mpc (Make sure you also run the simulator on the Windows host machine) If you see * * this message, it is working Listening to port 4567 Connected!!!

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.

Project Rubric

1. Compilation

1.1 Your code should compile.

Yes, it does.

2. Implementation

2.1 The Model

Please see my notes/comments/documentation in MPC.cpp.

2.2 Timestep Length and Elapsed Duration (N & dt)

The number of points(N) and the time step (dt) define the prediction horizon.
Larger N will consume more computational time which will affect the controller performance with no doubt.
Smaller N will have less computational time but the model will generate less points which might not suitable for high speed vehicle.
Larger dt will lower the accuracy of the predicition or mislead the prediction horizon.
Smaller dt will have higher solution but it mighy not necessary on a low speed vehicle.
Larger time horizon N * dt will generate a longer predicted path.
Smaller time horizon N * dt will genertate a shorter predicted path.

In conclusion, we will need to balance N and dt value for different purposes/metrics on our vehicle.

Our vehicle is assumed running as 50~80 mph for regular US high way speed limit.
Start with N = 25, dt = 0.05 then tried with different combinations.
Finally, I picked N = 10, dt = 0.1 to have a better result at MPC.cpp Line8-10.

2.3 Polynomial Fitting and MPC Preprocessing

Polynomial fitting was called at main.cpp Line120-124.
Polynomial fitting was implemented at main.cpp Line44-66.
MPC preprocessing was implemented at main.cpp Line104-118.
The model will transform the waypoints from map coordinates to car coordinates before polynomial fitting. main.cpp Line107.

2.4 Model Predictive Control with Latency

The latency was handled at main.cpp Line126-151.
Also, one line changed at main.cpp Line228.

The connectivity has a 100 millisecond latency.
Here, I defined the delay time as 0.1 second and 100 millisecond for different functions use. main.cpp Line129-132.
Then the state vector was initialized with the generated polynomial fitting coefficients. main.cpp Line134-140.
Next, the new state vector will be computed with the delay time. main.cpp Line142-148.
Finally, the new state vector was fed into the mpc.Solve() to get the new control inputs. main.cpp Line157.

3. Simulation

3.1 The vehicle must successfully drive a lap around the track.

Yes, it does. Please see the videos below.

Videos

Video recordings for success cases.
Success case for smooth driving.
Smooth_Driving
Success case for highest speed driving with around 57 mph.
Highest_Speed_Driving

carnd-term2-p5-mpc-project's People

Contributors

domluna avatar jinchaolu avatar baumanab avatar mvirgo avatar ianboyanzhang avatar swwelch avatar awbrown90 avatar

Watchers

James Cloos avatar

Forkers

guoquheweilai

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.