-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject.m
109 lines (96 loc) · 3.02 KB
/
project.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
clc; clear all; close all;
yumiFrame = [
-1 0 0 1
0 -1 0 0
0 0 1 0
0 0 0 1
];
iiwaFrame = eye(4);
% Cobot models
yumiRBT = loadrobot('abbYuMi');
iiwaRBT = loadrobot('kukaIiwa14');
% Inverse kinematics of cobots
iiwaIK = inverseKinematics('RigidBodyTree', iiwaRBT);
yumiIK = inverseKinematics('RigidBodyTree', yumiRBT);
iiwaDof = 7;
yumiDof = 18;
pCenter = [0.5, 0, 0.2, 0, pi, 0]; % position of center
pPick = [0.9,0.6, 0.2, 0, pi, 0]; %position of pick
pCenterHold = [0.5, 0.2, 0.2, 0, 0, pi/2]; % position of center but from right orientation
pTrans = [0.5, 0.3, 0.4, 0, pi, 0];
piiwaHalf = [0.5, 0, 0.7, 0, pi, 0];
piiwaHome = [0 0 1.306 0 0 0];
yumiPoints = [pTrans;pPick;pTrans;pCenter;pTrans;pPick;pTrans;pCenter;pCenterHold;pCenterHold];
iiwaPoints = [piiwaHome;piiwaHome;piiwaHome;piiwaHome;piiwaHome;piiwaHome;piiwaHome;piiwaHome;piiwaHalf;pCenter];
time = 25;
Ts = 0.001;
weights = ones(1,6);
% yumiTraj.q = [];
% yumiTraj.t = [];
% iiwaTraj.q = [];
% iiwaTraj.t = [];
robots = [yumiRBT; iiwaRBT];
for i = 1:length(robots)
figure(i);
if robots(i) == iiwaRBT
execCobot = iiwaRBT;
execIK = iiwaIK;
execEEName = 'iiwa_link_ee_kuka';
frame = iiwaFrame;
execDof = iiwaDof;
execPoints = iiwaPoints;
sgtitle('iiwa joints');
else
execCobot = yumiRBT;
execIK = yumiIK;
execEEName = 'gripper_r_base';
frame = yumiFrame;
execDof = yumiDof;
execPoints = yumiPoints;
sgtitle('Yumi joints');
end
execHomeConfig = homeConfiguration(execCobot);
prevConfig = execHomeConfig;
nPoints = length(execPoints(:,1));
jointPoints = zeros(execDof,nPoints);
for k = 1:nPoints
x = execPoints(k, :);%x,y,z,phi,theta,psi
posT = eul2tform(x(4:6));
posT(1:3,end) = x(1:3)';
posT = frame*posT;
[config, solInfo] = execIK(execEEName, posT, weights, prevConfig);
prevConfig = config;
jointPoints(:,k) = [config.JointPosition]';
end
for j = 1:execDof
positions = jointPoints(j,:);
tk = getTimeDistrubution(positions, 'eq');
tk = round(tk/Ts)*Ts*time;
points = [
tk
positions
zeros(1, length(positions))
];
if robots(i) == iiwaRBT
subplot(3, 3, j);
iiwaTraj(j) = multiPointImpV(points, Ts);
plot(iiwaTraj(j).t, iiwaTraj(j).q, 'LineWidth', 2);
title(strcat('joint ', num2str(j)));
xlabel('time');
ylabel('rad');
else
yumiTraj(j) = multiPointImpV(points, Ts);
if j >= 10 && j<=16
subplot(3, 3, j-9);
plot(yumiTraj(j).t, yumiTraj(j).q, 'LineWidth', 2);
title(strcat('joint ', num2str(j)));
xlabel('time');
ylabel('rad');
end
end
end
end
yumiTraj(1).q = ones(1, length(yumiTraj(1).q))*pi;
%%
open('projectSimscape.slx');
sim('projectSimscape.slx', time+5);