Pablitinho / Udacity_Term2_MPC

Model Predictive Control Project

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CarND-Controls-MPC

Self-Driving Car Engineer Nanodegree Program

MPC

Model predictive control is a well know method used in the industry. It is an advanced method of process control that predict the changes of the variables that belong to the system.


Model Description

The used model is the described by the image below:

Model

Figure 1. Kinematic model and cte and steering error of our system.

This model is called "Kinematic model" and it is a simplification of the dynamic model of the car. Where we have the x,y position of the car, the heading of car (psi), velocity (v) the error of the cross-track (cte) and the orientation error (epsi)

The vehicle model is one of the components that we need to modelate the controler. Other component is the trajectory, this component describe the path of the vehicle giving N steps with a delta time (dt).

The prediction of the MPC are the outputs of our system and determinate the steering angle and the Throttle that must be applied to the car in order to minimize the error. This error is determinated by the cost function that we try to minimize by mean of the solver. Finally we have constrains in our system and belong to the max and min value of the output of the system, i.e., steering and throttle.

The figure below illustrate the description of the whole system.

MPC_Model

Figure 2. Full description of the system

Timestep Length and Elapsed Duration (N & dt)

In order to determinate the prediction horizon T = N*dt we must take into account some factors. The first one is that we do not need long values of T due in real world the reaction is done in a short time. The value of the number of time steps N, must be small in our case should have a value in the range of 10-15 with a delta time dt of 0.1. In this case we will have a prediction horizon of 1-1.5 seconds. It is important to remark that the when we increase the number of timesteps the performance of the system decrease drastically.

Polynomial Fitting and MPC Preprocessing

In order to generate the polynomial, it is needed transform from World Coordinate System (WCS) to Vehicle Coordinate System (VCS). This is done by subtracting the vehicle position and rotating according to the heading of the car. Once we have this transformation we can apply the polynomial fitting of 3th degree by mean of the function polyfit().

Due we are working in VCS we have 0º in the heading (psi) and x and y are 0. We must take this into account in order to estimate the prediction of the state (Figure 1).

Model Predictive Control with Latency

In order to simulate a real conditions in a car, a delay of 100 ms is included before sending the JSON message. In this case we simulate a delay in real circumstances with the recieved data and the actuators.

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.

Tips

  1. 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.
  2. 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.
  3. For visualization this C++ matplotlib wrapper could be helpful.)
  4. Tips for setting up your environment are available here
  5. VM Latency: Some students have reported differences in behavior using VM's ostensibly a result of latency. Please let us know if issues arise as a result of a VM environment.

Editor Settings

We've purposefully kept editor configuration files out of this repo in order to keep it as simple and environment agnostic as possible. However, we recommend using the following settings:

  • indent using spaces
  • set tab width to 2 spaces (keeps the matrices in source code aligned)

Code Style

Please (do your best to) stick to Google's C++ style guide.

Project Instructions and Rubric

Note: regardless of the changes you make, your project must be buildable using cmake and make!

More information is only accessible by people who are already enrolled in Term 2 of CarND. If you are enrolled, see the project page for instructions and the project rubric.

Hints!

  • You don't have to follow this directory structure, but if you do, your work will span all of the .cpp files here. Keep an eye out for TODOs.

Call for IDE Profiles Pull Requests

Help your fellow students!

We decided to create Makefiles with cmake to keep this project as platform agnostic as possible. Similarly, we omitted IDE profiles in order to we ensure that students don't feel pressured to use one IDE or another.

However! I'd love to help people get up and running with their IDEs of choice. If you've created a profile for an IDE that you think other students would appreciate, we'd love to have you add the requisite profile files and instructions to ide_profiles/. For example if you wanted to add a VS Code profile, you'd add:

  • /ide_profiles/vscode/.vscode
  • /ide_profiles/vscode/README.md

The README should explain what the profile does, how to take advantage of it, and how to install it.

Frankly, I've never been involved in a project with multiple IDE profiles before. I believe the best way to handle this would be to keep them out of the repo root to avoid clutter. My expectation is that most profiles will include instructions to copy files to a new location to get picked up by the IDE, but that's just a guess.

One last note here: regardless of the IDE used, every submitted project must still be compilable with cmake and make./

How to write a README

A well written README file can enhance your project and portfolio. Develop your abilities to create professional README files by completing this free course.

About

Model Predictive Control Project

License:MIT License


Languages

Language:C++ 82.5%Language:Fortran 11.4%Language:C 2.2%Language:CMake 2.0%Language:Cuda 1.1%Language:Makefile 0.3%Language:Shell 0.2%Language:Ruby 0.1%Language:Python 0.1%Language:JavaScript 0.1%Language:CSS 0.0%