|
6 | 6 | from collections import UserList, namedtuple
|
7 | 7 | import numpy as np
|
8 | 8 | from spatialmath import SE3
|
| 9 | +from spatialmath.base import getvector |
9 | 10 |
|
10 | 11 |
|
11 | 12 | class ET(UserList): # TODO should be ETS
|
@@ -88,6 +89,38 @@ def T(self, q=None):
|
88 | 89 | else:
|
89 | 90 | return self.axis_func(q)
|
90 | 91 |
|
| 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 | + |
91 | 124 | def __str__(self):
|
92 | 125 | """
|
93 | 126 | Pretty prints the ET. Will output angles in degrees
|
@@ -262,15 +295,16 @@ def tz(cls, eta=None):
|
262 | 295 | return cls(SE3.Tz, axis='tz', eta=eta)
|
263 | 296 |
|
264 | 297 |
|
265 |
| -# if __name__ == "__main__": |
266 |
| - |
267 |
| -# from math import pi |
| 298 | +if __name__ == "__main__": |
268 | 299 |
|
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 |
271 | 306 |
|
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,)))) |
274 | 310 |
|
275 |
| -# e = ET.rx(pi/2) * ET.tx() * ET.ty() * ET.rx(-pi/2) |
276 |
| -# print(e) |
|
0 commit comments