8000 Add eval and joints methods · G-SS/robotics-toolbox-python@322e9d6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 322e9d6

Browse files
committed
Add eval and joints methods
1 parent 026e47a commit 322e9d6

File tree

1 file changed

+43
-9
lines changed
  • roboticstoolbox/robot

1 file changed

+43
-9
lines changed

roboticstoolbox/robot/ET.py

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from collections import UserList, namedtuple
77
import numpy as np
88
from spatialmath import SE3
9+
from spatialmath.base import getvector
910

1011

1112
class ET(UserList): # TODO should be ETS
@@ -88,6 +89,38 @@ def T(self, q=None):
8889
else:
8990
return self.axis_func(q)
9091

92+
def joints(self):
93+
"""
94+
Get index of joint transforms
95+
96+
:return: indices of transforms that are joints
97+
:rtype: list
98+
"""
99+
return np.where([e.jtype == self.VARIABLE for e in self])[0]
100+
101+
def eval(self, q):
102+
"""
103+
Evaluate an ETS with joint coordinate substitution
104+
105+
:param q: joint coordinates
106+
:type q: array-like
107+
:return: product of transformations
108+
:rtype: SE3
109+
110+
Effectively the forward-kinematics of the ET sequence. Compounds the
111+
transforms left to right, and substitutes in joint coordinates as
112+
needed from consecutive elements of ``q``.
113+
"""
114+
T = SE3()
115+
116+
q = getvector(q, out='sequence')
117+
for e in self:
118+
if e.jtype == self.VARIABLE:
119+
T *= e.T(q.pop(0))
120+
else:
121+
T *= e.T()
122+
return T
123+
91124
def __str__(self):
92125
"""
93126
Pretty prints the ET. Will output angles in degrees
@@ -262,15 +295,16 @@ def tz(cls, eta=None):
262295
return cls(SE3.Tz, axis='tz', eta=eta)
263296

264297

265-
# if __name__ == "__main__":
266-
267-
# from math import pi
298+
if __name__ == "__main__":
268299

269-
# e = ET.rx(pi/2)
270-
# print(e)
300+
l1 = 0.672
301+
l2 = -0.2337
302+
l3 = 0.4318
303+
l4 = 0.0203
304+
l5 = 0.0837
305+
l6 = 0.4318
271306

272-
# e = ET.rx(pi/2) * ET.tx(0.3) * ET.ty(0.4) * ET.rx(-pi/2)
273-
# print(e)
307+
e = ET.tz(l1) * ET.rz() * ET.ry() * ET.ty(l2) * ET.tz(l3) * ET.ry() * ET.tx(l4) * ET.ty(l5) * ET.tz(l6) * ET.rz() * ET.ry() * ET.rz()
308+
print(e.joints())
309+
print(e.eval(np.zeros((6,))))
274310

275-
# e = ET.rx(pi/2) * ET.tx() * ET.ty() * ET.rx(-pi/2)
276-
# print(e)

0 commit comments

Comments
 (0)
0