Class method.

do_mpc.estimator.MHE.set_objective(self, stage_cost, arrival_cost)

Set the stage cost \(l(\cdot)\) and arrival cost \(m(\cdot)\) function for the MHE problem:

\[\begin{split}\underset{ \begin{array}{c} \mathbf{x}_{0:N+1}, \mathbf{u}_{0:N}, p,\\ \mathbf{w}_{0:N}, \mathbf{v}_{0:N} \end{array} }{\mathrm{min}} &m(x_0,\tilde{x}_0, p,\tilde{p}) +\sum_{k=0}^{N-1} l(v_k, w_k, p, p_{\text{tv},k}),\\ &\left.\begin{aligned} \mathrm{s.t.}\quad x_{k+1} &= f(x_k,u_k,z_k,p,p_{\text{tv},k})+ w_k,\\ y_k &= h(x_k,u_k,z_k,p,p_{\text{tv},k}) + v_k, \\ &g(x_k,u_k,z_k,p_k,p_{\text{tv},k}) \leq 0 \end{aligned}\right\} k=0,\dots, N\end{split}\]

Use the class attributes:

  • mhe._w as \(w_k\)
  • mhe._v as \(v_k\)
  • mhe._x_prev as \(\tilde{x}_0\)
  • mhe._x as \(x_0\)
  • mhe._p_est_prev as \(\tilde{p}_0\)
  • mhe._p_est as \(p_0\)

To formulate the objective function and pass the stage cost and arrival cost independently.


The retrieved attributes are symbolic structures, which can be queried with the given variable names, e.g.:

x1 = mhe._x['state_1']

For a vector of all states, use the .cat method as shown in the example below.


# Get variables:
v =

stage_cost = v.T@np.diag(np.array([1,1,1,20,20]))@v

x_0 = mhe._x
x_prev = mhe._x_prev
p_0 = mhe._p_est
p_prev = mhe._p_est_prev

dx = -
dp = -

arrival_cost = 1e-4*dx.T@dx + 1e-4*dp.T@dp

mhe.set_objective(stage_cost, arrival_cost)


Use set_default_objective() as a high-level wrapper for this method, if you want to use the default MHE objective function.

  • stage_cost (CasADi expression) – Stage cost that is added to the MHE objective at each age.
  • arrival_cost (CasADi expression) – Arrival cost that is added to the MHE objective at the initial state.


Return type:


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