# set_objective¶

Class method.

do_mpc.controller.MPC.set_objective(self, mterm=None, lterm=None)

Sets the objective of the optimal control problem (OCP). We introduce the following cost function:

$J(x,u,z) = \sum_{k=0}^{N}\left(\underbrace{l(x_k,z_k,u_k,p_k,p_{\text{tv},k})}_{\text{lagrange term}} + \underbrace{\Delta u_k^T R \Delta u_k}_{\text{r-term}}\right) + \underbrace{m(x_{N+1})}_{\text{meyer term}}$

which is applied to the discrete-time model AND the discretized continuous-time model. For discretization we use orthogonal collocation on finite elements . The cost function is evaluated only on the first collocation point of each interval.

set_objective() is used to set the $$l(x_k,z_k,u_k,p_k,p_{\text{tv},k})$$ (lterm) and $$m(x_{N+1})$$ (mterm), where N is the prediction horizon. Please see set_rterm() for the penalization of the control inputs.

Parameters: lterm (CasADi SX or MX) – Stage cost - scalar symbolic expression with respect to _x, _u, _z, _tvp, _p mterm (CasADi SX or MX) – Terminal cost - scalar symbolic expression with respect to _x and _p assertion – mterm must have shape=(1,1) (scalar expression) assertion – lterm must have shape=(1,1) (scalar expression) None None