Functions
LinearMPC.MPCSettings — Type
MPC 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! — Method
add_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 — 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,l)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 disturbanceuprev- previous control actionl- linear cost on control (requiresmpc.settings.linear_cost = true). Can be:- Vector of length
nufor constant linear cost across horizon - Matrix of size
(nu, Np)for time-varying linear cost (mean computed per move block) - Matrix of size
(nu, Nc)for pre-blocked linear cost - Nothing (default) for no linear cost
- 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)
# With linear cost (requires mpc.settings.linear_cost = true)
u = compute_control(mpc, x; l=[1.0]) # Constant cost
# Time-varying linear cost
l_trajectory = [1.0 0.5 0.0 -0.5 -1.0] # nu × Np matrix
u = compute_control(mpc, x; l=l_trajectory)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_linear_cost — Method
format_linear_cost(mpc, l)Format linear cost input for MPC controller.
Arguments
mpc: MPC or ExplicitMPC controllerl: Linear cost input. Can be:nothing: Returns zero vector- Vector of length
nu: Broadcast across control horizon - Vector of length
nl: Used directly (already blocked) - Matrix of size
(nu, Np): Mean computed over each move block - Matrix of size
(nu, Nc): Used directly
LinearMPC.format_reference — Method
format_reference(mpc, r)Format reference input for MPC controller. Handles both single reference and reference preview scenarios.
LinearMPC.get_linear_cost_preview — Method
get_linear_cost_preview(ls, k, Nc)Extract linear cost preview from linear cost 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,umax)Sets the bounds umin ≤ u ≤ umax and ymin ≤ y ≤ umax
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)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_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_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 θ