made by CJ
The goal of this program is to navigate a track provided by this simulator.
The solution is made with C++, with the use of IPOPT and CPPAD libraries. It fits a third-degree polynomial dynamically to the given waypoints over a relatively short distance.
- Clone this repo.
- Make a build directory:
mkdir build && cd build
- Compile:
cmake .. && make
- Run it:
./mpc
.
The kinematic model includes the vehicle's:
x
andy
coordinates- orientation angle / heading direction (
psi
) - velocity
- cross-track error (
cte
) and psi error (epsi
)
Lf
is defined as the distance between the car's front and rear wheels.
The actuator outputs are:
- acceleration (
a
) - steering angle (
delta
)
The model combines the state and actuations from the previous timestep to calculate the next state based on the following functions:
The objective is to find the a
and the delta
that minimizes the errors (based on various factors).
The number of points (N
) and the time interval (dt
) define the prediction horizon, which is set to 10 and 0.1 respectively.
This means that the prediction polynomial is fitted to these N
points, every dt
second.
If you increase N
, or decrease dt
, the performance descreases, and the inverse leads to erratic behaviour.
The waypoints are pre-processed by transforming them to the vehicle's perspective. This puts the vehicle's x and y position at the origin (0, 0), and the orientation angle at 0.
A trajectory is then predicted, and a third-degree polynomial is fitted to the transformed waypoints.
The original kinematic equations depend on the previous actuation's timestep. With a delay, these actuations can only be applied another timestep later, so the model is altered to account for this.