-
Notifications
You must be signed in to change notification settings - Fork 449
/
models.m
101 lines (91 loc) · 3.31 KB
/
models.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
100
101
%MODELS Summarise and search available robot models
%
% MODELS() lists keywords associated with each of the models in Robotics Toolbox.
%
% MODELS(QUERY) lists those models that match the keyword QUERY. Case is
% ignored in the comparison.
%
% M = MODELS(QUERY) as above but returns a cell array (Nx1) of the names of the
% M-files that define the models.
%
% Examples::
% models
% models('modified_DH') % all models using modified DH notation
% models('kinova') % all Kinova robot models
% models('6dof') % all 6dof robot models
% models('redundant') % all redundant robot models, >6 DOF
% models('prismatic') % all robots with a prismatic joint
%
% Notes::
% - A model is a file mdl_*.m in the models folder of the RTB directory.
% - The keywords are indicated by a line '% MODEL: ' after the main comment
% block.
%
% Copyright (C) 1993-2017, by Peter I. Corke
%
% This file is part of The Robotics Toolbox for MATLAB (RTB).
%
% RTB is free software: you can redistribute it and/or modify
% it under the terms of the GNU Lesser General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% RTB is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU Lesser General Public License for more details.
%
% You should have received a copy of the GNU Leser General Public License
% along with RTB. If not, see <http://www.gnu.org/licenses/>.
%
% http://www.petercorke.com
function name_ = models(query)
% first find the path to the models
pth = mfilename('fullpath');
pth = fileparts(pth);
pth = fullfile(pth, 'models');
assert(exist(pth, 'dir') > 0, 'RTB:models:nomodel', 'models folder not found');
models = dir(fullfile(pth, 'mdl_*.m'));
info = {};
name = {};
for model=models'
fid = fopen( fullfile(pth, model.name), 'r');
while true
line = fgetl(fid);
if line == -1
break;
end
if (length(line) > 11) && (strcmp(line(1:11), '% Copyright:') == 1)
% an empty line, done with the header block
break;
end
[p,n,e] = fileparts(model.name);
if (length(line) > 8) && (strcmp(line(1:8), '% MODEL:') == 1)
% we have a model description line
line = line(10:end); % trim off the tag
if nargin > 0
% we have a query
if strfind(lower(line), lower(query))
info = [info; [line ' (' n ')' ]];
name = [name; n];
end
else
% no query, report all
info = [info; [line ' (' n ')' ]];
name = [name n];
end
break
end
end
fclose(fid);
end
% optionally return a list of model names
if nargout == 1
name_ = name';
else
% now sort and print the matching models
for i = sort(info)'
fprintf('%s\n', i{1});
end
end
end