Skip to content

Commit

Permalink
DS402: Restore operation mode after homing only on explicit request. (#…
Browse files Browse the repository at this point in the history
…262)

* ds402: Remove set_new_home functionality from BaseNode402.homing().

The homing() method will try to manipulate the Home Offset (0x607C)
parameter by default.  That's not the way the parameter is intended to
work.  After a successful homing procedure, the drive should set the
Actual Position (0x6063) to the Home Offset (0x607C) by itself.  By
default that is zero, so the selected reference switch flank will mark
the new zero position.

The library's default behavior here is backwards, and can only work
with absolute position encoders.  The whole point of homing is to find
a physical reference and align the logical coordinate system to it.
Trying to determine the desired offset from the value which an
unreferenced encoder had at the physical reference point actually
destroys that logical alignment.

The functionality of set_new_home=True is trivial to do from the
application, so remove it completely from homing().

* ds402: Restore operation mode after homing only on explicit request.

Add a new parameter restore_op_mode which defaults to False, and skip
changing back to the previous mode unless it is explicitly enabled by
passing True.  Note that most applications will decide on the needed
mode after homing and therefore do not need this behavior, hence the
new default.

Co-authored-by: André Filipe Silva <[email protected]>
  • Loading branch information
acolomb and af-silva authored Aug 16, 2021
1 parent b2ef201 commit 7462d0b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions canopen/profiles/p402.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,16 +320,18 @@ def is_homed(self, restore_op_mode=False):
self.op_mode = previous_op_mode
return homingstatus in ('TARGET REACHED', 'ATTAINED')

def homing(self, timeout=TIMEOUT_HOMING_DEFAULT):
def homing(self, timeout=TIMEOUT_HOMING_DEFAULT, restore_op_mode=False):
"""Execute the configured Homing method on the node.
:param int timeout: Timeout value (default: 30).
:param bool restore_op_mode:
Switch back to the previous operation mode after homing (default: no).
:return: If the homing was complete with success.
:rtype: bool
"""
if timeout is None:
timeout = self.TIMEOUT_HOMING_DEFAULT
previus_op_mode = self.op_mode
if restore_op_mode:
previous_op_mode = self.op_mode
self.state = 'SWITCHED ON'
self.op_mode = 'HOMING'
# The homing process will initialize at operation enabled
self.state = 'OPERATION ENABLED'
Expand All @@ -355,7 +357,8 @@ def homing(self, timeout=TIMEOUT_HOMING_DEFAULT):
except RuntimeError as e:
logger.info(str(e))
finally:
self.op_mode = previus_op_mode
if restore_op_mode:
self.op_mode = previous_op_mode
return False

@property
Expand Down

0 comments on commit 7462d0b

Please sign in to comment.