-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject_poe2.py
67 lines (52 loc) · 1.63 KB
/
project_poe2.py
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
import numpy as np
from math import pi, cos, sin, sqrt
def skew_symmetric(v):
return np.array([
[0, -v[2], v[1]],
[v[2], 0, -v[0]],
[-v[1], v[0], 0]
])
def exp_twist(theta, twist):
omega = np.array(twist[:3]) # Angular part
v = np.array(twist[3:]) # Linear part
if np.all(omega == 0): # Pure translation
R = np.eye(3)
p = v * theta
else: # Screw motion
omega_skew = skew_symmetric(omega)
omega_norm = np.linalg.norm(omega)
R = np.eye(3) + np.sin(theta) * omega_skew + (1 - np.cos(theta)) * np.dot(omega_skew, omega_skew)
p = (np.eye(3) * theta + (1 - np.cos(theta)) * omega_skew + (theta - np.sin(theta)) * np.dot(omega_skew, omega_skew)).dot(v)
p = p.reshape(3, 1)
return np.vstack((np.hstack((R, p)), np.array([0, 0, 0, 1])))
def forward_kinematics_poe(joints, L =[5,11,0,5]):
# twists = np.array([
# [0, 0, 1, 0, 0, 0],
# [0, -1, 0, L[0], 0, 0],
# [0, 0, 0, 0, 0, 1],
# [0, -1, 0, L[0] + L[1], 0, 0]
# ])
# M = np.array([
# [1, 0, 0, -L[3]],
# [0, 1, 0, 0],
# [0, 0, 1, L[0] + L[1]],
# [0, 0, 0, 1]
# ])
twists = np.array([
[0, 0, 1, 0, 0, 0],
[0, -1, 0, L[0], 0, 0],
[0, 0, 0, 1, 0, 0],
[0, -1, 0,L[0], 0, -L[2]]
])
M = np.array([
[1, 0, 0, L[1]+L[3]],
[0, 1, 0, 0],
[0, 0, 1, L[0]],
[0, 0, 0, 1]
])
T = np.eye(4)
for i in range(len(twists)):
T = np.dot(T, exp_twist(joints[i], twists[i]))
T = np.dot(T, M)
T=np.around(T, 4)
return T