direct_data_driven_mpc.lti_data_driven_mpc_controller.LTIDataDrivenMPCController#
- class LTIDataDrivenMPCController[source]#
A class that implements a Data-Driven Model Predictive Control (MPC) controller for Linear Time-Invariant (LTI) systems. This controller can be configured as either a Nominal or a Robust controller. The implementation is based on research by J. Berberich et al., as described in [1].
References
[1] J. Berberich, J. Köhler, M. A. Müller and F. Allgöwer, “Data-Driven Model Predictive Control With Stability and Robustness Guarantees,” in IEEE Transactions on Automatic Control, vol. 66, no. 4, pp. 1702-1717, April 2021, doi: 10.1109/TAC.2020.3000182.
- __init__(n: int, m: int, p: int, u_d: ndarray, y_d: ndarray, L: int, Q: ndarray, R: ndarray, u_s: ndarray, y_s: ndarray, eps_max: float | None = None, lamb_alpha: float | None = None, lamb_sigma: float | None = None, U: ndarray | None = None, c: float | None = None, slack_var_constraint_type: SlackVarConstraintType = SlackVarConstraintType.CONVEX, controller_type: LTIDataDrivenMPCType = LTIDataDrivenMPCType.NOMINAL, n_mpc_step: int = 1, use_terminal_constraints: bool = True)[source]#
Initialize a Direct LTI Data-Driven MPC with specified system model parameters, an initial input-output data trajectory measured from the system, and LTI Data-Driven MPC parameters.
Note
The input data u_d used to excite the system to get the initial output data must be persistently exciting of order (L + 2 * n), as defined in the Data-Driven MPC formulations in [1].
- Parameters:
n (
int) – The estimated order of the system.m (
int) – The number of control inputs.p (
int) – The number of system outputs.u_d (
numpy.ndarray) – A persistently exciting input sequence.y_d (
numpy.ndarray) – The system’s output response to u_d.L (
int) – The prediction horizon length.Q (
numpy.ndarray) – The output weighting matrix for the MPC formulation.R (
numpy.ndarray) – The input weighting matrix for the MPC formulation.u_s (
numpy.ndarray) – The setpoint for control inputs.y_s (
numpy.ndarray) – The setpoint for system outputs.eps_max (
float | None) – The estimated upper bound of the system measurement noise.lamb_alpha (
float | None) – The ridge regularization base weight for alpha. It is scaled by eps_max.lamb_sigma (
float | None) – The ridge regularization weight for sigma.U (
np.ndarray | None) – An array of shape (m, 2) containing the bounds for the m predicted inputs. Each row specifies the [min, max] bounds for a single input. If None, no input bounds are applied. Defaults to None.c (
float | None) – A constant used to define a Convex constraint for the slack variable sigma in a Robust MPC formulation.slack_var_constraint_type (
SlackVarConstraintType) – The constraint type for the slack variable sigma in a Robust MPC formulation.controller_type (
LTIDataDrivenMPCType) – The Data-Driven MPC controller type.n_mpc_step (
int) – The number of consecutive applications of the optimal input for an n-Step Data-Driven MPC Scheme (multi-step). Defaults to 1.use_terminal_constraints (
bool) – If True, include terminal equality constraints in the Data-Driven MPC formulation. If False, the controller will not enforce these constraints.
References
[1] J. Berberich, J. Köhler, M. A. Müller and F. Allgöwer, “Data-Driven Model Predictive Control With Stability and Robustness Guarantees,” in IEEE Transactions on Automatic Control, vol. 66, no. 4, pp. 1702-1717, April 2021, doi: 10.1109/TAC.2020.3000182.
- controller_type: LTIDataDrivenMPCType#
The LTI Data-Driven MPC controller type.
- U: ndarray | None#
An array of shape (m, 2) containing the bounds for the m predicted inputs. Each row specifies the [min, max] bounds for a single input. If None, no input bounds are applied.
- c: float | None#
A constant used to define a Convex constraint for the slack variable sigma in a Robust MPC formulation.
- slack_var_constraint_type: SlackVarConstraintType#
The constraint type for the slack variable sigma in a Robust MPC formulation.
- n_mpc_step: int#
The number of consecutive applications of the optimal input for an n-Step Data-Driven MPC Scheme (multi-step).
- use_terminal_constraints: bool#
Whether the Data-Driven MPC formulation enforces terminal equality constraints.
- update_and_solve_data_driven_mpc() None[source]#
Update the Data-Driven MPC optimization parameters, solve the problem, and store the optimal control input.
This method updates the MPC optimization parameters to incorporate the latest n input-output measurements of the system. It then solves the MPC problem and stores the resulting optimal control input.
References
[1]: See class-level docstring for full reference details.
- get_problem_solve_status() str[source]#
Get the solve status of the optimization problem of the Data-Driven MPC formulation.
- Returns:
str – The status of the optimization problem after attempting to solve it (e.g., “optimal”, “optimal_inaccurate”, “infeasible”, “unbounded”).
- get_optimal_cost_value() float[source]#
Get the cost value corresponding to the solved optimization problem of the Data-Driven MPC formulation.
- Returns:
float – The optimal cost value of the solved MPC optimization problem.
- get_optimal_control_input_at_step(n_step: int = 0) ndarray[source]#
Get the optimal control input from the MPC solution corresponding to a specified time step in the prediction horizon [0, L-1].
- Parameters:
n_step (
int) – The time step of the optimal control input to retrieve. It must be within the range [0, L-1].- Returns:
np.ndarray – An array containing the optimal control input for the specified prediction time step.
Note
This method assumes that the optimal control input from the MPC solution has been stored in the optimal_u attribute.
- Raises:
ValueError – If n_step is not within the range [0, L-1].
- store_input_output_measurement(u_current: ndarray, y_current: ndarray) None[source]#
Store an input-output measurement pair for the current time step in the input-output storage variables.
This method updates the input-output storage variables u_past and y_past by appending the current input-output measurements and removing the oldest measurements located at the first position. This ensures these variables only store the past n measurements, as required for the internal state constraints defined by Equations (3c) (Nominal) and (6b) (Robust) of [1].
- Parameters:
u_current (
numpy.ndarray) – The control input for the current time step, expected to match the dimensions of prior inputs.y_current (
numpy.ndarray) – The measured system output for the current time step, expected to match the dimensions of prior outputs. This output should correspond to the system’s response to u_current, as both represent a trajectory of the system.
- Raises:
ValueError – If u_current or y_current do not match the expected dimensions.
Note
This method modifies the u_past and y_past arrays directly to ensure that only the most recent n measurements are retained.
References
[1]: See class-level docstring for full reference details.
- set_past_input_output_data(u_past: ndarray, y_past: ndarray) None[source]#
Set the storage variables for past input-output measurements.
This method assigns the provided input-output measurements to the arrays storing past input-output measurements, u_past and y_past. It is intended to be used for setting the historical data used in the MPC problem formulation.
- Parameters:
u_past (
numpy.ndarray) – An array containing past control inputs. Expected to have a shape of (n * m, 1), where ‘n’ is the estimated system order and ‘m’ is the dimension of the input.y_past (
numpy.ndarray) – An array containing past measured system outputs. Expected to have a shape of (n * p, 1) where ‘n’ is the estimated system order and ‘p’ is the dimension of the output.
- Raises:
ValueError – If u_past or y_past do not have correct dimensions.
Note
This method sets the values of the u_past and y_past attributes with the provided new historical data.
- set_input_output_setpoints(u_s: ndarray, y_s: ndarray) None[source]#
Set the control and system setpoints of the Data-Driven MPC controller.
- Parameters:
u_s (
numpy.ndarray) – The setpoint for control inputs.y_s (
numpy.ndarray) – The setpoint for system outputs.
- Raises:
ValueError – If u_s or y_s do not have the expected dimensions.
Note
This method sets the values of the u_s and y_s attributes with the provided new setpoints and updates the values of u_s_param and y_s_param to update the data-driven MPC controller setpoint.