-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathRobotCADFromSTL.m
119 lines (101 loc) · 2.88 KB
/
RobotCADFromSTL.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
% This file provides an example on how to get .mat robot model from .stl
% file. 'filename' should be changed to the path to your stl files. Kinova
% robots use a different reference frame from Fanuc robot. Specifically,
% the Kinova robots' reference frame located at the latter joint. And the
% Fanuc robot's reference frame located at the former joint. To shift the
% reference frame from latter joint to former joint. We need to modify the
% original reference frame for each components first. Then we should
% calculate a new set of D-H parameters based on the modified reference
% frames.
%
% Function 'stlread' is available at
% https://www.mathworks.com/matlabcentral/fileexchange/29906-binary-stl-file-reader
base={};link={};
prefix=pwd;
filename=[prefix,'/meshes/base_link.STL'];
[v, f, n, c, stltitle]=stlread(filename);
base{1}.v = v;
base{1}.f = f;
base{1}.n = n;
base{1}.c = c;
base{1}.color = 'w';
i = 1;
filename=[prefix,'/meshes/shoulder_link.STL'];
[v, f, n, c, stltitle]=stlread(filename);
link{i}.v = v;
link{i}.f = f;
link{i}.n = n;
link{i}.c = c;
link{i}.color = 'w';
for j=1:size(v,1)
link{i}.v(j,:) = link{i}.v(j,:) + [0,0,0.1284];
end
for j=1:size(v,1)
link{i}.v(j,:) = link{i}.v(j,[1,3,2]);
link{i}.v(j,2) = link{i}.v(j,2);
link{i}.v(j,3) = -link{i}.v(j,3);
end
i = 2;
filename=[prefix,'/meshes/half_arm_1_link.STL'];
[v, f, n, c, stltitle]=stlread(filename);
link{i}.v = v;
link{i}.f = f;
link{i}.n = n;
link{i}.c = c;
link{i}.color = 'w';
for j=1:size(v,1)
link{i}.v(j,1) = -link{i}.v(j,1);
link{i}.v(j,3) = -link{i}.v(j,3);
link{i}.v(j,:) = link{i}.v(j,[1,3,2]);
end
i = 3;
filename=[prefix,'/meshes/half_arm_2_link.STL'];
[v, f, n, c, stltitle]=stlread(filename);
link{i}.v = v;
link{i}.f = f;
link{i}.n = n;
link{i}.c = c;
link{i}.color = 'w';
for j=1:size(v,1)
link{i}.v(j,2) = -link{i}.v(j,2);
link{i}.v(j,:) = link{i}.v(j,[1,3,2]);
link{i}.v(j,:) = link{i}.v(j,:) + [0, 0.2104, -0.0064];
end
i = 4;
filename=[prefix,'/meshes/forearm_link.STL'];
[v, f, n, c, stltitle]=stlread(filename);
link{i}.v = v;
link{i}.f = f;
link{i}.n = n;
link{i}.c = c;
link{i}.color = 'w';
for j=1:size(v,1)
link{i}.v(j,:) = link{i}.v(j,[1,3,2]);
end
i = 5;
filename=[prefix,'/meshes/spherical_wrist_2_link.STL'];
[v, f, n, c, stltitle]=stlread(filename);
link{i}.v = v;
link{i}.f = f;
link{i}.n = n;
link{i}.c = c;
link{i}.color = 'w';
for j=1:size(v,1)
link{i}.v(j,3) = -link{i}.v(j,3);
link{i}.v(j,2) = -link{i}.v(j,2);
link{i}.v(j,:) = link{i}.v(j,:) + [0, 0, -0.0064];
end
i = 6;
filename=[prefix,'/meshes/spherical_wrist_1_link.STL'];
[v, f, n, c, stltitle]=stlread(filename);
link{i}.v = v;
link{i}.f = f;
link{i}.n = n;
link{i}.c = c;
link{i}.color = 'w';
for j=1:size(v,1)
link{i}.v(j,3) = -link{i}.v(j,3);
link{i}.v(j,2) = -link{i}.v(j,2);
link{i}.v(j,:) = link{i}.v(j,:) + [0, 0, -0.1059];
end
save('figure/KinovaGen3.mat', 'base','link')