forked from acados/acados
/
check_acados_requirements.m
99 lines (89 loc) · 4.11 KB
/
check_acados_requirements.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
function check_acados_requirements()
% check environment variables
env_run = getenv('ENV_RUN');
if (~strcmp(env_run, 'true'))
error('env.sh has not been sourced! Before executing this example, run: source env.sh');
end
acados_dir = getenv('ACADOS_INSTALL_DIR');
if ~is_casadi_available
% offer to install CasADi
message = ['\nDear acados user, we could not import CasADi',...
',\n which is needed to run the acados Matlab/Octave examples.',...
'\n Press any key to proceed setting up the CasADi automatically.',...
'\n Press "n" or "N" to exit, if you wish to set up CasADi yourself.\n'];
In = input(message,'s');
if strcmpi( In, 'n')
error('Please set up CasADi yourself and try again.');
else
% download CasADi
CasADi_version = '3.5.1';
url = strcat('https://github.com/casadi/casadi/releases/download/',...
CasADi_version, '/');
external_folder = fullfile(acados_dir, 'external');
if ~is_octave
destination = fullfile(external_folder, 'casadi-matlab');
else
filename = strcat('casadi-linux-octave-4.4.1-v', CasADi_version, '.tar.gz');
destination = fullfile(external_folder, 'casadi-octave');
fprintf(['We cannot set up CasADi for octave.\n',...
'Please download\n', [url,filename],...
'\nand unpack it into <acados_root_dir>/external/casadi-octave.']);
error('exiting');
end
if isunix
if verLessThan('matlab', '8.4')
CasADi_version = '3.5.1';
filename = strcat('casadi-linux-matlabR2014a-v', CasADi_version, '.tar.gz');
else % R2014b or later
filename = strcat('casadi-linux-matlabR2014b-v', CasADi_version, '.tar.gz');
end
elseif ispc
if ~verLessThan('matlab', '9.0')
filename = strcat('casadi-windows-matlabR2016a-v', CasADi_version,'.zip');
elseif ~verLessThan('matlab', '8.4')
filename = strcat('casadi-windows-matlabR2014b-v', CasADi_version,'.zip');
elseif ~verLessThan('matlab', '8.3')
filename = strcat('casadi-windows-matlabR2014a-v', CasADi_version,'.zip');
end
elseif ismac
if ~verLessThan('matlab', '8.5')
filename = strcat('casadi-osx-matlabR2015a-v', CasADi_version, '.tar.gz');
elseif ~verLessThan('matlab', '8.4')
filename = strcat('casadi-osx-matlabR2014b-v', CasADi_version, '.tar.gz');
elseif ~verLessThan('matlab', '8.3')
filename = strcat('casadi-osx-matlabR2014a-v', CasADi_version, '.tar.gz');
end
end
try
file = websave(destination, [url,filename]);
[~,~,ending] = fileparts(file);
% unpack
if strcmp(ending, '.zip')
unzip(file, destination)
else
untar(file, destination)
end
addpath(destination)
catch
error(['Sorry, we could not set up CasADi for your system, please try manually\n.',...
'Instructions can be found on https://web.casadi.org/get/\n',...
'We recommend using CasADi version', CasADi_version]);
end
end
if ~is_casadi_available
error(['Sorry, we could not set up CasADi for your system, please try manually\n.',...
'Instructions can be found on https://web.casadi.org/get/\n',...
'We recommend using CasADi version', CasADi_version]);
end
end
end
function got_casadi = is_casadi_available()
got_casadi = 1;
try
% check CasADi availibility
import casadi.*
test = SX.sym('test');
catch e
got_casadi = 0;
end
end