I would like to use the Python auto generated code for a MHE solver directly from C++. As it was stated in MHE using algebraic variables, I was able to solve my problem using the Python interface thanks to the help provided here. However, I couldn’t use the auto generated solver from C++. So, I started from scratch with minimal_example_mhe.py to see if I could achieve that task.
After digging around with the code, I was able to create a CMake project where the
mhe_pendulum_ode_test.cpp file uses the auto generated code to solve the same problem that was solved using Python. One detail that is bugging me is that the errors between the true and the estimated states are a little different from the Python version.
The code is in this repository mhe_acados_cpp. You can try it by doing the following
CMakeLists.txtto fit your acados installation.
- Go to solver/mhe folder and run
python3 minimal_example_mhe.pyto get the auto generated code.
- Go back to the project root, create a build directory and run cmake and make to get an executable
mkdir build cd build cmake .. make ./mhe_acados_cpp
- After runing the executable you should have a text file called
builddirectory that contains the values of the MHE estimated states obtained using C++.
- Go into the
srcdirectory and run
python3 plot_cpp_results.pyto compare.
Could anyone point me if I’m missing something in the C++ code? It took me forever to realize how to set the parameters
p (hint: it was the
Thanks in advance!