@@ -277,15 +277,39 @@ def eval(self, q=None, unit='rad'):
277
277
T = T @ e .T ()
278
278
return SE3 (T )
279
279
280
- def __str__ (self ):
280
+ def __str__ (self , q = None ):
281
281
"""
282
282
Pretty prints the ETS
283
283
284
+ :param q: control how joint variables are displayed
285
+ :type q: str
284
286
:return: Pretty printed ETS
285
287
:rtype: str
286
288
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.
289
313
290
314
Example:
291
315
@@ -300,20 +324,25 @@ def __str__(self):
300
324
:SymPy: supported
301
325
"""
302
326
es = []
303
- joint = 0
327
+ j = 0
304
328
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"
306
334
307
335
# For et in the object, display it, data comes from properties
308
336
# which come from the named tuple
309
337
for et in self :
310
338
311
339
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 )
314
342
else :
315
- s = f"{ et .axis } ()"
316
- joint += 1
343
+ qvar = ""
344
+ s = f"{ et .axis } ({ qvar } )"
345
+ j += 1
317
346
else :
318
347
if et .isrevolute :
319
348
if issymbol (et .eta ):
@@ -356,9 +385,9 @@ def __mul__(self, rest):
356
385
prod .data = self .data + rest .data
357
386
return prod
358
387
359
- def __rmul__ (self , rest ):
388
+ def __imul__ (self , rest ):
360
389
prod = ETS ()
361
- prod .data = self .data + rest
390
+ prod .data = self .data + rest . data
362
391
return prod
363
392
364
393
# redefine so that indexing returns an ET type
@@ -609,3 +638,11 @@ def axis_func(eta):
609
638
# print(e.joints())
610
639
# print(e.config)
611
640
# 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