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,uprev)

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)
  • 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)
source
LinearMPC.correct_state!Method
set_correct_state!(mpcy)

Correct the state estimated based on measurement u. This updates the state of state_observer

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!Method
predict_state!(mpc,u)

Predict the state at the next time step if the control u is applied. This updates the state of state_observer

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_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,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

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