- Convex Optimization
- Linearization and Discretization
- Optimal Control
Before starting the lab, make sure you understand the formulation of the MPC problem from the lecture. We'll briefly go over it again here. The goal of the MPC is to generate valid input controls for
We use a kinematic model of the vehicle. The state space is
Where
Here
First we formulate the objective function of the optimization. We want to minimize three objectives:
- Deviation of the vehicle from the reference trajectory. Final state deviation weighted by Qf, other state deviations weighted by Q.
- Influence of the control inputs. Weighted by R.
- Difference between one control input and the next control input. Weighted by Rd.
We then formulate the constraints for the optimization problem. The constraints should inclue:
- Future vehicle states must follow the linearized vehicle dynamic model.
$$z_{t+1}=Az_t+Bu_t+C$$ - Initial state in the plan for the current horizon must match current vehicle state.
$$z_{0}=z_{\text{curr}}$$ - Inputs generated must be within vehicle limits.
$$a_{\text{min}} \leq a \leq a_{\text{max}}$$ $$\delta_{\text{min}} \leq \delta \leq \delta_{\text{max}}$$
In order to formulate the problem into a Quadratic Programming (QP), we need to first discretize the dynamical system, and also linearize it around some point.
Here we'll use Forward Euler discretization since it's the easiest. Other methods like RK4/6 should also work. We discretize with sampling time
We'll use first order Taylor expansion of the two variable function around some
You can then derive what are matrices
You'll need to create a reference trajectory that has velocity attached to each waypoint that you create. (You can follow instructions from the Pure Pursuit lab to create waypoints). For a smooth velocity profile, you can use the curvature information on the waypoint spline you've created to interpolate between a maximum and a minimum velocity. Make sure the reference has the same states as the vehicle model you've set up in the optimization problem. Please refer to the Pure Pursuit lab for instructions and hints on how to log and visualize waypoints.
In Python, we'll be using CVXPY to set up the optimization problem with the OSQP solver. Most of the problem set up and potential code optimization that speeds up the MPC are already done for you. Your first task is to fill in the objective function and the constraints for the MPC in the function mpc_prob_init()
. The second task is to fill in the pose_callback
. You can find missing parts in the code by searching for TODO
tags. Note that the template of this lab is only available in Python. But if you're comfortable with creating an MPC from scratch in C++, you're welcome to do so but the TAs won't be able to help as much.
It might be helpful to visualize the current selected segment of reference path and the predicted trajectory from MPC to debug.
- Deliverable 1: Commit your mpc package to GitHub. Your commited code should run smoothly in simulation.
- Deliverable 2: Submit a link to a video on YouTube showing the car tracking waypoints with MPC in Levine hallway in simulation.
- Compilation: 10 Points
- Correct objectives and constraints: 50 Points
- Working path tracker: 20 Points
- Video: 20 Points