Self-Driving Car Engineer Nanodegree Program
This README can also be found in this repo as a PDF (in case the equations don't show properly).
- cmake >= 3.5
- All OSes: click here for installation instructions
- make >= 4.1
- Linux: make is installed by default on most Linux distros
- Mac: install Xcode command line tools to get make
- Windows: Click here for installation instructions
- gcc/g++ >= 5.4
- Linux: gcc / g++ is installed by default on most Linux distros
- Mac: same deal as make - [install Xcode command line tools]((https://developer.apple.com/xcode/features/)
- Windows: recommend using MinGW
- uWebSockets == 0.14, but the master branch will probably work just fine
- Follow the instructions in the uWebSockets README to get setup for your platform. You can download the zip of the appropriate version from the releases page. Here's a link to the v0.14 zip.
- If you have MacOS and have Homebrew installed you can just run the ./install-mac.sh script to install this.
- Ipopt
- Mac:
brew install ipopt --with-openblas
- Linux
- You will need a version of Ipopt 3.12.1 or higher. The version available through
apt-get
is 3.11.x. If you can get that version to work great but if not there's a scriptinstall_ipopt.sh
that will install Ipopt. You just need to download the source from here. - Then call
install_ipopt.sh
with the source directory as the first argument, ex:bash install_ipopt.sh Ipopt-3.12.1
.
- You will need a version of Ipopt 3.12.1 or higher. The version available through
- Windows: TODO. If you can use the Linux subsystem and follow the Linux instructions.
- Mac:
- CppAD
- Mac:
brew install cppad
- Linux
sudo apt-get install cppad
or equivalent. - Windows: TODO. If you can use the Linux subsystem and follow the Linux instructions.
- Mac:
- 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.
- Clone this repo.
- Make a build directory:
mkdir build && cd build
- Compile:
cmake .. && make
- Run it:
./mpc
.
- docker build -t mpcp .
- docker run -p 127.0.0.1:4567:4567 mpcp ./mpc
All the waypoints are transformed from the global reference frame to the vehicle reference frame. The following transform is used for each of the waypoints:
Where
The transformed waypoints are fit to a 3rd order polynomial
$$
f(x_t) = c_0 + c_1x_t + c_2x_t^2 + c_3x_t^3
$$
With
Given that the waypoints are now in the reference frame of the vehicle, the current cross track error
The current orientation error
The state is a 6 element vector with the following elements:
-
$x$ position of vehicle -
$y$ position of vehicle -
$\psi$ - the orientation of the vehicle -
$v$ - speed of the vehicle -
$cte$ - cross track error -
$e \psi$ - orientation error
The actuators are contained in a 2 element vector:
-
$\delta$ - steering angle -
$a$ - acceleration
The following update equations were used:
$$ x_{t+1} = x_t + v_t * cos(\psi_t) * dt\ y_{t+1}= y_t + v_t *sin(\psi_t)*dt\ \psi_{t+1} = \psi_t + \frac{v_t}{L_f} * \delta * dt\ v_{t+1} = v_t + a_t dt\ cte_{t+1} = f(x_t) - y_t + v_t * sin(e\psi_t)dt\ e\psi_{t+1} = \psi_t - \psi des_t + \frac{v_t}{L_f}\delta_tdt\ $$
With the current state being
Given that MPC has a latency of 100ms, I decided to choose a
A demo video of this project can be found on Youtube here.