Skip to content

Commit 7462d0b

Browse files
acolombaf-silva
andauthored
DS402: Restore operation mode after homing only on explicit request. (#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]>
1 parent b2ef201 commit 7462d0b

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

canopen/profiles/p402.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,16 +320,18 @@ def is_homed(self, restore_op_mode=False):
320320
self.op_mode = previous_op_mode
321321
return homingstatus in ('TARGET REACHED', 'ATTAINED')
322322

323-
def homing(self, timeout=TIMEOUT_HOMING_DEFAULT):
323+
def homing(self, timeout=TIMEOUT_HOMING_DEFAULT, restore_op_mode=False):
324324
"""Execute the configured Homing method on the node.
325325
326326
:param int timeout: Timeout value (default: 30).
327+
:param bool restore_op_mode:
328+
Switch back to the previous operation mode after homing (default: no).
327329
:return: If the homing was complete with success.
328330
:rtype: bool
329331
"""
330-
if timeout is None:
331-
timeout = self.TIMEOUT_HOMING_DEFAULT
332-
previus_op_mode = self.op_mode
332+
if restore_op_mode:
333+
previous_op_mode = self.op_mode
334+
self.state = 'SWITCHED ON'
333335
self.op_mode = 'HOMING'
334336
# The homing process will initialize at operation enabled
335337
self.state = 'OPERATION ENABLED'
@@ -355,7 +357,8 @@ def homing(self, timeout=TIMEOUT_HOMING_DEFAULT):
355357
except RuntimeError as e:
356358
logger.info(str(e))
357359
finally:
358-
self.op_mode = previus_op_mode
360+
if restore_op_mode:
361+
self.op_mode = previous_op_mode
359362
return False
360363

361364
@property

0 commit comments

Comments
 (0)