Variable `nz_total` not found in context while rendering

Hi all!

I’m compiling my MPC with the newer version of Acados, but I run into this error:

Error using render_file
rendering acados_solver_sfun.in.c failed.
 command: C:\Users\samue\acados\bin\t_renderer.exe "C:\Users\samue\acados\interfaces\acados_template\acados_template\c_templates_tera\matlab_templates\**\*" "acados_solver_sfun.in.c"
 "C:\Users\samue\Documents\Ferrari\Matlab\Linear_MPC_with_Slacks\acados_ocp_nlp.json" "acados_solver_sfunction_mixed_dynamics_with_slacks.c"
 returned status 1, got result:
Error: Failed to render 'acados_solver_sfun.in.c'
Reason: Variable `nz_total` not found in context while rendering 'acados_solver_sfun.in.c'

Error in AcadosOcp/render_templates (line 953)
                render_file( in_file, out_file, json_fullfile )

Error in AcadosOcpSolver (line 65)
            ocp.render_templates()

Error in Linear_MPC_FULLM_mixed_dynamics_StbdExtension (line 644)
ocp_solver = AcadosOcpSolver(ocp);

I have no idea how to solve this issue. Any suggestion?

Thanks

Samuele

Hi,
found the issue:
in the file “acados_solver_sfun.in.c” :

  {%- if simulink_opts.outputs.ztraj == 1 %}
    {%- set i_output = i_output + 1 %}
    ssSetOutputPortVectorDimension(S, {{ i_output }}, {{ nz_total }} );
  {%- endif %}

It uses the variable “nz_total” if the setting “simulink_opts.outputs.ztraj == 1”, but nz_total is not properly defined in the case this condition is true:

{% if problem_class == "OCP" %}

which was my case.

Setting “simulink_opts.outputs.ztraj = 0” solved the problem, but I think a bugfix is needed

Thanks

Samuele

Hi Samuele,

Thanks for reporting this!
I pushed a bugfix here:

Best,
Jonathan