All Projects → NikolasEnt → Model-Predictive-Control

NikolasEnt / Model-Predictive-Control

Licence: other
Udacity Self-Driving Car Engineer Nanodegree. Project: Model Predictive Control

Programming Languages

C++
36643 projects - #6 most used programming language
fortran
972 projects
c
50402 projects - #5 most used programming language
CMake
9771 projects
Cuda
1817 projects
shell
77523 projects

Projects that are alternatives of or similar to Model-Predictive-Control

Model-Predictive-Control
C++ implementation of Model Predictive Control(MPC)
Stars: ✭ 51 (+2%)
Mutual labels:  controller, mpc, self-driving-car, control-systems
mpc
A software pipeline using the Model Predictive Control method to drive a car around a virtual track.
Stars: ✭ 119 (+138%)
Mutual labels:  controller, self-driving-car, control-systems
Advanced-Lane-Lines
Udacity Self-Driving Car Engineer Nanodegree. Project: Advanced Lane Finding
Stars: ✭ 52 (+4%)
Mutual labels:  carnd, self-driving-car
Airsim
Open source simulator for autonomous vehicles built on Unreal Engine / Unity, from Microsoft AI & Research
Stars: ✭ 12,528 (+24956%)
Mutual labels:  self-driving-car, control-systems
Algorithms-for-Automated-Driving
Each chapter of this (mini-)book guides you in programming one important software component for automated driving.
Stars: ✭ 153 (+206%)
Mutual labels:  self-driving-car, control-systems
awesome-secure-computation
Awesome list for cryptographic secure computation paper. This repo includes *Lattice*, *DifferentialPrivacy*, *MPC* and also a comprehensive summary for top conferences.
Stars: ✭ 125 (+150%)
Mutual labels:  mpc
DonkeyDrift
Open-source self-driving car based on DonkeyCar and programmable chassis
Stars: ✭ 15 (-70%)
Mutual labels:  self-driving-car
dklb
Expose Kubernetes services and ingresses through EdgeLB.
Stars: ✭ 13 (-74%)
Mutual labels:  controller
RoverController
LoRa/WiFi remote controller for driving my rover
Stars: ✭ 87 (+74%)
Mutual labels:  controller
ParNMPC
A Parallel Optimization Toolkit for Nonlinear Model Predictive Control (NMPC)
Stars: ✭ 173 (+246%)
Mutual labels:  mpc
chpc
CHPC: Cheap Heat Pump Controller
Stars: ✭ 27 (-46%)
Mutual labels:  controller
LiDAR-GTA-V
A plugin for Grand Theft Auto V that generates a labeled LiDAR point cloud from the game environment.
Stars: ✭ 127 (+154%)
Mutual labels:  self-driving-car
Traffic-Sign-CNN
Deep learning network for traffic sign image classification
Stars: ✭ 15 (-70%)
Mutual labels:  self-driving-car
carvel-secretgen-controller
secretgen-controller provides CRDs to specify what secrets need to be on Kubernetes cluster (to be generated or not)
Stars: ✭ 54 (+8%)
Mutual labels:  controller
NeuralNetworkAnalysis.jl
Reachability analysis for closed-loop control systems
Stars: ✭ 37 (-26%)
Mutual labels:  control-systems
whitebox-controller
Extensible generic controller for Kubernetes
Stars: ✭ 34 (-32%)
Mutual labels:  controller
xbox360-controller-manager
Turn OFF your wireless xbox 360 controller on PC and see the battery status of the connected controllers.
Stars: ✭ 38 (-24%)
Mutual labels:  controller
DualSenseWindows UE4
Unreal Engine 4 port of the Windows API for the PS5 DualSense controller created at Ohjurot/DualSense-Windows
Stars: ✭ 25 (-50%)
Mutual labels:  controller
stadiacontroller
Command line application that emulates an Xbox 360 controller from a wired Stadia controller on Windows.
Stars: ✭ 142 (+184%)
Mutual labels:  controller
dig-into-apollo
Apollo notes (Apollo学习笔记) - Apollo learning notes for beginners.
Stars: ✭ 1,786 (+3472%)
Mutual labels:  self-driving-car

CarND Controls MPC

Udacity Self-Driving Car Engineer Nanodegree. Project: Model Predictive Control

