Class method.

do_mpc.simulator.Simulator.set_tvp_fun(self, tvp_fun)

Method to set the function which returns the values of the time-varying parameters. This function must return a CasADi structure which can be obtained with get_tvp_template().

In the do_mpc.model.Model we have defined the following parameters:

a = model.set_variable('_tvp', 'a')

The integrate the ODE or evaluate the discrete dynamics, the simulator needs to obtain the numerical values of these parameters at each timestep. In the most general case, these values can change, which is why a function must be supplied that can be evaluted at each timestep to obtain the current values.

do-mpc requires this function to have a specific return structure which we obtain first by calling:

tvp_template = simulator.get_tvp_template()

The time-varying parameter function can look something like this:

def tvp_fun(t_now):
    tvp_template['a'] = 3
    return tvp_template


which results in constant parameters.


From the perspective of the simulator there is no difference between time-varying parameters and regular parameters. The difference is important only for the MPC controller and MHE estimator. These methods consider a finite sequence of future / past information, e.g. the weather, which can change over time. Parameters, on the other hand, are constant over the entire horizon.


tvp_fun (function) – Function which gives the values of the time-varying parameters

  • assertion – tvp_fun has incorrect return type.
  • assertion – Incorrect output of tvp_fun. Use get_tvp_template to obtain the required structure.


Return type:


This page is auto-generated. Page source is not available on Github.