Skip to content

Commit e6ab71b

Browse files
committed
Changes to closest_point
1 parent 6c61832 commit e6ab71b

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

roboticstoolbox/robot/Link.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,8 +759,8 @@ def closest_point(self, shape, inf_dist=1.0):
759759
760760
:returns: d, p1, p2 where d is the distance between the shapes,
761761
p1 and p2 are the points in the world frame on the respective
762-
shapes
763-
:rtype: float, SE3, SE3
762+
shapes. The points returned are homogeneous with [x, y, z, 1].
763+
:rtype: float, ndarray(1x4), ndarray(1x4)
764764
'''
765765

766766
d = 10000

roboticstoolbox/robot/Robot.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ def __init__(
7979
self._hasgeometry = False
8080
self._hascollision = False
8181

82-
8382
for link in links:
8483
if not isinstance(link, Link):
8584
raise TypeError('links should all be Link subclass')
@@ -309,7 +308,7 @@ def hasgeometry(self):
309308
>>> import roboticstoolbox as rtb
310309
>>> robot = rtb.models.DH.Puma560()
311310
>>> robot.hasgeometry
312-
311+
313312
:seealso: :func:`hascollision`
314313
"""
315314
return self._hasgeometry
@@ -336,7 +335,6 @@ def hascollision(self):
336335
"""
337336
return self._hascollision
338337

339-
340338
@property
341339
def qrandom(self):
342340
"""
@@ -535,7 +533,7 @@ def todegrees(self, q):
535533

536534
for j, revolute in enumerate(self.revolutejoints):
537535
if revolute:
538-
q[:,j] *= 180.0 / np.pi
536+
q[:, j] *= 180.0 / np.pi
539537
if q.shape[0] == 1:
540538
return q[0]
541539
else:
@@ -570,7 +568,7 @@ def toradians(self, q):
570568

571569
for j, revolute in enumerate(self.revolutejoints):
572570
if revolute:
573-
q[:,j] *= np.pi / 180.0
571+
q[:, j] *= np.pi / 180.0
574572
if q.shape[0] == 1:
575573
return q[0]
576574
else:
@@ -983,7 +981,7 @@ def base(self):
983981
else:
984982
self._base = SE3()
985983

986-
# return a copy, otherwise somebody with
984+
# return a copy, otherwise somebody with
987985
# reference to the base can change it
988986
return self._base.copy()
989987

@@ -1055,7 +1053,7 @@ def qlim(self):
10551053
10561054
Limits are extracted from the link objects. If joints limits are
10571055
not set for:
1058-
1056+
10591057
- a revolute joint [-𝜋. 𝜋] is returned
10601058
- a prismatic joint an exception is raised
10611059
@@ -1641,8 +1639,8 @@ def plot_vellipse(
16411639

16421640
def teach(
16431641
self, q=None, block=True, order='xyz', limits=None,
1644-
jointaxes=True, jointlabels=False,
1645-
vellipse=False, fellipse=False, eeframe=True, shadow=True,
1642+
jointaxes=True, jointlabels=False,
1643+
vellipse=False, fellipse=False, eeframe=True, shadow=True,
16461644
name=True, backend=None):
16471645
"""
16481646
Graphical teach pendant
@@ -1705,7 +1703,7 @@ def teach(
17051703
env.launch('Teach ' + self.name, limits=limits)
17061704
env.add(
17071705
self, readonly=True,
1708-
jointaxes=jointaxes, jointlabels=jointlabels, eeframe=eeframe,
1706+
jointaxes=jointaxes, jointlabels=jointlabels, eeframe=eeframe,
17091707
shadow=shadow, name=name)
17101708

17111709
env._add_teach_panel(self, q)
@@ -1718,7 +1716,6 @@ def teach(
17181716
fell = self.fellipse(centre='ee')
17191717
env.add(fell)
17201718

1721-
17221719
# Keep the plot open
17231720
if block: # pragma: no cover
17241721
env.hold()
@@ -1727,7 +1724,7 @@ def teach(
17271724

17281725
# --------------------------------------------------------------------- #
17291726

1730-
def closest_point(self, shape, inf_dist=1.0):
1727+
def closest_point(self, q, shape, inf_dist=1.0, skip=False):
17311728
'''
17321729
closest_point(shape, inf_dist) returns the minimum euclidean
17331730
distance between this robot and shape, provided it is less than
@@ -1739,14 +1736,20 @@ def closest_point(self, shape, inf_dist=1.0):
17391736
:param inf_dist: The minimum distance within which to consider
17401737
the shape
17411738
:type inf_dist: float
1739+
:param skip: Skip setting all shape transforms based on q, use this
1740+
option if using this method in conjuction with Swift to save time
1741+
:type skip: boolean
17421742
:returns: d, p1, p2 where d is the distance between the shapes,
17431743
p1 and p2 are the points in the world frame on the respective
1744-
shapes
1745-
:rtype: float, SE3, SE3
1744+
shapes. The points returned are homogeneous with [x, y, z, 1].
1745+
:rtype: float, ndarray(1x4), ndarray(1x4)
17461746
'''
17471747

1748+
if not skip:
1749+
self._set_link_fk(q)
1750+
17481751
d = 10000
1749-
p1 = None,
1752+
p1 = None
17501753
p2 = None
17511754

17521755
for link in self.links:
@@ -1762,15 +1765,21 @@ def closest_point(self, shape, inf_dist=1.0):
17621765

17631766
return d, p1, p2
17641767

1765-
def collided(self, shape):
1768+
def collided(self, q, shape, skip=False):
17661769
'''
17671770
collided(shape) checks if this robot and shape have collided
17681771
:param shape: The shape to compare distance to
17691772
:type shape: Shape
1773+
:param skip: Skip setting all shape transforms based on q, use this
1774+
option if using this method in conjuction with Swift to save time
1775+
:type skip: boolean
17701776
:returns: True if shapes have collided
17711777
:rtype: bool
17721778
'''
17731779

1780+
if not skip:
1781+
self._set_link_fk(q)
1782+
17741783
for link in self.links:
17751784
if link.collided(shape):
17761785
return True

0 commit comments

Comments
 (0)