@@ -307,7 +307,7 @@ class via the link above; nicely formatted api doc web page
307307
308308 HandGroups = {'rhand' : [2 , 3 , 4 , 5 ], 'lhand' : [6 , 7 , 8 , 9 ]}
309309
310- _RTClist = [
310+ _RTC_list = [
311311 ['seq' , "SequencePlayer" ],
312312 ['sh' , "StateHolder" ],
313313 ['fk' , "ForwardKinematics" ],
@@ -318,6 +318,9 @@ class via the link above; nicely formatted api doc web page
318318 ['log' , "DataLogger" ],
319319 ]
320320
321+ # List of the name of RT Components that hrpsys requires at minimum.
322+ _RTC_NAME_MINREQ = ['seq' , 'sh' , 'fk' ]
323+
321324 # servo controller (grasper)
322325 sc = None
323326 sc_svc = None
@@ -328,7 +331,7 @@ class via the link above; nicely formatted api doc web page
328331 "the function call was successful, since not " +
329332 "all methods internally called return status" )
330333
331- def init (self , robotname = "HiroNX(Robot)0" , url = "" , rtcs = _RTClist ):
334+ def init (self , robotname = "HiroNX(Robot)0" , url = "" , rtcs = None ):
332335 '''
333336 Calls init from its superclass, which tries to connect RTCManager,
334337 looks for ModelLoader, and starts necessary RTC components. Also runs
@@ -337,11 +340,10 @@ def init(self, robotname="HiroNX(Robot)0", url="", rtcs=_RTClist):
337340
338341 @type robotname: str
339342 @type url: str
340- @type rtcs: [[str, str]]
341- @param rtcs: List of list of RTC names. Each inner list consists of
342- 'SHORTENED' name and the 'FULLNAME'.
343+ @type rtcs: [str]
344+ @param rtcs: List of abbreviated RTC names.
343345
344- example: [[ 'seq', "SequencePlayer"], [ 'sh', "StateHolder"] ,,,]
346+ example: ['seq', 'sh',,,]
345347 '''
346348 # reload for hrpsys 315.1.8
347349 print (self .configurator_name + "waiting ModelLoader" )
@@ -367,7 +369,10 @@ def init(self, robotname="HiroNX(Robot)0", url="", rtcs=_RTClist):
367369 self .sensors = self .getSensors (url )
368370
369371 if rtcs :
370- self ._RTClist = rtcs
372+ # convert the list of abbreviated RTC names to the one that
373+ # getRTCList wants.
374+ self .getRTCList (rtcs )
375+
371376 # all([rtm.findRTC(rn[0], rtm.rootnc) for rn in self.getRTCList()]) # not working somehow...
372377 if set ([rn [0 ] for rn in self .getRTCList ()]).issubset (set ([x .name () for x in self .ms .get_components ()])) :
373378 print (self .configurator_name + "hrpsys components are already created and running" )
@@ -450,24 +455,55 @@ def goInitial(self, tm=7, wait=True, init_pose_type=0):
450455 self .seq_svc .waitInterpolationOfGroup (self .Groups [i ][0 ])
451456 return ret
452457
453- def getRTCList (self ):
458+ def getRTCList (self , rtcs_str = None ):
454459 '''
455460 @see: HrpsysConfigurator.getRTCList
456461
462+ @type rtcs_str: str
463+ @param rtcs_str: A single str for a set of abbreviated names of RTCs,
464+ each of which is comma-separated.
465+ example: "seq, sh, fk, ic, el, sc, log"
457466 @rtype [[str]]
458- @rerutrn List of available components. Each element consists of a list
467+ @return List of available components. Each element consists of a list
459468 of abbreviated and full names of the component.
469+ @raise TypeError: When rtcs_str isn't a string.
470+ @raise ValueError: When rtcs_str does not contain minimum
471+ required RTCs.
460472 '''
461- if hasattr (self , 'rmfo' ):
473+ if rtcs_str :
474+ if not isinstance (rtcs_str , basestring ):
475+ raise TypeError ('rtcs_str needs to be string.' )
476+ # Set a new list of RTCs
477+ new_rtcs = []
478+ # Separate by comma and remove whitespace.
479+ rtcs_req_list = [x .strip () for x in rtcs_str .split ("," )]
480+ # Check if minimum required RTCs are passed.
481+ if not all (x in rtcs_req_list for x in self ._RTC_NAME_MINREQ ):
482+ raise ValueError ('{} are required at minimum' .format (
483+ self ._RTC_NAME_MINREQ ))
484+ for rtc_requested in rtcs_req_list :
485+ for elem in self ._RTC_list :
486+ if elem [0 ] == rtc_requested :
487+ new_rtcs .append (elem )
488+ break
489+ self ._RTC_list = new_rtcs
490+
491+ is_rmfo_initiated = False
492+ # For some reason using built-in "any" method yields
493+ # `TypeError: 'module' object is not callable`, so do the iteration.
494+ for rtc_list in self ._RTC_list :
495+ if 'rmfo' in rtc_list :
496+ is_rmfo_initiated = True
497+ if hasattr (self , 'rmfo' ) and not is_rmfo_initiated :
462498 self .ms .load ("RemoveForceSensorLinkOffset" )
463499 self .ms .load ("AbsoluteForceSensor" )
464500 if "RemoveForceSensorLinkOffset" in self .ms .get_factory_names ():
465- self ._RTClist .append (['rmfo' , "RemoveForceSensorLinkOffset" ])
501+ self ._RTC_list .append (['rmfo' , "RemoveForceSensorLinkOffset" ])
466502 elif "AbsoluteForceSensor" in self .ms .get_factory_names ():
467- self ._RTClist .append (['rmfo' , "AbsoluteForceSensor" ])
503+ self ._RTC_list .append (['rmfo' , "AbsoluteForceSensor" ])
468504 else :
469505 print "Component rmfo is not loadable."
470- return self ._RTClist
506+ return self ._RTC_list
471507
472508 # hand interface
473509 # effort: 1~100[%]
0 commit comments