@@ -67,7 +67,7 @@ def fkine(robot, q):
67
67
68
68
69
69
70
- def ikine (robot , tr , q = None , m = None ):
70
+ def ikine (robot , tr , q0 = None , m = None , ** args ):
71
71
"""
72
72
Inverse manipulator kinematics.
73
73
Computes the joint coordinates corresponding to the end-effector transform C{tr}.
@@ -130,17 +130,18 @@ def ikine(robot, tr, q=None, m=None):
130
130
"""
131
131
132
132
#solution control parameters
133
+
134
+ print 'args' , args
133
135
134
- ilimit = 1000
135
- stol = 1e-12
136
136
n = robot .n
137
+
137
138
138
- if q == None :
139
- q = mat (zeros ((n ,1 )))
139
+ if q0 == None :
140
+ q0 = mat (zeros ((n ,1 )))
140
141
else :
141
- q = mat (q ).flatten ().T
142
+ q0 = mat (q0 ).flatten ().T
142
143
143
- if q != None and m != None :
144
+ if q0 != None and m != None :
144
145
m = mat (m ).flatten ().T
145
146
if len (m )!= 6 :
146
147
error ('Mask matrix should have 6 elements' )
@@ -151,35 +152,33 @@ def ikine(robot, tr, q=None, m=None):
151
152
print 'For a manipulator with fewer than 6DOF a mask matrix argument should be specified'
152
153
m = mat (ones ((6 ,1 )))
153
154
155
+ def solve (robot , tr , q , mask , ilimit = 1000 , stol = 1e-6 , gamma = 1 ):
156
+ print ilimit , stol , gamma
157
+ nm = inf ;
158
+ count = 0
159
+ while nm > stol :
160
+ e = multiply ( tr2diff (fkine (robot , q .T ),tr ), mask )
161
+ #dq = pinv(Jac.jacob0(robot, q.T)) * e
162
+ dq = Jac .jacob0 (robot , q .T ).T * e
163
+ q += gamma * dq ;
164
+ nm = norm (e )
165
+ count += 1
166
+ if count > ilimit :
167
+ error ("Solution wouldn't converge" )
168
+ print count , 'iterations'
169
+ return q ;
170
+
154
171
if isinstance (tr , list ):
155
172
#trajectory case
156
173
qt = mat (zeros ((0 ,n )))
157
174
for T in tr :
158
- nm = 1
159
- count = 0
160
- while nm > stol :
161
- e = multiply (tr2diff ( fkine (robot , q .T ), T ), m )
162
- dq = pinv (Jac .jacob0 (robot ,q .T ))* e
163
- q += dq
164
- nm = norm (dq )
165
- count += 1
166
- if count > ilimit :
167
- print 'i=' ,i ,' nm=' ,nm
168
- error ("Solution wouldn't converge" )
175
+ q = solve (robot , T , q0 , m , ** args );
169
176
qt = vstack ( (qt , q .T ) )
170
177
return qt ;
171
178
elif ishomog (tr ):
172
179
#single xform case
173
- nm = 1
174
- count = 0
175
- while nm > stol :
176
- e = multiply ( tr2diff (fkine (robot ,q .T ),tr ), m )
177
- dq = pinv (Jac .jacob0 (robot , q .T )) * e
178
- q += dq ;
179
- nm = norm (dq )
180
- count += 1
181
- if count > ilimit :
182
- error ("Solution wouldn't converge" )
180
+ q = solve (robot , tr , q0 , m , ** args );
181
+ print q
183
182
qt = q .T
184
183
return qt
185
184
else :
0 commit comments