Convert MPC into a QP problem
masterSince osqp-eigen only handles standard Quadratic Programming (QP) problems, users implementing Model Predictive Control (MPC) must manually cast the MPC formulation into a QP form.
An MPC problem involving a linear system tracking a reference state $x_r$ with state/input constraints can be mapped to the standard QP form:
Minimize: $\frac{1}{2} x^T P x + q^T x$ Subject to: $l \leq A_c x \leq u$
Where:
- Hessian ($P$): A diagonal matrix of the cost matrices (e.g., $Q$ and $R$).
- Gradient ($q$): Derived from the reference state $x_r$ and cost matrices.
- Constraint Matrix ($A_c$): Encodes the system dynamics ($x_{k+1} = Ax_k + Bu_k$) and initial state.
- Bounds ($l, u$): Encodes state/input limits and the initial state constraint.
Reference implementations for these conversion functions are available in the repository's example code.
// Reference implementation functions for casting MPC to QP
castMPCToQPHessian(Q, R, mpcWindow, hessian);
castMPCToQPGradient(Q, xRef, mpcWindow, gradient);
castMPCToQPConstraintMatrix(a, b, mpcWindow, linearMatrix);
castMPCToQPConstraintVectors(xMax, xMin, uMax, uMin, x0, mpcWindow, lowerBound, upperBound);