Functions

LinearMPC.MPCSettingsType

MPC controller settings.

Fields

  • reference_condensation::Bool = false: Collapse reference trajectory to setpoint
  • reference_tracking::Bool = true: Enable reference tracking
  • reference_preview::Bool = false: Enable time-varying reference preview
  • soft_weight::Float64 = 1e6: Penalty weight for soft constraint violations
  • solver_opts::Dict{Symbol,Any}: Additional solver options
source
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)

  • soft marks if the constraint should be softened (default false)
  • binary marks if either the upper or lower bounds should be enforced with equality (default false)
  • prio marks the relative priority of the constraint (default 0)
source
LinearMPC.certifyMethod
certify(mpc; range, AS0, opts)

Provide certificates on the iteration complexity of DAQP for solving the resulting optimization problems.

  • range is the parameter range over which the certification should be done
  • AS0 is the starting working set in DAQP (defaults to empty)
  • settings the settings used in the certification (see ASCertain.CertSettings())
source
LinearMPC.compute_controlMethod
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 ny for constant reference
    • Matrix of size (ny, Np) for reference preview (when mpc.settings.reference_preview = true)
  • d - measured disturbance
  • uprev - previous control action
  • l - linear cost on control (requires mpc.settings.linear_cost = true). Can be:
    • Vector of length nu for 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

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)
source
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

source
LinearMPC.format_linear_costMethod
format_linear_cost(mpc, l)

Format linear cost input for MPC controller.

Arguments

  • mpc: MPC or ExplicitMPC controller
  • l: 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
source
LinearMPC.format_referenceMethod
format_reference(mpc, r)

Format reference input for MPC controller. Handles both single reference and reference preview scenarios.

source
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 block is an Int, a vector with constant block size is created
source
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

source
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)

source
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.

source
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.

source
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

  • soft marks if the constraint should be softened (default false)
  • binary marks if either the upper or lower bounds should be enforced with equality (default false)
  • prio marks the relative priority of the constraint (default 0)
source
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

source
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.

source
LinearMPC.solveMethod
xdaqp,fval,exitflag,info = solve(mpc,θ)

Solve corresponding QP given the parameter θ

source