From ab37af397f7456ffe14e0eb08df08369fe0ed14a Mon Sep 17 00:00:00 2001 From: boccioli_m Date: Tue, 8 Sep 2015 10:51:08 +0200 Subject: [PATCH] Closedown --- plugins/NewTest.java | 30 +++-- .../Motor Test 2/Motor Test 2.py | 107 +++++++++--------- 2 files changed, 70 insertions(+), 67 deletions(-) diff --git a/plugins/NewTest.java b/plugins/NewTest.java index 0aba44f..7f203eb 100644 --- a/plugins/NewTest.java +++ b/plugins/NewTest.java @@ -557,17 +557,9 @@ public class NewTest extends javax.swing.JPanel { HashMap hmTestParams){ if (TESTS_TESTS_DEFAULT_DIR.toFile().isDirectory()) { //check that the tests suite dir exists. If not, create it - Path testSuiteDir = Paths.get(TESTS_TESTS_DEFAULT_DIR.toString(),cleanFileName(sTestSuite)); - if( !testSuiteDir.toFile().isDirectory()){ - boolean success = testSuiteDir.toFile().mkdirs(); - if (!success) { - // Directory creation failed - SwingUtils.showMessage(this, "generateTestFiles()", "Cannot create directory " + testSuiteDir.toString()); - return; - } - } + String testSuiteDir = generateTestSuite(sTestSuite); //new test directory inside tests suite dir - Path testDir = Paths.get(testSuiteDir.toString(),cleanFileName(sTestName)); + Path testDir = Paths.get(testSuiteDir,cleanFileName(sTestName)); if( testDir.toFile().isDirectory()){ //test already exists: ask to overwrite OptionResult res = SwingUtils.showOption(this, "Overwrite Test?", "Test already exists. Overwrite with this new one?", OptionType.YesNo); @@ -632,7 +624,9 @@ public class NewTest extends javax.swing.JPanel { String sTestSuite, HashMap hmTestParams){ if (TESTS_DEVICES_DEFAULT_DIR.toFile().isDirectory()) { - //new device directory inside tests suite dir + //check that the tests suite dir exists. If not, create it + String testSuiteDir = generateTestSuite(sTestSuite); + //new device directory inside devices dir Path testDir = Paths.get(TESTS_DEVICES_DEFAULT_DIR.toString(),cleanFileName(sTestName)); if( testDir.toFile().isDirectory()){ //device already exists: ask to overwrite @@ -666,6 +660,20 @@ public class NewTest extends javax.swing.JPanel { return Paths.get(testDir.toString(), cleanFileName(sTestName+".py")); } + private String generateTestSuite(String sTestSuite){ + //check that the tests suite dir exists. If not, create it + Path testSuiteDir = Paths.get(TESTS_TESTS_DEFAULT_DIR.toString(),cleanFileName(sTestSuite)); + if( !testSuiteDir.toFile().isDirectory()){ + boolean success = testSuiteDir.toFile().mkdirs(); + if (!success) { + // Directory creation failed + SwingUtils.showMessage(this, "generateTestFiles()", "Cannot create directory " + testSuiteDir.toString()); + return testSuiteDir.toString(); + } + } + return testSuiteDir.toString(); + } + /** * generate the python script that runs the test * diff --git a/script/tests/tests/Collimator Tests pro/Motor Test 2/Motor Test 2.py b/script/tests/tests/Collimator Tests pro/Motor Test 2/Motor Test 2.py index d456af6..23f9329 100644 --- a/script/tests/tests/Collimator Tests pro/Motor Test 2/Motor Test 2.py +++ b/script/tests/tests/Collimator Tests pro/Motor Test 2/Motor Test 2.py @@ -1,55 +1,46 @@ #Script Motor Test 2 for production system #Go to absolute position A, then move +B steps, then -2B steps, then +2Bsteps (ie oscillate round centre position, logging after each movement); repeat N times + ###### Init - DO NOT MODIFY THE CODE BELOW ###### -global print_log, sendFeedback, inspect, log, sys, inspect, os, traceback +global sys, inspect, os, traceback import sys, inspect, os, traceback - -def print_log(testName, DEVICE, text): - time.ctime() - now = time.strftime('%Y.%m.%d %H:%M:%S') - print now + ' ' + DEVICE + ' - ' + testName + ': ' + str(text) - log (now + ' ' + DEVICE + ' - ' + testName + ': ' + text ) -#prepare and send feedback to calling tool -def sendFeedback(testPath, testName, DEVICE, returnString, testPassed): - print_log(testName, DEVICE, 'End of test. Result:') - print_log(testName, DEVICE, 'Device: ' + DEVICE) - print_log(testName, DEVICE, 'Test name: ' + testName) - print_log(testName, DEVICE, 'Test path: ' + testPath) - print_log(testName, DEVICE, 'Test passed: ' + str(testPassed)) - print_log(testName, DEVICE, 'Return string: ' + returnString) - ret = [testPath, DEVICE, returnString, testPassed] - set_return(ret) - def startTest(testName, DEVICE, params): + #by default, assume the test failed + ret = 'Test failed' + status = False + #plot name to be given to the scan. Use: scan.setPlotName(plotName) + plotName = DEVICE + ' - ' + testName + #put the whole custom code under try/catch try: - import traceback #get the path of this script testPath = inspect.getfile(inspect.currentframe()) - #by default, failed - ret = 'Test failed' - success = False - #plot name to be given to the scan. Use: scan.setPlotName(plotName) - plotName = DEVICE + ' - ' + testName + #init the testing tool class. It can be sued in the following ways: + test = TestingTool(testName, testPath, DEVICE, params) + ######### WRITE YOUR CODE HERE BELOW ############# #get parameters from the calling interface try: - print_log(testName, DEVICE, "Running test Motor Test 2 for device " + DEVICE + " with the following parameters:\n" + str(params)) - middle = float(params["midPoint"]["value"]) - loopTimes = int(params["repeatTimes"]["value"]) - span = float(params["spanFromMidPoint"]["value"]) + test.log( "Running test Motor Test 2 for device " + DEVICE + " with the following parameters:\n" + str(params)) + middle = float(test.getParam("midPoint")) + loopTimes = int(test.getParam("repeatTimes")) + span = float(test.getParam("spanFromMidPoint")) except: ret = 'Could not retrieve testing parameters - ' + traceback.format_exc() success = False - sendFeedback(testPath, testName, DEVICE, ret, status) + test.sendFeedback( ret, status) return #scan = ManualScan(['idX', 'idInkr'], ['idMotorStatus', 'idLogicalPosition', 'idDiameter', 'idPotiPosFromBeam', 'idPotiRaw', 'idPotiProc', 'idBtvsRaw', 'idMotorStep', 'idDiff01', 'idDiff02'] , [-0.5, 0.0], [4.0, 3000.0], [3000, 20]) #scan = ManualScan(['idX'], ['idMotorStatus', 'idLogicalPosition', 'idDiameter', 'idPotiPosFromBeam', 'idPotiRaw', 'idPotiProc', 'idBtvsRaw', 'idMotorStep', 'idDiff01', 'idDiff02'] , [ 0.0], [ 3000.0], [20]) - scan = ManualScan(['idX'], ['idInkr', 'idInkrRb', 'idMotorStep', 'idPotiPosFromBeam', 'idPotiPosition', 'idPotiRef1Position', 'idPotiRef2Position', 'idDiameter', 'idPotiPosition-idInkrRb', 'idPortPosition-idMotorStep'] , [ 0.0], [ 3000.0], [20]) + scan = ManualScan(['idX'], ['idInkr', 'idInkrRb', 'idMotorStep', 'idPotiPosFromBeam', 'idPotiPosition', 'idPotiRef1Position', 'idPotiRef2Position', 'idDiameter', 'idPotiPosition-idInkrRb', 'idPortPosition-idMotorStep'] ) scan.setPlotName(plotName) scan.start() + + #coloured plot (one colour per scan) + p1 = plot(None,name="Poti-Increment difference", context = plotName + " difference")[0] + p2 = plot(None,name="Poti-MotorStep difference", context = plotName + " difference")[0] #Creating channels: dimension 1 try: @@ -64,29 +55,29 @@ def startTest(testName, DEVICE, params): except: ret = 'Unable to create channel - ' + traceback.format_exc() success = False - sendFeedback(testPath, testName, DEVICE, ret, status) - return + test.sendFeedback( ret, status) direction = 1.0 startDefault = middle - span endDefault = middle + span end = endDefault+1 #find position: it will be the middle point of the test - print_log(testName, DEVICE, 'Moving to middle point ' + str(middle) ) + test.log( 'Moving to middle point ' + str(middle) ) idInkr.put(middle, timeout=None) # TODO: Set appropriate timeout readback2 = idInkr.get() if abs(readback2 - middle) > 5 : # TODO: Check accuracy ret = 'Actor idInkr could not be set to the value ' + str(middle) + ' (current value: ' + str(readback2) + ')' success = False - sendFeedback(testPath, testName, DEVICE, ret, status) + test.sendFeedback( ret, status) return start = readback2+direction countSteps = 0 count = 0 - print_log(testName, DEVICE, 'Moving around middle point (+-' + str(span) + ')' ) + test.log( 'Moving around middle point (+-' + str(span) + ')' ) for setpoint1 in range(0, loopTimes*2): count = count + 1 sleep( 5 ) # Settling time + p1.addSeries(LinePlotSeries("Run"+str(count))) #RegionPositioner idInkr for setpoint2 in frange(start, end, direction): readback1 = setpoint1 @@ -96,43 +87,45 @@ def startTest(testName, DEVICE, params): if abs(readback2 - setpoint2) > 1 : # TODO: Check accuracy ret = 'Actor idInkr could not be set to the value ' + str(setpoint2) + ' (current value: ' + str(readback2) + ')' success = False - sendFeedback(testPath, testName, DEVICE, ret, status) + test.sendFeedback( ret, status) return #Detector idMotorStatus - detector1 = idInkrRb.get() + inkrRb = idInkrRb.get() #Detector idLogicalPosition - detector2 = idMotorStep.get() + motorStep = idMotorStep.get() #Detector idDiameter - detector3 = idPotiPosFromBeam.get() + potiPosFromBeam = idPotiPosFromBeam.get() #Detector idPotiPosFromBeam - detector4 = idPotiPosition.get() + potiPosition = idPotiPosition.get() #Detector idPotiRaw - detector5 = idPotiRef1Position.get() + potiRef1Position = idPotiRef1Position.get() #Detector idPotiProc - detector6 = idPotiRef2Position.get() + potiRef2Position = idPotiRef2Position.get() #Detector idBtvsRaw - detector7 = idDiameter.get() - #Manipulation idDiff02 - #Variable Mappings - idDiff02 = detector4-detector2 + diameter = idDiameter.get() #Manipulation idDiff01 #Variable Mappings - idDiff01 = detector4-detector1 + idDiff01 = potiPosition-inkrRb + #Manipulation idDiff02 + #Variable Mappings + idDiff02 = potiPosition-motorStep countSteps = countSteps + 1 - scan.append ([countSteps], [countSteps], [detector1, detector2, detector3, detector4, detector5, detector6, detector7, detector8, idDiff02, idDiff01]) + scan.append ([countSteps], [countSteps], [inkrRb, motorStep, potiPosFromBeam, potiPosition, potiRef1Position, potiRef2Position, diameter, detector8, idDiff02, idDiff01]) + p1.getSeries(count).appendData(setpoint2, idDiff01) + p2.getSeries(count).appendData(setpoint2, idDiff02) if (direction > 0.0 and setpoint2 >= end -1): #invert direction and swap start with end of translation end = startDefault-1 start = setpoint2 - direction direction = -1.0 - print_log(testName, DEVICE, 'End of span (' + str(setpoint2) + '), changing direction to ' + str(direction) ) + test.log( 'End of span (' + str(setpoint2) + '), changing direction to ' + str(direction) ) break if ( direction < 0.0 and setpoint2 <= end +1): #invert direction and swap start with end of translation end = endDefault+1 start = setpoint2 - direction direction = 1.0 - print_log(testName, DEVICE, 'End of span (' + str(setpoint2) + '), changing direction to ' + str(direction) ) + test.log( 'End of span (' + str(setpoint2) + '), changing direction to ' + str(direction) ) break @@ -149,15 +142,17 @@ def startTest(testName, DEVICE, params): scan.end() ret = 'Slide moved back and forth (' + str(count) + ' runs)' status = True - + ################ END OF YOUR CODE ################ -###### Final - DO NOT MODIFY THE CODE BELOW ###### - sendFeedback(testPath, testName, DEVICE, ret, success) +###### Final - DO NOT MODIFY THE CODE BELOW ###### + + #just in case the feedback was forgotten + test.sendFeedback(ret, success) except: + #generic error handler ret = traceback.format_exc() success = False - sendFeedback(testPath, testName, DEVICE, ret, success) - return + test.sendFeedback(ret, success) #launch the test -startTest(test, device, parameters) +startTest(test, device, parameters) \ No newline at end of file