Commit 447a735d authored by Andrey Filippov's avatar Andrey Filippov

Adding heater/fan control for thermal focal distance measurements

parent d3195f8c
This diff is collapsed.
...@@ -1797,12 +1797,99 @@ public class CalibrationHardwareInterface { ...@@ -1797,12 +1797,99 @@ public class CalibrationHardwareInterface {
throw new RuntimeException(ie); throw new RuntimeException(ie);
} }
} }
}
public static class PowerControl{
public int debugLevel=1;
private String powerIP="192.168.0.80";
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+"");
}
//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"));
} }
public boolean setPower (String group, String state){
if (!powerConrtolEnabled) {
System.out.println("=== Power control is disabled ===");
return false;
}
String url=String.format(urlFormat,this.powerIP,state,group);
if (this.debugLevel>2) System.out.println("setPower: "+url);
Document dom=null;
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
dom = db.parse(url);
if (!dom.getDocumentElement().getNodeName().equals(rootElement)) {
System.out.println("Root element: expected \""+rootElement+"\", got \"" + dom.getDocumentElement().getNodeName()+"\"");
IJ.showMessage("Error","Root element: expected \""+rootElement+"\", got \"" + dom.getDocumentElement().getNodeName()+"\"");
return false;
}
// boolean responceError= (dom.getDocumentElement().getElementsByTagName("error").getLength()!=0);
// if (responceError) {
// System.out.println("ERROR: register write ("+url+") FAILED" );
// IJ.showMessage("Error","register write ("+url+") FAILED");
// return false;
// }
} catch(MalformedURLException e){
System.out.println("Please check the URL:" + e.toString() );
return false;
} catch(IOException e1){
IJ.showStatus("");
String error = e1.getMessage();
if (error==null || error.equals("")) error = ""+e1;
IJ.showMessage("setPower ERROR", ""+error);
return false;
}catch(ParserConfigurationException pce) {
pce.printStackTrace();
return false;
}catch(SAXException se) {
se.printStackTrace();
return false;
}
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);
gd.addStringField("IP address of the power control",this.powerIP,15);
if (control){
gd.addCheckbox("Heater On", heaterOn);
gd.addCheckbox("Fan On", fanOn);
}
WindowTools.addScrollBars(gd);
if (control) gd.enableYesNoCancel("OK", "Control Power");
gd.showDialog();
if (gd.wasCanceled()) return false;
this.powerConrtolEnabled=gd.getNextBoolean();
this.powerIP=gd.getNextString();
if (control){
heaterOn=gd.getNextBoolean();
fanOn=gd.getNextBoolean();
if (!gd.wasOKed()) {
setPower("heater",heaterOn?"on":"off");
setPower("fan",fanOn?"on":"off");
}
}
return true;
}
public boolean isPowerControlEnabled(){
return this.powerConrtolEnabled;
}
public void setDebugLevel(int debugLevel){
this.debugLevel=debugLevel;
}
}
public static class LaserPointers{ public static class LaserPointers{
public int debugLevel=1; public int debugLevel=1;
......
...@@ -330,6 +330,12 @@ public class LensAdjustment { ...@@ -330,6 +330,12 @@ public class LensAdjustment {
public boolean lensDistanceShowResults=true; // show results window from foca public boolean lensDistanceShowResults=true; // show results window from foca
public boolean lensDistanceMoveToGoal=true; // Move to targetMicrons public boolean lensDistanceMoveToGoal=true; // Move to targetMicrons
public boolean powerControlEnable=true;
public double powerControlMaximalTemperature=60.0;
public double powerControlHeaterOnMinutes=10.0;
public double powerControlNeitherOnMinutes=5.0;
public double powerControlFanOnMinutes=15.0;
public String uvLasersIP="192.168.0.236"; // IP address of the camera with UV LEDs and aiming lasers are connected public String uvLasersIP="192.168.0.236"; // IP address of the camera with UV LEDs and aiming lasers are connected
public int uvLasersBus=0; // 0 if 103641 board is connected to the sensor port (through 10-359), 1 - to 10369 public int uvLasersBus=0; // 0 if 103641 board is connected to the sensor port (through 10-359), 1 - to 10369
public double [] uvLasersCurrents={40.0,40.0,40.0,40.0}; // default LED on currents (mA) public double [] uvLasersCurrents={40.0,40.0,40.0,40.0}; // default LED on currents (mA)
...@@ -546,6 +552,11 @@ public class LensAdjustment { ...@@ -546,6 +552,11 @@ public class LensAdjustment {
boolean lensDistanceInteractive, // Open dialog when calibrating focal distance boolean lensDistanceInteractive, // Open dialog when calibrating focal distance
boolean lensDistanceShowResults, // show results window from foca boolean lensDistanceShowResults, // show results window from foca
boolean lensDistanceMoveToGoal, // Move to targetMicrons boolean lensDistanceMoveToGoal, // Move to targetMicrons
boolean powerControlEnable,
double powerControlMaximalTemperature,
double powerControlHeaterOnMinutes,
double powerControlNeitherOnMinutes,
double powerControlFanOnMinutes,
String uvLasersIP, // IP address of the camera with UV LEDs and aiming lasers are connected String uvLasersIP, // IP address of the camera with UV LEDs and aiming lasers are connected
int uvLasersBus, // 0 if 103641 board is connected to the sensor port (through 10-359), 1 - to 10369 int uvLasersBus, // 0 if 103641 board is connected to the sensor port (through 10-359), 1 - to 10369
double [] uvLasersCurrents, // default LED on currents (mA) double [] uvLasersCurrents, // default LED on currents (mA)
...@@ -692,6 +703,11 @@ public class LensAdjustment { ...@@ -692,6 +703,11 @@ public class LensAdjustment {
this.lensDistanceInteractive=lensDistanceInteractive; // Open dialog when calibrating focal distance this.lensDistanceInteractive=lensDistanceInteractive; // Open dialog when calibrating focal distance
this.lensDistanceShowResults=lensDistanceShowResults; // show results window from foca this.lensDistanceShowResults=lensDistanceShowResults; // show results window from foca
this.lensDistanceMoveToGoal=lensDistanceMoveToGoal; // Move to targetMicrons this.lensDistanceMoveToGoal=lensDistanceMoveToGoal; // Move to targetMicrons
this.powerControlEnable=powerControlEnable;
this.powerControlMaximalTemperature=powerControlMaximalTemperature;
this.powerControlHeaterOnMinutes=powerControlHeaterOnMinutes;
this.powerControlNeitherOnMinutes=powerControlNeitherOnMinutes;
this.powerControlFanOnMinutes=powerControlFanOnMinutes;
this.uvLasersIP=new String(uvLasersIP); // IP address of the camera with UV LEDs and aiming lasers are connected this.uvLasersIP=new String(uvLasersIP); // IP address of the camera with UV LEDs and aiming lasers are connected
this.uvLasersBus=uvLasersBus; // 0 if 103641 board is connected to the sensor port (through 10-359), 1 - to 10369 this.uvLasersBus=uvLasersBus; // 0 if 103641 board is connected to the sensor port (through 10-359), 1 - to 10369
this.uvLasersCurrents=uvLasersCurrents.clone(); // default LED on currents (mA) this.uvLasersCurrents=uvLasersCurrents.clone(); // default LED on currents (mA)
...@@ -840,6 +856,11 @@ public class LensAdjustment { ...@@ -840,6 +856,11 @@ public class LensAdjustment {
this.lensDistanceInteractive, // Open dialog when calibrating focal distance this.lensDistanceInteractive, // Open dialog when calibrating focal distance
this.lensDistanceShowResults, // show results window from foca this.lensDistanceShowResults, // show results window from foca
this.lensDistanceMoveToGoal, // Move to targetMicrons this.lensDistanceMoveToGoal, // Move to targetMicrons
this.powerControlEnable,
this.powerControlMaximalTemperature,
this.powerControlHeaterOnMinutes,
this.powerControlNeitherOnMinutes,
this.powerControlFanOnMinutes,
this.uvLasersIP, // IP address of the camera with UV LEDs and aiming lasers are connected this.uvLasersIP, // IP address of the camera with UV LEDs and aiming lasers are connected
this.uvLasersBus, // 0 if 103641 board is connected to the sensor port (through 10-359), 1 - to 10369 this.uvLasersBus, // 0 if 103641 board is connected to the sensor port (through 10-359), 1 - to 10369
this.uvLasersCurrents, // default LED on currents (mA) this.uvLasersCurrents, // default LED on currents (mA)
...@@ -993,6 +1014,12 @@ public class LensAdjustment { ...@@ -993,6 +1014,12 @@ public class LensAdjustment {
properties.setProperty(prefix+"lensDistanceShowResults",this.lensDistanceShowResults+""); properties.setProperty(prefix+"lensDistanceShowResults",this.lensDistanceShowResults+"");
properties.setProperty(prefix+"lensDistanceMoveToGoal",this.lensDistanceMoveToGoal+""); properties.setProperty(prefix+"lensDistanceMoveToGoal",this.lensDistanceMoveToGoal+"");
properties.setProperty(prefix+"powerControlEnable",this.powerControlEnable+"");
properties.setProperty(prefix+"powerControlMaximalTemperature",this.powerControlMaximalTemperature+"");
properties.setProperty(prefix+"powerControlHeaterOnMinutes",this.powerControlHeaterOnMinutes+"");
properties.setProperty(prefix+"powerControlNeitherOnMinutes",this.powerControlNeitherOnMinutes+"");
properties.setProperty(prefix+"powerControlFanOnMinutes",this.powerControlFanOnMinutes+"");
properties.setProperty(prefix+"uvLasersIP",this.uvLasersIP); properties.setProperty(prefix+"uvLasersIP",this.uvLasersIP);
properties.setProperty(prefix+"uvLasersBus",this.uvLasersBus+""); properties.setProperty(prefix+"uvLasersBus",this.uvLasersBus+"");
properties.setProperty(prefix+"uvLasersCurrents_0",this.uvLasersCurrents[0]+""); properties.setProperty(prefix+"uvLasersCurrents_0",this.uvLasersCurrents[0]+"");
...@@ -1276,6 +1303,18 @@ public class LensAdjustment { ...@@ -1276,6 +1303,18 @@ public class LensAdjustment {
if (properties.getProperty(prefix+"lensDistanceMoveToGoal")!=null) if (properties.getProperty(prefix+"lensDistanceMoveToGoal")!=null)
this.lensDistanceMoveToGoal=Boolean.parseBoolean(properties.getProperty(prefix+"lensDistanceMoveToGoal")); this.lensDistanceMoveToGoal=Boolean.parseBoolean(properties.getProperty(prefix+"lensDistanceMoveToGoal"));
if (properties.getProperty(prefix+"powerControlEnable")!=null)
this.powerControlEnable=Boolean.parseBoolean(properties.getProperty(prefix+"powerControlEnable"));
if (properties.getProperty(prefix+"powerControlMaximalTemperature")!=null)
this.powerControlMaximalTemperature=Double.parseDouble(properties.getProperty(prefix+"powerControlMaximalTemperature"));
if (properties.getProperty(prefix+"powerControlHeaterOnMinutes")!=null)
this.powerControlHeaterOnMinutes=Double.parseDouble(properties.getProperty(prefix+"powerControlHeaterOnMinutes"));
if (properties.getProperty(prefix+"powerControlNeitherOnMinutes")!=null)
this.powerControlNeitherOnMinutes=Double.parseDouble(properties.getProperty(prefix+"powerControlNeitherOnMinutes"));
if (properties.getProperty(prefix+"powerControlFanOnMinutes")!=null)
this.powerControlFanOnMinutes=Double.parseDouble(properties.getProperty(prefix+"powerControlFanOnMinutes"));
if (properties.getProperty(prefix+"uvLasersIP")!=null) if (properties.getProperty(prefix+"uvLasersIP")!=null)
this.uvLasersIP=properties.getProperty(prefix+"uvLasersIP"); this.uvLasersIP=properties.getProperty(prefix+"uvLasersIP");
if (properties.getProperty(prefix+"uvLasersBus")!=null) if (properties.getProperty(prefix+"uvLasersBus")!=null)
...@@ -1528,6 +1567,12 @@ public class LensAdjustment { ...@@ -1528,6 +1567,12 @@ public class LensAdjustment {
gd.addCheckbox ("Show results window from focal distance calibration", this.lensDistanceShowResults); gd.addCheckbox ("Show results window from focal distance calibration", this.lensDistanceShowResults);
gd.addCheckbox ("Move motors together to the requested microns from the \"best focus\"", this.lensDistanceMoveToGoal); gd.addCheckbox ("Move motors together to the requested microns from the \"best focus\"", this.lensDistanceMoveToGoal);
gd.addCheckbox ("Enable power control for heater and fan", this.powerControlEnable);
gd.addNumericField("Maximal allowed temperature", this.powerControlMaximalTemperature, 3,5,"C");
gd.addNumericField("Heater ON time", this.powerControlHeaterOnMinutes, 1,5,"min");
gd.addNumericField("Both heater and fan OFF time", this.powerControlNeitherOnMinutes, 1,5,"min");
gd.addNumericField("Fan ON time", this.powerControlFanOnMinutes, 1,5,"min");
gd.addStringField ("IP address of the camera with 103641 board (UV LEDs and lasers) are attached", this.uvLasersIP,40); gd.addStringField ("IP address of the camera with 103641 board (UV LEDs and lasers) are attached", this.uvLasersIP,40);
gd.addNumericField("I2C bus where LED/laser board is attached (0 - through 10359, 1 - through 10369)",this.uvLasersBus, 0); gd.addNumericField("I2C bus where LED/laser board is attached (0 - through 10359, 1 - through 10369)",this.uvLasersBus, 0);
gd.addNumericField("UV LED1 \"on\" current (left/near when looking from the target)", this.uvLasersCurrents[0], 3,5,"mA"); gd.addNumericField("UV LED1 \"on\" current (left/near when looking from the target)", this.uvLasersCurrents[0], 3,5,"mA");
...@@ -1701,6 +1746,12 @@ public class LensAdjustment { ...@@ -1701,6 +1746,12 @@ public class LensAdjustment {
this.lensDistanceShowResults= gd.getNextBoolean(); this.lensDistanceShowResults= gd.getNextBoolean();
this.lensDistanceMoveToGoal= gd.getNextBoolean(); this.lensDistanceMoveToGoal= gd.getNextBoolean();
this.powerControlEnable= gd.getNextBoolean();
this.powerControlMaximalTemperature=gd.getNextNumber();
this.powerControlHeaterOnMinutes= gd.getNextNumber();
this.powerControlNeitherOnMinutes= gd.getNextNumber();
this.powerControlFanOnMinutes= gd.getNextNumber();
this.uvLasersIP= gd.getNextString(); this.uvLasersIP= gd.getNextString();
this.uvLasersBus= (int) gd.getNextNumber(); this.uvLasersBus= (int) gd.getNextNumber();
this.uvLasersCurrents[0]= gd.getNextNumber(); this.uvLasersCurrents[0]= gd.getNextNumber();
......
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