Giter Club home page Giter Club logo

model_predictive_control's Introduction

MPC-Controller

Self-Driving Car Engineer Nanodegree Program


Dependencies

Simulator.

  • You can download these from the releases tab.
  • Read the DATA.md for a description of the data sent back from the simulator.

Build Instructions

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

Model Predictive Control

1. The Model

The state variable in the model is constructed as below,

state = [ x
          y
          psi
          v
          cte
          epsi ]

The model used is a Kinematic model neglecting the complex interactions between the tires and the road. The model equations are as follow:

x[t] = x[t-1] + v[t-1] * cos(psi[t-1]) * dt
y[t] = y[t-1] + v[t-1] * sin(psi[t-1]) * dt
psi[t] = psi[t-1] + v[t-1] / Lf * delta[t-1] * dt
v[t] = v[t-1] + a[t-1] * dt
cte[t] = f(x[t-1]) - y[t-1] + v[t-1] * sin(epsi[t-1]) * dt
epsi[t] = psi[t] - psides[t-1] + v[t-1] * delta[t-1] / Lf * dt

where,

  • x, y : Car's position.
  • psi : Car's heading.
  • v : Car's velocity.
  • cte : Cross track error.
  • epsi : Heading error.

In addition to those above, Lf is the distance between the car of mass and the front wheels (this is provided by Udacity's seed project). The other two values are the model output:

  • delta : Steering angle.
  • a : Car's acceleration (throttle).

The objective is to find the steering angle delta and the acceleration a by means of minimizing the value of a cost function which is the combination of several factors:

  • Square sum of cte and epsi. It could be found here.
  • Square sum of the difference actuators to penalize a lot of actuator's actions. It could be found here.
  • Square sum of the difference between two consecutive actuator values to penalize sharp changes. It could be found here.

The weights assigned to each of these factors were tuned manually to obtain a stable and smooth track ride closest to the reference trajectory.

2. Timestep Length and Elapsed Duration (N & dt)

I tried several combinations of N and dt for comparison as shown in the below table,

N dt
25 0.01
10 0.05
10 0.1

The number of points N and the time interval dt determine the prediction horizon. The number of points impacts the controller performance as well. I tried to keep the horizon around the same time the waypoints were on the simulator. With too many points the controller starts to run slower, and some times it went wild very easily. After these trials, I finally picked the last combination which contributes a smoother drive.

3. Polynomial Fitting and MPC Preprocessing

The waypoints provided by the simulator are transformed to the car coordinate system at ./src/main.cpp. Then a 3-order polynomial is fitted to the transformed waypoints. These polynomial coefficients are used to calculate the cte and epsi later on. They are used by the solver as well to create a reference trajectory.

4. Model Predictive Control with Latency

To handle actuator latency, the state values are calculated using the model and the delay interval. These values are used instead of the initial one. The code implementing that could be found at ./src/main.cpp.

model_predictive_control's People

Contributors

zxy9815 avatar

Stargazers

 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.