forked from robotology/whole-body-controllers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
startup_WBC.m.in
92 lines (67 loc) · 2.93 KB
/
startup_WBC.m.in
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
%% startup_WBC.m
%
% Run this script once to permanently add the +wbc library to your MATLAB path.
clc
fprintf('\n## whole-body-controllers ##\n');
fprintf('\nAdding "+wbc" library to your pathdef.m...\n\n');
% path to whole-body-controllers
pathToInstallDir = '@CMAKE_INSTALL_PREFIX@';
% path to the matlab-wbc library
pathToLibrary = [pathToInstallDir, filesep, 'mex'];
pathToSimLib = [pathToInstallDir, filesep, 'mex/+wbc/simulink'];
if exist(pathToLibrary, 'dir')
addpath(pathToLibrary);
else
error('Path to the "+wbc" library not found or not correct.')
end
if exist(pathToSimLib, 'dir')
addpath(pathToSimLib);
else
error('Path to the "+wbc/simulink" library not found or not correct.')
end
% Path to the Matlab userpath
pathToUserpath = userpath;
pathSeparatorLocation = strfind(pathToUserpath, pathsep);
if isempty(pathToUserpath)
answer = input('Empty userpath. Do you want to reset the userpath? Y/N ','s');
if strcmpi(answer,'Y')
userpath('reset');
disp('Resetting userpath..');
pathToUserpath = userpath;
pathSeparatorLocation = strfind(pathToUserpath, pathsep);
else
error('Please set the userpath before running this script');
end
elseif size(pathSeparatorLocation, 2) > 1
answer = input('Multiple userpath. Do you want to reset the userpath? Y/N ','s');
if strcmpi(answer,'Y')
userpath('reset');
disp('Resetting userpath..');
pathToUserpath = userpath;
pathSeparatorLocation = strfind(pathToUserpath, pathsep);
else
error('Please set a single userpath before running this script');
end
end
% check again the userpath
if isempty(pathToUserpath)
error('userpath is still empty. Please set the userpath before running this script');
elseif size(pathSeparatorLocation, 2) > 1
error('There are still multiple userpath. Please set a single userpath before running this script');
end
if (~isempty(pathSeparatorLocation))
pathToUserpath(pathSeparatorLocation) = [];
end
fprintf('Saving paths to %s\n\n', [pathToUserpath, filesep, 'pathdef.m']);
if (~savepath([pathToUserpath, filesep, 'pathdef.m']))
fprintf(['A file called pathdef.m has been created in your %s folder.\n', ...
'This should be enough to permanently add +wbc to ', ...
'your MATLAB installation.\n'], pathToUserpath);
else
disp('There was an error generating the pathdef.m. Please manually add the +wbc folder to your matlabpath');
end
% inform the user that it is possible to generate the goToWholeBodyControllers script
fprintf('\n');
fprintf(['INFO: you may generate a file called goToWholeBodyControllers.m in your %s folder.\n', ...
'This will help to quickly reach the WBC-project folder after Matlab is launched.\n', ...
'To create the file, go to the ''WBC_SOURCE_DIR/config'' and run ''createGoToWBC.m.'' \n'], pathToUserpath);