Self-Driving Car Engineer Nanodegree Program
- cmake >= 3.5
- All OSes: click here for installation instructions
- Used version: 3.8.2
- 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
- Used version: 0.6.2 Beta
- uWebSockets
- Run either
install-mac.sh
orinstall-ubuntu.sh
. - If you install from source, checkout to commit
e94b6e1
, i.e.Some function signatures have changed in v0.14.x. See this PR for more details.git clone https://github.com/uWebSockets/uWebSockets cd uWebSockets git checkout e94b6e1
- Windows: Refer to the section "Windows Install Instructions" here
- Run either
- Fortran Compiler
- Mac:
brew install gcc
(might not be required) - Linux:
sudo apt-get install gfortran
. Additionall you have also have to install gcc and g++,sudo apt-get install gcc g++
. Look in this Dockerfile for more info.
- Mac:
- Ipopt
- Mac:
brew install ipopt
- 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 the Ipopt releases page or the Github releases page. - 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: Refer to the structure here
- Mac:
- CppAD
- Mac:
brew install cppad
- Linux
sudo apt-get install cppad
or equivalent. - Windows: Refer to the structure here
- 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.
- Not a dependency but read the DATA.md for a description of the data sent back from the simulator.
- Clone this repo.
- Make a build directory:
mkdir build && cd build
- Compile:
cmake .. && make
OR - Build the project "mpc.vcxproj" using Visual Studio 17 (should work normally using
cmake .. && make
but it did on Windows using the original files in the project directory. I used the files here after asking on forum) - Open the simulator in autonomous mode
- Run mpc.exe
- Exactly as in MPC quiz
- State: state vector consists of the following:
- Position
x
- Position
y
- Orientation angle
psi
- Velocity
v
- Cross-Track Error
cte
- Orientation Error
epsi
- Position
- Actuators: simulator accepts only the following actuators:
- Steering angle
delta
- Throttle, modeled by acceleration
a
- Steering angle
- Update equations:
* 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] + v[t] / Lf * delta[t] * dt
* v_[t+1] = v[t] + a[t] * dt
* cte[t+1] = f(x[t]) - y[t] + v[t] * sin(epsi[t]) * dt
* epsi[t+1] = psi[t] - psides[t] + v[t] * delta[t] / Lf * dt
- Where
dt
is a tuned parameter representing the time between current and next prediction - Where
Lf
is length from front to CoG that has a similar radius - Where
f(x(t))
is the predictedy
value according to the trajectory fitting polynomial - Where
psides
is the atan of the differential off(x(t))
with respect tox
N
(timestep length): was set to 10 according to the helper video- Having a larger
N
is better to predict more points but it consumes longer time for computing actuators (number of parameters to optimize is proportional toN
) - But having a larger
N
may also make the outcomes unpredictable because the optimizer may override controls that decrease cost in the near future to decrease cost in the far future - Other experimented value: 25 (like in MPC quiz)
- Having a larger
dt
(elapsed duration between timesteps): was set to 0.1 according to the helper video- Having a small
dt
is better to predict for more recent times but it increases computations - Having a large
dt
is worse because it makes the systen slower - Other experimented value: 0.05 (like in MPC quiz)
- Having a small
- So, we predict 1s into the future
- We have 6 way points given by the simulator, we fit a 3rd order polynomial as done in the helper video and in all discussions
- Preprocessing is done to convert from map coordinates to vehicle coordinates. This is done on 2 steps: Translate to car coordinate system then rotate to the car's orientation
x = ptsx[i] - px;
x = ptsx[i] - px;
ptsx[i] = (x * cos(psi) + y * sin(psi));
ptsy[i] = (-x * sin(psi) + y * cos(psi));
- Consequently,
x
,y
, andpsi
are always 0 in the state vector passed to MPC solver
- To account for 100ms latency between prediction and applying of controls, the idea in main.cpp is to provide the model with predicted outputs after 100ms
- Honestly on my machine it did not work. I posted this on forum, applied all the known solutions to me but nothing worked. I also got some code on Github from students that completed the project and also did not work on my laptop. I think my laptop may be the reason because it is extremely slow.
- 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.
- 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. - For visualization this C++ matplotlib wrapper could be helpful.