Python scripts could use some cleaning up
Consider this part of stress_test.py:
while True:
mov=10
if mov == 10:
print("Moving gap to %s" % mov)
done=ecmcSlitDemoLib.moveAxisPosition(gapMotor,mov)
if not done:
print("%s failed to position." % gapMotor)
sys.exit()
done=ecmcSlitDemoLib.waitForAxis(gapMotor,1800)
if not done:
print("%s failed waiting" % gapMotor)
sys.exit()
mov=60
time.sleep(2)
if mov == 60:
print("Moving gap to %s" % mov)
done=ecmcSlitDemoLib.moveAxisPosition(gapMotor,mov)
if not done:
print("%s failed to position" % gapMotor)
sys.exit()
done=ecmcSlitDemoLib.waitForAxis(gapMotor,1800)
if not done:
print("%s failed waiting" % gapMotor)
sys.exit()
time.sleep(2)
#mov=0
What is the purpose of the if
blocks? The value of mov
is set right above them in each case.
while True:
mov=10
print(f"Moving gap to {mov}")
if not ecmcSlitDemoLib.moveAxisPosition(gapMotor,mov):
print(f"{gapMotor} failed to position.")
sys.exit()
if not ecmcSlitDemoLib.waitForAxis(gapMotor,1800):
print(f"{gapMotor} failed waiting")
sys.exit()
time.sleep(2)
mov=60
print(f"Moving gap to {mov}")
if not ecmcSlitDemoLib.moveAxisPosition(gapMotor,mov):
print(f"{gapMotor} failed to position.")
sys.exit()
if not ecmcSlitDemoLib.waitForAxis(gapMotor,1800):
print(f"{gapMotor} failed waiting")
sys.exit()
time.sleep(2)
or even (refactored)
def test_ecmc_motion(position:int) -> None:
print(f"Moving gap to {position}")
if not ecmcSlitDemoLib.moveAxisPosition(gapMotor, position):
print(f"{gapMotor} failed to position.")
sys.exit()
if not ecmcSlitDemoLib.waitForAxis(gapMotor,1800):
print(f"{gapMotor} failed waiting")
sys.exit()
while True:
test_ecmc_motion(10)
time.sleep(2)
test_ecmc_motion(60)
time.sleep(2)
Furthermore, what is up with the sys.exit()
? Are these meant to be errors, or just stopping conditions?
Edited by Simon Rose