Commit d14a3970 authored by Andrey Filippov's avatar Andrey Filippov

Implemented simultaneous processing of multiple measurements (averaging,

thermal scan), fixed adjustment
parent f8e486b9
This diff is collapsed.
......@@ -47,6 +47,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import javax.xml.parsers.DocumentBuilder;
......@@ -1800,21 +1801,27 @@ public class CalibrationHardwareInterface {
}
public static class PowerControl{
public boolean [] states={false,false,false};
public String [] groups={"heater","fan","light"};
public int debugLevel=1;
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 rootElement="Document";
public boolean powerConrtolEnabled=false;
public void setProperties(String prefix,Properties properties){
properties.setProperty(prefix+"powerIP",this.powerIP+"");
properties.setProperty(prefix+"powerConrtolEnabled",this.powerConrtolEnabled+"");
properties.setProperty(prefix+"lightsDelay",this.lightsDelay+"");
}
//Integer.decode(string)
public void getProperties(String prefix,Properties properties){
if (properties.getProperty(prefix+"powerIP")!=null)
this.powerIP=properties.getProperty(prefix+"powerIP");
if (properties.getProperty(prefix+"powerConrtolEnabled")!=null)
this.powerConrtolEnabled=Boolean.parseBoolean(properties.getProperty(prefix+"powerConrtolEnabled"));
if (properties.getProperty(prefix+"powerConrtolEnabled")!=null)
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){
......@@ -1822,6 +1829,7 @@ public class CalibrationHardwareInterface {
System.out.println("=== Power control is disabled ===");
return false;
}
System.out.println("=== Power control: "+group+":"+state+" ===");
String url=String.format(urlFormat,this.powerIP,state,group);
if (this.debugLevel>2) System.out.println("setPower: "+url);
Document dom=null;
......@@ -1856,16 +1864,22 @@ public class CalibrationHardwareInterface {
se.printStackTrace();
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;
}
public boolean showDialog(String title, boolean control) {
GenericDialog gd = new GenericDialog(title);
boolean heaterOn=false, fanOn=false;
gd.addCheckbox("Enable power control (heater, fan) ", this.powerConrtolEnabled);
boolean heaterOn=false, fanOn=false, lightOn=false;
gd.addCheckbox("Enable power control (heater, fan, lights) ", this.powerConrtolEnabled);
gd.addStringField("IP address of the power control",this.powerIP,15);
gd.addNumericField("Delay after lights on", this.lightsDelay, 1,4,"sec");
if (control){
gd.addCheckbox("Heater On", heaterOn);
gd.addCheckbox("Fan On", fanOn);
gd.addCheckbox("Lights On", lightOn);
}
WindowTools.addScrollBars(gd);
if (control) gd.enableYesNoCancel("OK", "Control Power");
......@@ -1873,16 +1887,33 @@ public class CalibrationHardwareInterface {
if (gd.wasCanceled()) return false;
this.powerConrtolEnabled=gd.getNextBoolean();
this.powerIP=gd.getNextString();
this.lightsDelay=gd.getNextNumber();
if (control){
heaterOn=gd.getNextBoolean();
fanOn=gd.getNextBoolean();
lightOn=gd.getNextBoolean();
if (!gd.wasOKed()) {
setPower("heater",heaterOn?"on":"off");
setPower("fan",fanOn?"on":"off");
setPower("light",lightOn?"on":"off");
}
}
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(){
return this.powerConrtolEnabled;
}
......@@ -5218,22 +5249,26 @@ if (debugLevel>=debugThreshold) System.out.println(i+" "+diff[0]+" "+diff[1]+" "
}
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
){
if (numSamples<=0) numSamples=this.history.size();
if (numSamples>this.history.size()) numSamples=this.history.size();
int firstSample=this.history.size()-numSamples;
// if (numSamples<=0) this.history.size();
// if (numSamples>this.history.size()) numSamples=this.history.size();
// 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;
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
int index=0;
for (int nSample=0;nSample<numSamples;nSample++) if (ZTM[firstSample+nSample]!=null) {
data[index][0]=this.history.get(firstSample+nSample).getTemperature();
data[index++][1]=ZTM[firstSample+nSample][0]; // Z
for (int nSample=0;nSample<numSamples;nSample++) if (ZTT[firstSample+nSample]!=null) {
// data[index][0]=this.history.get(firstSample+nSample).getTemperature();
data[index][0]=ZTT[firstSample+nSample][3];
data[index++][1]=ZTT[firstSample+nSample][0]; // Z
}
PolynomialApproximation pa= new PolynomialApproximation(debugLevel);
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 {
public int lensSerialLength=4;
public String lensSerial=""; // Lens serial number
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 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
// 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 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 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
......@@ -583,7 +584,8 @@ public class LensAdjustment {
int numIterations, // maximal number of iterations
boolean cameraIsConfigured,
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.initialCalibrationFile=initialCalibrationFile;
......@@ -734,7 +736,7 @@ public class LensAdjustment {
this.cameraIsConfigured=cameraIsConfigured;
this.motorPos=motorPos;
this.ampsSeconds=ampsSeconds; // cumulative Amps*seconds (read only, but will be saved/restored)
this.reportTemperature=reportTemperature;
}
public FocusMeasurementParameters clone(){
......@@ -887,7 +889,8 @@ public class LensAdjustment {
this.numIterations,
this.cameraIsConfigured,
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){
......@@ -1049,6 +1052,7 @@ public class LensAdjustment {
properties.setProperty(prefix+"numIterations",this.numIterations+"");
for (int i=0;i<this.ampsSeconds.length;i++)
properties.setProperty(prefix+"ampsSeconds_"+i,this.ampsSeconds[i]+"");
properties.setProperty(prefix+"reportTemperature",this.reportTemperature+"");
}
public void getProperties(String prefix,Properties properties){
if (properties.getProperty(prefix+"gridGeometryFile")!=null)
......@@ -1368,9 +1372,10 @@ public class LensAdjustment {
this.thresholdFinish=Double.parseDouble(properties.getProperty(prefix+"thresholdFinish"));
if (properties.getProperty(prefix+"numIterations")!=null)
this.numIterations=Integer.parseInt(properties.getProperty(prefix+"numIterations"));
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));
if (properties.getProperty(prefix+"reportTemperature")!=null)
this.reportTemperature=Double.parseDouble(properties.getProperty(prefix+"reportTemperature"));
}
public boolean getLensSerial(){
while (true) { // loop until OK-ed
......@@ -1628,13 +1633,23 @@ public class LensAdjustment {
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("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.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_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_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_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);
......@@ -1650,6 +1665,7 @@ public class LensAdjustment {
if (!Double.isNaN(this.result_FocalLength)) gd.addMessage("Lens focal length "+this.result_FocalLength+" mm");
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)");
WindowTools.addScrollBars(gd);
gd.showDialog();
if (gd.wasCanceled()) return false;
......@@ -1803,6 +1819,7 @@ public class LensAdjustment {
this.flatFieldExpand= gd.getNextNumber();
this.thresholdFinish= gd.getNextNumber();
this.numIterations= (int) gd.getNextNumber();
this.reportTemperature= gd.getNextNumber();
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