Skip to content

Commit

Permalink
pytest36/AxisMr: simplify moveWait()
Browse files Browse the repository at this point in the history
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()
  • Loading branch information
tboegi committed Nov 11, 2024
1 parent f9a5b4a commit de5eaa4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 32 deletions.
39 changes: 28 additions & 11 deletions test/pytests36/110_Ethercat_HOMF_-ProcHom.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,54 @@ 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"))
if msta & self.axisMr.MSTA_BIT_HOMED and old_high_limit > old_low_limit:
# 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
jvel = self.axisCom.get(".JVEL")
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")
Expand Down Expand Up @@ -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):
Expand Down
24 changes: 15 additions & 9 deletions test/pytests36/AxisCom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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
Expand All @@ -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"
Expand Down
14 changes: 2 additions & 12 deletions test/pytests36/AxisMr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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.
Expand Down

0 comments on commit de5eaa4

Please sign in to comment.