Skip to content

Commit 08b2aa3

Browse files
author
Rachel
committed
add getPointFrom to util
1 parent fe4c12c commit 08b2aa3

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/prpy/util.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,3 +1598,35 @@ def GetManipulatorIndex(robot, manip=None):
15981598
manip_idx = manip.GetRobot().GetActiveManipulatorIndex()
15991599

16001600
return (manip, manip_idx)
1601+
1602+
def GetPointFrom(env, focus):
1603+
"""
1604+
Given a kinbody, array or transform, returns the xyz
1605+
location.
1606+
param env The environment where the item exists
1607+
param focus THe area to be referred to
1608+
"""
1609+
#Pointing at an object
1610+
if isinstance(focus, (openravepy.KinBody, openravepy.KinBody.Link)):
1611+
with env:
1612+
focus_trans = focus.GetTransform()
1613+
coord = list(focus_trans[0:3, 3])
1614+
1615+
#Pointing at a point in space as numpy array
1616+
elif (isinstance(focus, numpy.ndarray) and (focus.ndim == 1)
1617+
and (len(focus) == 3)):
1618+
coord = list(focus)
1619+
1620+
#Pointing at point in space as 4x4 transform
1621+
elif isinstance(focus, numpy.ndarray) and (focus.shape == (4, 4)):
1622+
coord = list(focus[0:3, 3])
1623+
1624+
#Pointing at a point in space as list or tuple
1625+
elif (isinstance(focus, (tuple, list)) and len(focus) == 3):
1626+
coord = focus
1627+
1628+
else:
1629+
raise prpy.exceptions.PrPyException(
1630+
'Focus of the point is an unknown object')
1631+
1632+
return coord

0 commit comments

Comments
 (0)