Skip to content

rdhelli/carnd-t2p4-MPC

 
 

Repository files navigation

CarND-Controls-MPC

Self-Driving Car Engineer Nanodegree Program

Project reflection


1. The Model

(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.


2. Timestep Length and Elapsed Duration (N & dt)

(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.


3. Polynomial Fitting and MPC Preprocessing

(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


4. Model Predictive Control with Latency

(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.


Dependencies

Basic Build Instructions

  1. Clone this repo.
  2. Make a build directory: mkdir build && cd build
  3. Compile: cmake .. && make
  4. Run it: ./mpc.

Packages

No packages published

Languages

  • C++ 83.1%
  • Fortran 11.5%
  • C 2.0%
  • CMake 1.8%
  • Cuda 1.1%
  • Shell 0.2%
  • Other 0.3%