Model predictive control with a linear model, a quadratic cost and bounds on the inputs and the states.
More...
|
| | LinearMPC (uint_t n_states, uint_t n_inputs, uint_t horizon, const QPSettings &settings=QPSettings()) |
| void | set_model (const Matrix &A, const Matrix &B) |
| | A time-invariant model, \(x_{k+1} = A x_k + B u_k\), in discrete time; see discretise().
|
| void | set_model (const std::vector< Matrix > &A, const std::vector< Matrix > &B, const std::vector< Vector > &c={}) |
| | A model that changes along the horizon: N matrices A and B, and N vectors c, or none for c = 0.
|
| void | set_weights (const Matrix &Q, const Matrix &R) |
| | The weights. Without P, it is the Riccati solution of a time-invariant model, or Q.
|
| void | set_weights (const Matrix &Q, const Matrix &R, const Matrix &P) |
| void | set_input_bounds (const Vector &lower, const Vector &upper) |
| | Bounds on each input; \(\pm\infty\) for none.
|
| void | set_state_bounds (const Vector &lower, const Vector &upper, real_t penalty=0.0) |
| | Bounds on each state, at the steps 1 to N.
|
| void | set_reference (const Vector &x_ref, const Vector &u_ref) |
| | The same reference at every step: the state and the input that holds it.
|
| void | set_reference (const std::vector< Vector > &x_ref, const std::vector< Vector > &u_ref) |
| | A reference that changes along the horizon: the states at the steps 1 to N, N of them, and the inputs at the steps 0 to N - 1, N of them.
|
| Vector | solve (const Vector &x0) |
| | Plan from the state x0.
|
| const std::vector< Vector > & | predicted_states () const noexcept |
| const std::vector< Vector > & | predicted_inputs () const noexcept |
| QPStatus | status () const noexcept |
| uint_t | iterations () const noexcept |
| uint_t | horizon () const noexcept |
| uint_t | n_states () const noexcept |
| uint_t | n_inputs () const noexcept |
| const Matrix & | terminal_weight () const noexcept |
Model predictive control with a linear model, a quadratic cost and bounds on the inputs and the states.
At every step it plans the inputs \(u_0, \dots, u_{N-1}\) over a horizon of N steps, from the state now, \(x_0\), that minimise
\[\sum_{k=1}^{N-1} (x_k - r_k)^T Q (x_k - r_k) + (x_N - r_N)^T P (x_N - r_N)
+ \sum_{k=0}^{N-1} (u_k - v_k)^T R (u_k - v_k)
\]
subject to the model \(x_{k+1} = A_k x_k + B_k u_k + c_k\) and the bounds \(u_{min} \le u_k \le u_{max}\) and \(x_{min} \le x_k \le x_{max}\), hard or soft, with r the reference of the states and v that of the inputs. The application uses \(u_0\) and plans again at the next step, from the state then.
The model is time-invariant, set_model(A, B), or changes along the horizon, set_model(As, Bs, cs): a nonlinear model linearised along a reference trajectory, with \(c_k = f(\bar x_k, \bar u_k) - A_k \bar x_k - B_k \bar u_k\). The terminal weight P is by default the solution of the discrete Riccati equation of a time-invariant model, which makes the cost beyond the horizon that of the LQR, and Q otherwise.
The problem is condensed: the states are written in terms of \(x_0\) and the inputs, so the QP has the N m inputs as its variables. maths::optimization::QPSolver solves it, starting from the solution of the step before. A bound of \(\pm\infty\) is no bound. State bounds that the system cannot meet make the QP infeasible: solve() then returns the inputs of the last iteration, and status() says that it did not converge.