Acados status 1 in MHE example in MATLAB (Pendulum on cart)

Hello Acados community :wave:

I am new to acados and I am working on developing an MHE example in MATLAB on Windows. It is based on the Python Pendulum on cart example which can be found here

For the estimation of states, the example uses the controls as parameters and state noise as controls which are based on the state covariance. The equations can be found inside the model file of MHE.

The OCP is compiled without any errors but does not produce results. It can be seen that acados fails and return status β€˜ 1 ’ after the solve function is called. I am not able to figure out the reason for this failure.

The developed MATLAB code can be found here

There are 2 sets of files (6 in total) in the folder.

  1. Pend_on_cart_example_ocp.m: This is the main simulation file that uses the model function (export_pendulum_ode_model.m) and a function for setup the acados problem for the simulation (setup_sim). It generates the states and the control to solve the OCP. This part of the problem is working fine and generates good results. The state and control outputs are saved to be used for the MHE estimation.

  2. Pend_on_cart_with_noisy_param_MHE.m: This is the main file for the MHE estimation which uses the model (export_mhe_ode_model_with_noisy_param.m) and the estimator is set up in the setup_estimator.m function also called in the main file.

It is here that acados fails and does not generate results after the solve function is called. This is the output obtained from printing the status


iter      res_stat  res_eq    res_ineq      res_comp   qp_stat    qp_iter     alpha

0            NaN      NaN   0.000000e+00  0.000000e+00    0         0        0.000000e+00

The plots from the results are as below:

Looking forward to your support. Thank you!

Hi,

Let me try to give a few hints.
Did you look at the MHE example in matlab, which is located in acados/examples/acados_matlab_octave/lorentz?
I am not sure if I am aware of all minor differences between Matlab and Python interfaces.

One common mistake though, is 0 vs 1 based indexing.
i.e. the indices of the shooting nodes in acados also in the Matlab go from 0 to N.
Thus, the loop here: only sets p and y_sim for the nodes 1 to N-1 and is missing the first and the last one.

acados status 1 means that there is a NaN. More specifically from your stats, one can see that it is in the equality residual evaluation, so the dynamics. Most likely there is a division by zero somewhere in there.

Best,
Jonathan

I fixed the example here.
As I expected first something was initialized by zero by which you divide.
Took me still a while to find it…

Cheers!