Skip to content

Commit 745847e

Browse files
committed
Add a bunch of new attributes for Robot object
1 parent 3a95b35 commit 745847e

File tree

3 files changed

+170
-7
lines changed

3 files changed

+170
-7
lines changed

roboticstoolbox/robot/DHRobot.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,28 @@ def reach(self):
497497
self._reach = d
498498
return self._reach
499499

500+
@property
501+
def nbranches(self):
502+
"""
503+
Number of branches
504+
505+
:return: number of branches in the robot's kinematic tree
506+
:rtype: int
507+
508+
Number of branches in this robot.
509+
510+
Example:
511+
512+
.. runblock:: pycon
513+
514+
>>> import roboticstoolbox as rtb
515+
>>> robot = rtb.models.DH.Panda()
516+
>>> robot.nbranches
517+
518+
:seealso: :func:`n`, :func:`nlinks`
519+
"""
520+
return 1
521+
500522
def A(self, j, q=None):
501523
"""
502524
Link forward kinematics

roboticstoolbox/robot/ERobot.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,25 @@ def n(self):
382382
def nbranches(self):
383383
"""
384384
Number of branches
385+
385386
:return: number of branches in the robot's kinematic tree
386387
:rtype: int
387-
Computed as the number of links with zero children
388+
389+
Number of branches in this robot. Computed as the number of links with
390+
zero children
391+
392+
Example:
393+
394+
.. runblock:: pycon
395+
396+
>>> import roboticstoolbox as rtb
397+
>>> robot = rtb.models.ETS.Panda()
398+
>>> robot.nbranches
399+
400+
:seealso: :func:`n`, :func:`nlinks`
388401
"""
389402
return self._nbranches
403+
390404
# --------------------------------------------------------------------- #
391405

392406
@property

roboticstoolbox/robot/Robot.py

Lines changed: 133 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ def __init__(
7575

7676
self._hasdynamics = False
7777
self._hasgeometry = False
78+
self._hascollision = False
79+
7880

7981
for link in links:
8082
if not isinstance(link, Link):
@@ -83,13 +85,18 @@ def __init__(
8385
# add link back to roboto
8486
link._robot = self
8587

86-
if link._hasdynamics:
88+
if link.hasdynamics:
8789
self._hasdynamics = True
90+
if link.geometry:
91+
self._hasgeometry = []
92+
if link.collision:
93+
self._hascollision = True
8894

8995
if isinstance(link, rtb.ELink):
9096
if len(link.geometry) > 0:
9197
self._hasgeometry = True
9298
self._links = links
99+
self._nlinks = len(links)
93100

94101
# Current joint angles of the robot
95102
self.q = np.zeros(self.n)
@@ -217,9 +224,117 @@ def n(self):
217224
>>> robot = rtb.models.DH.Puma560()
218225
>>> robot.n
219226
227+
:seealso: :func:`nlinks`, :func:`nbranches`
228+
"""
229+
return self._n
230+
231+
@property
232+
def nlinks(self):
233+
"""
234+
Number of links (Robot superclass)
235+
236+
:return: Number of links
237+
:rtype: int
238+
239+
Example:
240+
241+
.. runblock:: pycon
242+
243+
>>> import roboticstoolbox as rtb
244+
>>> robot = rtb.models.DH.Puma560()
245+
>>> robot.nlinks
246+
247+
:seealso: :func:`n`, :func:`nbranches`
248+
"""
249+
return self._nlinks
250+
251+
@abstractproperty
252+
def nbranches(self):
253+
pass
254+
255+
"""
256+
Number of branches (Robot superclass)
257+
258+
:return: Number of branches
259+
:rtype: int
260+
261+
Example:
262+
263+
.. runblock:: pycon
264+
265+
>>> import roboticstoolbox as rtb
266+
>>> robot = rtb.models.DH.Puma560()
267+
>>> robot.nbranches
268+
269+
:seealso: :func:`n`, :func:`nlinks`
220270
"""
221271
return self._n
222272

273+
@property
274+
def hasdynamics(self):
275+
"""
276+
Robot has dynamic parameters (Robot superclass)
277+
278+
:return: Robot has dynamic parameters
279+
:rtype: bool
280+
281+
At least one link has associated dynamic parameters.
282+
283+
Example:
284+
285+
.. runblock:: pycon
286+
287+
>>> import roboticstoolbox as rtb
288+
>>> robot = rtb.models.DH.Puma560()
289+
>>> robot.hasdynamics:
290+
"""
291+
return self._hasdynamics
292+
293+
@property
294+
def hasgeometry(self):
295+
"""
296+
Robot has geometry model (Robot superclass)
297+
298+
:return: Robot has geometry model
299+
:rtype: bool
300+
301+
At least one link has associated mesh to describe its shape.
302+
303+
Example:
304+
305+
.. runblock:: pycon
306+
307+
>>> import roboticstoolbox as rtb
308+
>>> robot = rtb.models.DH.Puma560()
309+
>>> robot.hasgeometry
310+
311+
:seealso: :func:`hascollision`
312+
"""
313+
return self._hasgeometry
314+
315+
@property
316+
def hascollision(self):
317+
"""
318+
Robot has collision model (Robot superclass)
319+
320+
:return: Robot has collision model
321+
:rtype: bool
322+
323+
At least one link has associated collision model.
324+
325+
Example:
326+
327+
.. runblock:: pycon
328+
329+
>>> import roboticstoolbox as rtb
330+
>>> robot = rtb.models.DH.Puma560()
331+
>>> robot.hascollision
332+
333+
:seealso: :func:`hasgeometry`
334+
"""
335+
return self._hascollision
336+
337+
223338
@property
224339
def qrandom(self):
225340
"""
@@ -330,7 +445,8 @@ def structure(self):
330445

331446
return ''.join(structure)
332447

333-
def isrevolute(self):
448+
@property
449+
def revolutejoints(self):
334450
"""
335451
Revolute joints as bool array
336452
@@ -343,16 +459,27 @@ def isrevolute(self):
343459
344460
>>> import roboticstoolbox as rtb
345461
>>> puma = rtb.models.DH.Puma560()
346-
>>> puma.isrevolute()
462+
>>> puma.revolutejoints()
347463
>>> stanford = rtb.models.DH.Stanford()
348-
>>> stanford.isrevolute()
464+
>>> stanford.revolutejoints()
349465
350466
.. note:: Fixed joints, that maintain a constant link relative pose,
351467
are not included. ``len(self.structure) == self.n``.
468+
469+
:seealso: :func:`Link.isrevolute`, :func:`prismaticjoints`
352470
"""
353-
return [link.isrevolute for link in self]
471+
return [link.isrevolute for link in self if link.isjoint]
472+
473+
# TODO not very efficient
474+
# TODO keep a mapping from joint to link
475+
def isrevolute(self, j):
476+
return self.revolutejoints[j]
354477

355-
def isprismatic(self):
478+
def isprismatic(self, j):
479+
return self.prismaticjoints[j]
480+
481+
@property
482+
def prismaticjoints(self):
356483
"""
357484
Revolute joints as bool array
358485

0 commit comments

Comments
 (0)