Skip to content

Commit

Permalink
ds402: Support checking the homing status. (#248)
Browse files Browse the repository at this point in the history
Implement a new method BaseNode402.is_homed() which will switch to the
corresponding operation mode HOMING and then examine the Statusword
for the homing status bits.

This allows to skip the homing procedure in case the drive controller
still knows its position, but e.g. the Python application was
restarted.

Co-authored-by: André Filipe Silva <[email protected]>
  • Loading branch information
acolomb and af-silva authored Aug 2, 2021
1 parent 509f553 commit 179022c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions canopen/profiles/p402.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,21 @@ def is_faulted(self):
bitmask, bits = State402.SW_MASK['FAULT']
return self.statusword & bitmask == bits

def is_homed(self, restore_op_mode=False):
"""Switch to homing mode and determine its status."""
previous_op_mode = self.op_mode
if previous_op_mode != 'HOMING':
logger.info('Switch to HOMING from %s', previous_op_mode)
self.op_mode = 'HOMING'
homingstatus = None
for key, value in Homing.STATES.items():
bitmask, bits = value
if self.statusword & bitmask == bits:
homingstatus = key
if restore_op_mode:
self.op_mode = previous_op_mode
return homingstatus in ('TARGET REACHED', 'ATTAINED')

def homing(self, timeout=TIMEOUT_HOMING_DEFAULT, set_new_home=True):
"""Function to execute the configured Homing Method on the node
:param int timeout: Timeout value (default: 30)
Expand Down

0 comments on commit 179022c

Please sign in to comment.