-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinv_kin_iiwa_del_qSNS.m
117 lines (92 loc) · 2.34 KB
/
inv_kin_iiwa_del_qSNS.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
function [ qSNS ] = inv_kin_iiwa_del_qSNS( q, eps, qN )
%inv_kin_iiwa_del_qSNS cal delta q for inv_kin_iiwa
% Calculated delta q by SNS algorithm
if nargin==2
qN=[0 0 0 0 0 0 0];
end
% kuka params
eye_vec=[170 130 170 130 170 130 175];
Qmin=(-pi*eye_vec/180 - q)/0.1;
Qmax=(pi*eye_vec/180 - q)/0.1;
speed=[85 85 100 75 130 135 135]*pi/180;
% speed=0.2;
for i=1:7
Qmin(i)=max(Qmin(i),-speed(i));
Qmax(i)=min(Qmax(i),speed(i));
end
Qmin=round(Qmin,5);
Qmax=round(Qmax,5);
W=eye(7);
s=1;
s2=0;
Smin=[0 0 0 0 0 0 0];
Smax=[0 0 0 0 0 0 0];
J=jac_iiwa2(q);
JW=J*W;
limit_exceeded=true;
while limit_exceeded
limit_exceeded=false;
J2=pinv(JW);
qSNS=qN'+J2*(s*eps'-J*qN');
condition_variable=false;
for i=1:7
if qSNS(i)<Qmin(i)||qSNS(i)>Qmax(i)
condition_variable=true;
break;
end
end
if condition_variable
limit_exceeded=true;
a=J2*eps';
b=qSNS-a;
for c=1:7
if W(c,c)~=0
Smin(c)=-1;
Smax(c)=1;
else
Smin(c)=(Qmin(c)-b(c))/a(c);
Smax(c)=(Qmax(c)-b(c))/a(c);
if Smin(c)>Smax(c)
swap_variable=Smin(c);
Smin(c)=Smax(c);
Smax(c)=swap_variable;
end
end
end
smax_=min(Smax);
smin_=max(Smin);
for i=1:7
if smax_==Smax(i); j=i; end
end
if smin_>smax_ || smax_<0 || smin_>1
task_scaling=0;
else
task_scaling=min([smax_,1]);
end
if task_scaling>=s2
s2=task_scaling;
W2=W;
qN2=qN;
end
% max_j=0;
% for i=1:7
% if round(qSNS(i),5)~=0
% if max_j<(qSNS(i))^2 && (W(i,i)~=0)
% max_j=(qSNS(i))^2; j=i;
% end
% end
% end
% j=most critical join;
W(j,j)=0;
if qSNS(j)>Qmax(j); qN(j)=Qmax(j); end
if qSNS(j)<Qmin(j); qN(j)=Qmin(j); end
JW=J*W;
r=rank(JW);
if r<6
s=s2; W=W2; qN=qN2;
qSNS=qN'+pinv(J*W)*(s*eps'-J*qN');
limit_exceeded=false;
end
end
end
end