-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdh_manual.py
73 lines (59 loc) · 1.99 KB
/
dh_manual.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
import sympy as sp
from sympy.matrices import rot_axis3
# Para poder Graficar
import matplotlib.pyplot as plt
import numpy as np
# Para generar la matriz DH
from spatialmath import *
from spatialmath.base import *
# Definir los símbolos
theta, d, a, alpha = sp.symbols('theta, d, a, alpha')
# Matriz RzTzTxRx
# TDH= trotz(theta) @ transl(0,0, d) @ transl(a,0, 0) @ trotx(alpha)
# sp.pprint(TDH)
# print(type(TDH))
#Declarandola explicitamente
T = sp.Matrix([
[sp.cos(theta), -sp.sin(theta) * sp.cos(alpha), sp.sin(theta) * sp.sin(alpha), a * sp.cos(theta)],
[sp.sin(theta), sp.cos(theta)* sp.cos(alpha), -sp.cos(theta) * sp.sin(alpha), a * sp.sin(theta)],
[0, sp.sin(alpha), sp.cos(alpha), d],
[0, 0, 0, 1]
])
# sp.pprint(T)
# print(type(T))
theta_1, theta_2,theta_3, theta_4,theta_5, theta_6 = sp.symbols('theta_1, theta_2,theta_3, theta_4,theta_5, theta_6')
#De la tabla DH
T01 = T.subs({d: 0.680, a: 0.200, alpha: -sp.pi/2})
T01 = T01.subs({theta: theta_1})
# sp.pprint(T01)
T12 = T.subs({d: 0, a: 0.890, alpha: 0}) #theta2-sp.pi/2
T12 = T12.subs({theta: theta_2})
# sp.pprint(T12)
T23 = T.subs({d: 0, a: 0.150, alpha: -sp.pi/2})
T23 = T23.subs({theta: theta_3})
# sp.pprint(T23)
T34 = T.subs({d: 0.880, a: 0, alpha: sp.pi/2})
T34 = T34.subs({theta: theta_4})
# sp.pprint(T34)
T45 = T.subs({d: 0, a: 0, alpha: -sp.pi/2})
T45 = T45.subs({theta: theta_5})
# sp.pprint(T45)
T56 = T.subs({d: 0.140, a: 0, alpha: 0})
T56 = T56.subs({theta: theta_6})
# sp.pprint(T56)
T06 = T01 @ T12 @ T23 @ T34 @ T45 @ T56
T06_s= T06.applyfunc(sp.simplify)
# sp.pprint(T06_s)
#Para exportar a LateX
# latex_str = sp.latex(T06_s)
# print(latex_str)
#EJEMPLO Y VALIDACION RAPIDA
#Para modificar los angulos comodamente
joint1 = np.deg2rad(0)
joint2 = np.deg2rad(0) - sp.pi/2 #Offset
joint3 = np.deg2rad(0)
joint4 = np.deg2rad(0)
joint5 = np.deg2rad(0)
joint6 = np.deg2rad(0)
T06_solved = T06_s.subs({theta_1: joint1, theta_2: joint2,theta_3: joint3,theta_4: joint4,theta_5: joint5,theta_6: joint6})
sp.pprint(T06_solved)