forked from stack-of-tasks/pinocchio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinverse-kinematics.py
More file actions
44 lines (36 loc) · 1.06 KB
/
inverse-kinematics.py
File metadata and controls
44 lines (36 loc) · 1.06 KB
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
from __future__ import print_function
import numpy as np
from numpy.linalg import norm, solve
import pinocchio
model = pinocchio.buildSampleModelManipulator()
data = model.createData()
JOINT_ID = 6
oMdes = pinocchio.SE3(np.eye(3), np.array([1., 0., 1.]))
q = pinocchio.neutral(model)
eps = 1e-4
IT_MAX = 1000
DT = 1e-1
damp = 1e-12
i=0
while True:
pinocchio.forwardKinematics(model,data,q)
dMi = oMdes.actInv(data.oMi[JOINT_ID])
err = pinocchio.log(dMi).vector
if norm(err) < eps:
success = True
break
if i >= IT_MAX:
success = False
break
J = pinocchio.computeJointJacobian(model,data,q,JOINT_ID)
v = - J.T.dot(solve(J.dot(J.T) + damp * np.eye(6), err))
q = pinocchio.integrate(model,q,v*DT)
if not i % 10:
print('%d: error = %s' % (i, err.T))
i += 1
if success:
print("Convergence achieved!")
else:
print("\nWarning: the iterative algorithm has not reached convergence to the desired precision")
print('\nresult: %s' % q.flatten().tolist())
print('\nfinal error: %s' % err.T)