8000 Fix error in ikine() with premature termination of iteration loop. · tixidi/robotics-toolbox-python@220e818 · GitHub
[go: up one dir, main page]

Skip to content

Commit 220e818

Browse files
committed
Fix error in ikine() with premature termination of iteration loop.
1 parent f88ec0d commit 220e818

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

robot/kinematics.py

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def fkine(robot, q):
6767

6868

6969

70-
def ikine(robot, tr, q=None, m=None):
70+
def ikine(robot, tr, q0=None, m=None, **args):
7171
"""
7272
Inverse manipulator kinematics.
7373
Computes the joint coordinates corresponding to the end-effector transform C{tr}.
@@ -130,17 +130,18 @@ def ikine(robot, tr, q=None, m=None):
130130
"""
131131

132132
#solution control parameters
133+
134+
print 'args', args
133135

134-
ilimit = 1000
135-
stol = 1e-12
136136
n = robot.n
137+
137138

138-
if q == None:
139-
q = mat(zeros((n,1)))
139+
if q0 == None:
140+
q0 = mat(zeros((n,1)))
140141
else:
141-
q = mat(q).flatten().T
142+
q0 = mat(q0).flatten().T
142143

143-
if q != None and m != None:
144+
if q0 != None and m != None:
144145
m = mat(m).flatten().T
145146
if len(m)!=6:
146147
error('Mask matrix should have 6 elements')
@@ -151,35 +152,33 @@ def ikine(robot, tr, q=None, m=None):
151152
print 'For a manipulator with fewer than 6DOF a mask matrix argument should be specified'
152153
m = mat(ones((6,1)))
153154

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+
154171
if isinstance(tr, list):
155172
#trajectory case
156173
qt = mat(zeros((0,n)))
157174
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);
169176
qt = vstack( (qt, q.T) )
170177
return qt;
171178
elif ishomog(tr):
172179
#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
183182
qt = q.T
184183
return qt
185184
else:

0 commit comments

Comments
 (0)
0