@@ -54,6 +54,7 @@ def wrapped_func(robot, kinbody, *args, **kw_args):
54
54
55
55
class TSRLibrary (object ):
56
56
all_factories = collections .defaultdict (lambda : collections .defaultdict (dict ))
57
+ generic_kinbody_key = "_*" # Something that is unlikely to be an actual kinbody name
57
58
58
59
def __init__ (self , robot , robot_name = None ):
59
60
"""
@@ -83,12 +84,19 @@ def __call__(self, kinbody, action_name, *args, **kw_args):
83
84
kinbody_name = self .get_object_type (kinbody )
84
85
logger .debug ('Inferred KinBody name "%s" for TSR.' , kinbody_name )
85
86
87
+ f = None
86
88
try :
87
89
f = self .all_factories [self .robot_name ][kinbody_name ][action_name ]
88
- except KeyError :
89
- raise KeyError ('There is no TSR factory registered for action "{:s}"'
90
- ' with robot "{:s}" and object "{:s}".' .format (
91
- action_name , self .robot_name , kinbody_name ))
90
+ except KeyError , ignored :
91
+ pass
92
+
93
+ if f is None :
94
+ try :
95
+ f = self .all_factories [self .robot_name ][self .generic_kinbody_key ][action_name ]
96
+ except KeyError :
97
+ raise KeyError ('There is no TSR factory registered for action "{:s}"'
98
+ ' with robot "{:s}" and object "{:s}".' .format (
99
+ action_name , self .robot_name , kinbody_name ))
92
100
93
101
return f (self .robot , kinbody , * args , ** kw_args )
94
102
@@ -166,6 +174,9 @@ def add_factory(cls, func, robot_name, object_name, action_name):
166
174
logger .debug ('Adding TSRLibrary factory for robot "%s", object "%s", action "%s".' ,
167
175
robot_name , object_name , action_name )
168
176
177
+ if object_name is None :
178
+ object_name = cls .generic_kinbody_key
179
+
169
180
if action_name in cls .all_factories [robot_name ][object_name ]:
170
181
logger .warning ('Overwriting duplicate TSR factory for action "%s"'
171
182
' with robot "%s" and object "%s"' ,
0 commit comments