Commit c9f2789f authored by Andrey Filippov's avatar Andrey Filippov

Added abort to scanning

parent 4fb1b103
...@@ -9569,6 +9569,7 @@ if (MORE_BUTTONS) { ...@@ -9569,6 +9569,7 @@ if (MORE_BUTTONS) {
if (centerMotorPos==null) centerMotorPos=focusingMotors.readElphel10364Motors().clone(); if (centerMotorPos==null) centerMotorPos=focusingMotors.readElphel10364Motors().clone();
boolean allOK=true; boolean allOK=true;
boolean aborted=false;
long startTime=System.nanoTime(); long startTime=System.nanoTime();
if (debugLevel>0) System.out.println("Starting scanning focus in the center, number of steps="+ focusMeasurementParameters.scanNumber+ if (debugLevel>0) System.out.println("Starting scanning focus in the center, number of steps="+ focusMeasurementParameters.scanNumber+
", of them "+focusMeasurementParameters.scanNumberNegative+" in negative direction"+ ", of them "+focusMeasurementParameters.scanNumberNegative+" in negative direction"+
...@@ -9610,9 +9611,15 @@ if (MORE_BUTTONS) { ...@@ -9610,9 +9611,15 @@ if (MORE_BUTTONS) {
// do not advance position after last measurement // do not advance position after last measurement
if (numStep<(focusMeasurementParameters.scanNumber-1)) for (int nm=0;nm<3;nm++) scanPos[nm]+=focusMeasurementParameters.scanStep; if (numStep<(focusMeasurementParameters.scanNumber-1)) for (int nm=0;nm<3;nm++) scanPos[nm]+=focusMeasurementParameters.scanStep;
scanPosLast=scanPos.clone(); scanPosLast=scanPos.clone();
if (!allOK) break; // failed if (this.SYNC_COMMAND.stopRequested.get()>0){
aborted=true;
allOK=false;
System.out.println("Stop requested, command aborted, returning motors to initial position");
break;
}
if (!allOK) break; // failed
} }
if (focusMeasurementParameters.scanTiltEnable) { if (allOK && focusMeasurementParameters.scanTiltEnable) {
if (focusMeasurementParameters.scanTiltStepsX >1 ) { // 0 or 1 STOPS - do not scan if (focusMeasurementParameters.scanTiltStepsX >1 ) { // 0 or 1 STOPS - do not scan
double scanStepX=1.0*focusMeasurementParameters.scanTiltRangeX/(focusMeasurementParameters.scanTiltStepsX-1); double scanStepX=1.0*focusMeasurementParameters.scanTiltRangeX/(focusMeasurementParameters.scanTiltStepsX-1);
if (debugLevel>0) System.out.println("Starting scanning tilt in X direction, number of stops="+ focusMeasurementParameters.scanTiltStepsX+ if (debugLevel>0) System.out.println("Starting scanning tilt in X direction, number of stops="+ focusMeasurementParameters.scanTiltStepsX+
...@@ -9620,9 +9627,9 @@ if (MORE_BUTTONS) { ...@@ -9620,9 +9627,9 @@ if (MORE_BUTTONS) {
for (int numStep=0;numStep<focusMeasurementParameters.scanTiltStepsX;numStep++){ for (int numStep=0;numStep<focusMeasurementParameters.scanTiltStepsX;numStep++){
int delta=(int) Math.round(focusMeasurementParameters.scanTiltRangeX* int delta=(int) Math.round(focusMeasurementParameters.scanTiltRangeX*
(1.0*numStep/(focusMeasurementParameters.scanTiltStepsX-1) -0.5)); (1.0*numStep/(focusMeasurementParameters.scanTiltStepsX-1) -0.5));
scanPos[0]=centerMotorPos[0]+delta; scanPos[0]=centerMotorPos[0]-delta;
scanPos[1]=centerMotorPos[1]-delta; scanPos[1]=centerMotorPos[1]-delta;
scanPos[2]=centerMotorPos[2]+0; scanPos[2]=centerMotorPos[2]+delta;
if (debugLevel>0) System.out.println("Scanning tilt in X direction, step#"+(numStep+1)+" (of "+ if (debugLevel>0) System.out.println("Scanning tilt in X direction, step#"+(numStep+1)+" (of "+
(focusMeasurementParameters.scanTiltStepsX-1)+") at "+ IJ.d2s(0.000000001*(System.nanoTime()-startTime),3)); (focusMeasurementParameters.scanTiltStepsX-1)+") at "+ IJ.d2s(0.000000001*(System.nanoTime()-startTime),3));
allOK &=moveAndMaybeProbe( allOK &=moveAndMaybeProbe(
...@@ -9643,20 +9650,26 @@ if (MORE_BUTTONS) { ...@@ -9643,20 +9650,26 @@ if (MORE_BUTTONS) {
updateStatus, updateStatus,
debugLevel, debugLevel,
loopDebugLevel); loopDebugLevel);
if (!allOK) break; // failed if (this.SYNC_COMMAND.stopRequested.get()>0){
aborted=true;
allOK=false;
System.out.println("Stop requested, command aborted, returning motors to initial position");
break;
}
if (!allOK) break; // failed
} }
} }
if (focusMeasurementParameters.scanTiltStepsY >1 ) { // 0 or 1 STOPS - do not scan if (allOK && (focusMeasurementParameters.scanTiltStepsY >1 )) { // 0 or 1 STOPS - do not scan
double scanStepY=1.0*focusMeasurementParameters.scanTiltRangeY/(focusMeasurementParameters.scanTiltStepsY-1); double scanStepY=1.0*focusMeasurementParameters.scanTiltRangeY/(focusMeasurementParameters.scanTiltStepsY-1);
if (debugLevel>0) System.out.println("Starting scanning tilt in Y direction, number of stops="+ focusMeasurementParameters.scanTiltStepsY+ if (debugLevel>0) System.out.println("Starting scanning tilt in Y direction, number of stops="+ focusMeasurementParameters.scanTiltStepsY+
", step size="+IJ.d2s(scanStepY,0)); ", step size="+IJ.d2s(scanStepY,0));
for (int numStep=0;numStep<focusMeasurementParameters.scanTiltStepsY;numStep++){ for (int numStep=0;numStep<focusMeasurementParameters.scanTiltStepsY;numStep++){
int delta=(int) Math.round(focusMeasurementParameters.scanTiltRangeY* int delta=(int) Math.round(focusMeasurementParameters.scanTiltRangeY*
(1.0*numStep/(focusMeasurementParameters.scanTiltStepsY-1) -0.5)); (1.0*numStep/(focusMeasurementParameters.scanTiltStepsY-1) -0.5));
scanPos[0]=centerMotorPos[0]-delta; scanPos[0]=centerMotorPos[0]+delta;
scanPos[1]=centerMotorPos[1]-delta; scanPos[1]=centerMotorPos[1]-delta;
scanPos[2]=centerMotorPos[2]+delta; scanPos[2]=centerMotorPos[2]+0;
if (debugLevel>0) System.out.println("Scanning tilt in Y direction, step#"+(numStep+1)+" (of "+ if (debugLevel>0) System.out.println("Scanning tilt in Y direction, step#"+(numStep+1)+" (of "+
(focusMeasurementParameters.scanTiltStepsY-1)+") at "+ IJ.d2s(0.000000001*(System.nanoTime()-startTime),3)); (focusMeasurementParameters.scanTiltStepsY-1)+") at "+ IJ.d2s(0.000000001*(System.nanoTime()-startTime),3));
allOK &=moveAndMaybeProbe( allOK &=moveAndMaybeProbe(
...@@ -9677,14 +9690,20 @@ if (MORE_BUTTONS) { ...@@ -9677,14 +9690,20 @@ if (MORE_BUTTONS) {
updateStatus, updateStatus,
debugLevel, debugLevel,
loopDebugLevel); loopDebugLevel);
if (!allOK) break; // failed if (this.SYNC_COMMAND.stopRequested.get()>0){
aborted=true;
allOK=false;
System.out.println("Stop requested, command aborted, returning motors to initial position");
break;
}
if (!allOK) break; // failed
} }
} }
} }
if (focusMeasurementParameters.scanHysteresis && (scanPosLast!=null)){ if (allOK && focusMeasurementParameters.scanHysteresis && (scanPosLast!=null)){
focusingMotors.moveElphel10364Motors( // return to last direct scan position focusingMotors.moveElphel10364Motors( // return to last direct scan position
true, //boolean wait, true, //boolean wait,
scanPosLast, scanPosLast,
...@@ -9718,31 +9737,50 @@ if (MORE_BUTTONS) { ...@@ -9718,31 +9737,50 @@ if (MORE_BUTTONS) {
updateStatus, updateStatus,
debugLevel, debugLevel,
loopDebugLevel); loopDebugLevel);
if (!allOK) break; // failed if (this.SYNC_COMMAND.stopRequested.get()>0){
aborted=true;
allOK=false;
System.out.println("Stop requested, command aborted, returning motors to initial position");
break;
}
if (!allOK) break; // failed
} }
} }
allOK &= moveAndMaybeProbe( if (aborted) {
true, System.out.println("Returning motors to initial position due to command aborted at "+ IJ.d2s(0.000000001*(System.nanoTime()-startTime),3));
centerMotorPos, // null OK focusingMotors.moveElphel10364Motors( // return to last direct scan position
focusingMotors, true, //boolean wait,
camerasInterface, centerMotorPos,
lensDistortionParameters, 0.0, //double sleep,
matchSimulatedPattern, // should not bee null true, //boolean showStatus,
focusMeasurementParameters, "", //String message,
patternDetectParameters, false); //focusMeasurementParameters.compensateHysteresis); //boolean hysteresis)
distortionParameters, return null;
simulParameters, }
colorComponents, if (allOK) {
otfFilterParameters, allOK &= moveAndMaybeProbe(
psfParameters, true,
threadsMax, centerMotorPos, // null OK
updateStatus, focusingMotors,
debugLevel, camerasInterface,
loopDebugLevel); lensDistortionParameters,
matchSimulatedPattern, // should not bee null
focusMeasurementParameters,
patternDetectParameters,
distortionParameters,
simulParameters,
colorComponents,
otfFilterParameters,
psfParameters,
threadsMax,
updateStatus,
debugLevel,
loopDebugLevel);
}
if (debugLevel>0) System.out.println("Scanning focus in the center, number of steps="+ focusMeasurementParameters.scanNumber+ if (debugLevel>0) System.out.println("Scanning focus in the center, number of steps="+ focusMeasurementParameters.scanNumber+
", step size="+focusMeasurementParameters.scanStep+" finished at "+ IJ.d2s(0.000000001*(System.nanoTime()-startTime),3)); ", step size="+focusMeasurementParameters.scanStep+" finished at "+ IJ.d2s(0.000000001*(System.nanoTime()-startTime),3)+
", allOK="+allOK);
// focusMeasurementParameters.scanStep // focusMeasurementParameters.scanStep
// focusMeasurementParameters.scanNumber // focusMeasurementParameters.scanNumber
return allOK?range:null; return allOK?range:null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment