yaocptool.mpc package¶
Submodules¶
yaocptool.mpc.mpc module¶
-
class
MPC(plant, solution_method, **kwargs)[source]¶ Bases:
object-
__init__(plant, solution_method, **kwargs)[source]¶ Model Predictive control class. Requires a plant and a solution_method.
Parameters: - plant (Plant|PlantSimulation) –
- solution_method (SolutionMethodsBase) –
- estimator (EstimatorAbstract) –
- default_p (DM) – is a default parameter vector that will be used by the ‘solution_method’
- default_theta (DM) – is a default theta parameter that will be used by the ‘solution_method’
- include_cost_in_state_vector (bool) – Typically the optimal control problem has one extra state than the plant, the dynamic cost state. By setting this variable to True, it automatically include an zero the in state vector obtained from the estimator.
- mean_as_parameter (bool) – The mean estimated by the Estimator as parameter of the OCP. It will be put in the end of parameter vector, before the covariance if covariance_as_parameter=True.
- covariance_as_parameter (bool) – The covariance estimated by the Estimator as parameter of the OCP. It will be put in the end of parameter vector.
- mean_p_indices (list) – If mean_as_parameter=True, mean_p_indices is a list of tuples (pairs), where the first element of the tuple is the index in the mean vector and the second is the index in the p vector.
- cov_p_indices (list) – If covariance_as_parameter=True, cov_p_indices is a list of tuples (pairs), where the first element of the tuple is the index in the vectorized covariance matrix and the second is the index in the p vector.
- state_rearrangement_function (function) – A function that can be used to rearrange the initial condition in cases where the estimated states is not equal to initial condition vector of the OCP. For instance, when the OCP has multiple representations of the system. The provided function has the estimated stated as input and has to return a initial condition vector.
-
get_measurement()[source]¶ Get measurements from the plant. It will return a tuple with the current measurement and the current control
Return type: tuple
-
get_new_control(x_k, u_k, p=None)[source]¶ Use solution_method to obtain new controls
Parameters: - x_k – DM
- u_k – DM
- p –
-
get_states(t_k, y_k, u_k)[source]¶ Get states out of a measurement.
Parameters: - t_k (DM) – time of the measurement
- y_k (DM) – measurements
- u_k (DM) – controls
Returns: DM
-
run(iterations=0)[source]¶ Starts computing control and sending it to the plant.
Parameters: iterations (int) – the number of iterations that the MPC will run. To run it indefinitely use iterations = 0
-
run_fixed_control(u, iterations)[source]¶ Run the plant with a fixed control, can be used for initialization purposes.
Parameters: - u (list|DM|float|int) – control value
- iterations (int) – the number of iterations that the MPC will run.
-
yaocptool.mpc.plant module¶
-
class
PlantSimulation(model, x_0, **kwargs)[source]¶ Bases:
yaocptool.mpc.plant.PlantSimulates a plant using a model.
-
__init__(model, x_0, **kwargs)[source]¶ - Plant which uses a SystemModel.simulate to obtain the measurements.
Parameters: - model (SystemModel) – simulation model
- x_0 (DM) – initial condition
- t_s (DM) – (default: 1) sampling time
- u (DM) – (default: 0) initial control
- y_guess (DM) – initial guess for algebraic variables for simulation
- t_0 (DM) – (default: 0) initial time
- integrator_options (dict) – integrator options
- has_noise (bool) – Turn on/off the process/measurement noise
- r_n (DM) – Measurement noise covariance matrix
- r_v (DM) – Process noise covariance matrix
- noise_seed – Seed for the random number generator used to create noise. Use the same seed for the repeatability in the experiments.
-