Functions

LinearMPC.MPCSettingsType

MPC controller settings.

Fields

  • condensation_weights = zeros(0): weights used in the reference condensation
  • preprocess_mpqp::Bool = true: Run preprocessing of mpqp to merge/remove constraints
  • 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
  • disturbance_preview::Bool = false: Enable time-varying disturbance preview
  • parameter_preview::Bool = false: Enable time-varying generalized-parameter 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, 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)

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

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

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

source
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. can be used as a shorthand alias for Adelta. The same constraints could also be added directly with add_constraint!.

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

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

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. Can be:
    • Vector of length nd for constant disturbance
    • Matrix of size (nd, Np) for disturbance preview (when mpc.settings.disturbance_preview = true)
  • uprev - previous control action
  • p - generalized parameter trajectory. Can be:
    • Vector of length np for a constant parameter across the horizon
    • Matrix of size (np, Np) for time-varying generalized parameters when mpc.settings.parameter_preview = true
    • Nothing (default) for no generalized-parameter contribution

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])
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_disturbanceMethod
format_disturbance(mpc, d)

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

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

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_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 with Ke = I
  • :output_disturbance, using a pure output-bias disturbance model
  • :general, using user-provided Bd and Cd

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.

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