Self-Driving Car Engineer Nanodegree Program
(Student describes their model in detail. This includes the state, actuators and update equations.)
The kinematic model is the one used in class, with a minor modification.
The states:
- x , the position of the car along the x axis in global coordinates
- y , the position of the car along the y axis in global coordinates
- psi , the counter-clockwise angle of the car around the z axis
- v , the current vehicle speed
- cte , the cross-track error from the desired trajectory
- epsi , the orientation error from the desired orientation, the tangent of the trajectory
The actuator values:
- delta , the steering wheel angle, between -25° and 25°
- a , the throttle and brake pedals, between 1 (full throttle) and -1 (full brake)
The update equations:
The increment of psi needs to be negative to counter the fact that in the simulator, psi and delta have opposite directions.
Cost function members:
- Difference from reference signals (cross-track error, psi error, reference speed)
- Actuator values (steering and throttle)
- Actuator rates (rates of steering and throttle)
All these members had their respective weights to chip in to the sum of cost in a comparable level.
(Student discusses the reasoning behind the chosen N (timestep length) and dt (elapsed duration between timesteps) values. Additionally the student details the previous values tried.)
After trying the values shown in the lessons (N = 25, dt = 0.05), it quickly turns out, that picking a too high N and too low dt makes the calculation overly complicated and thus causing performance problems. It increases the horizon of the cost function too, which means that some features of the trajectory are reckoned with that are not yet relevant.
Based on the walkthrough recommendation, I ended up with the values N = 10 and dt = 0.1, giving a prediction horizon of 1 second. Increasing or decreasing these values did not yield better results, so I left them as they are.
(A polynomial is fitted to waypoints. If the student preprocesses waypoints, the vehicle state, and/or actuators prior to the MPC procedure it is described.)
There is one important preprocessing step that can make our life easier in this project. It is to transform the waypoints from map coordinates to car coordinates. It can easily be done on the batch of received waypoints, and then the polynomial fitting becomes a lot simpler. When using car coordinates, the x, y and psi variables turn into zeros and so the higher cross-track error calculation terms and psi error calculation terms can be eliminated.
See line 99 of main.cpp
(The student implements Model Predictive Control that handles a 100 millisecond latency. Student provides details on how they deal with latency.)
One of the ways latency can be handled is to make a future-forward simulation based on the current state and initialize the MPC solver with the resulting simulated state. We can apply the kinematic motion model to make an estimation of where the car will be at the time our commands get actuated, thus the MPC can explicitly take the 100 millisecond latency into account.
See line 110 of main.cpp
Another advantage of the above explained preprocessing, is that in car coordinates, the motion model calculation simplifies as well, with the coordinate variables being zero.
-
cmake >= 3.5
-
All OSes: click here for installation instructions
-
make >= 4.1(mac, linux), 3.81(Windows)
- 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
-
- 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
- Run either
-
Ipopt and CppAD: Please refer to this document for installation instructions.
-
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
- Run it:
./mpc
.