@@ -204,7 +204,6 @@ class BaseNode402(RemoteNode):
204204 TIMEOUT_SWITCH_STATE_SINGLE = 0.4 # seconds
205205 INTERVAL_CHECK_STATE = 0.01 # seconds
206206 TIMEOUT_HOMING_DEFAULT = 30 # seconds
207- INTERVAL_CHECK_HOMING = 0.1 # seconds
208207
209208 def __init__ (self , node_id , object_dictionary ):
210209 super (BaseNode402 , self ).__init__ (node_id , object_dictionary )
@@ -276,18 +275,6 @@ def is_faulted(self):
276275 bitmask , bits = State402 .SW_MASK ['FAULT' ]
277276 return self .statusword & bitmask == bits
278277
279- def _homing_status (self ):
280- """Interpret the current Statusword bits as homing state string."""
281- # Wait to make sure an RPDO was received. Should better check for reception
282- # instead of this hard-coded delay, but at least it can be configured per node.
283- time .sleep (self .INTERVAL_CHECK_HOMING )
284- status = None
285- for key , value in Homing .STATES .items ():
286- bitmask , bits = value
287- if self .statusword & bitmask == bits :
288- status = key
289- return status
290-
291278 def is_homed (self , restore_op_mode = False ):
292279 """Switch to homing mode and determine its status.
293280
@@ -299,7 +286,11 @@ def is_homed(self, restore_op_mode=False):
299286 if previous_op_mode != 'HOMING' :
300287 logger .info ('Switch to HOMING from %s' , previous_op_mode )
301288 self .op_mode = 'HOMING'
302- homingstatus = self ._homing_status ()
289+ homingstatus = None
290+ for key , value in Homing .STATES .items ():
291+ bitmask , bits = value
292+ if self .statusword & bitmask == bits :
293+ homingstatus = key
303294 if restore_op_mode :
304295 self .op_mode = previous_op_mode
305296 return homingstatus in ('TARGET REACHED' , 'ATTAINED' )
@@ -320,10 +311,16 @@ def homing(self, timeout=TIMEOUT_HOMING_DEFAULT):
320311 t = time .monotonic () + timeout
321312 try :
322313 while homingstatus not in ('TARGET REACHED' , 'ATTAINED' ):
323- homingstatus = self ._homing_status ()
314+ for key , value in Homing .STATES .items ():
315+ # check if the Statusword after applying the bitmask
316+ # corresponds with the needed bits to determine the current status
317+ bitmask , bits = value
318+ if self .statusword & bitmask == bits :
319+ homingstatus = key
324320 if homingstatus in ('INTERRUPTED' , 'ERROR VELOCITY IS NOT ZERO' ,
325321 'ERROR VELOCITY IS ZERO' ):
326322 raise RuntimeError ('Unable to home. Reason: {0}' .format (homingstatus ))
323+ time .sleep (self .INTERVAL_CHECK_STATE )
327324 if time .monotonic () > t :
328325 raise RuntimeError ('Unable to home, timeout reached' )
329326 logger .info ('Homing mode carried out successfully.' )
0 commit comments