Commit d14a3970 authored by Andrey Filippov's avatar Andrey Filippov

Implemented simultaneous processing of multiple measurements (averaging,

thermal scan), fixed adjustment
parent f8e486b9
...@@ -784,6 +784,7 @@ if (MORE_BUTTONS) { ...@@ -784,6 +784,7 @@ if (MORE_BUTTONS) {
addButton("Focus Average",panelFocusing,color_report); addButton("Focus Average",panelFocusing,color_report);
addButton("Power Control",panelFocusing,color_configure); addButton("Power Control",panelFocusing,color_configure);
addButton("Temp. Scan",panelFocusing,color_process); addButton("Temp. Scan",panelFocusing,color_process);
addButton("Replay Hist",panelFocusing,color_debug);
// //
addButton("List History",panelFocusing,color_report); addButton("List History",panelFocusing,color_report);
addButton("Show PSF",panelFocusing,color_report); addButton("Show PSF",panelFocusing,color_report);
...@@ -1006,6 +1007,7 @@ if (MORE_BUTTONS) { ...@@ -1006,6 +1007,7 @@ if (MORE_BUTTONS) {
if (DEBUG_LEVEL>0) System.out.println("--- Free memory="+runtime.freeMemory()+" (of "+runtime.totalMemory()+")"); if (DEBUG_LEVEL>0) System.out.println("--- Free memory="+runtime.freeMemory()+" (of "+runtime.totalMemory()+")");
if (label==null) return; if (label==null) return;
if (FOCUSING_FIELD!=null) FOCUSING_FIELD.setThreads(THREADS_MAX);
/* ======================================================================== */ /* ======================================================================== */
if (label.equals("Configure Globals")) { if (label.equals("Configure Globals")) {
showConfigureGlobalsDialog(); showConfigureGlobalsDialog();
...@@ -2540,6 +2542,7 @@ if (MORE_BUTTONS) { ...@@ -2540,6 +2542,7 @@ if (MORE_BUTTONS) {
// reset histories // reset histories
MOTORS.clearPreFocus(); MOTORS.clearPreFocus();
MOTORS.clearHistory(); MOTORS.clearHistory();
POWER_CONTROL.lightsOnWithDelay();
return; return;
} }
/* ======================================================================== */ /* ======================================================================== */
...@@ -2550,6 +2553,7 @@ if (MORE_BUTTONS) { ...@@ -2550,6 +2553,7 @@ if (MORE_BUTTONS) {
CAMERAS.probeCameraState(); // testing detection CAMERAS.probeCameraState(); // testing detection
CAMERAS.setupCameraAcquisition(); CAMERAS.setupCameraAcquisition();
POWER_CONTROL.lightsOnWithDelay();
return; return;
} }
/* ======================================================================== */ /* ======================================================================== */
...@@ -2557,8 +2561,8 @@ if (MORE_BUTTONS) { ...@@ -2557,8 +2561,8 @@ if (MORE_BUTTONS) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL; DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
CAMERAS.debugLevel=DEBUG_LEVEL; CAMERAS.debugLevel=DEBUG_LEVEL;
CAMERAS.setNumberOfThreads(THREADS_MAX); CAMERAS.setNumberOfThreads(THREADS_MAX);
POWER_CONTROL.lightsOnWithDelay();
CAMERAS.test1(true); CAMERAS.test1(true);
return; return;
} }
/* ======================================================================== */ /* ======================================================================== */
...@@ -2566,6 +2570,7 @@ if (MORE_BUTTONS) { ...@@ -2566,6 +2570,7 @@ if (MORE_BUTTONS) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL; DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
CAMERAS.debugLevel=DEBUG_LEVEL; CAMERAS.debugLevel=DEBUG_LEVEL;
CAMERAS.setNumberOfThreads(THREADS_MAX); CAMERAS.setNumberOfThreads(THREADS_MAX);
POWER_CONTROL.lightsOnWithDelay();
CAMERAS.test1(false); CAMERAS.test1(false);
return; return;
} }
...@@ -2598,6 +2603,7 @@ if (MORE_BUTTONS) { ...@@ -2598,6 +2603,7 @@ if (MORE_BUTTONS) {
} }
// acquire camera image here, no lasers. // acquire camera image here, no lasers.
FOCUS_MEASUREMENT_PARAMETERS.sensorTemperature=CAMERAS.getSensorTemperature(0,FOCUS_MEASUREMENT_PARAMETERS.EEPROM_channel); FOCUS_MEASUREMENT_PARAMETERS.sensorTemperature=CAMERAS.getSensorTemperature(0,FOCUS_MEASUREMENT_PARAMETERS.EEPROM_channel);
POWER_CONTROL.lightsOnWithDelay();
imp_sel= CAMERAS.acquireSingleImage ( imp_sel= CAMERAS.acquireSingleImage (
false, //boolean useLasers, false, //boolean useLasers,
UPDATE_STATUS); UPDATE_STATUS);
...@@ -2625,6 +2631,7 @@ if (MORE_BUTTONS) { ...@@ -2625,6 +2631,7 @@ if (MORE_BUTTONS) {
} }
DISTORTION_PROCESS_CONFIGURATION.sourceDirectory=src_dir; DISTORTION_PROCESS_CONFIGURATION.sourceDirectory=src_dir;
CAMERAS.setNumberOfThreads(THREADS_MAX); CAMERAS.setNumberOfThreads(THREADS_MAX);
POWER_CONTROL.lightsOnWithDelay();
long startTime=System.nanoTime(); long startTime=System.nanoTime();
CAMERAS.acquire(DISTORTION_PROCESS_CONFIGURATION.sourceDirectory,true, UPDATE_STATUS); // true - use lasers CAMERAS.acquire(DISTORTION_PROCESS_CONFIGURATION.sourceDirectory,true, UPDATE_STATUS); // true - use lasers
System.out.println("\"Acquire\" command finished in ("+IJ.d2s(0.000000001*(System.nanoTime()-startTime),3)+" sec"); System.out.println("\"Acquire\" command finished in ("+IJ.d2s(0.000000001*(System.nanoTime()-startTime),3)+" sec");
...@@ -3419,6 +3426,7 @@ if (MORE_BUTTONS) { ...@@ -3419,6 +3426,7 @@ if (MORE_BUTTONS) {
} }
// acquire camera image here, no lasers. // acquire camera image here, no lasers.
FOCUS_MEASUREMENT_PARAMETERS.sensorTemperature=CAMERAS.getSensorTemperature(0,FOCUS_MEASUREMENT_PARAMETERS.EEPROM_channel); FOCUS_MEASUREMENT_PARAMETERS.sensorTemperature=CAMERAS.getSensorTemperature(0,FOCUS_MEASUREMENT_PARAMETERS.EEPROM_channel);
POWER_CONTROL.lightsOnWithDelay();
imp_sel= CAMERAS.acquireSingleImage ( imp_sel= CAMERAS.acquireSingleImage (
false, //boolean useLasers, false, //boolean useLasers,
UPDATE_STATUS); UPDATE_STATUS);
...@@ -3533,6 +3541,7 @@ if (MORE_BUTTONS) { ...@@ -3533,6 +3541,7 @@ if (MORE_BUTTONS) {
// long startTime=System.nanoTime(); // long startTime=System.nanoTime();
FOCUS_MEASUREMENT_PARAMETERS.sensorTemperature=CAMERAS.getSensorTemperature(0,FOCUS_MEASUREMENT_PARAMETERS.EEPROM_channel); FOCUS_MEASUREMENT_PARAMETERS.sensorTemperature=CAMERAS.getSensorTemperature(0,FOCUS_MEASUREMENT_PARAMETERS.EEPROM_channel);
CAMERAS.debugLevel=DEBUG_LEVEL; CAMERAS.debugLevel=DEBUG_LEVEL;
POWER_CONTROL.lightsOnWithDelay();
imp_sel= CAMERAS.acquireSingleImage ( imp_sel= CAMERAS.acquireSingleImage (
UV_LED_LASERS, UV_LED_LASERS,
UPDATE_STATUS); UPDATE_STATUS);
...@@ -3587,6 +3596,7 @@ if (MORE_BUTTONS) { ...@@ -3587,6 +3596,7 @@ if (MORE_BUTTONS) {
return; return;
} }
} }
POWER_CONTROL.lightsOnWithDelay();
long startTime=System.nanoTime(); long startTime=System.nanoTime();
FOCUS_MEASUREMENT_PARAMETERS.sensorTemperature=CAMERAS.getSensorTemperature(0,FOCUS_MEASUREMENT_PARAMETERS.EEPROM_channel); FOCUS_MEASUREMENT_PARAMETERS.sensorTemperature=CAMERAS.getSensorTemperature(0,FOCUS_MEASUREMENT_PARAMETERS.EEPROM_channel);
imp_sel= CAMERAS.acquireSingleImage ( imp_sel= CAMERAS.acquireSingleImage (
...@@ -3874,6 +3884,7 @@ if (MORE_BUTTONS) { ...@@ -3874,6 +3884,7 @@ if (MORE_BUTTONS) {
return; return;
} }
} }
POWER_CONTROL.lightsOnWithDelay();
if (matchSimulatedPattern==null) { if (matchSimulatedPattern==null) {
matchSimulatedPattern= new MatchSimulatedPattern(DISTORTION.FFTSize); // new instance, all reset matchSimulatedPattern= new MatchSimulatedPattern(DISTORTION.FFTSize); // new instance, all reset
} }
...@@ -4145,7 +4156,7 @@ if (MORE_BUTTONS) { ...@@ -4145,7 +4156,7 @@ if (MORE_BUTTONS) {
sampleCoord, sampleCoord,
this.SYNC_COMMAND.stopRequested); this.SYNC_COMMAND.stopRequested);
FOCUSING_FIELD.setDebugLevel(DEBUG_LEVEL); FOCUSING_FIELD.setDebugLevel(DEBUG_LEVEL);
FOCUSING_FIELD.setAdjustMode(false); FOCUSING_FIELD.setAdjustMode(false,null);
if (PROPERTIES!=null) FOCUSING_FIELD.getProperties("FOCUSING_FIELD.", PROPERTIES, true); if (PROPERTIES!=null) FOCUSING_FIELD.getProperties("FOCUSING_FIELD.", PROPERTIES, true);
MOTORS.addCurrentHistoryToFocusingField(FOCUSING_FIELD); MOTORS.addCurrentHistoryToFocusingField(FOCUSING_FIELD);
System.out.println("Saving measurement history to "+path); System.out.println("Saving measurement history to "+path);
...@@ -4171,10 +4182,12 @@ if (MORE_BUTTONS) { ...@@ -4171,10 +4182,12 @@ if (MORE_BUTTONS) {
double rms_pure= FOCUSING_FIELD.calcErrorDiffY(focusing_fx, true); double rms_pure= FOCUSING_FIELD.calcErrorDiffY(focusing_fx, true);
System.out.println("rms="+rms+", rms_pure="+rms_pure+" - with old parameters may be well off."); System.out.println("rms="+rms+", rms_pure="+rms_pure+" - with old parameters may be well off.");
remoteNotifyComplete(); remoteNotifyComplete();
POWER_CONTROL.setPower("light","off");
if (FOCUS_MEASUREMENT_PARAMETERS.scanRunLMA){ if (FOCUS_MEASUREMENT_PARAMETERS.scanRunLMA){
FOCUSING_FIELD.setAdjustMode(false); FOCUSING_FIELD.setAdjustMode(false,null);
boolean OK=FOCUSING_FIELD.LevenbergMarquardt( boolean OK=FOCUSING_FIELD.LevenbergMarquardt(
null, // measurement null, //int [] zTxTyAdjustMode, // z, tx, ty - 0 - fixed, 1 - common, 2 - individual
null, // measurements
false, // true, // open dialog false, // true, // open dialog
true,// boolean autoSel, true,// boolean autoSel,
DEBUG_LEVEL); //boolean openDialog, int debugLevel){ DEBUG_LEVEL); //boolean openDialog, int debugLevel){
...@@ -4601,7 +4614,7 @@ if (MORE_BUTTONS) { ...@@ -4601,7 +4614,7 @@ if (MORE_BUTTONS) {
if (!restoreFocusingHistory(false)) return; // try to restore from the saved history file if (!restoreFocusingHistory(false)) return; // try to restore from the saved history file
} }
FOCUSING_FIELD.setDebugLevel(DEBUG_LEVEL); FOCUSING_FIELD.setDebugLevel(DEBUG_LEVEL);
FOCUSING_FIELD.setAdjustMode(false); FOCUSING_FIELD.setAdjustMode(false,null);
if (!FOCUSING_FIELD.configureDataVector( if (!FOCUSING_FIELD.configureDataVector(
false, // boolean silent, false, // boolean silent,
"Re-configure curvature parameters", // String title "Re-configure curvature parameters", // String title
...@@ -4662,9 +4675,10 @@ if (MORE_BUTTONS) { ...@@ -4662,9 +4675,10 @@ if (MORE_BUTTONS) {
} }
FOCUSING_FIELD.setDebugLevel(DEBUG_LEVEL); FOCUSING_FIELD.setDebugLevel(DEBUG_LEVEL);
FOCUSING_FIELD.setAdjustMode(false); FOCUSING_FIELD.setAdjustMode(false,null);
boolean OK=FOCUSING_FIELD.LevenbergMarquardt( boolean OK=FOCUSING_FIELD.LevenbergMarquardt(
null, // measurement null, // int [] zTxTyAdjustMode, // z, tx, ty - 0 - fixed, 1 - common, 2 - individual
null, // measurements
true, // open dialog true, // open dialog
true,// boolean autoSel, true,// boolean autoSel,
DEBUG_LEVEL); //boolean openDialog, int debugLevel){ DEBUG_LEVEL); //boolean openDialog, int debugLevel){
...@@ -4871,10 +4885,10 @@ if (MORE_BUTTONS) { ...@@ -4871,10 +4885,10 @@ if (MORE_BUTTONS) {
double pX0; double pX0;
double pY0; double pY0;
if (FOCUSING_FIELD!=null){ if (FOCUSING_FIELD!=null){
FOCUSING_FIELD.setDebugLevel(DEBUG_LEVEL);
sampleCoord=FOCUSING_FIELD.getSampleCoord(); sampleCoord=FOCUSING_FIELD.getSampleCoord();
pX0=FOCUSING_FIELD.pX0_distortions; pX0=FOCUSING_FIELD.pX0_distortions;
pY0=FOCUSING_FIELD.pY0_distortions; pY0=FOCUSING_FIELD.pY0_distortions;
} else { } else {
pX0=FOCUS_MEASUREMENT_PARAMETERS.result_PX0; pX0=FOCUS_MEASUREMENT_PARAMETERS.result_PX0;
pY0=FOCUS_MEASUREMENT_PARAMETERS.result_PY0; pY0=FOCUS_MEASUREMENT_PARAMETERS.result_PY0;
...@@ -5240,6 +5254,7 @@ if (MORE_BUTTONS) { ...@@ -5240,6 +5254,7 @@ if (MORE_BUTTONS) {
} }
double [][][] sampleCoord=null; double [][][] sampleCoord=null;
if (FOCUSING_FIELD!=null){ if (FOCUSING_FIELD!=null){
FOCUSING_FIELD.setDebugLevel(DEBUG_LEVEL);
sampleCoord=FOCUSING_FIELD.getSampleCoord(); sampleCoord=FOCUSING_FIELD.getSampleCoord();
FOCUSING_FIELD.testQualB(false); // optimize qualB, store results in this.qualBOptimizationResults FOCUSING_FIELD.testQualB(false); // optimize qualB, store results in this.qualBOptimizationResults
} else { } else {
...@@ -5281,75 +5296,140 @@ if (MORE_BUTTONS) { ...@@ -5281,75 +5296,140 @@ if (MORE_BUTTONS) {
POWER_CONTROL.showDialog("Configure power control", true); POWER_CONTROL.showDialog("Configure power control", true);
return; return;
} }
//"Replay Hist"
/* ======================================================================== */
FocusingField ffReplay=null; // will be passed to a next command
if (label.equals("Replay Hist")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
if (FOCUSING_FIELD==null) {
String msg="FOCUSING_FIELD is null";
System.out.println("msg");
IJ.showMessage("Error",msg);
return;
}
FOCUSING_FIELD.setDebugLevel(DEBUG_LEVEL);
ffReplay=new FocusingField(
false, // true, // boolean smart, // do not open dialog if default matches
FOCUS_MEASUREMENT_PARAMETERS.focusingHistoryFile, // FOCUSING_FIELD_HISTORY_PATH, //"",//); //String defaultPath); // AtomicInteger stopRequested
this.SYNC_COMMAND.stopRequested);
String path=FOCUSING_FIELD.getHistoryPath();
if (path==null) return; // did not load
GenericDialog gd=new GenericDialog("Select Replay mode");
boolean modeTempScan=true;
gd.addCheckbox("Calculate Thermal parameters from the restored history (false - just average)", modeTempScan);
gd.showDialog();
if (gd.wasCanceled()) return;
modeTempScan=gd.getNextBoolean();
label=modeTempScan?"Temp. Scan":"Focus Average";
FOCUS_MEASUREMENT_PARAMETERS.useLMAMetrics=true;
// And fall through to the next command
}
// "Restore History"
/* ======================================================================== */ /* ======================================================================== */
if (label.equals("Temp. Scan") || label.equals("Focus Average")) { if (label.equals("Temp. Scan") || label.equals("Focus Average")) {
checkSerialAndRestore(); // returns true if did not change or was restored checkSerialAndRestore(); // returns true if did not change or was restored
boolean modeAverage=label.equals("Focus Average"); boolean modeAverage=label.equals("Focus Average");
boolean noTiltScan=true; boolean noTiltScan=true;
boolean replayMode= ffReplay != null;
String [] zTxTyAdjustModeNames={"keep", "common","individual"};
String [] zTxTyNames={"z", "tx","ty"};
// boolean useLMA=true; // boolean useLMA=true;
DEBUG_LEVEL=MASTER_DEBUG_LEVEL; DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
MOTORS.focusingHistory.optimalMotorPosition( // recalculate calibration to estimate current distance from center PSF MOTORS.focusingHistory.optimalMotorPosition( // recalculate calibration to estimate current distance from center PSF
FOCUS_MEASUREMENT_PARAMETERS, FOCUS_MEASUREMENT_PARAMETERS,
MOTORS.getMicronsPerStep(), //double micronsPerStep, MOTORS.getMicronsPerStep(), //double micronsPerStep,
DEBUG_LEVEL); DEBUG_LEVEL);
GenericDialog gd = new GenericDialog("Temperature Scan"); GenericDialog gd = new GenericDialog(modeAverage?"Averaging measurements":"Temperature Scan");
if (modeAverage) { //replayMode
gd.addMessage("This program will repetitively measure focal distance for specified time and average (and record) results."); double scanMinutes=modeAverage?2.0:30.0;
if (replayMode){
} else { } else {
gd.addMessage("This program will repetitively measure focal distance and temperature, recording the results."); if (modeAverage) {
gd.addMessage("Temperature has to be varied separately."); gd.addMessage("This program will repetitively measure focal distance for specified time and average (and record) results.");
gd.addMessage("Use \"List History\" to see the results."); } else {
gd.addCheckbox("Turn lasers off to protect from overheating",true); gd.addMessage("This program will repetitively measure focal distance and temperature, recording the results.");
if (!POWER_CONTROL.isPowerControlEnabled()){ gd.addMessage("Temperature has to be varied separately.");
gd.addMessage("Power control hardware is disabled, use \"Power Control\" command to enable it before proceeding"); gd.addMessage("Use \"List History\" to see the results.");
gd.addCheckbox("Turn lasers off to protect from overheating",true);
if (!POWER_CONTROL.isPowerControlEnabled()){
gd.addMessage("Power control hardware is disabled, use \"Power Control\" command to enable it before proceeding");
}
}
gd.addCheckbox("Erase previous measurement history",modeAverage);
// gd.addCheckbox("Allow tilt scan when looking for the best fit",!noTiltScan);
gd.addCheckbox ("Use lens aberration model (if available) for focal distance and tilts", FOCUS_MEASUREMENT_PARAMETERS.useLMAMetrics);
// gd.addCheckbox("Use LMA calculations for focus/tilt",useLMA);
if (modeAverage) {
gd.addNumericField("Measure for ", scanMinutes , 1,5," minutes");
} else {
gd.addCheckbox ("Enable power control for heater and fan", FOCUS_MEASUREMENT_PARAMETERS.powerControlEnable);
gd.addNumericField("Maximal allowed temperature", FOCUS_MEASUREMENT_PARAMETERS.powerControlMaximalTemperature, 3,5,"C");
gd.addNumericField("Heater ON time", FOCUS_MEASUREMENT_PARAMETERS.powerControlHeaterOnMinutes, 1,5,"min");
gd.addNumericField("Both heater and fan OFF time", FOCUS_MEASUREMENT_PARAMETERS.powerControlNeitherOnMinutes, 1,5,"min");
gd.addNumericField("Fan ON time", FOCUS_MEASUREMENT_PARAMETERS.powerControlFanOnMinutes, 1,5,"min");
gd.addNumericField("Report focal length at this temperature", FOCUS_MEASUREMENT_PARAMETERS.reportTemperature, 1,5,"C");
} }
} }
gd.addCheckbox("Erase previous measurement history",modeAverage);
gd.addCheckbox("Allow tilt scan when looking for the best fit",!noTiltScan); gd.addCheckbox("Allow tilt scan when looking for the best fit",!noTiltScan);
gd.addCheckbox ("Use lens aberration model (if available) for focal distance and tilts", FOCUS_MEASUREMENT_PARAMETERS.useLMAMetrics);
// gd.addCheckbox("Use LMA calculations for focus/tilt",useLMA); if (FOCUSING_FIELD!=null) {
double scanMinutes=modeAverage?2.0:30.0; FOCUSING_FIELD.setDebugLevel(DEBUG_LEVEL);
if (modeAverage) { for (int n=0;n<FOCUSING_FIELD.zTxTyAdjustMode.length;n++){
gd.addNumericField("Measure for ", scanMinutes , 1,5," minutes"); gd.addChoice("Adjust "+zTxTyNames[n]+" mode",zTxTyAdjustModeNames,zTxTyAdjustModeNames[FOCUSING_FIELD.zTxTyAdjustMode[n]]);
}
gd.addChoice("Recalculate tilts during averaging",zTxTyAdjustModeNames,zTxTyAdjustModeNames[FOCUSING_FIELD.recalculateAverageTilts]);
// gd.addCheckbox ("Store new calculated (during averaging) tilts", FOCUSING_FIELD.updateAverageTilts);
}
gd.showDialog();
if (gd.wasCanceled()) return;
if (replayMode){
} else { } else {
gd.addCheckbox ("Enable power control for heater and fan", FOCUS_MEASUREMENT_PARAMETERS.powerControlEnable); if (!modeAverage && gd.getNextBoolean()){ // was only asked in thermal scan mode
gd.addNumericField("Maximal allowed temperature", FOCUS_MEASUREMENT_PARAMETERS.powerControlMaximalTemperature, 3,5,"C"); UV_LED_LASERS.debugLevel=DEBUG_LEVEL;
gd.addNumericField("Heater ON time", FOCUS_MEASUREMENT_PARAMETERS.powerControlHeaterOnMinutes, 1,5,"min"); UV_LED_LASERS.lasersOff(FOCUS_MEASUREMENT_PARAMETERS);
gd.addNumericField("Both heater and fan OFF time", FOCUS_MEASUREMENT_PARAMETERS.powerControlNeitherOnMinutes, 1,5,"min"); if (MASTER_DEBUG_LEVEL>0) System.out.println ("Turned laser pointers off to protect from overheating");
gd.addNumericField("Fan ON time", FOCUS_MEASUREMENT_PARAMETERS.powerControlFanOnMinutes, 1,5,"min"); }
if (gd.getNextBoolean()) MOTORS.clearHistory();
// noTiltScan=!gd.getNextBoolean();
FOCUS_MEASUREMENT_PARAMETERS.useLMAMetrics=gd.getNextBoolean();
// Only try to read history if useLMAMetrics is set
if (FOCUS_MEASUREMENT_PARAMETERS.useLMAMetrics && (FOCUSING_FIELD==null)) {
if (DEBUG_LEVEL>0) System.out.println("FOCUSING_FIELD==null, trying to restore from the previously saved file");
if (!restoreFocusingHistory(false)) { // try to restore from the saved history file
System.out.println("Failed to restore history, disabling use of lens aberration model");
}
FOCUSING_FIELD.setDebugLevel(DEBUG_LEVEL);
}
// boolean useLMA=FOCUS_MEASUREMENT_PARAMETERS.useLMAMetrics && (FOCUSING_FIELD!=null);
if (modeAverage) {
scanMinutes=gd.getNextNumber();
} else {
FOCUS_MEASUREMENT_PARAMETERS.powerControlEnable=gd.getNextBoolean();
FOCUS_MEASUREMENT_PARAMETERS.powerControlMaximalTemperature=gd.getNextNumber();
FOCUS_MEASUREMENT_PARAMETERS.powerControlHeaterOnMinutes=gd.getNextNumber();
FOCUS_MEASUREMENT_PARAMETERS.powerControlNeitherOnMinutes=gd.getNextNumber();
FOCUS_MEASUREMENT_PARAMETERS.powerControlFanOnMinutes=gd.getNextNumber();
FOCUS_MEASUREMENT_PARAMETERS.reportTemperature=gd.getNextNumber();
scanMinutes=FOCUS_MEASUREMENT_PARAMETERS.powerControlMaximalTemperature+
FOCUS_MEASUREMENT_PARAMETERS.powerControlHeaterOnMinutes+
FOCUS_MEASUREMENT_PARAMETERS.powerControlNeitherOnMinutes+
FOCUS_MEASUREMENT_PARAMETERS.powerControlFanOnMinutes;
}
} }
gd.showDialog();
if (gd.wasCanceled()) return;
if (!modeAverage && gd.getNextBoolean()){ // was only asked in thermal scan mode
UV_LED_LASERS.debugLevel=DEBUG_LEVEL;
UV_LED_LASERS.lasersOff(FOCUS_MEASUREMENT_PARAMETERS);
if (MASTER_DEBUG_LEVEL>0) System.out.println ("Turned laser pointers off to protect from overheating");
}
if (gd.getNextBoolean()) MOTORS.clearHistory();
noTiltScan=!gd.getNextBoolean(); noTiltScan=!gd.getNextBoolean();
FOCUS_MEASUREMENT_PARAMETERS.useLMAMetrics=gd.getNextBoolean();
// Only try to read history if useLMAMetrics is set if (FOCUSING_FIELD!=null) {
if (FOCUS_MEASUREMENT_PARAMETERS.useLMAMetrics && (FOCUSING_FIELD==null)) { for (int n=0;n<FOCUSING_FIELD.zTxTyAdjustMode.length;n++){
if (DEBUG_LEVEL>0) System.out.println("FOCUSING_FIELD==null, trying to restore from the previously saved file"); FOCUSING_FIELD.zTxTyAdjustMode[n]=gd.getNextChoiceIndex();
if (!restoreFocusingHistory(false)) { // try to restore from the saved history file
System.out.println("Failed to restore history, disabling use of lens aberration model");
} }
FOCUSING_FIELD.setDebugLevel(DEBUG_LEVEL); FOCUSING_FIELD.recalculateAverageTilts=gd.getNextChoiceIndex();
// FOCUSING_FIELD.updateAverageTilts=gd.getNextBoolean();
} }
boolean useLMA=FOCUS_MEASUREMENT_PARAMETERS.useLMAMetrics && (FOCUSING_FIELD!=null); boolean useLMA=FOCUS_MEASUREMENT_PARAMETERS.useLMAMetrics && (FOCUSING_FIELD!=null);
if (modeAverage) {
scanMinutes=gd.getNextNumber();
} else {
FOCUS_MEASUREMENT_PARAMETERS.powerControlEnable=gd.getNextBoolean();
FOCUS_MEASUREMENT_PARAMETERS.powerControlMaximalTemperature=gd.getNextNumber();
FOCUS_MEASUREMENT_PARAMETERS.powerControlHeaterOnMinutes=gd.getNextNumber();
FOCUS_MEASUREMENT_PARAMETERS.powerControlNeitherOnMinutes=gd.getNextNumber();
FOCUS_MEASUREMENT_PARAMETERS.powerControlFanOnMinutes=gd.getNextNumber();
scanMinutes=FOCUS_MEASUREMENT_PARAMETERS.powerControlMaximalTemperature+
FOCUS_MEASUREMENT_PARAMETERS.powerControlHeaterOnMinutes+
FOCUS_MEASUREMENT_PARAMETERS.powerControlNeitherOnMinutes+
FOCUS_MEASUREMENT_PARAMETERS.powerControlFanOnMinutes;
}
long startTime=System.nanoTime(); long startTime=System.nanoTime();
long endTime=startTime+(long) (6E10*scanMinutes); long endTime=startTime+(long) (6E10*scanMinutes);
if (MASTER_DEBUG_LEVEL>0) System.out.println(" startTime= "+startTime+", endTime="+endTime); if (MASTER_DEBUG_LEVEL>0) System.out.println(" startTime= "+startTime+", endTime="+endTime);
...@@ -5377,141 +5457,139 @@ if (MORE_BUTTONS) { ...@@ -5377,141 +5457,139 @@ if (MORE_BUTTONS) {
System.out.println("Optimal Ty="+FOCUSING_FIELD.qualBOptimizationResults[2]); System.out.println("Optimal Ty="+FOCUSING_FIELD.qualBOptimizationResults[2]);
} }
} }
long stateEndTime=endTime; if (!replayMode){
if (!modeAverage) { long stateEndTime=endTime;
POWER_CONTROL.setPower("fan","off"); String [] stateNames={"IDLE","HEATING","WAITING","COOLING","FINISHED"};
POWER_CONTROL.setPower("heater","on"); if (!modeAverage) {
stateEndTime=startTime+(long) (6E10*FOCUS_MEASUREMENT_PARAMETERS.powerControlHeaterOnMinutes); POWER_CONTROL.setPower("fan","off");
} POWER_CONTROL.setPower("heater","on");
int scanState=(!modeAverage && FOCUS_MEASUREMENT_PARAMETERS.powerControlEnable)?1:-1; stateEndTime=startTime+(long) (6E10*FOCUS_MEASUREMENT_PARAMETERS.powerControlHeaterOnMinutes);
if (scanState>=0){
endTime=startTime+(long) (6E10*(
FOCUS_MEASUREMENT_PARAMETERS.powerControlHeaterOnMinutes+
FOCUS_MEASUREMENT_PARAMETERS.powerControlNeitherOnMinutes+
FOCUS_MEASUREMENT_PARAMETERS.powerControlFanOnMinutes));
}
String [] stateNames={"IDLE","HEATING","WAITING","COOLING","FINISHED"};
while (System.nanoTime()<endTime){
moveAndMaybeProbe(
true, // just move, not probe
null, // no move, just measure
MOTORS,
CAMERAS,
LENS_DISTORTION_PARAMETERS,
matchSimulatedPattern, // should not be null
FOCUS_MEASUREMENT_PARAMETERS,
PATTERN_DETECT,
DISTORTION,
SIMUL,
COMPONENTS,
OTF_FILTER,
PSF_PARS,
sampleCoord,
THREADS_MAX,
UPDATE_STATUS,
MASTER_DEBUG_LEVEL,
DISTORTION.loop_debug_level);
runs++;
if (this.SYNC_COMMAND.stopRequested.get()>0) {
System.out.println("User requested stop");
break;
} }
// Temperature within limits? int scanState=(!modeAverage && FOCUS_MEASUREMENT_PARAMETERS.powerControlEnable)?1:-1;
if (FOCUS_MEASUREMENT_PARAMETERS.sensorTemperature>=FOCUS_MEASUREMENT_PARAMETERS.powerControlMaximalTemperature){ if (scanState>=0){
POWER_CONTROL.setPower("heater","off"); endTime=startTime+(long) (6E10*(
FOCUS_MEASUREMENT_PARAMETERS.powerControlHeaterOnMinutes+
FOCUS_MEASUREMENT_PARAMETERS.powerControlNeitherOnMinutes+
FOCUS_MEASUREMENT_PARAMETERS.powerControlFanOnMinutes));
} }
// long secondsLeft=(long) (0.000000001*(endTime-System.nanoTime())); while (System.nanoTime()<endTime){
long secondsLeft=(long) (0.000000001*(endTime-System.nanoTime())); moveAndMaybeProbe(
if (secondsLeft<0) secondsLeft=0; true, // just move, not probe
long secondsLeftState=(long) (0.000000001*(stateEndTime-System.nanoTime())); null, // no move, just measure
if (secondsLeftState<0) secondsLeftState=0; MOTORS,
CAMERAS,
boolean timerOver=(System.nanoTime()>=stateEndTime) || LENS_DISTORTION_PARAMETERS,
((scanState==1) && (FOCUS_MEASUREMENT_PARAMETERS.sensorTemperature>=FOCUS_MEASUREMENT_PARAMETERS.powerControlMaximalTemperature)); matchSimulatedPattern, // should not be null
if ((scanState>0) && timerOver) { FOCUS_MEASUREMENT_PARAMETERS,
scanState++; PATTERN_DETECT,
switch (scanState) { DISTORTION,
case 2: SIMUL,
POWER_CONTROL.setPower("heater","off"); COMPONENTS,
POWER_CONTROL.setPower("fan","off"); OTF_FILTER,
stateEndTime=System.nanoTime()+(long) (6E10*FOCUS_MEASUREMENT_PARAMETERS.powerControlNeitherOnMinutes); PSF_PARS,
sampleCoord,
THREADS_MAX,
UPDATE_STATUS,
MASTER_DEBUG_LEVEL,
DISTORTION.loop_debug_level);
runs++;
if (this.SYNC_COMMAND.stopRequested.get()>0) {
System.out.println("User requested stop");
break; break;
case 3: }
// Temperature within limits?
if (FOCUS_MEASUREMENT_PARAMETERS.sensorTemperature>=FOCUS_MEASUREMENT_PARAMETERS.powerControlMaximalTemperature){
POWER_CONTROL.setPower("heater","off"); POWER_CONTROL.setPower("heater","off");
POWER_CONTROL.setPower("fan","on");
stateEndTime=System.nanoTime()+(long) (6E10*FOCUS_MEASUREMENT_PARAMETERS.powerControlFanOnMinutes);
break;
} }
// nothing specific is needed for case 4 - it will end anyway // long secondsLeft=(long) (0.000000001*(endTime-System.nanoTime()));
} long secondsLeft=(long) (0.000000001*(endTime-System.nanoTime()));
if (MASTER_DEBUG_LEVEL>0) { if (secondsLeft<0) secondsLeft=0;
if (scanState>=0){ long secondsLeftState=(long) (0.000000001*(stateEndTime-System.nanoTime()));
System.out.println(" Measured "+runs+", state="+stateNames[scanState]+", t="+ if (secondsLeftState<0) secondsLeftState=0;
FOCUS_MEASUREMENT_PARAMETERS.sensorTemperature+"C, "+secondsLeftState+" seconds left ("+secondsLeft+")");
} else { boolean timerOver=(System.nanoTime()>=stateEndTime) ||
System.out.println(" Measured "+runs+", t="+FOCUS_MEASUREMENT_PARAMETERS.sensorTemperature+"C, "+secondsLeftState+" seconds left "); ((scanState==1) && (FOCUS_MEASUREMENT_PARAMETERS.sensorTemperature>=FOCUS_MEASUREMENT_PARAMETERS.powerControlMaximalTemperature));
if ((scanState>0) && timerOver) {
scanState++;
switch (scanState) {
case 2:
POWER_CONTROL.setPower("heater","off");
POWER_CONTROL.setPower("fan","off");
stateEndTime=System.nanoTime()+(long) (6E10*FOCUS_MEASUREMENT_PARAMETERS.powerControlNeitherOnMinutes);
break;
case 3:
POWER_CONTROL.setPower("heater","off");
POWER_CONTROL.setPower("fan","on");
stateEndTime=System.nanoTime()+(long) (6E10*FOCUS_MEASUREMENT_PARAMETERS.powerControlFanOnMinutes);
break;
}
// nothing specific is needed for case 4 - it will end anyway
} }
if (MASTER_DEBUG_LEVEL>0) {
if (scanState>=0){
System.out.println(" Measured "+runs+", state="+stateNames[scanState]+", t="+
FOCUS_MEASUREMENT_PARAMETERS.sensorTemperature+"C, "+secondsLeftState+" seconds left ("+secondsLeft+")");
} else {
System.out.println(" Measured "+runs+", t="+FOCUS_MEASUREMENT_PARAMETERS.sensorTemperature+"C, "+secondsLeftState+" seconds left ");
}
}
if (scanState>=(stateNames.length-1)) break; // last state is "Finished"
}
if (!modeAverage) {
if (DEBUG_LEVEL>0) System.out.println("Turning both heater and fan off");
POWER_CONTROL.setPower("fan","off");
POWER_CONTROL.setPower("heater","off");
} }
if (scanState>=(stateNames.length-1)) break; // last state is "Finished"
}
if (!modeAverage) {
if (DEBUG_LEVEL>0) System.out.println("Turning both heater and fan off");
POWER_CONTROL.setPower("fan","off");
POWER_CONTROL.setPower("heater","off");
} }
// LMA version // LMA version
FocusingField ff= null; FocusingField ff= null;
double [] ZTM=null;
if (useLMA){ if (useLMA){
ff= new FocusingField( // boolean replayMode= ffReplay != null;
EYESIS_CAMERA_PARAMETERS.getSensorWidth(),
EYESIS_CAMERA_PARAMETERS.getSensorHeight(), if (replayMode) {
0.001*EYESIS_CAMERA_PARAMETERS.getPixelSize(0), //subCamera_0.pixelSize, ff=ffReplay;
FOCUS_MEASUREMENT_PARAMETERS.serialNumber, ff.setDebugLevel(DEBUG_LEVEL);
FOCUS_MEASUREMENT_PARAMETERS.lensSerial, // String lensSerial, // if null - do not add average ff.setAdjustMode(false,null);
FOCUS_MEASUREMENT_PARAMETERS.comment, // String comment, if (PROPERTIES!=null) ff.getProperties("FOCUSING_FIELD.", PROPERTIES,true);
pX0, runs=ff.measurements.size();
pY0, } else {
sampleCoord, ff= new FocusingField(
this.SYNC_COMMAND.stopRequested); EYESIS_CAMERA_PARAMETERS.getSensorWidth(),
ff.setDebugLevel(DEBUG_LEVEL); EYESIS_CAMERA_PARAMETERS.getSensorHeight(),
ff.setAdjustMode(false); 0.001*EYESIS_CAMERA_PARAMETERS.getPixelSize(0), //subCamera_0.pixelSize,
if (PROPERTIES!=null) ff.getProperties("FOCUSING_FIELD.", PROPERTIES,true); FOCUS_MEASUREMENT_PARAMETERS.serialNumber,
MOTORS.addCurrentHistoryToFocusingField( FOCUS_MEASUREMENT_PARAMETERS.lensSerial, // String lensSerial, // if null - do not add average
ff, FOCUS_MEASUREMENT_PARAMETERS.comment, // String comment,
(runs==0)?0:(MOTORS.historySize()-runs), pX0,
MOTORS.historySize()); // all newly acquired pY0,
// TODO: Remove after checking average sampleCoord,
/* this.SYNC_COMMAND.stopRequested);
ff.setDebugLevel(DEBUG_LEVEL);
ff.setAdjustMode(false,null);
if (PROPERTIES!=null) ff.getProperties("FOCUSING_FIELD.", PROPERTIES,true);
MOTORS.addCurrentHistoryToFocusingField(
ff,
(runs==0)?0:(MOTORS.historySize()-runs),
MOTORS.historySize()); // all newly acquired
}
// TODO: Remove after checking average - no, it is needed again as it calculates average through LMA simultaneously
if (modeAverage && (FOCUSING_FIELD!=null)){ // calculate/show average over the last run - only in "average" mode if (modeAverage && (FOCUSING_FIELD!=null)){ // calculate/show average over the last run - only in "average" mode
double [] ZTM=FOCUSING_FIELD.averageZTM( ZTM= FOCUSING_FIELD.averageZTM( // finds zc, not z0
noTiltScan, noTiltScan,
ff, // no tilt scan - faster ff, // no tilt scan - faster
true); // noMotors FOCUSING_FIELD.recalculateAverageTilts); // boolean keepTilt){ // keep existent tilt
if (MASTER_DEBUG_LEVEL>0) { if (MASTER_DEBUG_LEVEL>0) {
String msg="Failed to calulate average focus/tilt";
if (ZTM!=null) {
msg="Average:\n"+
"Relative focal shift "+IJ.d2s(ZTM[0],3)+"um (absolute - "+IJ.d2s(ZTM[0]+FOCUSING_FIELD.qualBOptimizationResults[0],3)+"um)\n"+
"Relative horizontal tilt "+IJ.d2s(ZTM[1],3)+"um/mm (absolute - "+IJ.d2s(ZTM[1]+FOCUSING_FIELD.qualBOptimizationResults[1],3)+"um.mm)\n"+
"Relative vertical tilt "+IJ.d2s(ZTM[2],3)+"um/mm (absolute - "+IJ.d2s(ZTM[2]+FOCUSING_FIELD.qualBOptimizationResults[2],3)+"um.mm)\n";
if (ZTM.length>3) {
msg+="Suggested M1 "+IJ.d2s(ZTM[3],0)+"steps\n"+
"Suggested M2 "+IJ.d2s(ZTM[4],0)+"steps\n"+
"Suggested M3 "+IJ.d2s(ZTM[5],0)+"steps";
}
}
System.out.println(msg);
IJ.showMessage(msg);
} }
} }
*/
//
} }
if (FOCUS_MEASUREMENT_PARAMETERS.saveResults) { if (FOCUS_MEASUREMENT_PARAMETERS.saveResults && !replayMode) {
String dir=getResultsPath(FOCUS_MEASUREMENT_PARAMETERS); String dir=getResultsPath(FOCUS_MEASUREMENT_PARAMETERS);
File dFile=new File(dir); File dFile=new File(dir);
if (!dFile.isDirectory() && !dFile.mkdirs()) { if (!dFile.isDirectory() && !dFile.mkdirs()) {
...@@ -5521,7 +5599,6 @@ if (MORE_BUTTONS) { ...@@ -5521,7 +5599,6 @@ if (MORE_BUTTONS) {
} }
String lensPrefix=""; String lensPrefix="";
if (FOCUS_MEASUREMENT_PARAMETERS.includeLensSerial && (FOCUS_MEASUREMENT_PARAMETERS.lensSerial.length()>0)){ if (FOCUS_MEASUREMENT_PARAMETERS.includeLensSerial && (FOCUS_MEASUREMENT_PARAMETERS.lensSerial.length()>0)){
// lensPrefix=String.format("LENS%S-",FOCUS_MEASUREMENT_PARAMETERS.lensSerial);
lensPrefix=String.format("LENS%S-S%02d-",FOCUS_MEASUREMENT_PARAMETERS.lensSerial,FOCUS_MEASUREMENT_PARAMETERS.manufacturingState); lensPrefix=String.format("LENS%S-S%02d-",FOCUS_MEASUREMENT_PARAMETERS.lensSerial,FOCUS_MEASUREMENT_PARAMETERS.manufacturingState);
} }
String path=dFile+Prefs.getFileSeparator()+lensPrefix+CAMERAS.getLastTimestampUnderscored()+ String path=dFile+Prefs.getFileSeparator()+lensPrefix+CAMERAS.getLastTimestampUnderscored()+
...@@ -5565,68 +5642,22 @@ if (MORE_BUTTONS) { ...@@ -5565,68 +5642,22 @@ if (MORE_BUTTONS) {
// Calculate and show average distances and tilts for measured history // Calculate and show average distances and tilts for measured history
if (!modeAverage) { if (!modeAverage) {
remoteNotifyComplete(); double [] lastKT;
double [] lastKT=MOTORS.focusingHistory.temperatureLinearApproximation( double [] allKT;
useLMA, if (!replayMode){
runs, // number of last samples from history to use, 0 - use all remoteNotifyComplete();
FOCUS_MEASUREMENT_PARAMETERS.lensDistanceWeightK, POWER_CONTROL.setPower("light","off");
FOCUS_MEASUREMENT_PARAMETERS.lensDistanceWeightY
);
double [] allKT=MOTORS.focusingHistory.temperatureLinearApproximation(
useLMA,
0, // number of last samples from history to use, 0 - use all
FOCUS_MEASUREMENT_PARAMETERS.lensDistanceWeightK,
FOCUS_MEASUREMENT_PARAMETERS.lensDistanceWeightY
);
FOCUS_MEASUREMENT_PARAMETERS.result_lastKT=lastKT[1]; // focal distance temperature coefficient (um/C), measured from last run
FOCUS_MEASUREMENT_PARAMETERS.result_lastFD20=lastKT[0]+20*lastKT[1]; // focal distance for 20C, measured from last run
FOCUS_MEASUREMENT_PARAMETERS.result_allHistoryKT=allKT[1]; // focal distance temperature coefficient (um/C), measured from all the measurement histgory
FOCUS_MEASUREMENT_PARAMETERS.result_allHistoryFD20=allKT[0]+20*allKT[1]; // focal distance for 20C, measured from all the measurement histgory
if (MASTER_DEBUG_LEVEL>0){
String msg=
"Focal distance temperature expansion is "+IJ.d2s(FOCUS_MEASUREMENT_PARAMETERS.result_lastKT,2)+
" ("+IJ.d2s(FOCUS_MEASUREMENT_PARAMETERS.result_allHistoryKT,2)+")"+
" microns per C, measured from this run (measured from all the history)\n"+
"Focal distance at 20C is "+IJ.d2s(FOCUS_MEASUREMENT_PARAMETERS.result_lastFD20,2)+
" ("+IJ.d2s(FOCUS_MEASUREMENT_PARAMETERS.result_allHistoryFD20,2)+")"+
" microns, measured from this run (measured from all the history)";
System.out.println(msg);
IJ.showMessage("Info",msg);
}
// Now in LMA mode - recalculate and overwrite
/*
if (useLMA){
ff= new FocusingField(
EYESIS_CAMERA_PARAMETERS.getSensorWidth(),
EYESIS_CAMERA_PARAMETERS.getSensorHeight(),
0.001*EYESIS_CAMERA_PARAMETERS.getPixelSize(0), //subCamera_0.pixelSize,
FOCUS_MEASUREMENT_PARAMETERS.serialNumber,
FOCUS_MEASUREMENT_PARAMETERS.lensSerial, // String lensSerial, // if null - do not add average
FOCUS_MEASUREMENT_PARAMETERS.comment, // String comment,
pX0,
pY0,
sampleCoord,
this.SYNC_COMMAND.stopRequested);
ff.setDebugLevel(DEBUG_LEVEL);
ff.setAdjustMode(false);
if (PROPERTIES!=null) ff.getProperties("FOCUSING_FIELD.", PROPERTIES,true);
MOTORS.addCurrentHistoryToFocusingField(ff); // all, not just newly acquired
if (MASTER_DEBUG_LEVEL>0){
System.out.println ("*** Calculating focal distance shift for each of "+MOTORS.historySize()+" recorded measurments ***");
}
boolean noMotors=true;
double [][] allZTM=FOCUSING_FIELD.getAllZTM(
noTiltScan,
ff, // no tilt scan (supposed to be adjusted
noMotors); // boolean noMotors) // do not calculate correction
lastKT=MOTORS.focusingHistory.temperatureLinearApproximation( lastKT=MOTORS.focusingHistory.temperatureLinearApproximation(
allZTM, useLMA,
runs runs, // number of last samples from history to use, 0 - use all
FOCUS_MEASUREMENT_PARAMETERS.lensDistanceWeightK,
FOCUS_MEASUREMENT_PARAMETERS.lensDistanceWeightY
); );
allKT=MOTORS.focusingHistory.temperatureLinearApproximation( allKT=MOTORS.focusingHistory.temperatureLinearApproximation(
allZTM, useLMA,
0 0, // number of last samples from history to use, 0 - use all
FOCUS_MEASUREMENT_PARAMETERS.lensDistanceWeightK,
FOCUS_MEASUREMENT_PARAMETERS.lensDistanceWeightY
); );
FOCUS_MEASUREMENT_PARAMETERS.result_lastKT=lastKT[1]; // focal distance temperature coefficient (um/C), measured from last run FOCUS_MEASUREMENT_PARAMETERS.result_lastKT=lastKT[1]; // focal distance temperature coefficient (um/C), measured from last run
FOCUS_MEASUREMENT_PARAMETERS.result_lastFD20=lastKT[0]+20*lastKT[1]; // focal distance for 20C, measured from last run FOCUS_MEASUREMENT_PARAMETERS.result_lastFD20=lastKT[0]+20*lastKT[1]; // focal distance for 20C, measured from last run
...@@ -5634,23 +5665,131 @@ if (MORE_BUTTONS) { ...@@ -5634,23 +5665,131 @@ if (MORE_BUTTONS) {
FOCUS_MEASUREMENT_PARAMETERS.result_allHistoryFD20=allKT[0]+20*allKT[1]; // focal distance for 20C, measured from all the measurement histgory FOCUS_MEASUREMENT_PARAMETERS.result_allHistoryFD20=allKT[0]+20*allKT[1]; // focal distance for 20C, measured from all the measurement histgory
if (MASTER_DEBUG_LEVEL>0){ if (MASTER_DEBUG_LEVEL>0){
String msg= String msg=
"Determined by LMA: Focal distance temperature expansion is "+IJ.d2s(FOCUS_MEASUREMENT_PARAMETERS.result_lastKT,2)+ "Focal distance temperature expansion is "+IJ.d2s(FOCUS_MEASUREMENT_PARAMETERS.result_lastKT,3)+
" ("+IJ.d2s(FOCUS_MEASUREMENT_PARAMETERS.result_allHistoryKT,2)+")"+ " ("+IJ.d2s(FOCUS_MEASUREMENT_PARAMETERS.result_allHistoryKT,3)+")"+
" microns per C, measured from this run (measured from all the history)\n"+ " microns per C, measured from this run (measured from all the history)\n"+
"Focal distance at 20C is "+IJ.d2s(FOCUS_MEASUREMENT_PARAMETERS.result_lastFD20,2)+ "Focal distance at 20C is "+IJ.d2s(FOCUS_MEASUREMENT_PARAMETERS.result_lastFD20,2)+
" ("+IJ.d2s(FOCUS_MEASUREMENT_PARAMETERS.result_allHistoryFD20,2)+")"+ " ("+IJ.d2s(FOCUS_MEASUREMENT_PARAMETERS.result_allHistoryFD20,2)+")"+
" microns, measured from this run (measured from all the history)\n"+
"Focal distance at "+FOCUS_MEASUREMENT_PARAMETERS.reportTemperature+ "C is "+
IJ.d2s(FOCUS_MEASUREMENT_PARAMETERS.result_lastFD20+
(FOCUS_MEASUREMENT_PARAMETERS.reportTemperature-20)*FOCUS_MEASUREMENT_PARAMETERS.result_lastKT,2)+
" ("+IJ.d2s(FOCUS_MEASUREMENT_PARAMETERS.result_allHistoryFD20+
(FOCUS_MEASUREMENT_PARAMETERS.reportTemperature-20)*FOCUS_MEASUREMENT_PARAMETERS.result_allHistoryKT,2)+")"+
" microns, measured from this run (measured from all the history)"; " microns, measured from this run (measured from all the history)";
System.out.println(msg); System.out.println(msg);
IJ.showMessage("Info",msg); IJ.showMessage("Info",msg);
} }
} }
*/ // Now in LMA mode - recalculate and overwrite
/* */
if (useLMA){
if (replayMode) {
ff=ffReplay;
ff.setDebugLevel(DEBUG_LEVEL);
ff.setAdjustMode(false,null);
if (PROPERTIES!=null) ff.getProperties("FOCUSING_FIELD.", PROPERTIES,true);
runs=ff.measurements.size();
} else {
ff= new FocusingField(
EYESIS_CAMERA_PARAMETERS.getSensorWidth(),
EYESIS_CAMERA_PARAMETERS.getSensorHeight(),
0.001*EYESIS_CAMERA_PARAMETERS.getPixelSize(0), //subCamera_0.pixelSize,
FOCUS_MEASUREMENT_PARAMETERS.serialNumber,
FOCUS_MEASUREMENT_PARAMETERS.lensSerial, // String lensSerial, // if null - do not add average
FOCUS_MEASUREMENT_PARAMETERS.comment, // String comment,
pX0,
pY0,
sampleCoord,
this.SYNC_COMMAND.stopRequested);
ff.setDebugLevel(DEBUG_LEVEL);
ff.setAdjustMode(false,null);
if (PROPERTIES!=null) ff.getProperties("FOCUSING_FIELD.", PROPERTIES,true);
MOTORS.addCurrentHistoryToFocusingField(ff); // all, not just newly acquired
if (MASTER_DEBUG_LEVEL>0){
System.out.println ("*** Calculating focal distance shift for each of "+MOTORS.historySize()+" recorded measurments ***");
}
}
// finds zc, not z0
double [][] allZTT=FOCUSING_FIELD.getAllZTT( // z, tx, ty, temperature - may contain null for bad measurements
noTiltScan,
ff, // no tilt scan - faster
FOCUSING_FIELD.recalculateAverageTilts); // boolean keepTilt){ // keep existent tilt
lastKT=MOTORS.focusingHistory.temperatureLinearApproximation(
allZTT,
runs
);
allKT=MOTORS.focusingHistory.temperatureLinearApproximation(
allZTT,
0
);
FOCUS_MEASUREMENT_PARAMETERS.result_lastKT=lastKT[1]; // focal distance temperature coefficient (um/C), measured from last run
FOCUS_MEASUREMENT_PARAMETERS.result_lastFD20=lastKT[0]+20*lastKT[1]; // focal distance for 20C, measured from last run
FOCUS_MEASUREMENT_PARAMETERS.result_allHistoryKT=allKT[1]; // focal distance temperature coefficient (um/C), measured from all the measurement histgory
FOCUS_MEASUREMENT_PARAMETERS.result_allHistoryFD20=allKT[0]+20*allKT[1]; // focal distance for 20C, measured from all the measurement histgory
}
/* */
}
if (useLMA){
gd=new GenericDialog(modeAverage?"Averaging results":"Thermal scanning results");
String msg="";
if (modeAverage){
if (ZTM!=null) {
msg="Average (through LMA):\n"+
"Relative focal shift "+IJ.d2s(ZTM[0],3)+"um (absolute - "+IJ.d2s(ZTM[0]+FOCUSING_FIELD.qualBOptimizationResults[0],3)+"um)\n"+
"Relative horizontal tilt "+IJ.d2s(ZTM[1],3)+"um/mm (absolute - "+IJ.d2s(ZTM[1]+FOCUSING_FIELD.qualBOptimizationResults[1],3)+"um.mm)\n"+
"Relative vertical tilt "+IJ.d2s(ZTM[2],3)+"um/mm (absolute - "+IJ.d2s(ZTM[2]+FOCUSING_FIELD.qualBOptimizationResults[2],3)+"um.mm)\n";
} else {
msg="Failed to calulate average focus/tilt";
}
}else {
msg=
"Determined by LMA: Focal distance temperature expansion is "+IJ.d2s(FOCUS_MEASUREMENT_PARAMETERS.result_lastKT,3)+
" ("+IJ.d2s(FOCUS_MEASUREMENT_PARAMETERS.result_allHistoryKT,3)+")"+
" microns per C, measured from this run (measured from all the history)\n"+
"Focal distance at 20C is "+IJ.d2s(FOCUS_MEASUREMENT_PARAMETERS.result_lastFD20,2)+
" ("+IJ.d2s(FOCUS_MEASUREMENT_PARAMETERS.result_allHistoryFD20,2)+")"+
" microns, measured from this run (measured from all the history)\n"+
"Focal distance at "+FOCUS_MEASUREMENT_PARAMETERS.reportTemperature+ "C is "+
IJ.d2s(FOCUS_MEASUREMENT_PARAMETERS.result_lastFD20+
(FOCUS_MEASUREMENT_PARAMETERS.reportTemperature-20)*FOCUS_MEASUREMENT_PARAMETERS.result_lastKT,2)+
" ("+IJ.d2s(FOCUS_MEASUREMENT_PARAMETERS.result_allHistoryFD20+
(FOCUS_MEASUREMENT_PARAMETERS.reportTemperature-20)*FOCUS_MEASUREMENT_PARAMETERS.result_allHistoryKT,2)+")"+
" microns, measured from this run (measured from all the history)";
}
System.out.println(msg);
gd.addMessage(msg);
double [][] zTxTyAbsRel=null;
if (FOCUSING_FIELD.recalculateAverageTilts==1){ // only if recalculated
zTxTyAbsRel=FOCUSING_FIELD.getZ0TxTyAbsRel(); // z - z0, not zc here !
double [][] zcZ0TxTy=FOCUSING_FIELD.getZcZ0TxTy(ff.measurements);
gd.addMessage("----------------------");
msg= "Average relative z0 parameter: "+IJ.d2s(zTxTyAbsRel[1][0],3)+"um (absolute: "+IJ.d2s(zTxTyAbsRel[0][0],3)+"um\n"+
"Average relative tx parameter: "+IJ.d2s(zTxTyAbsRel[1][1],3)+"um/mm (absolute: "+IJ.d2s(zTxTyAbsRel[0][1],3)+"um/mm\n"+
"Average relative ty parameter: "+IJ.d2s(zTxTyAbsRel[1][2],3)+"um/mm (absolute: "+IJ.d2s(zTxTyAbsRel[0][2],3)+"um/mm\n\n";
msg+= "Average zc: "+IJ.d2s(zcZ0TxTy[0][0],3)+"um\n"+
"Average Tilt x: "+IJ.d2s(zcZ0TxTy[0][1],3)+"um/mm\n"+
"Average Tilt y: "+IJ.d2s(zcZ0TxTy[0][2],3)+"um/mm\n";
System.out.println(msg);
gd.addMessage(msg);
gd.addCheckbox("Store calculated tilts, defaultValue",FOCUSING_FIELD.updateAverageTilts);
}
gd.showDialog();
if (!gd.wasCanceled()){
if (FOCUSING_FIELD.recalculateAverageTilts==1){ // only if recalculated
FOCUSING_FIELD.updateAverageTilts=gd.getNextBoolean();
if (FOCUSING_FIELD.updateAverageTilts){
FOCUSING_FIELD.avgTx=zTxTyAbsRel[0][1]; // average absolute tilt X (optionally used when finding Z of the glued SFE)
FOCUSING_FIELD.avgTy=zTxTyAbsRel[0][2]; // average absolute tilt Y (optionally used when finding Z of the glued SFE)
}
}
}
} }
saveCurrentConfig(); saveCurrentConfig();
return; return;
} }
/// "No-move measure"
/* ======================================================================== */ /* ======================================================================== */
if (label.equals("Configure Goniometer")) { if (label.equals("Configure Goniometer")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL; DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
...@@ -5710,12 +5849,14 @@ if (MORE_BUTTONS) { ...@@ -5710,12 +5849,14 @@ if (MORE_BUTTONS) {
"Taget angular size vertical: "+IJ.d2s(targetAngleVertical,1)+" degrees\n" "Taget angular size vertical: "+IJ.d2s(targetAngleVertical,1)+" degrees\n"
); );
GONIOMETER.debugLevel=DEBUG_LEVEL; GONIOMETER.debugLevel=DEBUG_LEVEL;
POWER_CONTROL.lightsOnWithDelay();
boolean goniometerScanOK=GONIOMETER.scanAndAcquire( boolean goniometerScanOK=GONIOMETER.scanAndAcquire(
targetAngleHorizontal, targetAngleHorizontal,
targetAngleVertical, targetAngleVertical,
this.SYNC_COMMAND.stopRequested, this.SYNC_COMMAND.stopRequested,
UPDATE_STATUS); UPDATE_STATUS);
System.out.println ("GONIOMETER.scanAndAcquireI() "+(goniometerScanOK?"finished OK":"failed")); System.out.println ("GONIOMETER.scanAndAcquireI() "+(goniometerScanOK?"finished OK":"failed"));
POWER_CONTROL.setPower("light","off");
return; return;
} }
...@@ -9226,7 +9367,8 @@ if (MORE_BUTTONS) { ...@@ -9226,7 +9367,8 @@ if (MORE_BUTTONS) {
if (path==null) return false; // did not load if (path==null) return false; // did not load
FOCUS_MEASUREMENT_PARAMETERS.focusingHistoryFile=path; FOCUS_MEASUREMENT_PARAMETERS.focusingHistoryFile=path;
FOCUSING_FIELD.setDebugLevel(DEBUG_LEVEL); FOCUSING_FIELD.setDebugLevel(DEBUG_LEVEL);
FOCUSING_FIELD.setAdjustMode(false); FOCUSING_FIELD.setThreads(THREADS_MAX);
FOCUSING_FIELD.setAdjustMode(false, null);
if (PROPERTIES!=null) FOCUSING_FIELD.getProperties("FOCUSING_FIELD.", PROPERTIES,true); // keep distortions center from history if (PROPERTIES!=null) FOCUSING_FIELD.getProperties("FOCUSING_FIELD.", PROPERTIES,true); // keep distortions center from history
System.out.println("Loaded FocusingField from "+path); System.out.println("Loaded FocusingField from "+path);
if (!FOCUSING_FIELD.configureDataVector( if (!FOCUSING_FIELD.configureDataVector(
...@@ -9295,7 +9437,9 @@ if (MORE_BUTTONS) { ...@@ -9295,7 +9437,9 @@ if (MORE_BUTTONS) {
//get measurement //get measurement
FocusingField.FocusingFieldMeasurement fFMeasurement=MOTORS.getThisFFMeasurement(FOCUSING_FIELD); FocusingField.FocusingFieldMeasurement fFMeasurement=MOTORS.getThisFFMeasurement(FOCUSING_FIELD);
// calculate z, tx, ty, m1,m2,m3 // calculate z, tx, ty, m1,m2,m3
int [] adjustModeAllCommon={1,1,1};
double [] zTxTyM1M2M3 = FOCUSING_FIELD.adjustLMA( double [] zTxTyM1M2M3 = FOCUSING_FIELD.adjustLMA(
adjustModeAllCommon, // FOCUSING_FIELD.zTxTyAdjustMode,
false, // allow tilt scan false, // allow tilt scan
fFMeasurement, fFMeasurement,
false, // parallel move false, // parallel move
...@@ -9450,7 +9594,9 @@ if (MORE_BUTTONS) { ...@@ -9450,7 +9594,9 @@ if (MORE_BUTTONS) {
} }
} }
if (parallelMove){ // ignore/recalculate newMotors data if (parallelMove){ // ignore/recalculate newMotors data
int [] adjustZOnly={1,0,0};
zTxTyM1M2M3 = FOCUSING_FIELD.adjustLMA( zTxTyM1M2M3 = FOCUSING_FIELD.adjustLMA(
adjustZOnly, // adjustAll,
false,// disable tilt scan false,// disable tilt scan
fFMeasurement, fFMeasurement,
true, // recalculate with parallel move only true, // recalculate with parallel move only
...@@ -11247,6 +11393,7 @@ if (MORE_BUTTONS) { ...@@ -11247,6 +11393,7 @@ if (MORE_BUTTONS) {
"", //String message, "", //String message,
!noHysteresis); //false); //focusMeasurementParameters.compensateHysteresis); //boolean hysteresis) !noHysteresis); //false); //focusMeasurementParameters.compensateHysteresis); //boolean hysteresis)
focusMeasurementParameters.sensorTemperature=camerasInterface.getSensorTemperature(0,focusMeasurementParameters.EEPROM_channel); focusMeasurementParameters.sensorTemperature=camerasInterface.getSensorTemperature(0,focusMeasurementParameters.EEPROM_channel);
POWER_CONTROL.lightsOnWithDelay();
ImagePlus imp= camerasInterface.acquireSingleImage ( ImagePlus imp= camerasInterface.acquireSingleImage (
false, //boolean useLasers, false, //boolean useLasers,
updateStatus); updateStatus);
...@@ -11306,13 +11453,17 @@ if (MORE_BUTTONS) { ...@@ -11306,13 +11453,17 @@ if (MORE_BUTTONS) {
focusMeasurementParameters.sensorTemperature, focusMeasurementParameters.sensorTemperature,
focusingMotors.readElphel10364Motors(), //focusingHistory.getPosition(), //null? focusingMotors.readElphel10364Motors(), //focusingHistory.getPosition(), //null?
rFullResults[0]); //focusingState.getSamples()); rFullResults[0]); //focusingState.getSamples());
try{
zTxTy=FOCUSING_FIELD.adjustLMA( zTxTy=FOCUSING_FIELD.adjustLMA(
true, // false, // noTiltScan FOCUSING_FIELD.zTxTyAdjustMode,
fFMeasurement, true, // false, // noTiltScan
false, // parallel move fFMeasurement,
true, // boolean noQualB, // do not re-claculate testQualB false, // parallel move
true); // boolean noAdjust); // do not calculate correction true, // boolean noQualB, // do not re-claculate testQualB
true); // boolean noAdjust); // do not calculate correction
} catch (Exception e){
System.out.println("FOCUSING_FIELD.adjustLMA() failed");
}
if (zTxTy!=null){ if (zTxTy!=null){
metrics[ca][0]=zTxTy[0]; // was far/near metrics[ca][0]=zTxTy[0]; // was far/near
metrics[ca][1]=zTxTy[1]; metrics[ca][1]=zTxTy[1];
...@@ -11402,6 +11553,7 @@ if (MORE_BUTTONS) { ...@@ -11402,6 +11553,7 @@ if (MORE_BUTTONS) {
focusMeasurementParameters.compensateHysteresis); //boolean hysteresis) focusMeasurementParameters.compensateHysteresis); //boolean hysteresis)
} }
focusMeasurementParameters.sensorTemperature=camerasInterface.getSensorTemperature(0,FOCUS_MEASUREMENT_PARAMETERS.EEPROM_channel); focusMeasurementParameters.sensorTemperature=camerasInterface.getSensorTemperature(0,FOCUS_MEASUREMENT_PARAMETERS.EEPROM_channel);
POWER_CONTROL.lightsOnWithDelay();
ImagePlus imp= camerasInterface.acquireSingleImage ( ImagePlus imp= camerasInterface.acquireSingleImage (
false, //boolean useLasers, false, //boolean useLasers,
updateStatus); updateStatus);
......
...@@ -47,6 +47,7 @@ import java.util.ArrayList; ...@@ -47,6 +47,7 @@ import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
...@@ -1800,21 +1801,27 @@ public class CalibrationHardwareInterface { ...@@ -1800,21 +1801,27 @@ public class CalibrationHardwareInterface {
} }
public static class PowerControl{ public static class PowerControl{
public boolean [] states={false,false,false};
public String [] groups={"heater","fan","light"};
public int debugLevel=1; public int debugLevel=1;
private String powerIP="192.168.0.80"; private String powerIP="192.168.0.80";
private double lightsDelay=5.0;
private final String urlFormat="http://%s/insteon/index.php?cmd=%s&group=%s"; private final String urlFormat="http://%s/insteon/index.php?cmd=%s&group=%s";
private final String rootElement="Document"; private final String rootElement="Document";
public boolean powerConrtolEnabled=false; public boolean powerConrtolEnabled=false;
public void setProperties(String prefix,Properties properties){ public void setProperties(String prefix,Properties properties){
properties.setProperty(prefix+"powerIP",this.powerIP+""); properties.setProperty(prefix+"powerIP",this.powerIP+"");
properties.setProperty(prefix+"powerConrtolEnabled",this.powerConrtolEnabled+""); properties.setProperty(prefix+"powerConrtolEnabled",this.powerConrtolEnabled+"");
properties.setProperty(prefix+"lightsDelay",this.lightsDelay+"");
} }
//Integer.decode(string) //Integer.decode(string)
public void getProperties(String prefix,Properties properties){ public void getProperties(String prefix,Properties properties){
if (properties.getProperty(prefix+"powerIP")!=null) if (properties.getProperty(prefix+"powerIP")!=null)
this.powerIP=properties.getProperty(prefix+"powerIP"); this.powerIP=properties.getProperty(prefix+"powerIP");
if (properties.getProperty(prefix+"powerConrtolEnabled")!=null) if (properties.getProperty(prefix+"powerConrtolEnabled")!=null)
this.powerConrtolEnabled=Boolean.parseBoolean(properties.getProperty(prefix+"powerConrtolEnabled")); this.powerConrtolEnabled=Boolean.parseBoolean(properties.getProperty(prefix+"powerConrtolEnabled"));
if (properties.getProperty(prefix+"lightsDelay")!=null)
this.lightsDelay=Double.parseDouble(properties.getProperty(prefix+"lightsDelay"));
} }
public boolean setPower (String group, String state){ public boolean setPower (String group, String state){
...@@ -1822,6 +1829,7 @@ public class CalibrationHardwareInterface { ...@@ -1822,6 +1829,7 @@ public class CalibrationHardwareInterface {
System.out.println("=== Power control is disabled ==="); System.out.println("=== Power control is disabled ===");
return false; return false;
} }
System.out.println("=== Power control: "+group+":"+state+" ===");
String url=String.format(urlFormat,this.powerIP,state,group); String url=String.format(urlFormat,this.powerIP,state,group);
if (this.debugLevel>2) System.out.println("setPower: "+url); if (this.debugLevel>2) System.out.println("setPower: "+url);
Document dom=null; Document dom=null;
...@@ -1856,16 +1864,22 @@ public class CalibrationHardwareInterface { ...@@ -1856,16 +1864,22 @@ public class CalibrationHardwareInterface {
se.printStackTrace(); se.printStackTrace();
return false; return false;
} }
for (int i=0;i<this.groups.length;i++) if (this.groups[i].equals(group)){
this.states[i]=state.equals("on");
}
return true; return true;
} }
public boolean showDialog(String title, boolean control) { public boolean showDialog(String title, boolean control) {
GenericDialog gd = new GenericDialog(title); GenericDialog gd = new GenericDialog(title);
boolean heaterOn=false, fanOn=false; boolean heaterOn=false, fanOn=false, lightOn=false;
gd.addCheckbox("Enable power control (heater, fan) ", this.powerConrtolEnabled); gd.addCheckbox("Enable power control (heater, fan, lights) ", this.powerConrtolEnabled);
gd.addStringField("IP address of the power control",this.powerIP,15); gd.addStringField("IP address of the power control",this.powerIP,15);
gd.addNumericField("Delay after lights on", this.lightsDelay, 1,4,"sec");
if (control){ if (control){
gd.addCheckbox("Heater On", heaterOn); gd.addCheckbox("Heater On", heaterOn);
gd.addCheckbox("Fan On", fanOn); gd.addCheckbox("Fan On", fanOn);
gd.addCheckbox("Lights On", lightOn);
} }
WindowTools.addScrollBars(gd); WindowTools.addScrollBars(gd);
if (control) gd.enableYesNoCancel("OK", "Control Power"); if (control) gd.enableYesNoCancel("OK", "Control Power");
...@@ -1873,16 +1887,33 @@ public class CalibrationHardwareInterface { ...@@ -1873,16 +1887,33 @@ public class CalibrationHardwareInterface {
if (gd.wasCanceled()) return false; if (gd.wasCanceled()) return false;
this.powerConrtolEnabled=gd.getNextBoolean(); this.powerConrtolEnabled=gd.getNextBoolean();
this.powerIP=gd.getNextString(); this.powerIP=gd.getNextString();
this.lightsDelay=gd.getNextNumber();
if (control){ if (control){
heaterOn=gd.getNextBoolean(); heaterOn=gd.getNextBoolean();
fanOn=gd.getNextBoolean(); fanOn=gd.getNextBoolean();
lightOn=gd.getNextBoolean();
if (!gd.wasOKed()) { if (!gd.wasOKed()) {
setPower("heater",heaterOn?"on":"off"); setPower("heater",heaterOn?"on":"off");
setPower("fan",fanOn?"on":"off"); setPower("fan",fanOn?"on":"off");
setPower("light",lightOn?"on":"off");
} }
} }
return true; return true;
} }
public void lightsOnWithDelay(){
if (this.states[2] || !this.powerConrtolEnabled) return; // already on
setPower("light","on");
System.out.print("Sleeping "+this.lightsDelay+" seconds to let lights stibilize on...");
try {
TimeUnit.MILLISECONDS.sleep((long) (1000*this.lightsDelay));
} catch (InterruptedException e) {
System.out.println("Sleep was interrupted");
// TODO Auto-generated catch block
}
System.out.println(" Done");
}
public boolean isPowerControlEnabled(){ public boolean isPowerControlEnabled(){
return this.powerConrtolEnabled; return this.powerConrtolEnabled;
} }
...@@ -5218,22 +5249,26 @@ if (debugLevel>=debugThreshold) System.out.println(i+" "+diff[0]+" "+diff[1]+" " ...@@ -5218,22 +5249,26 @@ if (debugLevel>=debugThreshold) System.out.println(i+" "+diff[0]+" "+diff[1]+" "
} }
public double [] temperatureLinearApproximation( public double [] temperatureLinearApproximation(
double [][] ZTM, // Z, tXx, tY, m1,m2,m3 found with LMA double [][] ZTT, // Z, tXx, tY, m1,m2,m3 found with LMA - may contain NaN
int numSamples // number of last samples from history to use, 0 - use all int numSamples // number of last samples from history to use, 0 - use all
){ ){
if (numSamples<=0) numSamples=this.history.size(); // if (numSamples<=0) this.history.size();
if (numSamples>this.history.size()) numSamples=this.history.size(); // if (numSamples>this.history.size()) numSamples=this.history.size();
int firstSample=this.history.size()-numSamples; // int firstSample=this.history.size()-numSamples;
if (numSamples<=0) numSamples=ZTT.length;
if (numSamples>ZTT.length) numSamples=ZTT.length;
int firstSample=ZTT.length-numSamples;
int numGoodSamples=0; int numGoodSamples=0;
for (int nSample=0;nSample<numSamples;nSample++){ for (int nSample=0;nSample<numSamples;nSample++){
if (ZTM[firstSample+nSample]!=null) numGoodSamples++; if (ZTT[firstSample+nSample]!=null) numGoodSamples++;
} }
double [][] data =new double [numGoodSamples][2]; // no weights double [][] data =new double [numGoodSamples][2]; // no weights
int index=0; int index=0;
for (int nSample=0;nSample<numSamples;nSample++) if (ZTM[firstSample+nSample]!=null) { for (int nSample=0;nSample<numSamples;nSample++) if (ZTT[firstSample+nSample]!=null) {
data[index][0]=this.history.get(firstSample+nSample).getTemperature(); // data[index][0]=this.history.get(firstSample+nSample).getTemperature();
data[index++][1]=ZTM[firstSample+nSample][0]; // Z data[index][0]=ZTT[firstSample+nSample][3];
data[index++][1]=ZTT[firstSample+nSample][0]; // Z
} }
PolynomialApproximation pa= new PolynomialApproximation(debugLevel); PolynomialApproximation pa= new PolynomialApproximation(debugLevel);
double [] polyCoeff=pa.polynomialApproximation1d(data, 1); // just linear double [] polyCoeff=pa.polynomialApproximation1d(data, 1); // just linear
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -226,13 +226,14 @@ public class LensAdjustment { ...@@ -226,13 +226,14 @@ public class LensAdjustment {
public int lensSerialLength=4; public int lensSerialLength=4;
public String lensSerial=""; // Lens serial number public String lensSerial=""; // Lens serial number
public boolean askLensSerial=true; // Ask lens serial on camera power cycle public boolean askLensSerial=true; // Ask lens serial on camera power cycle
public double reportTemperature=50; // temperature to report focal length
public boolean includeLensSerial=true; // add lens serial to config filename public boolean includeLensSerial=true; // add lens serial to config filename
public double centerDeltaX=0.0; // required X-difference between lens center and sensor center public double centerDeltaX=0.0; // required X-difference between lens center and sensor center
public double centerDeltaY=0.0; // required Y-difference between lens center and sensor center public double centerDeltaY=0.0; // required Y-difference between lens center and sensor center
// with the seam in the middle - make even # of samples horizontally // with the seam in the middle - make even # of samples horizontally
public Rectangle margins=new Rectangle (100,100,2392,1736) ; // maximal height 1816 (1936-120) public Rectangle margins=new Rectangle (100,100,2392,1736) ; // maximal height 1816 (1936-120)
public int [] numSamples={4,3}; // number of samples in x and y directions public int [] numSamples={8,5}; // number of samples in x and y directions
public int sampleSize=256;// 512; // size of square (2^n), in sensor pixels (twice FFT size) public int sampleSize=256;// 512; // size of square (2^n), in sensor pixels (twice FFT size)
public int numInCenter=(numSamples[0]-2)*(numSamples[1]-2);// 2 - number of "center" samples public int numInCenter=(numSamples[0]-2)*(numSamples[1]-2);// 2 - number of "center" samples
public boolean centerSamples=true; // Select samples in the WOI symmetrical around the lens center public boolean centerSamples=true; // Select samples in the WOI symmetrical around the lens center
...@@ -583,7 +584,8 @@ public class LensAdjustment { ...@@ -583,7 +584,8 @@ public class LensAdjustment {
int numIterations, // maximal number of iterations int numIterations, // maximal number of iterations
boolean cameraIsConfigured, boolean cameraIsConfigured,
int [] motorPos, int [] motorPos,
double [] ampsSeconds // cumulative Amps*seconds (read only, but will be saved/restored) double [] ampsSeconds, // cumulative Amps*seconds (read only, but will be saved/restored)
double reportTemperature // temperature to report focal length
){ ){
this.gridGeometryFile=gridGeometryFile; this.gridGeometryFile=gridGeometryFile;
this.initialCalibrationFile=initialCalibrationFile; this.initialCalibrationFile=initialCalibrationFile;
...@@ -734,7 +736,7 @@ public class LensAdjustment { ...@@ -734,7 +736,7 @@ public class LensAdjustment {
this.cameraIsConfigured=cameraIsConfigured; this.cameraIsConfigured=cameraIsConfigured;
this.motorPos=motorPos; this.motorPos=motorPos;
this.ampsSeconds=ampsSeconds; // cumulative Amps*seconds (read only, but will be saved/restored) this.ampsSeconds=ampsSeconds; // cumulative Amps*seconds (read only, but will be saved/restored)
this.reportTemperature=reportTemperature;
} }
public FocusMeasurementParameters clone(){ public FocusMeasurementParameters clone(){
...@@ -887,7 +889,8 @@ public class LensAdjustment { ...@@ -887,7 +889,8 @@ public class LensAdjustment {
this.numIterations, this.numIterations,
this.cameraIsConfigured, this.cameraIsConfigured,
this.motorPos, this.motorPos,
this.ampsSeconds // cumulative Amps*seconds (read only, but will be saved/restored) this.ampsSeconds, // cumulative Amps*seconds (read only, but will be saved/restored)
this.reportTemperature
); );
} }
public void setProperties(String prefix,Properties properties){ public void setProperties(String prefix,Properties properties){
...@@ -1049,6 +1052,7 @@ public class LensAdjustment { ...@@ -1049,6 +1052,7 @@ public class LensAdjustment {
properties.setProperty(prefix+"numIterations",this.numIterations+""); properties.setProperty(prefix+"numIterations",this.numIterations+"");
for (int i=0;i<this.ampsSeconds.length;i++) for (int i=0;i<this.ampsSeconds.length;i++)
properties.setProperty(prefix+"ampsSeconds_"+i,this.ampsSeconds[i]+""); properties.setProperty(prefix+"ampsSeconds_"+i,this.ampsSeconds[i]+"");
properties.setProperty(prefix+"reportTemperature",this.reportTemperature+"");
} }
public void getProperties(String prefix,Properties properties){ public void getProperties(String prefix,Properties properties){
if (properties.getProperty(prefix+"gridGeometryFile")!=null) if (properties.getProperty(prefix+"gridGeometryFile")!=null)
...@@ -1368,9 +1372,10 @@ public class LensAdjustment { ...@@ -1368,9 +1372,10 @@ public class LensAdjustment {
this.thresholdFinish=Double.parseDouble(properties.getProperty(prefix+"thresholdFinish")); this.thresholdFinish=Double.parseDouble(properties.getProperty(prefix+"thresholdFinish"));
if (properties.getProperty(prefix+"numIterations")!=null) if (properties.getProperty(prefix+"numIterations")!=null)
this.numIterations=Integer.parseInt(properties.getProperty(prefix+"numIterations")); this.numIterations=Integer.parseInt(properties.getProperty(prefix+"numIterations"));
for (int i=0;i<this.ampsSeconds.length;i++) if (properties.getProperty(prefix+"ampsSeconds_"+i)!=null) for (int i=0;i<this.ampsSeconds.length;i++) if (properties.getProperty(prefix+"ampsSeconds_"+i)!=null)
this.ampsSeconds[i]=Double.parseDouble(properties.getProperty(prefix+"ampsSeconds_"+i)); this.ampsSeconds[i]=Double.parseDouble(properties.getProperty(prefix+"ampsSeconds_"+i));
if (properties.getProperty(prefix+"reportTemperature")!=null)
this.reportTemperature=Double.parseDouble(properties.getProperty(prefix+"reportTemperature"));
} }
public boolean getLensSerial(){ public boolean getLensSerial(){
while (true) { // loop until OK-ed while (true) { // loop until OK-ed
...@@ -1628,13 +1633,23 @@ public class LensAdjustment { ...@@ -1628,13 +1633,23 @@ public class LensAdjustment {
gd.addNumericField("Expand during extrapolation (relative to the average grid period)", this.flatFieldExpand, 3); gd.addNumericField("Expand during extrapolation (relative to the average grid period)", this.flatFieldExpand, 3);
gd.addNumericField("Threshold RMS to exit LMA", this.thresholdFinish, 7,9,"pix"); gd.addNumericField("Threshold RMS to exit LMA", this.thresholdFinish, 7,9,"pix");
gd.addNumericField("Maximal number of LMA iterations per series",this.numIterations, 0); gd.addNumericField("Maximal number of LMA iterations per series",this.numIterations, 0);
gd.addMessage("-----");
gd.addNumericField("Report focal length at this temperature", this.reportTemperature, 1,5,"C");
if (!Double.isNaN(this.sensorTemperature)) gd.addMessage("Last measured sensor temperature is "+this.sensorTemperature+" C"); if (!Double.isNaN(this.sensorTemperature)) gd.addMessage("Last measured sensor temperature is "+this.sensorTemperature+" C");
if (!Double.isNaN(this.result_lastKT)) gd.addMessage("Temperature focal distance coefficient measured in last run is "+this.result_lastKT+"microns/C"); if (!Double.isNaN(this.result_lastKT)) gd.addMessage("Temperature focal distance coefficient measured in last run is "+this.result_lastKT+"microns/C");
if (!Double.isNaN(this.result_lastFD20)) gd.addMessage("Focal distance @20C measured at last run is "+this.result_lastFD20+" microns"); if (!Double.isNaN(this.result_lastFD20)) gd.addMessage("Focal distance @20C measured at last run is "+this.result_lastFD20+" microns");
if (!Double.isNaN(this.result_lastKT) && !Double.isNaN(this.result_lastFD20)){
gd.addMessage("Focal distance @"+this.reportTemperature+"C measured at last run is "+
(this.result_lastFD20+(this.reportTemperature-20.0)*this.result_lastKT)+" microns");
}
if (!Double.isNaN(this.result_allHistoryKT)) gd.addMessage("Temperature focal distance coefficient calculated from all measurements is "+this.result_allHistoryKT+" microns"); if (!Double.isNaN(this.result_allHistoryKT)) gd.addMessage("Temperature focal distance coefficient calculated from all measurements is "+this.result_allHistoryKT+" microns");
if (!Double.isNaN(this.result_allHistoryFD20)) gd.addMessage("Focal distance @20C calculated from all measurements is "+this.result_allHistoryFD20+" microns"); if (!Double.isNaN(this.result_allHistoryFD20)) gd.addMessage("Focal distance @20C calculated from all measurements is "+this.result_allHistoryFD20+" microns");
if (!Double.isNaN(this.result_allHistoryKT) && !Double.isNaN(this.result_allHistoryFD20)){
gd.addMessage("Focal distance @"+this.reportTemperature+"C calculated from all measurements is "+
(this.result_allHistoryFD20+(this.reportTemperature-20.0)*this.result_allHistoryKT)+" microns");
}
if (!Double.isNaN(this.result_fDistance)) gd.addMessage("Focal distance is "+this.result_fDistance+" microns"); if (!Double.isNaN(this.result_fDistance)) gd.addMessage("Focal distance is "+this.result_fDistance+" microns");
if (!Double.isNaN(this.result_tiltX)) gd.addMessage("Horizontal angular/tangential asymmetry "+this.result_tiltX); if (!Double.isNaN(this.result_tiltX)) gd.addMessage("Horizontal angular/tangential asymmetry "+this.result_tiltX);
if (!Double.isNaN(this.result_tiltY)) gd.addMessage("Vertical angular/tangential asymmetry "+this.result_tiltY); if (!Double.isNaN(this.result_tiltY)) gd.addMessage("Vertical angular/tangential asymmetry "+this.result_tiltY);
...@@ -1650,6 +1665,7 @@ public class LensAdjustment { ...@@ -1650,6 +1665,7 @@ public class LensAdjustment {
if (!Double.isNaN(this.result_FocalLength)) gd.addMessage("Lens focal length "+this.result_FocalLength+" mm"); if (!Double.isNaN(this.result_FocalLength)) gd.addMessage("Lens focal length "+this.result_FocalLength+" mm");
gd.addMessage("Cumulative currents that ran through UV LEDs:"); gd.addMessage("Cumulative currents that ran through UV LEDs:");
for (int i=0;i<this.ampsSeconds.length;i++) gd.addMessage("UV LED "+(i+1)+":"+IJ.d2s(this.ampsSeconds[i],3)+" coulombs (amp-seconds)"); for (int i=0;i<this.ampsSeconds.length;i++) gd.addMessage("UV LED "+(i+1)+":"+IJ.d2s(this.ampsSeconds[i],3)+" coulombs (amp-seconds)");
WindowTools.addScrollBars(gd); WindowTools.addScrollBars(gd);
gd.showDialog(); gd.showDialog();
if (gd.wasCanceled()) return false; if (gd.wasCanceled()) return false;
...@@ -1803,6 +1819,7 @@ public class LensAdjustment { ...@@ -1803,6 +1819,7 @@ public class LensAdjustment {
this.flatFieldExpand= gd.getNextNumber(); this.flatFieldExpand= gd.getNextNumber();
this.thresholdFinish= gd.getNextNumber(); this.thresholdFinish= gd.getNextNumber();
this.numIterations= (int) gd.getNextNumber(); this.numIterations= (int) gd.getNextNumber();
this.reportTemperature= gd.getNextNumber();
return true; return true;
} }
/* ======================================================================== */ /* ======================================================================== */
......
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