コード例 #1
0
def make_custom_mpc_model(state_space_model, prediction_horizon,
                          control_horizon):
    """
    Make the MPC model for the Euler state space model. This function exposes the interface
    to the MPC class instance, so it is easy to see what is being passed as the arguments from the state
    space model. Furthermore, the control and prediction horizon is also added.
    :param state_space_model: Euler model state space model.
    :param prediction_horizon: Length of the prediction horizon.
    :param control_horizon: Length of the control horizon
    :return: Augmented state space model dictionary with the state space model as a new entry.
    """

    num_states = state_space_model["num_states"]

    ref = set_custom_model_ref(prediction_horizon, num_states)

    mpc_model = mpco.MpcObj(state_space_model["system_model"],
                            state_space_model["B_matrix"], control_horizon,
                            prediction_horizon, state_space_model["Q"],
                            state_space_model["R"], state_space_model["x0"],
                            state_space_model["u0"], ref,
                            state_space_model["b_disturbance"],
                            state_space_model["disturbance_array"])

    state_space_model["mpc_model"] = mpc_model

    return state_space_model
コード例 #2
0
def make_euler_mpc_model(state_space_model, prediction_horizon,
                         control_horizon):
    """
    Make the MPC model for the Euler state space model. This function exposes the interface
    to the MPC class instance, so it is easy to see what is being passed as the arguments from the state
    space model. Furthermore, the control and prediction horizon is also added.
    :param state_space_model: Euler model state space model.
    :param prediction_horizon: Length of the prediction horizon.
    :param control_horizon: Length of the control horizon
    :return: Augmented state space model dictionary with the state space model as a new entry.
    """

    num_states = state_space_model["num_states"]

    ref = set_euler_ref(prediction_horizon, num_states)

    mpc_model = mpco.MpcObj(
        state_space_model["system_model"],
        state_space_model["b_matrix"],
        control_horizon,
        prediction_horizon,
        state_space_model["Q"],
        state_space_model["R"],
        input_cost=state_space_model["S"],
        initial_control_signal=state_space_model["u0"],
        ref=ref,
        operating_point=state_space_model["operating_point"],
        input_matrix_d=state_space_model["b_disturbance"],
        lower_bounds_input=state_space_model["lower_bounds_input"],
        lower_bounds_slew_rate=state_space_model["lower_bounds_slew_rate"],
        lower_bounds_states=state_space_model["lower_bounds_states"],
        upper_bounds_input=state_space_model["upper_bounds_input"],
        upper_bounds_slew_rate=state_space_model["upper_bounds_slew_rate"],
        upper_bounds_states=state_space_model["upper_bounds_states"])

    state_space_model["mpc_model"] = mpc_model

    return state_space_model
コード例 #3
0
import casadi as ca
from controller import mpc, mpco
import numpy as np

A = ca.DM([[1, 0], [0, 1.5]])
B = ca.DM([[0.1, 0], [0, 0.5]])
Hp = 40
Hu = 30

Q = ca.DM([[1, 0], [0, 3]])
Qb = mpc.blockdiag(Q, Hp)

R = ca.DM([[1, 0], [0, 2]])
Rb = mpc.blockdiag(R, Hu)
x0 = ca.DM([[10], [11]])
u_prev = ca.DM([-1, -3])
ref = ca.DM.ones(Hp * 2, 1)
ref[1::A.size1()] = np.cumsum(ref[1::A.size1()]) / 20 + 2

mmpc = mpco.MpcObj(A, B, Hu, Hp, Q, R, x0, u_prev, ref)

for i in range(0, 10):
    input("press key")
コード例 #4
0
ファイル: Demo.py プロジェクト: dmicha16/waterlab_mpc
lower_bounds_slew_rate = None
lower_bounds_states = None
upper_bounds_input = None
upper_bounds_slew_rate = None
upper_bounds_states = None
#lower_bounds_states = operating_point -100

mmpc = mpco.MpcObj(Ap,
                   Bp,
                   Hu,
                   Hp,
                   Q,
                   R,
                   ref=ref,
                   initial_control_signal=u0,
                   input_matrix_d=Bp_d,
                   lower_bounds_input=lower_bounds_input,
                   lower_bounds_slew_rate=lower_bounds_slew_rate,
                   upper_bounds_slew_rate=upper_bounds_slew_rate,
                   upper_bounds_input=upper_bounds_input,
                   lower_bounds_states=lower_bounds_states,
                   upper_bounds_states=upper_bounds_states,
                   operating_point=operating_point,
                   input_cost=S,
                   input_linear_cost=L)
mmpc.step(x0, u0, ref, initial_disturbance, dist)

mmpc.plot_progress({'drawU': 'U'})
mmpc.print_solver()
mmpc.print_result()
steps = 100