MPC

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. Use get_tvp_template() and set_tvp_fun() to create a method to obtain new time-varying parameters at each iteration.
  7. To finalize the class configuration there are two routes. The default approach is to call setup(). For deep customization use the combination of prepare_nlp() and create_nlp(). See graph below for an illustration of the process.

digraph G { graph [fontname = "helvetica"]; rankdir=LR; subgraph cluster_main { node [fontname = "helvetica", shape=box, fontcolor="#404040", color="#707070"]; edge [fontname = "helvetica", color="#707070"]; start [label="Two ways to setup"]; setup [label="setup", href="../api/do_mpc.controller.MPC.setup.html", target="_top", fontname = "Consolas"]; create_nlp [label="create_nlp", href="../api/do_mpc.controller.MPC.create_nlp.html", target="_top", fontname = "Consolas"]; process [label="Modify NLP"]; prepare_nlp [label="prepare_nlp", href="../api/do_mpc.controller.MPC.prepare_nlp.html", target="_top", fontname = "Consolas"]; finish [label="Configured MPC class"] start -> setup, prepare_nlp; prepare_nlp -> process; process -> create_nlp; setup, create_nlp -> finish; color=none; } subgraph cluster_modification { rankdir=TB; node [fontname = "helvetica", shape=box, fontcolor="#404040", color="#707070"]; edge [fontname = "helvetica", color="#707070"]; opt_x [label="opt_x", href="../api/do_mpc.controller.MPC.opt_x.html", target="_top", fontname = "Consolas"]; opt_p [label="opt_p", href="../api/do_mpc.controller.MPC.opt_p.html", target="_top", fontname = "Consolas"]; nlp_cons [label="nlp_cons", href="../api/do_mpc.controller.MPC.nlp_cons.html", target="_top", fontname = "Consolas"]; nlp_obj [label="nlp_obj", href="../api/do_mpc.controller.MPC.nlp_obj.html", target="_top", fontname = "Consolas"]; opt_x -> nlp_cons, nlp_obj; opt_p -> nlp_cons, nlp_obj; label = "Attributes to modify the NLP."; color=black; } nlp_cons -> process; nlp_obj -> process; }

Route to setting up the MPC class.

Warning

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\).

Attributes

MPC.bounds Query and set bounds of the optimization variables.
MPC.nlp_cons Query and modify (symbolically) the NLP constraints.
MPC.nlp_cons_lb Query and modify the lower bounds of the nlp_cons.
MPC.nlp_cons_ub Query and modify the upper bounds of the nlp_cons.
MPC.nlp_obj Query and modify (symbolically) the NLP objective function.
MPC.opt_p Full structure of (symbolic) MPC parameters.
MPC.opt_p_num Full MPC parameter vector.
MPC.opt_x Full structure of (symbolic) MPC optimization variables.
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.

Methods

MPC.create_nlp Create the optimization problem.
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.prepare_nlp Prepare the optimization problem.
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.