Skip to content

Commit 9d6d95e

Browse files
committed
more control of printing
added __imul__
1 parent 4859a35 commit 9d6d95e

File tree

1 file changed

+48
-11
lines changed

1 file changed

+48
-11
lines changed

roboticstoolbox/robot/ETS.py

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,39 @@ def eval(self, q=None, unit='rad'):
277277
T = T @ e.T()
278278
return SE3(T)
279279

280-
def __str__(self):
280+
def __str__(self, q=None):
281281
"""
282282
Pretty prints the ETS
283283
284+
:param q: control how joint variables are displayed
285+
:type q: str
284286
:return: Pretty printed ETS
285287
:rtype: str
286288
287-
Angular parameters are converted to degrees, except if they are
288-
symbolic.
289+
``q`` controls how the joint variables are displayed:
290+
291+
- None, format depends on number of joint variables
292+
- one, display joint variable as q
293+
- more, display joint variables as q0, q1, ...
294+
- "", display all joint variables as empty parentheses ``()``
295+
- "θ", display all joint variables as ``(θ)``
296+
- format string with passed joint variables ``(j, j+1)``, so "θ{0}"
297+
would display joint variables as θ0, θ1, ... while "θ{1}" would
298+
display joint variables as θ1, θ2, ...
299+
300+
Example:
301+
302+
.. runblock:: pycon
303+
304+
>>> from roboticstoolbox import ETS
305+
>>> e = ETS.rz() * ETS.tx(1) * ETS.rz()
306+
>>> print(e[:2])
307+
>>> print(e)
308+
>>> print(e.__str__(""))
309+
>>> print(e.__str__("θ{1}"))
310+
311+
.. note:: Angular parameters are converted to degrees, except if they
312+
are symbolic.
289313
290314
Example:
291315
@@ -300,20 +324,25 @@ def __str__(self):
300324
:SymPy: supported
301325
"""
302326
es = []
303-
joint = 0
327+
j = 0
304328

305-
show_q = len(self.joints()) > 1
329+
if q is None:
330+
if len(self.joints()) > 1:
331+
q = "q{0}"
332+
else:
333+
q = "q"
306334

307335
# For et in the object, display it, data comes from properties
308336
# which come from the named tuple
309337
for et in self:
310338

311339
if et.isjoint:
312-
if show_q:
313-
s = f"{et.axis}(q{joint})"
340+
if q is not None:
341+
qvar = q.format(j, j+1)
314342
else:
315-
s = f"{et.axis}()"
316-
joint += 1
343+
qvar = ""
344+
s = f"{et.axis}({qvar})"
345+
j += 1
317346
else:
318347
if et.isrevolute:
319348
if issymbol(et.eta):
@@ -356,9 +385,9 @@ def __mul__(self, rest):
356385
prod.data = self.data + rest.data
357386
return prod
358387

359-
def __rmul__(self, rest):
388+
def __imul__(self, rest):
360389
prod = ETS()
361-
prod.data = self.data + rest
390+
prod.data = self.data + rest.data
362391
return prod
363392

364393
# redefine so that indexing returns an ET type
@@ -609,3 +638,11 @@ def axis_func(eta):
609638
# print(e.joints())
610639
# print(e.config)
611640
# print(e.eval(np.zeros((6,))))
641+
642+
e = ETS()
643+
e *= ETS.rx()
644+
e *= ETS.tz()
645+
print(e)
646+
647+
print(e.__str__("θ{0}"))
648+
print(e.__str__("θ{1}"))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy