Code Monkey home page Code Monkey logo

mpc_cman's Introduction

MPC_Cman

Submission for Term2 Project 5: Model Predicted Controller

Objective: Implement a Model Predictive Control (MPC) algorithm in C++ to control steering and throttle of a simulated vehicle driving a simulator track of reference waypoints.

Passing the project requires a successful simulator track run and documentation, pls see project rubics: https://review.udacity.com/#!/rubrics/896/view. Boilerplate code provided by Udacity under https://github.com/udacity/CarND-MPC-Project.

Improvements made to:

Implementation

The Model

Detailed description of the used model including state, actuators and update equations.

The MPC uses a global kinematic model (bicycle) to resolve the vehicle state for a prediction horizon. The state is described by 6 dimensions: x- and y-coordinate of vehicle position, vehicle heading psi, vehicle velocity v, cross track error cte as deviation from reference line, and the error in heading epsi. The horizon T is N steps of duration dt. The IPOPT solver uses the initial state and actuators (steering delta and throttle a within specific constraints) returning a vector of control inputs for each time step [delta_1..N a_1..N] that minimize the cost function of the model. Actuations for the next time step are pushed to the vehicle state and the prediction loop is repeated. The model is simplified eg. ignoring tire dynamics.

Image

Timestep Length and Elapsed Duration (N & dt)

Discussion of the reasoning behind the chosen N (timestep length) and dt (elapsed duration between timesteps) values including previous values tried.

N determines the number of steps for which the cost function will be optimized for by the solver. Large N lead to consuming solver calculations impacting MPC performance. dt determines the distance between consequent actuations and large dt result in larger devitations from the reference trajectory. Increasing oscillations indicate thresholds for the specific configuration. Choise is N=8 and dt=0.12s where the vehicle is able to properly navigate the track and resulting in prediction horizon T=~1sec with fixed set of weights and including latency. Thus, models optimizer is looking at a 1sec duration to determine a corrective trajectory. Adjusting N or dt mainly causes erratic behavior, oszillation, soon off track running. Other values tried include 20/0.05, 10/0.10, 6/0.15, 5/0.2, and more.

Polynomial Fitting and MPC Preprocessing

Description of polynomial fitting and preprocessing of waypoints, vehicle state and actuators prior to the MPC procedure.

The reference trajectory is calculated with fitting a 3rd-order polynomial to waypoints returned by the simulator. In advance to the fitting the waypoints are converted to car-coordinate scheme. Waypoints are shifted and rotated. Then cte and epsi are calculated by solving the polynomial at x=0. Thus, the angle of the reference trajectory rests with the x-axis at the origin.

Weights were tuned so that large actuations were penalized but change rates of delta and a still set reactive to curvey road conditions. This helps for smoother steering but a brief tendency to overshoot running high speed. Larger weight on cte caused instability. Orientation error psi was penalized stronger to allow curvey road adaption. Weight of the velocity difference dif v gradually increased until reference velocity of ~90mph achieved. Pls see final weight values:

  • weight cte: 20
  • weight epsi: 3000
  • weight dif v: 1000
  • weight delta: 5000
  • weight a: 500
  • weight delra rate: 500
  • weight a rate: 50

Model Predictive Control with Latency

Details on the 100 millisecond latency handling.

Latency of 100ms is modeled in projecting the x-position of the current state and speed into the future. The x-position with 0.1sec updated and all unchanged state variables are passed to the solver.

Note: Steering angle is flipped (multiplied by -1) to reflect turning conventions of simulator and MPC model. The calculated steer value is normalized and flipped before back-passing to the simulator.

Compilation and Simulation

build instructions: run shell-commands from the project directory

  1. Clone this repo.
  2. Make a build directory: mkdir build && cd build
  3. Compile: cmake .. && make
  4. Run it: ./mpc.
  5. Run and start the MPC simulator (resolution: 600x800, Mode: fantastic)

Environment

mpc_cman's People

Contributors

tochalid avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.