Skip to content

Latest commit

 

History

History

MPC-Controller

Model Predictive Control

Udacity - Self-Driving Car NanoDegree Build Status

Jun Zhu


Dependencies

uWebSockets == 0.13

# install dependencies for uWebSockets
$ sudo apt-get install libssl-dev libuv1-dev
$ sudo apt-get install zlib1g-dev # may not be required

Follow the instruction.

Eigen >= 3.3.3

$ git clone --branch 3.3.7 https://github.com/eigenteam/eigen-git-mirror.git
$ cd eigen-git-mirror
$ mkdir build && cd build
$ cmake .. && make install

Build and run

Build

  • Linux
$ mkdir build && cd build
$ cmake .. && make
  • Mac
$ mkdir build && cd build
$ cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl/ .. && make

Run

Start the controller by

$ ./mpc

Then, download and run the simulator.

Vehicle model

A kinematic model (ignoring tire forces, gravity and mass) is used to describe the vehicle in the simulator. The units used in this simulator is not self-consistent. For simplicity, let's say the speed is in MPH and the time is in second.

vehicle state is described by (x, y, psi, v), where x, y are the x, y coordinates respectively, psi is the orientation with respect to the x axis and v is the velocity.

vehicle actuator is described by (delta, a), where delta is the steering angle and a is the acceleration/deceleration.

L_f determines the turning rate of the vehicle. The larger the value, the smaller the turning rate! In this project, L_f = 2.67.

|

Prediction

First, the prediction time step should be longer enough to make the system be able to response timely. In the meanwhile, a smaller time step is desired for a higher speed. However, it is found that the fit tends to become mad when making a sharp turn with a smaller time step.

Second, it does not help too much to predict the system evolution in a very long period, which is computationally expensive. But the car will lose control quickly if the total prediction period is too short.

As a compromise, 0.2 s time step and a total period of 1.6 s is being using.

Latency

The latency can be compensated by tracking the vehicle at the time of measurement to the current time.

Output

Run with 100 ms latency

alt text

Run without latency (maximum speed = 110 MPH)

This is for fun!!! The steering is fitted exponentially. Only 3 variables need to be optimized.

alt text

References