Skip to content

Commit 9a208d8

Browse files
committed
Create an ERobot direct from ETS
add pretty print for ERobot
1 parent 3cefa21 commit 9a208d8

File tree

2 files changed

+67
-30
lines changed

2 files changed

+67
-30
lines changed

roboticstoolbox/models/ETS/Puma560.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from roboticstoolbox import ETS as ET
2+
from roboticstoolbox import ERobot
3+
l1 = 0.672
4+
l2 = 0.2337
5+
l3 = 0.4318
6+
l4 = -0.0837
7+
l5 = 0.4318
8+
l6 = 0.0203
9+
10+
e = ET.tz(l1) * ET.rz() * ET.ty(l2) * ET.ry() * ET.tz(l3) * ET.tx(l6) * \
11+
ET.ty(l4) * ET.ry() * ET.tz(l5) * ET.rz() * ET.ry() * ET.rz() * ET.tx(0.2)
12+
13+
robot = ERobot(e, name="my first ERobot")
14+
print(robot)

roboticstoolbox/robot/ERobot.py

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
# import spatialmath as sp
1111
from spatialmath import SE3
1212
from spatialmath.base.argcheck import getvector, verifymatrix
13-
from roboticstoolbox.robot.ELink import ELink
13+
from roboticstoolbox.robot.ELink import ELink, ETS
1414
# from roboticstoolbox.backend.PyPlot.functions import \
1515
# _plot, _teach, _fellipse, _vellipse, _plot_ellipse, \
1616
# _plot2, _teach2
1717
from roboticstoolbox.backend import xacro
1818
from roboticstoolbox.backend import URDF
1919
from roboticstoolbox.robot.Robot import Robot
2020
from pathlib import PurePath, PurePosixPath
21+
from ansitable import ANSITable, Column
2122

2223
# try:
2324
# import pybullet as p
@@ -65,6 +66,35 @@ def __init__(
6566
self._M = 0
6667
self._q_idx = []
6768

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+
6898
# Set up a dictionary for looking up links by name
6999
for link in elinks:
70100
if isinstance(link, ELink):
@@ -930,36 +960,29 @@ def jacobm(self, q=None, J=None, H=None, from_link=None, to_link=None):
930960

931961
return Jm
932962

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
961967
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+
963986

964987
def jacobev(
965988
self, q=None, from_link=None, to_link=None,

0 commit comments

Comments
 (0)