From 6fdcc33a48c39a26084f0258e02a7f506d8a1a5b Mon Sep 17 00:00:00 2001 From: sfop Date: Mon, 7 Nov 2016 13:24:05 +0100 Subject: [PATCH] Startup --- devices/CurrentCamera.properties | 14 +-- plugins/ScreenPanel.java | 176 ++++++++++++++++++------------- 2 files changed, 107 insertions(+), 83 deletions(-) diff --git a/devices/CurrentCamera.properties b/devices/CurrentCamera.properties index 0cd40ac..af94428 100644 --- a/devices/CurrentCamera.properties +++ b/devices/CurrentCamera.properties @@ -1,7 +1,7 @@ -#Fri Nov 04 13:41:07 CET 2016 -colormap=Rainbow +#Mon Nov 07 09:15:29 CET 2016 +colormap=Temperature colormapAutomatic=true -colormapMax=0.0 +colormapMax=2.0 colormapMin=0.0 flipHorizontally=false flipVertically=false @@ -18,9 +18,9 @@ roiY=0 rotation=0.0 rotationCrop=false scale=1.0 -spatialCalOffsetX=-685.0 -spatialCalOffsetY=-874.0 -spatialCalScaleX=13.612279307222428 -spatialCalScaleY=12.708498808578236 +spatialCalOffsetX=-1057.0 +spatialCalOffsetY=-1420.0 +spatialCalScaleX=-8.51063829787234 +spatialCalScaleY=-8.559201141226819 spatialCalUnits=mm transpose=false diff --git a/plugins/ScreenPanel.java b/plugins/ScreenPanel.java index 6195a22..f61c228 100644 --- a/plugins/ScreenPanel.java +++ b/plugins/ScreenPanel.java @@ -20,7 +20,10 @@ import ch.psi.pshell.core.JsonSerializer; import ch.psi.pshell.device.Device; import ch.psi.pshell.device.DeviceAdapter; import ch.psi.pshell.epics.ArraySource; +import ch.psi.pshell.epics.ChannelDouble; +import ch.psi.pshell.epics.ChannelDoubleArray; import ch.psi.pshell.epics.ChannelInteger; +import ch.psi.pshell.epics.ChannelIntegerArray; import ch.psi.pshell.epics.DiscretePositioner; import ch.psi.pshell.epics.Epics; import ch.psi.pshell.imaging.Colormap; @@ -485,10 +488,13 @@ public class ScreenPanel extends Panel { ((Camtool)camera).shape.addListener(new DeviceAdapter(){ @Override public void onValueChanged(Device device, Object value, Object former) { - if ((camera instanceof Camtool) &&(device==((Camtool)camera).shape) && (camera.getState().isInitialized())) { + if ((camera instanceof Camtool) + &&(device==((Camtool)camera).shape) + && (camera.getState().isInitialized()) + && (camera.getImage()!=null)) { try { if ((value != null) && (value.getClass() == int[].class)) { - final int[] s = (int[]) value; + final int[] s = (int[]) value; if ((s.length > 1) && (s[0] * s[1] > 0) && ((s[0] != camera.getConfig().imageHeight) || (s[1] != camera.getConfig().imageWidth))) { SwingUtilities.invokeLater(new Runnable() { @@ -742,43 +748,52 @@ public class ScreenPanel extends Panel { int profileSize = renderer.getProfileSize(); if ((useCamtoolStats) &&(camera instanceof Camtool)){ try{ - profileSize/=4; - double[] gX = ((Camtool)camera).gaussX.read(); + profileSize/=4; double[] pX = ((Camtool)camera).profileX.read(); - int[] x = Arr.indexesInt(gX.length); - int[] y = new int[gX.length]; - int[] p = new int[gX.length]; - - List l = Arrays.asList((Double[]) Convert.toWrapperArray(pX)); - Double min = Collections.min(l); - Double max = Collections.max(l); - double minPlot = min; - double rangePlot = max- min; - - for (int i = 0; i < x.length; i++) { - y[i] = (int) (data.getHeight() - 1 - (((gX[i] - minPlot) / rangePlot) * profileSize)); - p[i] = (int) (data.getHeight() - 1 - (((pX[i] - minPlot) / rangePlot) * profileSize)); - } - vgaussian = new Overlays.Polyline(penFit, x, y); - vprofile = new Overlays.Polyline(renderer.getPenProfile(), x, p); - - double[] gY = ((Camtool)camera).gaussY.read(); - double[] pY = ((Camtool)camera).profileY.read(); - y = Arr.indexesInt(gY.length); - x = new int[gY.length]; - p = new int[gY.length]; - l = Arrays.asList((Double[]) Convert.toWrapperArray(pY)); - min = Collections.min(l); - max = Collections.max(l); - minPlot = min; - rangePlot = max- min; + if (pX!=null){ + int[] x = Arr.indexesInt(pX.length); + int[] y = new int[pX.length]; + int[] p = new int[pX.length]; + double[] gX = ((Camtool)camera).gaussX.read(); - for (int i = 0; i < x.length; i++) { - x[i] = (int) (((gY[i] - minPlot) / rangePlot) * profileSize); - p[i] = (int) (((pY[i] - minPlot) / rangePlot) * profileSize); - } - hgaussian = new Overlays.Polyline(penFit, x, y); - hprofile = new Overlays.Polyline(renderer.getPenProfile(), p, y); + List l = Arrays.asList((Double[]) Convert.toWrapperArray(pX)); + Double min = Collections.min(l); + Double max = Collections.max(l); + double minPlot = min; + double rangePlot = max- min; + + for (int i = 0; i < x.length; i++) { + if (gX!=null){ + y[i] = (int) (data.getHeight() - 1 - (((gX[i] - minPlot) / rangePlot) * profileSize)); + } + p[i] = (int) (data.getHeight() - 1 - (((pX[i] - minPlot) / rangePlot) * profileSize)); + } + vgaussian = new Overlays.Polyline(penFit, x, y); + vprofile = new Overlays.Polyline(renderer.getPenProfile(), x, p); + } + + double[] pY = ((Camtool)camera).profileY.read(); + if (pX!=null){ + double[] gY = ((Camtool)camera).gaussY.read(); + int[] y = Arr.indexesInt(pY.length); + int[] x = new int[pY.length]; + int[] p = new int[pY.length]; + + List l = Arrays.asList((Double[]) Convert.toWrapperArray(pY)); + Double min = Collections.min(l); + Double max = Collections.max(l); + double minPlot = min; + double rangePlot = max- min; + + for (int i = 0; i < x.length; i++) { + if (gY!=null){ + x[i] = (int) (((gY[i] - minPlot) / rangePlot) * profileSize); + } + p[i] = (int) (((pY[i] - minPlot) / rangePlot) * profileSize); + } + hgaussian = new Overlays.Polyline(penFit, x, y); + hprofile = new Overlays.Polyline(renderer.getPenProfile(), p, y); + } xMean = ((Camtool)camera).gaussCenterX.read(); yMean = ((Camtool)camera).gaussCenterY.read(); @@ -963,7 +978,7 @@ public class ScreenPanel extends Panel { } return fit; } -/* + public class Camtool extends ArraySource { final String prefix; @@ -992,6 +1007,10 @@ public class ScreenPanel extends Panel { } public Camtool(String name, String prefix, boolean latch) { + this(name, prefix, false, false); + } + + public Camtool(String name, String prefix, boolean latch, boolean gr) { super(name, prefix + (latch ? ":latch" : ":pipeline") + ".roi.output"); this.prefix = prefix + ":"; this.latch = latch; @@ -1001,8 +1020,6 @@ public class ScreenPanel extends Panel { channelLatch = new ChannelInteger(name + " latch", this.prefix + "latch.capture"); channelTimestamp = new ChannelDouble(name + " timestamp", dataPrefix + "timestamp"); channelTimestamp.setMonitored(true); - posX = new ChannelDouble(name + " com x", dataPrefix + "x_stats.com_egu"); - posY = new ChannelDouble(name + " com y", dataPrefix + "y_stats.com_egu"); profileX = new ChannelDoubleArray(name + " profile x", dataPrefix + "profile.x"); profileY = new ChannelDoubleArray(name + " profile y", dataPrefix + "profile.y"); shape = new ChannelIntegerArray(name + " shape", dataPrefix + ("roi.output.shape")); @@ -1017,12 +1034,16 @@ public class ScreenPanel extends Panel { calScaleX = new ChannelDouble(name + " cal scale x", this.prefix + "pipeline.egu.eslo_x"); calScaleY = new ChannelDouble(name + " cal scale y", this.prefix + "pipeline.egu.eslo_y"); - gaussX = new ChannelDoubleArray(name + " gauss x", dataPrefix + ("x_stats.gauss")); - gaussY = new ChannelDoubleArray(name + " gauss y", dataPrefix + ("y_stats.gauss")); - gaussCenterX = new ChannelDouble(name + "gauss center x", dataPrefix + "x_stats.g_center_egu"); - gaussCenterY = new ChannelDouble(name + "gauss center y", dataPrefix + "y_stats.g_center_egu"); - gaussStdDivX = new ChannelDouble(name + "gauss stddiv x", dataPrefix + "x_stats.g_stddiv_egu"); - gaussStdDivY = new ChannelDouble(name + "gauss stddiv t", dataPrefix + "y_stats.g_stddiv_egu"); + String x_stats = dataPrefix + "x_stats" + (gr ? "_gr": "")+ "."; + String y_stats = dataPrefix + "y_stats" + (gr ? "_gr": "")+ "."; + posX = new ChannelDouble(name + " com x", x_stats + "com_egu"); + posY = new ChannelDouble(name + " com y", y_stats + "com_egu"); + gaussX = new ChannelDoubleArray(name + " gauss x", x_stats+ "gauss"); + gaussY = new ChannelDoubleArray(name + " gauss y", y_stats+ "gauss"); + gaussCenterX = new ChannelDouble(name + "gauss center x", x_stats+ "g_center_egu"); + gaussCenterY = new ChannelDouble(name + "gauss center y", y_stats+ "g_center_egu"); + gaussStdDivX = new ChannelDouble(name + "gauss stddiv x", x_stats+ "g_stddiv_egu"); + gaussStdDivY = new ChannelDouble(name + "gauss stddiv t", y_stats+ "g_stddiv_egu"); } @Override @@ -1031,16 +1052,17 @@ public class ScreenPanel extends Panel { getDevice().setMonitored(value); } - void safeInitialize(Device dev, int timeout) throws IOException, InterruptedException { - for (int retries = 0; retries < 10; retries++) { + void safeInitialize(Device dev, int retries) throws IOException, InterruptedException { + for (int i = 0; i < retries; i++) { try { dev.initialize(); break; } catch (IOException ex) { - if (retries == 9) { + if (i == (retries-1)) { throw ex; } - Thread.sleep(timeout / 10); + System.out.println("Failed initializing " + dev.getName() + ". Retrying"); + Thread.sleep(1); } } } @@ -1048,38 +1070,40 @@ public class ScreenPanel extends Panel { @Override protected void doInitialize() throws IOException, InterruptedException { try { - channelRun.initialize(); - channelLatch.initialize(); + System.out.println("Started initialization"); + int retries = 5; + safeInitialize(channelTimestamp, retries); + safeInitialize(channelTimestamp, retries); if (latch) { start(); latch(); - } - safeInitialize(channelTimestamp, 2000); - posX.initialize(); - posY.initialize(); - profileX.initialize(); - profileY.initialize(); - shape.initialize(); - roiEnabled.initialize(); - roi.initialize(); - origin.initialize(); - bgEnable.initialize(); - bgCapture.initialize(); - bgCaptureRemain.initialize(); + } + safeInitialize(channelTimestamp, retries); + safeInitialize(posX, retries); + safeInitialize(posY, retries); + safeInitialize(profileX, retries); + safeInitialize(profileY, retries); + safeInitialize(shape, retries); + safeInitialize(roiEnabled, retries); + safeInitialize(roi, retries); + safeInitialize(origin, retries); + safeInitialize(bgEnable, retries); + safeInitialize(bgCapture, retries); + safeInitialize(bgCaptureRemain, retries); try { - calOffX.initialize(); - calOffY.initialize(); - calScaleX.initialize(); - calScaleY.initialize(); + safeInitialize(calOffX, retries); + safeInitialize(calOffY, retries); + safeInitialize(calScaleX, retries); + safeInitialize(calScaleY, retries); } catch (Exception ex) { ex.printStackTrace(); } - gaussX.initialize(); - gaussY.initialize(); - gaussCenterX.initialize(); - gaussCenterY.initialize(); - gaussStdDivX.initialize(); - gaussStdDivY.initialize(); + safeInitialize(gaussX, retries); + safeInitialize(gaussY, retries); + safeInitialize(gaussCenterX, retries); + safeInitialize(gaussCenterY, retries); + safeInitialize(gaussStdDivX, retries); + safeInitialize(gaussStdDivY, retries); int[] s = shape.read(); getConfig().imageHeight = s[0]; @@ -1209,7 +1233,7 @@ public class ScreenPanel extends Panel { } } } -*/ + void setHistogramVisible(boolean value) { if (value) {