class do_mpc.controller.MPC(model)[source]

Model predictive controller.

For general information on model predictive control, please read our background article.

The MPC controller extends the do_mpc.optimizer.Optimizer base class (which is also used for the do_mpc.estimator.MHE estimator).

Use this class to configure and run the MPC controller based on a previously configured do_mpc.model.Model instance.

Configuration and setup:

Configuring and setting up the MPC controller involves the following steps:

  1. Use set_param() to configure the MPC instance.
  2. Set the objective of the control problem with set_objective() and set_rterm()
  3. Set upper and lower bounds with bounds (optional).
  4. Set further (non-linear) constraints with set_nl_cons() (optional).
  5. Use the low-level API (get_p_template() and set_p_fun()) or high level API (set_uncertainty_values()) to create scenarios for robust MPC (optional).
  6. Finally, call setup().


Before running the controller, make sure to supply a valid initial guess for all optimized variables (states, algebraic states and inputs). Simply set the initial values of x0, z0 and u0 and then call set_initial_guess().

To take full control over the initial guess, modify the values of opt_x_num.

During runtime call make_step() with the current state \(x\) to obtain the optimal control input \(u\).


MPC.bounds Query and set bounds of the optimization variables.
MPC.opt_p_num Full MPC parameter vector.
MPC.opt_x_num Full MPC solution and initial guess.
MPC.scaling Query and set scaling of the optimization variables.
MPC.t0 Current time marker of the class.
MPC.terminal_bounds Query and set the terminal bounds for the states.
MPC.u0 Initial input and current iterate.
MPC.x0 Initial state and current iterate.
MPC.z0 Initial algebraic state and current iterate.


MPC.get_p_template Obtain output template for set_p_fun().
MPC.get_tvp_template Obtain output template for set_tvp_fun().
MPC.make_step Main method of the class during runtime.
MPC.reset_history Reset the history of the optimizer.
MPC.set_initial_guess Initial guess for optimization variables.
MPC.set_nl_cons Introduce new constraint to the class.
MPC.set_objective Sets the objective of the optimal control problem (OCP).
MPC.set_p_fun Set function which returns parameters.
MPC.set_param Set the parameters of the MPC class.
MPC.set_rterm Set the penality factor for the inputs.
MPC.set_tvp_fun Set function which returns time-varying parameters.
MPC.set_uncertainty_values Define scenarios for the uncertain parameters.
MPC.setup Setup the MPC class.
MPC.solve Solves the optmization problem.

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