Getting started - Windows (for use with Matlab)

Hi :wave:

I am trying to run the ‘minimal_example_ocp’ from the getting started folder using the Matlab interface (Matlab R2022a) on Windows (Windows 10 Education). I managed to install acados via the manual procedure and when trying to run ‘minimal_example_ocp’, the following error message is displayed:

MEX completed successfully.
delete template...
Warning: The following error was caught while executing 'pendulum_mex_solver' class destructor:
Error using cd
Path must be a text scalar.

Error in pendulum_mex_solver/delete (line 64)
            cd(obj.code_gen_dir);

Error in pendulum_mex_solver (line 49)
            make_mex_pendulum();

Error in acados_ocp (line 209)
            obj.t_ocp = mex_solver();

Error in minimal_example_ocp (line 110)
ocp = acados_ocp(ocp_model, ocp_opts, simulink_opts); 
> In pendulum_mex_solver (line 49)
In acados_ocp (line 209)
In minimal_example_ocp (line 110) 
Invalid MEX-file
'F:\MATLAB\external\acados\examples\acados_matlab_octave\getting_started\c_generated_code\acados_mex_create_pendulum.mexw64':
Das angegebene Modul wurde nicht gefunden.

Error in pendulum_mex_solver (line 50)
            obj.C_ocp = acados_mex_create_pendulum();

Error in acados_ocp (line 209)
            obj.t_ocp = mex_solver();

Error in minimal_example_ocp (line 110)
ocp = acados_ocp(ocp_model, ocp_opts, simulink_opts);

obj.code_gen_dir is empty at the point when the error is thrown.

Since casadi was already installed, I changed the casadi directory in acados_env_variables_windows to casadi_dir = fullfile(acados_dir, '..', 'casadi-v3.5.5');.

Thank you very much in advance!
Best
Lukas

Hi Lukas,

I think the cd error is hiding something else.
It seems the cd error is thrown when Matlab tries to delete the solver object, which has not been created successfully.
So, the actual error is this:

Invalid MEX-file
'F:\MATLAB\external\acados\examples\acados_matlab_octave\getting_started\c_generated_code\acados_mex_create_pendulum.mexw64':
Das angegebene Modul wurde nicht gefunden.

Error in pendulum_mex_solver (line 50)
            obj.C_ocp = acados_mex_create_pendulum();

Error in acados_ocp (line 209)
            obj.t_ocp = mex_solver();

Could you check if 'F:\MATLAB\external\acados\examples\acados_matlab_octave\getting_started\c_generated_code\acados_mex_create_pendulum.mexw64
is there?

Hi Jonathan,

thanks for the quick response!
Yes, this file is created while running the script.

And if you run:

acados_mex_create_pendulum();

you just get this invalid Mex file error?

Were there any error before that maybe?

Yes, it’s the same error message.

This is the full command window output:

>> minimal_example_ocp
using acados simulink default options
--------------------------------------------------------------
Structure detection for path cost
Cost function is quadratic -> Reformulating as linear_ls cost.


reformulated cost term in linear least squares form with:
cost = 0.5 * || Vx * x + Vu * u + Vz * z - y_ref ||_W

Vx
     1     0     0     0
     0     1     0     0
     0     0     1     0
     0     0     0     1
     0     0     0     0


Vu
     0
     0
     0
     0
     1


Vz

W
   1.0e+03 *

    2.0000         0         0         0         0
         0    2.0000         0         0         0
         0         0    0.0000         0         0
         0         0         0    0.0000         0
         0         0         0         0    0.0000


y_ref
     0
     0
     0
     0
     0


y (symbolic)
[p, theta, v, dtheta, F]

NOTE: These numerical values can be updated online using the appropriate setters.
--------------------------------------------------------------
--------------------------------------------------------------
Structure detection for terminal cost term
Cost function is quadratic -> Reformulating as linear_ls cost.


reformulated cost term in linear least squares form with:
cost = 0.5 * || Vx * x + Vu * u + Vz * z - y_ref ||_W

Vx
     1     0     0     0
     0     1     0     0
     0     0     1     0
     0     0     0     1


Vu
     0
     0
     0
     0


Vz

W
   1.0e+03 *

    2.0000         0         0         0
         0    2.0000         0         0
         0         0    0.0000         0
         0         0         0    0.0000


y_ref
     0
     0
     0
     0


y (symbolic)
[p, theta, v, dtheta]

NOTE: These numerical values can be updated online using the appropriate setters.
--------------------------------------------------------------

Constraint detection for path constraints.
constraint 1 is reformulated as bound on u.
F
 
