forked from ryanGT/teaching
-
Notifications
You must be signed in to change notification settings - Fork 0
/
robotics_sympy.py
43 lines (33 loc) · 969 Bytes
/
robotics_sympy.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
import sympy
from sympy import Matrix, cos, sin, eye
def Rx(th):
R = Matrix([[1.0,0.0,0.0],\
[0.0,cos(th),-sin(th)],\
[0.0,sin(th),cos(th)]])
return R
def HT(R, Px=0.0, Py=0.0, Pz=0.0):
T = eye(4)
T[0:3,0:3] = R
T[0,3] = Px
T[1,3] = Py
T[2,3] = Pz
return T
def HTx(alpha, Px=0.0, Py=0.0, Pz=0.0):
R = Rx(alpha)
T = HT(R, Px, Py, Pz)
return T
def Rz(th):
R = Matrix([[cos(th),-sin(th),0.0],\
[sin(th),cos(th),0.0],\
[0.0,0.0,1.0]])
return R
def HTz(theta, Px=0.0, Py=0.0, Pz=0.0):
R = Rz(theta)
T = HT(R, Px, Py, Pz)
return T
def DH(alpha, a, theta, d):
T = Matrix([[cos(theta),-sin(theta), 0, a], \
[sin(theta)*cos(alpha), cos(theta)*cos(alpha),-sin(alpha),-sin(alpha)*d], \
[sin(theta)*sin(alpha), cos(theta)*sin(alpha), cos(alpha), cos(alpha)*d],\
[0,0,0,1]])
return T