Giter Club home page Giter Club logo

carnd-mpc-project's Introduction

CarND-Controls-MPC

Self-Driving Car Engineer Nanodegree Program


Background and Purpose

This repository contains my programming model and discussion for the Udacity SDC nanodegree Model Predictive Control (MPC) project. MPC is to use optimization approach to actuate autonomous vehicles following the road lane. It uses a vehicle dynamics model to predict and optimize the future behavior of systems. This implementation was built in C++ and tries to calculate an optimal trajectory for the car simulator to follow around the track.

Model Description

This implementation uses a Kinetic model, which is a simplification of a vehicle model. Model inputs include: vehicle location (x,y), orientation (psi), velocity (v), cross track error (cte), error of psi, as well as acceleration (a) and steering angle (delta). Acceleration and steering angle are used as actuators to propel and guide the car. The update step employs the following equation:



Timestep Length and Elapsed Duration Rationale

I selected the values 10 for N and .1 for dt. This represents the number of time steps (N) and duration of a time-step (dt), and together they define the duration of time where the model can predict the trajectory. The more time steps, the slower the computation is. However, enough time steps is a crucial element to obtain the accuracy of this discrete model.

    //one second into the future
    size_t N = 10;
    double dt = 0.1;
    
    //I also tried
    N = 100
    dt = 0.1
    This results a much slower prediction step and the vehicle in the simulator cannot follow the track.
    
    // and 
    N = 10
    dt = 1
    This combination of time and step parameter consider too far in the fututre, which makes the car drive slowly to minimize all the errors in the predicted track.

Polynomial Fitting and MPC Preprocessing Discussion

At each step, a bit of per-processing was performed on the car's location data (waypoints) before a polynomial was calculated. First the values of x,y,and psi were normalized, in order to simplify the math in the polynomial calculation. Next the x and y vectors had to be cast into VectorXd collection, so they could be used in the provided polynomial method (polyfit()).

     //convert vector double to VectorXd for polyfit function
      Eigen::Map waypoints_x_eig(ptrx, 6);
      Eigen::Map waypoints_y_eig(ptry, 6);

Polyfit() returns the coefficients of a third order polynomial. A 3rd-order polynomial is used to fit the line.

     auto coeffs = polyfit(waypoints_x_eig, waypoints_y_eig, 3);
 

MPC Latency

The purpose of latency in the model is to simulate real world driving conditions where the car does respond to commands instantly, as well as the latency between getting sensor data and processing it. I used the dynamic model of the vehicle to predict the vehicle states after 100ms before feed the states to the solver.

Result

The vehicle could reach 85 mph on the straight track and reduce speed to follow the trach at the sharp turn.

carnd-mpc-project's People

Contributors

awbrown90 avatar baumanab avatar domluna avatar ianboyanzhang avatar owenhua666 avatar swwelch 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.