Functions
LinearMPC.MPCSettings — TypeMPC controller settings.
Fields
reference_condensation::Bool = false: Collapse reference trajectory to setpointreference_tracking::Bool = true: Enable reference trackingreference_preview::Bool = false: Enable time-varying reference previewsoft_weight::Float64 = 1e6: Penalty weight for soft constraint violationssolver_opts::Dict{Symbol,Any}: Additional solver options
LinearMPC.add_constraint! — Methodadd_constraint!(mpc::MPC;
Ax, Au, Ar, Aw, Ad, Aup,
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⁻ₖ 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.certify — Methodcertify(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 — Methodcompute_control(mpc,x;r,uprev)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
uprev- previous control action
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)LinearMPC.condense_reference — Methodcondense_reference(mpc, r)Condense reference trajectory to single setpoint.
LinearMPC.constraint_violation — Methodconstraint_violation(c,xs,us)evaluates the possible violation of constraint c at state x and control u
LinearMPC.correct_state! — Methodset_correct_state!(mpcy)Correct the state estimated based on measurement u. This updates the state of state_observer
LinearMPC.evaluate_cost — Functionevaluate_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 — Methodevaluate_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_reference — Methodformat_reference(mpc, r)Format reference input for MPC controller. Handles both single reference and reference preview scenarios.
LinearMPC.get_reference_preview — Methodget_reference_preview(rs, k, Np)Extract reference preview from reference trajectory starting at time step k.
LinearMPC.get_state — Methodget_state!(mpc)Get the current state of the observer
LinearMPC.move_block! — Methodmove_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 — Methodmpc2mpqp(mpc)For a given MPC structure mpc, form the multi-parametric QP mpQP.
LinearMPC.predict_state! — Methodpredict_state!(mpc,u)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! — Methodset_binary_controls!(mpc,bin_ids)Makes the controls in bin_ids to binary controls
LinearMPC.set_bounds! — Methodset_bounds!(mpc;umin,umax,ymin,umax)Sets the bounds umin ≤ u ≤ umax and ymin ≤ y ≤ umax
LinearMPC.set_disturbance! — Methodset_disturbance!(mpc,wmin,wmax)LinearMPC.set_horizon! — Functionset_horizon!(mpc,Np)Sets the prediction horizon Np
LinearMPC.set_input_bounds! — Methodset_input_bounds!(mpc;umin,umax)Sets the input bounds umin ≤ u ≤ umax
LinearMPC.set_labels! — Methodset_labels!(mpc;x,u,y,d)Sets the name of the states x, controls u, output u, disturbance d
LinearMPC.set_objective! — Methodset_objective!(mpc;Q,R,Rr,S,Qf)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ₖ
A vector is interpreted as a diagonal matrix.
LinearMPC.set_output_bounds! — Methodset_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! — Methodset_prestabilizing_feedback!(mpc,K)Sets the prestabilizing feedback K
LinearMPC.set_prestabilizing_feedback! — Methodset_prestabilizing_feedback!(mpc)Sets the prestabilizing feedback K to the infinte horizon LQR gain`
LinearMPC.set_state! — Methodset_state!(mpc,x)Set the state of state_observer to x
LinearMPC.set_state_observer! — Methodset_state_observer!(mpc;F,G,C,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! — Methodset_terminal_cost!(mpc)Sets the terminal cost Qf to the inifinite horizon LQR cost
LinearMPC.settings! — Methodsettings!(mpc,key1=value1, key2=value2,...)LinearMPC.setup! — Methodsetup!(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 — Methodxdaqp,fval,exitflag,info = solve(mpc,θ)Solve corresponding QP given the parameter θ