This Project is the tenth task of the Udacity Self-Driving Car Nanodegree program. The main goal of the project is to implement in C++ Model Predictive Control to drive the car around the track. The program uses a simple Global Kinematic Model. Parameters were tuned in order to reach maximal speed.

Title animation

Result: YouTube video

The project was created with the Udacity Starter Code and Simulator v1.4.


Model

A simple Kinematic model (ignores tire forces, gravity, mass, etc) was used for the Controller. Some attempts to build more complicated dynamic model were made, but with low success. It is essential to know parameters of the vehicle (such as law of response on the throttle, geometry of the car, drag model, tires properties, etc) to construct a reasonable dynamic model but such parameters are not derectly accessible from provided materials for the project.

Position (x,y), heading (ψ) and velocity (v) form the vehicle state vector:

State: [x,y,ψ,v]

State

There are two actuators. Stearing angle (δ) is the first one, it should be in range [-25,25] deg. For simplicity the throttle and brake represented as a singular actuator (a), with negative values signifying braking and positive values signifying acceleration. It should be in range [-1,1].

Actuators: [δ,a]

The kinematic model can predict the state on the next time step by taking into account the current state and actuators as follows:

Kinematic model

where Lf measures the distance between the front of the vehicle and its center of gravity. The parameter was provided by Udacity.

Errors: cross track error (cte) and ψ error () were used to build the cost function for the MPC. They could be updated on a new time step using the following equations:

Erroers update model

MPC

One of the most important tasks was to tune parameters of the cost function and other parameters for the Model Predictive Controller.

First of all, data about waypoints was transformed into the vehicle space and a 3d order polynomial was fitted to the data. Actual state of the vehicle was "shifted" into the future by 100 ms latency. It helps to reduce negative effects of the latency and increase stability of the controller. The latency was introduced to simulate real delay of a human driver or physical actuators in case of a self driving car. Cross track error and orientation error were calculated, is then they were passed into the MPC routine.

The time horizon (T) was chosen to 2 s after experiments. It was shown that the MPC could drive safely around the track with T = 1 s, but on a slow speed. Higher speed requires more future information to make smart decisions in serial turns. Time step duration (dt) was setted equal to the latancy of the simulation (0.1 s), hense, 20 time steps (N) was used.

The cost function parameters were tuned by try-and-error method. All these parameters are stored in the src/MPC.h file. They were tuned in order to reach maximal speed and agressive race style with use of the whole width of the road and breaking before turns.

Note: To obtain relatively slow, but safe behavior use the following parameters in MPC.h:

#define REF_CTE 0
#define REF_EPSI 0
#define REF_V 40
#define W_CTE 2
#define W_EPSI 20
#define W_V 1
#define W_DELTA 100000
#define W_A 20
#define W_DDELTA 0
#define W_DA 0

Hardware

It was noticed that performance and quality of the controller strongly depend on computational power of your hardware. The MPC involves intense calculations during optimisation, that is why, weak PC can cause some problems due to extra latency. The project was developed and run on an AMD A8-5500 cpu with 16 GB of RAM. Simulator was setted to use 640x480 px resolution and the "Fastest" graphical quality preset. In case of higher resolution or quality of graphics the controller prone to bad behaviour.

Dependencies

The project was build under environment provided by the Udacity Docker container.

  • cmake >= 3.5
  • All OSes: click here for installation instructions
  • make >= 4.1
  • gcc/g++ >= 5.4
  • uWebSockets
    • Run either install-mac.sh or install-ubuntu.sh.
    • If you install from source, checkout to commit e94b6e1, i.e.
      git clone https://github.com/uWebSockets/uWebSockets 
      cd uWebSockets
      git checkout e94b6e1
      
      Some function signatures have changed in v0.14.x. See this PR for more details.
  • 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.
  • 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 script install_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.
    • Windows: TODO. If you can use the Linux subsystem and follow the Linux instructions.
  • CppAD
    • Mac: brew install cppad
    • Linux sudo apt-get install cppad or equivalent.
    • Windows: TODO. If you can use the Linux subsystem and follow the Linux 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.

Content of this repo

  • src/main.cpp the main code for the project includes communication with the Simulator and data preprocessing
  • src/MPC.cpp the MPC implementation
  • src/MPC.h MPC parameters

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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].