-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobotics_week5.py
129 lines (104 loc) · 3.32 KB
/
robotics_week5.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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
import numpy as np
import math
def solve_theta1_theta2_theta3(l1,l2,x,y,phi):
a = l1**2 + l2**2 - (x**2 + y**2)
b = -2*l1*l2
theta2 = np.arccos( a/b )
a = l1**2 + (x**2 + y**2) - l2**2
b = 2*l1*np.sqrt(x**2+y**2)
gamma = np.arccos( a/b )
if theta2 < 0:
theta1 = np.arctan2(y,x) + gamma
else:
theta1 = np.arctan2(y,x) - gamma
theta3 = phi - theta1 - theta2
return theta1, theta2, theta3
if __name__ == "__main__":
delta_t1 = 2
delta_t2 = 2
delta_t3 = 5
T12_mat = np.array(
[[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[1, delta_t1, delta_t1**2, delta_t1**3, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, delta_t2, delta_t2**2, delta_t2**3, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 1, delta_t3, delta_t3**2, delta_t3**3],
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2*delta_t3, 3*(delta_t3**2)],
[0, 1, 2*delta_t1, 3*(delta_t1**2), 0, -1, 0, 0, 0, 0, 0, 0],
[0, 0, 2, 6*delta_t1, 0, 0, -2, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 2*delta_t2, 3*(delta_t2**2), 0, -1, 0, 0],
[0, 0, 0, 0, 0, 0, 2, 6*delta_t2, 0, 0, -2, 0]
]
)
np.set_printoptions(precision=4, suppress=True)
print(T12_mat)
print("###########################################################")
print("\n")
inv_T12 = np.linalg.inv(T12_mat)
# theta = np.array(
# [[-4, 0, math.pi/2],
# [0, 3, math.pi/4],
# [0, 3, math.pi/4],
# [3, 3, math.pi/6],
# [3, 3, math.pi/6],
# [4, 0, 0],
# [0, 0, 0],
# [0, 0, 0],
# [0, 0, 0],
# [0, 0, 0],
# [0, 0, 0],
# [0, 0, 0]
# ]
# )
theta = np.array(
[[-4, 0, 120],
[-5, 5, 45],
[-5, 5, 45],
[2, 3, 30],
[2, 3, 30],
[2, -3, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
]
)
a = np.matmul(inv_T12, theta)
print("ans:")
print(a)
print("###########################################################")
print("\n")
#get joint space mat
l1, l2 = 5, 3
theta1, theta2, theta3 = solve_theta1_theta2_theta3(l1=l1, l2=l2, x=-4, y=0, phi=120/180*math.pi)
t0_row = [theta1, theta2, theta3]
theta1, theta2, theta3 = solve_theta1_theta2_theta3(l1=l1, l2=l2, x=-5, y=5, phi=45/180*math.pi)
t1_row = [theta1, theta2, theta3]
theta1, theta2, theta3 = solve_theta1_theta2_theta3(l1=l1, l2=l2, x=2, y=3, phi=30/180*math.pi)
t2_row = [theta1, theta2, theta3]
theta1, theta2, theta3 = solve_theta1_theta2_theta3(l1=l1, l2=l2, x=2, y=-3, phi=0/180*math.pi)
t3_row = [theta1, theta2, theta3]
theta = np.array(
[t0_row,
t1_row,
t1_row,
t2_row,
t2_row,
t3_row,
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
]
)
a = np.matmul(inv_T12, theta)
print("ans:")
print(a)
print("###########################################################")
print("\n")