Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/tsr gripper library #313

Merged
merged 7 commits into from
Jul 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/prpy/base/endeffector.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ def SetActive(self):
This both: (1) sets the current manipulator as active and (2) sets the
active DOF values to thosse associated with this end-effector.
"""
self.GetRobot().SetActiveManipulator(self.manipulator)
self.GetRobot().SetActiveDOFs(self.GetArmIndices())
self.manipulator.GetRobot().SetActiveManipulator(self.manipulator)
self.manipulator.GetRobot().SetActiveDOFs(self.manipulator.GetArmIndices())
20 changes: 20 additions & 0 deletions src/prpy/tsr/tsrlibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def wrapped_func(robot, kinbody, *args, **kw_args):
class TSRLibrary(object):
all_factories = collections.defaultdict(lambda: collections.defaultdict(dict))
generic_kinbody_key = "_*" # Something that is unlikely to be an actual kinbody name
generic_robot_key = "_*"

def __init__(self, robot, robot_name=None):
"""
Expand Down Expand Up @@ -88,12 +89,28 @@ def __call__(self, kinbody, action_name, *args, **kw_args):
f = None
try:
f = self.all_factories[self.robot_name][kinbody_name][action_name]
logger.info('Using robot specific TSR for object')
except KeyError:
pass

if f is None:
try:
f = self.all_factories[self.generic_robot_key][kinbody_name][action_name]
logger.info('Using generic TSR for object')
except KeyError:
pass

if f is None:
try:
f = self.all_factories[self.robot_name][self.generic_kinbody_key][action_name]
logger.info('Using robot specific generic object')
except KeyError:
pass

if f is None:
try:
f = self.all_factories[self.generic_robot_key][self.generic_kinbody_key][action_name]
logger.info('Using generic object')
except KeyError:
raise KeyError('There is no TSR factory registered for action "{:s}"'
' with robot "{:s}" and object "{:s}".'.format(
Expand Down Expand Up @@ -181,6 +198,9 @@ def add_factory(cls, func, robot_name, object_name, action_name):
if object_name is None:
object_name = cls.generic_kinbody_key

if robot_name is None:
robot_name = cls.generic_robot_key

if action_name in cls.all_factories[robot_name][object_name]:
logger.warning('Overwriting duplicate TSR factory for action "%s"'
' with robot "%s" and object "%s"',
Expand Down