From d3841a18d2be92edbed029df9724d585cfaef169 Mon Sep 17 00:00:00 2001 From: Federico Rojas <federico.rojas@ess.eu> Date: Fri, 12 Jul 2024 12:05:45 +0200 Subject: [PATCH 1/4] Update motionFunctionsLib.py to the latest version Before deleting the https://gitlab.esss.lu.se/mcag/sources/pyads-motion-library repo to avoid having the same code in two places, merge files qith latest changes. modified: control/motionFunctionsLib.py --- control/motionFunctionsLib.py | 41 ++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/control/motionFunctionsLib.py b/control/motionFunctionsLib.py index 4b8fa69..f1e1c0a 100644 --- a/control/motionFunctionsLib.py +++ b/control/motionFunctionsLib.py @@ -201,6 +201,9 @@ class axis: def getInterlockedBwd(self): return self.getGenericVariable("stStatus.bInterlockedBwd", pyads.PLCTYPE_BOOL) + def getInTargetPosition(self): + return self.getGenericVariable("stStatus.bInTargetPosition", pyads.PLCTYPE_BOOL) + def getGearedStatus(self): return self.getGenericVariable("stStatus.bGeared", pyads.PLCTYPE_BOOL) @@ -294,6 +297,12 @@ class axis: def getVelocityMax(self): return self.getGenericVariable("stConfig.fVeloMax", pyads.PLCTYPE_LREAL) + + def getAccelMax(self): + return self.getGenericVariable("stConfig.fMaxAcc", pyads.PLCTYPE_LREAL) + + def getDecelMax(self): + return self.getGenericVariable("stConfig.fMaxDec", pyads.PLCTYPE_LREAL) def getSoftLimitFwdValue(self): return self.getGenericVariable("stConfig.fMaxSoftPosLimit", pyads.PLCTYPE_LREAL) @@ -709,6 +718,31 @@ class axis: if self.waitForStatusBit(self.getEnabledStatus, True): print(f" Axis Enabled") + def waitForVariable(self, varName, plcVarType, expectedValue, timeout=30, sleepInterval=SLEEP_INTERVAL): + # If timeout is negative time then just use a default + if timeout < 0: + timeout = 1 + + timeLimit = time.time() + timeout + timeoutError = False + while True: + variableValue=self.plc.connection.read_by_name(varName, plcVarType) + if str(variableValue) == str(expectedValue): + break + if time.time() > timeLimit: + timeoutError = True + break + if sleepInterval > 0: + time.sleep(sleepInterval) + + if timeoutError: + print( + f" Axis {self.axisNum}: Timeout error waiting for {varName} with value {variableValue} to return {expectedValue}" + ) + return False + else: + return True + # boolValue is the status you're waiting for # if you're waiting a bit to go high then this should be True def waitForStatusBit( @@ -722,8 +756,6 @@ class axis: timeoutError = False while True: statusBit = getStatusBitFunction() - if not verboseMode: - sys.stdout = open(os.devnull, "w") if statusBit == boolValue: break if time.time() > timeLimit: @@ -732,7 +764,6 @@ class axis: if sleepInterval > 0: time.sleep(sleepInterval) - sys.stdout = sys.__stdout__ if timeoutError: print( f" Axis {self.axisNum}: Timeout error waiting for {getStatusBitFunction.__name__} to return {boolValue}" @@ -798,7 +829,7 @@ class axis: timeLimit = time.time() + timeout bTimeoutError = False while True: - if round(self.getActVel(), roundVelDecimalPlaces) == 0: + if round(self.getActVel(), roundVelDecimalPlaces) == 0 or not self.getMovingStatus(): break if time.time() > timeLimit: bTimeoutError = True @@ -1038,7 +1069,7 @@ class PneumaticAxis: def getPSSPermitOKStatus(self): return self.getGenericVariable("stPneumaticAxisStatus.bPSSPermitOK", pyads.PLCTYPE_BOOL) - def getErrortatus(self): + def getErrorStatus(self): return self.getGenericVariable("stPneumaticAxisStatus.bError", pyads.PLCTYPE_BOOL) def getTimeElapsedExtend(self): -- GitLab From ffdc06f29986e46a465081951c08d57199fc7060 Mon Sep 17 00:00:00 2001 From: Federico Rojas <federico.rojas@ess.eu> Date: Fri, 12 Jul 2024 13:27:21 +0200 Subject: [PATCH 2/4] Update motionTests.py Before deleting the https://gitlab.esss.lu.se/mcag/sources/pyads-motion-library repo to avoid having the same code in two places, merge files with latest changes. modified: control/motionFunctionsLib.py modified: control/motionTests.py --- control/motionTests.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/control/motionTests.py b/control/motionTests.py index 4a820d3..aeee4a6 100644 --- a/control/motionTests.py +++ b/control/motionTests.py @@ -1,6 +1,9 @@ -from motionFunctionsLib import * +#!/usr/bin/env python + +import motionFunctionsLib from eAxisParameters import E_AxisParameters + # A good way to think about testing is the three As # Arrange, Act, Assert @@ -16,6 +19,20 @@ def powerOn(axis): axis.enableAxis() return axis.waitForStatusBit(axis.getEnabledStatus, True) +def axisHomed(axis): + print(f"Test: Axis Homed") + return axis.getHomedStatus + +def softLimitsOn(axis): + print(f"Test: Turn Soft Limits On") + axis.setSoftLimitsOn() + softLimFwd = axis.getSoftLimitFwdEnableStatus() + softLimBwd = axis.getSoftLimitBwdEnableStatus() + return softLimFwd and softLimBwd + +def noError(axis): + print(f"Test: No error") + return axis.getErrorStatus() def powerOff(axis): print(f"Test Power OFF") @@ -147,7 +164,10 @@ def limitSwitchFwd(axis): axis.waitForStop() return returnValue -def limitSwitchBwd(axis): +def limitSwitchBwd(axis, timeout): + if timeout == None: + timeout = axis.calcTravelTimeForRange() + print(f"Test: Activate Limit Switch Backward") timeout = axis.calcTravelTimeForRange() axis.jogBwd() -- GitLab From 881a9ebec66f7b0d729730fc17ff7f2800ee35de Mon Sep 17 00:00:00 2001 From: Federico Rojas <federico.rojas@ess.eu> Date: Wed, 17 Jul 2024 13:34:18 +0200 Subject: [PATCH 3/4] Bug fix: Change object axis 1 to slef in function moveToSwitchBwd --- control/motionFunctionsLib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/control/motionFunctionsLib.py b/control/motionFunctionsLib.py index f1e1c0a..a17bfd5 100644 --- a/control/motionFunctionsLib.py +++ b/control/motionFunctionsLib.py @@ -559,7 +559,7 @@ class axis: def moveToSwitchBwd(self, velo, timeout): if velo is None: - velo = axis1.getJogVelocity() + velo = self.getJogVelocity() print(f" Activate moving to Backward Limit Switch sequence...") if self.getSoftLimitFwdEnableStatus() or self.getSoftLimitBwdEnableStatus(): -- GitLab From 7b128b46b3e884c8a1ab553dba42c332ca28d633 Mon Sep 17 00:00:00 2001 From: Federico Rojas <federico.rojas@ess.eu> Date: Wed, 17 Jul 2024 13:54:00 +0200 Subject: [PATCH 4/4] Import Time library, time.sleep is used in motionTests.py --- control/motionTests.py | 1 + 1 file changed, 1 insertion(+) diff --git a/control/motionTests.py b/control/motionTests.py index aeee4a6..caf03b7 100644 --- a/control/motionTests.py +++ b/control/motionTests.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +import time import motionFunctionsLib from eAxisParameters import E_AxisParameters -- GitLab