@@ -307,7 +307,10 @@ 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+ # This shouldn't be accessed once turned to True during `init` method.
311+ is_rtc_activated = False
312+
313+ _RTC_list = [
311314 ['seq' , "SequencePlayer" ],
312315 ['sh' , "StateHolder" ],
313316 ['fk' , "ForwardKinematics" ],
@@ -318,6 +321,9 @@ class via the link above; nicely formatted api doc web page
318321 ['log' , "DataLogger" ],
319322 ]
320323
324+ # List of the name of RT Components that hrpsys requires at minimum.
325+ _RTC_NAME_MINREQ = ['seq' , 'sh' , 'fk' ]
326+
321327 # servo controller (grasper)
322328 sc = None
323329 sc_svc = None
@@ -328,7 +334,7 @@ class via the link above; nicely formatted api doc web page
328334 "the function call was successful, since not " +
329335 "all methods internally called return status" )
330336
331- def init (self , robotname = "HiroNX(Robot)0" , url = "" , rtcs = _RTClist ):
337+ def init (self , robotname = "HiroNX(Robot)0" , url = "" , rtcs = None ):
332338 '''
333339 Calls init from its superclass, which tries to connect RTCManager,
334340 looks for ModelLoader, and starts necessary RTC components. Also runs
@@ -337,11 +343,10 @@ def init(self, robotname="HiroNX(Robot)0", url="", rtcs=_RTClist):
337343
338344 @type robotname: str
339345 @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'.
346+ @type rtcs: [str]
347+ @param rtcs: List of abbreviated RTC names.
343348
344- example: [[ 'seq', "SequencePlayer"], [ 'sh', "StateHolder"] ,,,]
349+ example: ['seq', 'sh',,,]
345350 '''
346351 # reload for hrpsys 315.1.8
347352 print (self .configurator_name + "waiting ModelLoader" )
@@ -366,10 +371,8 @@ def init(self, robotname="HiroNX(Robot)0", url="", rtcs=_RTClist):
366371 # HrpsysConfigurator.init(self, robotname=robotname, url=url)
367372 self .sensors = self .getSensors (url )
368373
369- if rtcs :
370- self ._RTClist = rtcs
371374 # all([rtm.findRTC(rn[0], rtm.rootnc) for rn in self.getRTCList()]) # not working somehow...
372- if set ([rn [0 ] for rn in self .getRTCList ()]).issubset (set ([x .name () for x in self .ms .get_components ()])) :
375+ if set ([rn [0 ] for rn in self .getRTCList (rtcs )]).issubset (set ([x .name () for x in self .ms .get_components ()])) :
373376 print (self .configurator_name + "hrpsys components are already created and running" )
374377 self .findComps (max_timeout_count = 0 , verbose = True )
375378 else :
@@ -450,24 +453,68 @@ def goInitial(self, tm=7, wait=True, init_pose_type=0):
450453 self .seq_svc .waitInterpolationOfGroup (self .Groups [i ][0 ])
451454 return ret
452455
453- def getRTCList (self ):
456+ def getRTCList (self , rtcs_str = None ):
454457 '''
458+ @summary: Return the list of activated RT components. As opposed to
459+ its naming, this also:
460+ 1) activate an rmfo (stands for "remove force offset")
461+ RTC.
462+ 2) selectively activate RTCs passed by rtcs_str. This is
463+ possible ONLY during the initialization process done
464+ by `init` method.
455465 @see: HrpsysConfigurator.getRTCList
456466
467+ @type rtcs_str: str
468+ @param rtcs_str: A single str for a set of abbreviated names of RTCs,
469+ each of which is comma-separated. This is possible
470+ ONLY during the initialization process done by
471+ `init` method.
472+ example: "seq, sh, fk, ic, el, sc, log"
457473 @rtype [[str]]
458- @rerutrn List of available components. Each element consists of a list
474+ @return List of available components. Each element consists of a list
459475 of abbreviated and full names of the component.
476+ @raise TypeError: When rtcs_str isn't a string.
477+ @raise ValueError: When rtcs_str does not contain minimum
478+ required RTCs.
460479 '''
461- if hasattr (self , 'rmfo' ):
480+ if rtcs_str :
481+ if self .is_rtc_activated :
482+ print ('RTCs are already activated. Skipping the passed request: {}' .format (rtcs_str ))
483+ else :
484+ if not isinstance (rtcs_str , basestring ):
485+ raise TypeError ('rtcs_str needs to be string.' )
486+ # Set a new list of RTCs
487+ new_rtcs = []
488+ # Separate by comma and remove whitespace.
489+ rtcs_req_list = [x .strip () for x in rtcs_str .split ("," )]
490+ # Check if minimum required RTCs are passed.
491+ if not all (x in rtcs_req_list for x in self ._RTC_NAME_MINREQ ):
492+ raise ValueError ('{} are required at minimum' .format (
493+ self ._RTC_NAME_MINREQ ))
494+ for rtc_requested in rtcs_req_list :
495+ for elem in self ._RTC_list :
496+ if elem [0 ] == rtc_requested :
497+ new_rtcs .append (elem )
498+ break
499+ self ._RTC_list = new_rtcs
500+ self .is_rtc_activated = True
501+
502+ is_rmfo_initiated = False
503+ # For some reason using built-in "any" method yields
504+ # `TypeError: 'module' object is not callable`, so do the iteration.
505+ for rtc_list in self ._RTC_list :
506+ if 'rmfo' in rtc_list :
507+ is_rmfo_initiated = True
508+ if hasattr (self , 'rmfo' ) and not is_rmfo_initiated :
462509 self .ms .load ("RemoveForceSensorLinkOffset" )
463510 self .ms .load ("AbsoluteForceSensor" )
464511 if "RemoveForceSensorLinkOffset" in self .ms .get_factory_names ():
465- self ._RTClist .append (['rmfo' , "RemoveForceSensorLinkOffset" ])
512+ self ._RTC_list .append (['rmfo' , "RemoveForceSensorLinkOffset" ])
466513 elif "AbsoluteForceSensor" in self .ms .get_factory_names ():
467- self ._RTClist .append (['rmfo' , "AbsoluteForceSensor" ])
514+ self ._RTC_list .append (['rmfo' , "AbsoluteForceSensor" ])
468515 else :
469516 print "Component rmfo is not loadable."
470- return self ._RTClist
517+ return self ._RTC_list
471518
472519 # hand interface
473520 # effort: 1~100[%]
0 commit comments