Functions
LinearMPC.MPCSettings — Type
MPC controller settings.
Fields
condensation_weights = zeros(0): weights used in the reference condensationpreprocess_mpqp::Bool = true: Run preprocessing of mpqp to merge/remove constraintsreference_condensation::Bool = false: Collapse reference trajectory to setpointreference_tracking::Bool = true: Enable reference trackingreference_preview::Bool = false: Enable time-varying reference previewdisturbance_preview::Bool = false: Enable time-varying disturbance previewparameter_preview::Bool = false: Enable time-varying generalized-parameter previewsoft_weight::Float64 = 1e6: Penalty weight for soft constraint violationssolver_opts::Dict{Symbol,Any}: Additional solver options
LinearMPC.add_constraint! — Method
add_constraint!(mpc::MPC;
Ax, Au, Ar, Aw, Ad, Aup, Ap,
ub, lb, ks, soft, binary, prio)
add_constraint!(mpc;Ax,Au,ub,lb,
ks, soft, binary,prio)Adds the constraints lb ≤ Ax xₖ + Au uₖ ≤ ub for the time steps k ∈ ks (additional terms Ar rₖ, Aw wₖ, Ad dₖ, Aup u⁻ₖ, Ap pₖ are possible)
softmarks if the constraint should be softened (default false)binarymarks if either the upper or lower bounds should be enforced with equality (default false)priomarks the relative priority of the constraint (default 0)
LinearMPC.add_ifthenelse_constraint! — Method
add_ifthenelse_constraint!(mpc, z_id, delta_id;
Ax_then, Au_then, c_then, Ax_else, Au_else, c_else,
m_then, M_then, m_else, M_else, ks, prio)Adds a mixed-integer if/then/else relation for an auxiliary input u[z_id].
If u[delta_id] = 1, then u[z_id] = Ax_then*xₖ + Au_then*uₖ + c_then. Otherwise, u[z_id] = Ax_else*xₖ + Au_else*uₖ + c_else.
The m_* and M_* arguments bound the corresponding affine branch values.
LinearMPC.add_ifthenelse_input_constraint! — Method
add_ifthenelse_input_constraint!(mpc, u_id, delta_id;
Ax_then, Au_then, c_then, Ax_else, Au_else, c_else,
m_then, M_then, m_else, M_else, ks, prio)Adds a mixed-integer if/then/else relation for an input u[u_id].
If u[delta_id] = 1, then u[u_id] = Ax_then*xₖ + Au_then*uₖ + c_then. Otherwise, u[u_id] = Ax_else*xₖ + Au_else*uₖ + c_else.
The m_* and M_* arguments bound the corresponding affine branch values.
LinearMPC.add_indicator_constraint! — Method
add_indicator_constraint!(mpc, delta_id;
Ax, Au, c, m, M, ϵ, sense, ks, prio)Adds a big-M indicator relation between a control u[delta_id] and an affine expression in the state and controller inputs. The selected input should already be marked as binary with set_binary_controls!.
With sense = :le, the constraint encodes u[delta_id] = 1 ↔ Ax*xₖ + Au*uₖ + c ≤ 0. With sense = :ge, it encodes u[delta_id] = 1 ↔ Ax*xₖ + Au*uₖ + c ≥ 0.
The scalars m and M are the lower and upper big-M bounds for the affine expression, and ϵ is the strictness margin used in the reverse implication.
LinearMPC.add_logic_constraint! — Method
add_logic_constraint!(mpc; delta_ids, Adelta, ub, lb, ks, prio)Adds inequalities involving only controls that have already been marked as binary with set_binary_controls!.
This is a convenience wrapper for relations of the form lb ≤ Adelta*δₖ ≤ ub. Aδ can be used as a shorthand alias for Adelta. The same constraints could also be added directly with add_constraint!.
LinearMPC.add_product_constraint! — Method
add_product_constraint!(mpc, z_id, delta_id;
Ax, Au, c, m, M, ks, prio)Adds a mixed-integer reformulation of the product u[z_id] = u[delta_id] * (Ax*xₖ + Au*uₖ + c), where u[delta_id] is expected to be one of the controls marked as binary with set_binary_controls!.
The scalars m and M must bound the affine factor over the relevant domain.
LinearMPC.certify — Method
certify(mpc; range, AS0, opts)Provide certificates on the iteration complexity of DAQP for solving the resulting optimization problems.
rangeis the parameter range over which the certification should be doneAS0is the starting working set in DAQP (defaults to empty)settingsthe settings used in the certification (see ASCertain.CertSettings())
LinearMPC.compute_control — Method
compute_control(mpc,x;r,d,uprev,p)For a given MPC mpc and state x, compute the optimal control action.
Optional arguments:
r- reference value. Can be:- Vector of length
nyfor constant reference - Matrix of size
(ny, Np)for reference preview (whenmpc.settings.reference_preview = true)
- Vector of length
d- measured disturbance. Can be:- Vector of length
ndfor constant disturbance - Matrix of size
(nd, Np)for disturbance preview (whenmpc.settings.disturbance_preview = true)
- Vector of length
uprev- previous control actionp- generalized parameter trajectory. Can be:- Vector of length
npfor a constant parameter across the horizon - Matrix of size
(np, Np)for time-varying generalized parameters whenmpc.settings.parameter_preview = true - Nothing (default) for no generalized-parameter contribution
- Vector of length
All arguments default to zero.
Examples
# Standard reference tracking
u = compute_control(mpc, x; r=[1.0, 0.0])
# Reference preview (requires mpc.settings.reference_preview = true)
r_trajectory = [1.0 1.5 2.0 2.0 2.0; # ny × Np matrix
0.0 0.0 0.5 1.0 1.0]
u = compute_control(mpc, x; r=r_trajectory)
# Disturbance preview (requires mpc.settings.disturbance_preview = true)
d_trajectory = [0.0 0.2 0.4 0.4 0.4] # nd × Np matrix
u = compute_control(mpc, x; d=d_trajectory)
# Generalized parameter preview
u = compute_control(mpc, x; p=[0.5, -0.25])
# Generalized parameter preview over the horizon
mpc.settings.parameter_preview = true
u = compute_control(mpc, x; p=[0.5 0.25 0.0 -0.25 -0.5])LinearMPC.condense_reference — Method
condense_reference(mpc, r)Condense reference trajectory to single setpoint.
LinearMPC.constraint_violation — Method
constraint_violation(c,xs,us)evaluates the possible violation of constraint c at state x and control u
LinearMPC.correct_state! — Function
correct_state!(mpc,y,d=nothing)Correct the state estimated based on measurement u. This updates the state of state_observer
LinearMPC.evaluate_cost — Function
evaluate_cost(mpc,xs,us,rs;Q,Rr,S)Compute the cost 0.5 ∑ x'*Q x + u' R u + Δu' Rr Δu + x' S u
LinearMPC.evaluate_cost — Method
evaluate_cost(mpc,sim;Q,Rr,S)Compute the cost 0.5 ∑ x'*Q x + u' R u + Δu' Rr Δu + x' S u
LinearMPC.format_affine_parameters — Method
format_affine_parameters(mpc, p)Format generalized parameter input for MPC controller.
LinearMPC.format_disturbance — Method
format_disturbance(mpc, d)Format disturbance input for MPC controller. Handles both single disturbance and disturbance preview scenarios.
LinearMPC.format_reference — Method
format_reference(mpc, r)Format reference input for MPC controller. Handles both single reference and reference preview scenarios.
LinearMPC.get_disturbance_preview — Method
get_disturbance_preview(ds, k, Np)Extract disturbance preview from disturbance trajectory starting at time step k.
LinearMPC.get_reference_preview — Method
get_reference_preview(rs, k, Np)Extract reference preview from reference trajectory starting at time step k.
LinearMPC.get_state — Method
get_state!(mpc)Get the current state of the observer
LinearMPC.move_block! — Method
move_block!(mpc,block)Reduce the number of controls by keeping it constant in blocks. For example, block=[2,1,3] keeps the control constant for 2 time-steps, 1 time step, and 3 time steps.
- if sum(block) ≠ mpc.Np, the resulting block will be padded or clipped
- if
blockis an Int, a vector with constant block size is created
LinearMPC.mpc2mpqp — Method
mpc2mpqp(mpc)For a given MPC structure mpc, form the multi-parametric QP mpQP.
LinearMPC.predict_state! — Function
predict_state!(mpc,u,d=nothing)Predict the state at the next time step if the control u is applied. This updates the state of state_observer
LinearMPC.set_binary_controls! — Function
set_binary_controls!(mpc,bin_ids, Nc_binary=nothing)Makes the controls in binids to binary controls. Ncbinary is the "binary control horizon" (default = control horizon)
LinearMPC.set_bounds! — Method
set_bounds!(mpc;umin,umax,ymin,ymax)Sets the bounds umin ≤ u ≤ umax and ymin ≤ y ≤ ymax
LinearMPC.set_disturbance! — Method
set_disturbance!(mpc,wmin,wmax)LinearMPC.set_horizon! — Function
set_horizon!(mpc,Np)Sets the prediction horizon Np
LinearMPC.set_input_bounds! — Method
set_input_bounds!(mpc;umin,umax)Sets the input bounds umin ≤ u ≤ umax
LinearMPC.set_labels! — Method
set_labels!(mpc;x,u,y,d)Sets the name of the states x, controls u, output u, disturbance d
LinearMPC.set_objective! — Method
set_objective!(mpc;Q,R,Rr,S,Qf,Ex,ex,Eu,eu)Set the weights in the objective function `xN' C' Qf C xN^T + ∑ (C xₖ - rₖ)' Q (C xₖ - rₖ) + uₖ' R uₖ + Δuₖ' Rr Δuₖ + xₖ' S uₖ + (Ex pₖ + ex)'xₖ + (Eu pₖ + eu)'uₖ
A vector is interpreted as a diagonal matrix.
LinearMPC.set_offset! — Method
set_offset!(mpc;xo,uo,doff,fo,ho)Set bias terms in dynamics and measurements.
Concretely we have that f_offet = fo - F * xo - G * uo - Gd * doff and h_offet = ho - C * xo - Dd * doff, which adds a constant term to the dynamics and measurement function, respectively. Note that if the system is linearized, these offsets are set automatically. If some of the offset are not entered, they are interpreted as zero.
LinearMPC.set_offset_free_observer! — Method
set_offset_free_observer!(mpc; method=:state_disturbance, Q, R, K, Bd, Cd, Kx, Kd, x0, d0, disturbance_labels)Create an offset-free observer/controller pair following the formulations reviewed by Pannocchia (2015). The controller model is augmented with constant disturbance channels, and the observer estimates both the nominal state and the disturbance.
Supported methods are:
:state_disturbance(default), using the equivalent disturbance-model realization from Theorem 9:velocity, using the equivalent disturbance-model realization from Theorem 15 withKe = I:output_disturbance, using a pure output-bias disturbance model:general, using user-providedBdandCd
For :state_disturbance and :velocity, the nominal observer gain K can be provided directly or obtained from the existing steady-state Kalman filter tuning through Q and R.
LinearMPC.set_operating_point! — Method
set_operating_point!(mpc;xo,uo)Sets the operating point to the state xo and control uo and linearize
LinearMPC.set_output_bounds! — Method
set_output_bounds!(mpc;ymin,ymax,
ks, soft, binary,prio)Adds the constraints lb ≤ C x ≤ ub for the time steps k ∈ ks
softmarks if the constraint should be softened (default false)binarymarks if either the upper or lower bounds should be enforced with equality (default false)priomarks the relative priority of the constraint (default 0)
LinearMPC.set_prestabilizing_feedback! — Method
set_prestabilizing_feedback!(mpc,K)Sets the prestabilizing feedback K
LinearMPC.set_prestabilizing_feedback! — Method
set_prestabilizing_feedback!(mpc)Sets the prestabilizing feedback K to the infinte horizon LQR gain`
LinearMPC.set_state! — Method
set_state!(mpc,x)Set the state of state_observer to x
LinearMPC.set_state_observer! — Method
set_state_observer!(mpc;F,G,Gd,C,Dd,Q,R,x0)Creates a steady-state Kalman filter for estimating the sate. If F,G, and C are not provided, the model used in mpc is used in the filter
LinearMPC.set_terminal_cost! — Method
set_terminal_cost!(mpc)Sets the terminal cost Qf to the inifinite horizon LQR cost
LinearMPC.set_x0_uncertainty! — Method
set_x0_uncertainty!(mpc,wmin,wmax)LinearMPC.settings! — Method
settings!(mpc,key1=value1, key2=value2,...)LinearMPC.setup! — Method
setup!(mpc)Sets up the mpc given its current parameters and settings Internally, this means generating an mpQP, and setting up a DAQP workspace.
LinearMPC.solve — Method
xdaqp,fval,exitflag,info = solve(mpc,θ)Solve corresponding QP given the parameter θ