Skip to content

Commit 179022c

Browse files
acolombaf-silva
andauthored
ds402: Support checking the homing status. (#248)
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]>
1 parent 509f553 commit 179022c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

canopen/profiles/p402.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,21 @@ def is_faulted(self):
274274
bitmask, bits = State402.SW_MASK['FAULT']
275275
return self.statusword & bitmask == bits
276276

277+
def is_homed(self, restore_op_mode=False):
278+
"""Switch to homing mode and determine its status."""
279+
previous_op_mode = self.op_mode
280+
if previous_op_mode != 'HOMING':
281+
logger.info('Switch to HOMING from %s', previous_op_mode)
282+
self.op_mode = 'HOMING'
283+
homingstatus = None
284+
for key, value in Homing.STATES.items():
285+
bitmask, bits = value
286+
if self.statusword & bitmask == bits:
287+
homingstatus = key
288+
if restore_op_mode:
289+
self.op_mode = previous_op_mode
290+
return homingstatus in ('TARGET REACHED', 'ATTAINED')
291+
277292
def homing(self, timeout=TIMEOUT_HOMING_DEFAULT, set_new_home=True):
278293
"""Function to execute the configured Homing Method on the node
279294
:param int timeout: Timeout value (default: 30)

0 commit comments

Comments
 (0)