|
10 | 10 | # import spatialmath as sp
|
11 | 11 | from spatialmath import SE3
|
12 | 12 | from spatialmath.base.argcheck import getvector, verifymatrix
|
13 |
| -from roboticstoolbox.robot.ELink import ELink |
| 13 | +from roboticstoolbox.robot.ELink import ELink, ETS |
14 | 14 | # from roboticstoolbox.backend.PyPlot.functions import \
|
15 | 15 | # _plot, _teach, _fellipse, _vellipse, _plot_ellipse, \
|
16 | 16 | # _plot2, _teach2
|
17 | 17 | from roboticstoolbox.backend import xacro
|
18 | 18 | from roboticstoolbox.backend import URDF
|
19 | 19 | from roboticstoolbox.robot.Robot import Robot
|
20 | 20 | from pathlib import PurePath, PurePosixPath
|
| 21 | +from ansitable import ANSITable, Column |
21 | 22 |
|
22 | 23 | # try:
|
23 | 24 | # import pybullet as p
|
@@ -65,6 +66,35 @@ def __init__(
|
65 | 66 | self._M = 0
|
66 | 67 | self._q_idx = []
|
67 | 68 |
|
| 69 | + if isinstance(elinks, ETS): |
| 70 | + # were passed an ETS string |
| 71 | + ets = elinks |
| 72 | + elinks = [] |
| 73 | + # for j, k in enumerate(ets.joints()): |
| 74 | + # if j == 0: |
| 75 | + # parent = None |
| 76 | + # else: |
| 77 | + # parent = elinks[-1] |
| 78 | + # print(ets[:k+1]) |
| 79 | + # elink = ELink(ets[:k+1], parent=parent, name=f"link{j:d}") |
| 80 | + # elinks.append(elink) |
| 81 | + # ets = ets[k+1:] |
| 82 | + |
| 83 | + start = 0 |
| 84 | + for j, k in enumerate(ets.joints()): |
| 85 | + ets_j = ets[start:k+1] |
| 86 | + start = k + 1 |
| 87 | + if j == 0: |
| 88 | + parent = None |
| 89 | + else: |
| 90 | + parent = elinks[-1] |
| 91 | + elink = ELink(ets_j, parent=parent, name=f"link{j:d}") |
| 92 | + elinks.append(elink) |
| 93 | + |
| 94 | + tool = ets[start:] |
| 95 | + if len(tool) > 0: |
| 96 | + elinks.append(ELink(tool, parent=elinks[-1], name="ee")) |
| 97 | + |
68 | 98 | # Set up a dictionary for looking up links by name
|
69 | 99 | for link in elinks:
|
70 | 100 | if isinstance(link, ELink):
|
@@ -930,36 +960,29 @@ def jacobm(self, q=None, J=None, H=None, from_link=None, to_link=None):
|
930 | 960 |
|
931 | 961 | return Jm
|
932 | 962 |
|
933 |
| - # def __str__(self): |
934 |
| - # """ |
935 |
| - # Pretty prints the ETS Model of the robot. Will output angles in |
936 |
| - # degrees |
937 |
| - |
938 |
| - # :return: Pretty print of the robot model |
939 |
| - # :rtype: str |
940 |
| - # """ |
941 |
| - # axes = '' |
942 |
| - |
943 |
| - # for i in range(self.n): |
944 |
| - # axes += self.ets[self.q_idx[i]].axis |
945 |
| - |
946 |
| - # rpy = tr2rpy(self.tool.A, unit='deg') |
947 |
| - |
948 |
| - # for i in range(3): |
949 |
| - # if rpy[i] == 0: |
950 |
| - # rpy[i] = 0 |
951 |
| - |
952 |
| - # model = '\n%s (%s): %d axis, %s, ETS\n'\ |
953 |
| - # 'Elementary Transform Sequence:\n'\ |
954 |
| - # '%s\n'\ |
955 |
| - # 'tool: t = (%g, %g, %g), RPY/xyz = (%g, %g, %g) deg' % ( |
956 |
| - # self.name, self.manuf, self.n, axes, |
957 |
| - # self.ets, |
958 |
| - # self.tool.A[0, 3], self.tool.A[1, 3], |
959 |
| - # self.tool.A[2, 3], rpy[0], rpy[1], rpy[2] |
960 |
| - # ) |
| 963 | + def __str__(self): |
| 964 | + """ |
| 965 | + Pretty prints the ETS Model of the robot. Will output angles in |
| 966 | + degrees |
961 | 967 |
|
962 |
| - # return model |
| 968 | + :return: Pretty print of the robot model |
| 969 | + :rtype: str |
| 970 | + """ |
| 971 | + table = ANSITable( |
| 972 | + Column("link"), |
| 973 | + Column("parent"), |
| 974 | + Column("ETS", headalign="^", colalign="<"), |
| 975 | + border="thin") |
| 976 | + for link in self: |
| 977 | + if link.isjoint: |
| 978 | + color = "" |
| 979 | + else: |
| 980 | + color = "<<blue>>" |
| 981 | + table.row(color + link.name, |
| 982 | + link.parent.name if link.parent is not None else "-", |
| 983 | + link.ets * link.v if link.v is not None else link.ets) |
| 984 | + return str(table) |
| 985 | + |
963 | 986 |
|
964 | 987 | def jacobev(
|
965 | 988 | self, q=None, from_link=None, to_link=None,
|
|
0 commit comments