From 74d3e695032eee1973e5473d3d351083c26ede25 Mon Sep 17 00:00:00 2001 From: Jonathan Frey Date: Fri, 5 Mar 2021 10:45:17 +0100 Subject: [PATCH] MEX: fix generic_external_cost example --- interfaces/acados_matlab_octave/acados_ocp.m | 5 ++++- interfaces/acados_matlab_octave/generate_c_code_ext_cost.m | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/interfaces/acados_matlab_octave/acados_ocp.m b/interfaces/acados_matlab_octave/acados_ocp.m index ec5a1c34ef..a892f1ab31 100644 --- a/interfaces/acados_matlab_octave/acados_ocp.m +++ b/interfaces/acados_matlab_octave/acados_ocp.m @@ -90,7 +90,10 @@ elseif (strcmp(obj.model_struct.cost_type, 'nonlinear_ls')) obj.model_struct.cost_expr_y_0 = obj.model_struct.cost_expr_y; elseif (strcmp(obj.model_struct.cost_type, 'ext_cost')) - obj.model_struct.cost_expr_ext_cost_0 = obj.model_struct.cost_expr_ext_cost; + obj.model_struct.ext_fun_type_0 = obj.model_struct.ext_fun_type; + if strcmp(obj.model_struct.ext_fun_type_0, 'casadi') + obj.model_struct.cost_expr_ext_cost_0 = obj.model_struct.cost_expr_ext_cost; + end end if (strcmp(obj.model_struct.cost_type, 'linear_ls')) || (strcmp(obj.model_struct.cost_type, 'nonlinear_ls')) obj.model_struct.cost_W_0 = obj.model_struct.cost_W; diff --git a/interfaces/acados_matlab_octave/generate_c_code_ext_cost.m b/interfaces/acados_matlab_octave/generate_c_code_ext_cost.m index 03d99c1d47..df9402a02b 100644 --- a/interfaces/acados_matlab_octave/generate_c_code_ext_cost.m +++ b/interfaces/acados_matlab_octave/generate_c_code_ext_cost.m @@ -92,7 +92,7 @@ function generate_c_code_ext_cost( model, opts, target_dir ) ext_cost_fun_jac.generate([model_name,'_cost_ext_cost_fun_jac'], casadi_opts); end -if isfield(model, 'cost_expr_ext_cost_0')% && strcmp(model.ext_fun_type_e, 'casadi') +if isfield(model, 'cost_expr_ext_cost_0') && strcmp(model.ext_fun_type_0, 'casadi') ext_cost_0 = model.cost_expr_ext_cost_0; % generate jacobian, hessian [full_hess, grad] = hessian(ext_cost_0, vertcat(u, x));