Skip to content

Commit

Permalink
mex: compile_interface is auto, true or false
Browse files Browse the repository at this point in the history
  • Loading branch information
FreyJo committed Oct 3, 2019
1 parent 1701d8e commit 71ad0c8
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 28 deletions.
46 changes: 29 additions & 17 deletions interfaces/acados_matlab_octave/acados_ocp.m
Expand Up @@ -70,30 +70,42 @@
obj.model_struct = detect_cost_type(obj.model_struct, 1);
end

% check if mex interface exists already
if is_octave()
mex_exists = exist( fullfile(obj.opts_struct.output_dir,...
'/ocp_create.mex'), 'file');
else
mex_exists = exist( fullfile(obj.opts_struct.output_dir,...
'/ocp_create.mexa64'), 'file');
end

if mex_exists
% recompile if qpOAES is needed and not linked against in existing interface
recompile_with_qpOASES = false;
if ~isempty(strfind(obj.opts_struct.qp_solver,'qpoases'))
flag_file = fullfile(obj.opts_struct.output_dir, '_compiled_with_qpoases.txt');
recompile_with_qpOASES = ~exist(flag_file, 'file');
% compile mex interface (without model dependency)
if ( strcmp(obj.opts_struct.compile_interface, 'true') )
compile_interface = true;
elseif ( strcmp(obj.opts_struct.compile_interface, 'false') )
compile_interface = false;
elseif ( strcmp(obj.opts_struct.compile_interface, 'auto') )
% check if mex interface exists already
if is_octave()
mex_exists = exist( fullfile(obj.opts_struct.output_dir,...
'/ocp_create.mex'), 'file');
else
mex_exists = exist( fullfile(obj.opts_struct.output_dir,...
'/ocp_create.mexa64'), 'file');
end
% check if mex interface is linked against external libs, like qpOASES,...
if mex_exists
if ~isempty(strfind(obj.opts_struct.qp_solver,'qpoases'))
flag_file = fullfile(obj.opts_struct.output_dir, '_compiled_with_qpoases.txt');
compile_interface = ~exist(flag_file, 'file');
else
compile_interface = false;
end
else
compile_interface = true;
end
else
obj.model_struct.cost_type
error('acados_ocp: field compile_interface is , supported values are: true, false, auto');
end

% compile mex interface (without model dependency)
if ( strcmp(obj.opts_struct.compile_interface, 'true') || ~mex_exists ...
|| recompile_with_qpOASES )
if ( compile_interface )
ocp_compile_interface(obj.opts_struct);
end

% create C object
obj.C_ocp = ocp_create(obj.model_struct, obj.opts_struct);

% generate and compile casadi functions
Expand Down
4 changes: 2 additions & 2 deletions interfaces/acados_matlab_octave/acados_ocp_opts.m
Expand Up @@ -48,7 +48,7 @@
% model stuct
obj.opts_struct = struct;
% default values
obj.opts_struct.compile_interface = 'false';
obj.opts_struct.compile_interface = 'auto'; % auto, true, false
obj.opts_struct.codgen_model = 'true';
obj.opts_struct.param_scheme = 'multiple_shooting_unif_grid';
obj.opts_struct.param_scheme_N = 10;
Expand Down Expand Up @@ -155,7 +155,7 @@
elseif (strcmp(field, 'compile_mex'))
disp(['Option compile_mex is not supported anymore,'...
'please use compile_interface instead or dont set the option.', ...
'note: false will compile the interface, if not compiled already.']);
'options are: true, false, auto.']);
keyboard
else
disp(['acados_ocp_opts: set: wrong field: ', field]);
Expand Down
26 changes: 19 additions & 7 deletions interfaces/acados_matlab_octave/acados_sim.m
Expand Up @@ -62,20 +62,32 @@
end
end

%% compile mex without model dependency
% check if mex interface exists already
if is_octave()
mex_exists = exist( fullfile(obj.opts_struct.output_dir,...
'/sim_create.mex'), 'file');
if strcmp(obj.opts_struct.compile_interface, 'true')
compile_interface = true;
elseif strcmp(obj.opts_struct.compile_interface, 'false')
compile_interface = false;
elseif strcmp(obj.opts_struct.compile_interface, 'auto')
if is_octave()
compile_interface = ~exist( fullfile(obj.opts_struct.output_dir,...
'/sim_create.mex'), 'file');
else
compile_interface = ~exist( fullfile(obj.opts_struct.output_dir,...
'/sim_create.mexa64'), 'file');
end
else
mex_exists = exist( fullfile(obj.opts_struct.output_dir,...
'/sim_create.mexa64'), 'file');
obj.model_struct.cost_type
error('acados_sim: field compile_interface is , supported values are: true, false, auto');
end

% compile mex without model dependency
if (strcmp(obj.opts_struct.compile_interface, 'true') || ~mex_exists)
if ( compile_interface )
sim_compile_interface(obj.opts_struct);
end

sim_check_dims(obj.model_struct);

% create C object
obj.C_sim = sim_create(obj.model_struct, obj.opts_struct);

% generate and compile casadi functions
Expand Down
4 changes: 2 additions & 2 deletions interfaces/acados_matlab_octave/acados_sim_opts.m
Expand Up @@ -46,7 +46,7 @@

function obj = acados_sim_opts()
obj.opts_struct = struct;
obj.opts_struct.compile_interface = 'false';
obj.opts_struct.compile_interface = 'auto'; % auto, true, false
obj.opts_struct.codgen_model = 'true';
obj.opts_struct.method = 'irk';
obj.opts_struct.num_stages = 4;
Expand Down Expand Up @@ -95,7 +95,7 @@
elseif (strcmp(field, 'compile_mex'))
disp(['Option compile_mex is not supported anymore,'...
'please use compile_interface instead or dont set the option.', ...
'note: false will compile the interface, if not compiled already.']);
'options are: true, false, auto.']);
keyboard
else
disp(['acados_sim_opts: set: wrong field: ', field]);
Expand Down

0 comments on commit 71ad0c8

Please sign in to comment.