compiling F:\MATLAB\external\acados\examples\acados_matlab_octave\..\..\interfaces\acados_matlab_octave\ocp_get_cost.c
Building with 'MinGW64 Compiler (C)'.
MEX completed successfully.
compiling F:\MATLAB\external\acados\examples\acados_matlab_octave\..\..\interfaces\acados_matlab_octave\ocp_get.c
Building with 'MinGW64 Compiler (C)'.
MEX completed successfully.
compiling F:\MATLAB\external\acados\examples\acados_matlab_octave\..\..\interfaces\acados_matlab_octave\ocp_eval_param_sens.c
Building with 'MinGW64 Compiler (C)'.
MEX completed successfully.
acados MEX interface compiled successfully

obj = 

  ocp_nlp_solver_options_json with properties:

                             qp_solver: 'PARTIAL_CONDENSING_HPIPM'
                        hessian_approx: 'GAUSS_NEWTON'
                       integrator_type: 'ERK'
                                    tf: []
                                  Tsim: []
                            time_steps: []
                       nlp_solver_type: 'SQP_RTI'
                  sim_method_num_steps: 1
                 sim_method_num_stages: 2
                sim_method_newton_iter: 3
                 sim_method_newton_tol: 0
                  sim_method_jac_reuse: 0
                   nlp_solver_max_iter: 50
                   nlp_solver_tol_stat: []
                     nlp_solver_tol_eq: []
                   nlp_solver_tol_ineq: []
                   nlp_solver_tol_comp: []
                nlp_solver_step_length: 1
        nlp_solver_warm_start_first_qp: []
                             rti_phase: 0
                      qp_solver_cond_N: []
                    qp_solver_iter_max: []
                    qp_solver_tol_stat: []
                           reg_epsilon: 1.0000e-04
                      qp_solver_tol_eq: []
                    qp_solver_tol_ineq: []
                    qp_solver_tol_comp: []
                  qp_solver_warm_start: []
                           print_level: []
                   initialize_t_slacks: []
                   levenberg_marquardt: []
                     regularize_method: []
                       exact_hess_cost: []
                     exact_hess_constr: []
                        exact_hess_dyn: []
                     ext_cost_num_hess: []
                             alpha_min: []
                       alpha_reduction: []
                         globalization: []
                      collocation_type: 'GAUSS_LEGENDRE'
    line_search_use_sufficient_descent: []
                 globalization_use_SOC: []
                        full_step_dual: []
                eps_sufficient_descent: []
                            hpipm_mode: []
                     qp_solver_ric_alg: []
                qp_solver_cond_ric_alg: []
                 nlp_solver_ext_qp_res: []
                 ext_fun_compile_flags: []
                   cost_discretization: []

Successfully rendered acados templates!
compiling acados_mex_create_pendulum.c
Building with 'MinGW64 Compiler (C)'.
MEX completed successfully.
compiling acados_mex_free_pendulum.c
Building with 'MinGW64 Compiler (C)'.
MEX completed successfully.
compiling acados_mex_solve_pendulum.c
Building with 'MinGW64 Compiler (C)'.
MEX completed successfully.
compiling acados_mex_set_pendulum.c
Building with 'MinGW64 Compiler (C)'.
MEX completed successfully.
delete template...
Warning: The following error was caught while executing 'pendulum_mex_solver' class destructor:
Error using cd
Path must be a text scalar.

Error in pendulum_mex_solver/delete (line 64)
            cd(obj.code_gen_dir);

Error in pendulum_mex_solver (line 49)
            make_mex_pendulum();

Error in acados_ocp (line 209)
            obj.t_ocp = mex_solver();

Error in minimal_example_ocp (line 110)
ocp = acados_ocp(ocp_model, ocp_opts, simulink_opts); 
> In pendulum_mex_solver (line 49)
In acados_ocp (line 209)
In minimal_example_ocp (line 110) 
Invalid MEX-file
'F:\MATLAB\external\acados\examples\acados_matlab_octave\getting_started\c_generated_code\acados_mex_create_pendulum.mexw64':
Das angegebene Modul wurde nicht gefunden.

Error in pendulum_mex_solver (line 50)
            obj.C_ocp = acados_mex_create_pendulum();

Error in acados_ocp (line 209)
            obj.t_ocp = mex_solver();

Error in minimal_example_ocp (line 110)
ocp = acados_ocp(ocp_model, ocp_opts, simulink_opts);
 
>> 

I am sorry, it is really hard to tell what is wrong just from:
Invalid MEX file.
Is the acados directory set properly?
getenv('ACADOS_INSTALL_DIR')

I just re-installed acados and now the minimal example is working :slight_smile:
Thanks again for your support and your quick responses!

Great! I’m glad it works now :sweat_smile: