From de5eaa4ff0f7acc1fe5e9e619e7245c3eef25644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20B=C3=B6gershausen?= Date: Mon, 11 Nov 2024 11:48:52 +0100 Subject: [PATCH] pytest36/AxisMr: simplify moveWait() Make sure that moveWait() does not a lot of hokus-pokus: Calculate a timeout, then write to the .VAL field with wait=True. Needed to equip both moveWait() in AxisMr and put() in AxisCom with a throw=throw parameter Note: More test cases needs to be changed to check the result of moveWait() --- test/pytests36/110_Ethercat_HOMF_-ProcHom.py | 39 ++++++++++++++------ test/pytests36/AxisCom.py | 24 +++++++----- test/pytests36/AxisMr.py | 14 +------ 3 files changed, 45 insertions(+), 32 deletions(-) diff --git a/test/pytests36/110_Ethercat_HOMF_-ProcHom.py b/test/pytests36/110_Ethercat_HOMF_-ProcHom.py index 19bbff9b..ca63c4a3 100755 --- a/test/pytests36/110_Ethercat_HOMF_-ProcHom.py +++ b/test/pytests36/110_Ethercat_HOMF_-ProcHom.py @@ -28,12 +28,15 @@ def lineno(): def homeTheMotor(self, tc_no, homProc, jogToLSBefore, homeViaDriver): + print( + f"{datetime.datetime.now():%Y-%m-%d %H:%M:%S} {filnam} {tc_no} homProc={homProc} jogToLSBefore={jogToLSBefore} homeViaDriver={homeViaDriver}" + ) self.axisCom.putDbgStrToLOG("Start " + str(tc_no), wait=True) old_high_limit = self.axisCom.get(".HLM") old_low_limit = self.axisCom.get(".LLM") old_HomProc = 0 # default old_HomPos = 0.0 # default - passed = True + testPassed = True if jogToLSBefore != 0: msta = int(self.axisCom.get(".MSTA")) @@ -41,10 +44,16 @@ def homeTheMotor(self, tc_no, homProc, jogToLSBefore, homeViaDriver): # if we are homed, move absolute to the soft limit # This is faster than jogging if jogToLSBefore > 0: - self.axisMr.moveWait(tc_no, old_high_limit) + testPassed = testPassed and self.axisMr.moveWait( + tc_no, old_high_limit, throw=False + ) else: - self.axisMr.moveWait(tc_no, old_low_limit) - + testPassed = testPassed and self.axisMr.moveWait( + tc_no, old_low_limit, throw=False + ) + print( + f"{datetime.datetime.now():%Y-%m-%d %H:%M:%S} {filnam}:{lineno()} {tc_no} testPassed={testPassed}" + ) self.axisMr.setSoftLimitsOff(tc_no) # soft limit range assumed to be = hard range /1.5 or so # It is only needed to calculate a good timeout @@ -52,13 +61,21 @@ def homeTheMotor(self, tc_no, homProc, jogToLSBefore, homeViaDriver): accl = self.axisCom.get(".ACCL") time_to_wait = 1.5 * (old_high_limit - old_low_limit) / jvel + 2 * accl - passed = passed and self.axisMr.jogDirectionTimeout( + testPassed = testPassed and self.axisMr.jogDirectionTimeout( tc_no, jogToLSBefore, time_to_wait ) + print( + f"{datetime.datetime.now():%Y-%m-%d %H:%M:%S} {filnam}:{lineno()} {tc_no} testPassed={testPassed}" + ) self.axisCom.put(".LLM", old_low_limit) self.axisCom.put(".HLM", old_high_limit) else: - self.axisMr.moveWait(tc_no, (old_high_limit + old_low_limit) / 2.0) + testPassed = testPassed and self.axisMr.moveWait( + tc_no, (old_high_limit + old_low_limit) / 2.0, throw=False + ) + print( + f"{datetime.datetime.now():%Y-%m-%d %H:%M:%S} {filnam}:{lineno()} {tc_no} testPassed={testPassed}" + ) if homProc != 0: old_HomProc = self.axisCom.get("-HomProc") @@ -129,20 +146,20 @@ def homeTheMotor(self, tc_no, homProc, jogToLSBefore, homeViaDriver): f"{datetime.datetime.now():%Y-%m-%d %H:%M:%S} {tc_no} msta2=={self.axisMr.getMSTAtext(msta2)}" ) if msta2 & self.axisMr.MSTA_BIT_SLIP_STALL: - passed = False + testPassed = False if not msta2 & self.axisMr.MSTA_BIT_HOMED: - passed = False + testPassed = False if msta2 & self.axisMr.MSTA_BIT_PROBLEM: - passed = False + testPassed = False errId = int(self.axisCom.get("-ErrId", use_monitor=False)) print(f"{datetime.datetime.now():%Y-%m-%d %H:%M:%S} {tc_no} errId={errId:x}") self.axisMr.resetAxis(tc_no) - if passed: + if testPassed: self.axisCom.putDbgStrToLOG("Passed " + str(tc_no), wait=True) else: self.axisCom.putDbgStrToLOG("Failed " + str(tc_no), wait=True) - assert passed + assert testPassed class Test(unittest.TestCase): diff --git a/test/pytests36/AxisCom.py b/test/pytests36/AxisCom.py index 36c1b8e6..d0166fd6 100644 --- a/test/pytests36/AxisCom.py +++ b/test/pytests36/AxisCom.py @@ -142,13 +142,7 @@ def onChangesDmovPVA(self, value): f"{datetime.datetime.now():%Y-%m-%d %H:%M:%S} {filnam} onChangesPVA: value={int(value)} old_val={old_val} dmov_false={self.change_cnts['dmov_false']} dmov_true={self.change_cnts['dmov_true']}" ) - def put( - self, - pvsuf, - value, - wait=False, - timeout=5.0, - ): + def put(self, pvsuf, value, wait=False, timeout=5.0, throw=True): pvname = self.pvpfx + pvsuf fullname = self.url_scheme + pvname ret = None @@ -161,7 +155,8 @@ def put( f"{datetime.datetime.now():%Y-%m-%d %H:%M:%S} {filnam} put {fullname} value={value}" ) if self.ctxt is not None: - ret = self.ctxt.put(pvname, value, timeout=timeout, wait=wait) + # p4p + ret = self.ctxt.put(pvname, value, timeout=timeout, wait=wait, throw=throw) if self.log_debug: if ret is None: print( @@ -171,7 +166,12 @@ def put( print( f"{datetime.datetime.now():%Y-%m-%d %H:%M:%S} {filnam} put {fullname} value={value} ret={ret}" ) + if ret is None: + return True + return False + else: + # pyepics caput_ret = self.epics.caput(pvname, value, timeout=timeout, wait=wait) # This function returns 1 on success, # and a negative number if the timeout has been exceeded @@ -180,7 +180,13 @@ def put( f"{datetime.datetime.now():%Y-%m-%d %H:%M:%S} {filnam} put {fullname} value={value} caput_ret={ret}" ) if caput_ret != 1: - raise Exception(f"caput({pvname},{value}) returned error {caput_ret}") + if throw: + raise Exception( + f"caput({pvname},{value}) returned error {caput_ret}" + ) + else: + return False + return True def putDbgStrToLOG(self, value, wait=True, timeout=5.0): pvsuf = "-DbgStrToLOG" diff --git a/test/pytests36/AxisMr.py b/test/pytests36/AxisMr.py index dd1c93c2..da1cbe89 100644 --- a/test/pytests36/AxisMr.py +++ b/test/pytests36/AxisMr.py @@ -691,16 +691,7 @@ def moveIntoLS( return passed - def moveWait(self, tc_no, destination, field=".VAL"): - rbv = self.axisCom.get(".RBV", use_monitor=False) - rdbd = self.axisCom.get(".RDBD") - - inrange = self.calcAlmostEqual(tc_no, destination, rbv, rdbd, doPrint=False) - if inrange: - print( - f"{datetime.datetime.now():%Y-%m-%d %H:%M:%S} {tc_no}: moveWait destination={destination:.2f} rbv={rbv:.2f}" - ) - return True + def moveWait(self, tc_no, destination, field=".VAL", throw=True): timeout = 30 acceleration = self.axisCom.get(".ACCL") velocity = self.axisCom.get(".VELO") @@ -709,8 +700,7 @@ def moveWait(self, tc_no, destination, field=".VAL"): distance = math.fabs(self.axisCom.get(".RBV") - destination) timeout += distance / velocity - self.axisCom.put(field, destination) - return self.waitForStartAndDone(str(tc_no) + " moveWait", timeout, throw=False) + return self.axisCom.put(field, destination, wait=True, timeout=timeout) def postMoveCheck(self, tc_no): # Check the motor for the correct state at the end of move.