diff --git a/config/devices.properties b/config/devices.properties index 9e6f044..afc34a6 100755 --- a/config/devices.properties +++ b/config/devices.properties @@ -22,3 +22,4 @@ gsx=ch.psi.pshell.epics.Positioner|SINEG01-MSOL130:X_SP SINEG01-MSOL130:X|||true gsy=ch.psi.pshell.epics.Positioner|SINEG01-MSOL130:Y_SP SINEG01-MSOL130:Y|||true gsrx=ch.psi.pshell.epics.Positioner|SINEG01-MSOL130:ROT_X_SP SINEG01-MSOL130:ROT_X|||true gsry=ch.psi.pshell.epics.Positioner|SINEG01-MSOL130:ROT_Y_SP SINEG01-MSOL130:ROT_Y|||true +camtool=Camtool|SINEG01-DSCR190||| diff --git a/plugins/Camtool.java b/plugins/Camtool.java index cb388db..6c5bd9d 100644 --- a/plugins/Camtool.java +++ b/plugins/Camtool.java @@ -2,35 +2,217 @@ * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. */ -import ch.psi.pshell.ui.Plugin; -import ch.psi.utils.State; +import ch.psi.pshell.device.Readable; +import ch.psi.pshell.epics.*; +import java.io.IOException; +import java.util.ArrayList; /** * */ -public class Camtool implements Plugin { - - //Overridable callbacks - @Override - public void onStart() { +public class Camtool extends ArraySource { + final String prefix; + final String dataPrefix; + final boolean latch; + + final public ChannelInteger channelRun; + final public ChannelInteger channelLatch; + final public ChannelDouble channelTimestamp; + final public ChannelDouble posX, posY; + final public ChannelDoubleArray profileX, profileY; + final public ChannelIntegerArray shape; + final public ChannelInteger bgEnable, bgCapture, bgCaptureRemain; + final public CamToolPosX posMeanX; + final public CamToolPosY posMeanY; + final public CamToolVarX posVarX; + final public CamToolVarY posVarY; + + + public Camtool(String name, String prefix) { + this(name, prefix, false); + } + + public Camtool(String name, String prefix, boolean latch) { + super(name, prefix + (latch ? ":latch": ":pipeline") + ".image"); + this.prefix = prefix+":"; + this.latch = latch; + dataPrefix = prefix + (latch ? "latch": "pipeline") + "."; + + channelRun = new ChannelInteger(name + " run", prefix + "camera.run"); + channelLatch = new ChannelInteger(name + " latch", prefix + "latch.capture"); + channelTimestamp = new ChannelDouble(name + " timestamp", dataPrefix + "timestamp"); + channelTimestamp.setMonitored(true); + //posX = new ChannelDouble(name + " com x", dataPrefix + "x_stats.com"); + //posY = new ChannelDouble(name + " com y", dataPrefix + "y_stats.com"); + 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 + "image.shape"); + bgEnable = new ChannelInteger(name + " bg enable", prefix + "pipeline.bg.enabled"); + bgCapture = new ChannelInteger(name + " bg capture", prefix + "pipeline.bg.capture"); + bgCaptureRemain = new ChannelInteger(name + " bg capture remain", prefix + "pipeline.bg.capture_remain"); + + posMeanX = new CamToolPosX(); + posMeanY = new CamToolPosY(); + posVarX = new CamToolVarX(); + posVarY = new CamToolVarY(); } - + @Override - public void onStop() { + public void doSetMonitored(boolean value){ + super.doSetMonitored(value); + getDevice().setMonitored(value); } - + @Override - public void onInitialize(int runCount) { - + public void doUpdate() throws IOException, InterruptedException{ + super.doUpdate(); + getDevice().update(); } - + @Override - public void onStateChange(State state, State former) { - - } - - @Override - public void onExecutedFile(String fileName, Object result) { + protected void doInitialize() throws IOException, InterruptedException { + try { + channelRun.initialize(); + channelLatch.initialize(); + channelTimestamp.initialize(); + posX.initialize(); posY.initialize(); + profileX.initialize(); profileY.initialize(); + shape.initialize(); + bgEnable.initialize(); bgCapture.initialize(); bgCaptureRemain.initialize(); + + int[] s = shape.read(); + getConfig().imageHeight = s[0]; + getConfig().imageWidth = s[1]; + getConfig().save(); + getDevice().setSize(s[0] * s[1]); + super.doInitialize(); + } catch (InterruptedException ex) { + throw ex; + } catch (Exception ex) { + throw new IOException(ex); + } } + + int numImages = 1; + public int getNumImages(){ + return numImages; + } + + public void setNumImages(int value){ + numImages = value; + } + + double grabTimeout = 3.0; + public double getGrabTimeout(){ + return grabTimeout; + } + + public void setGrabTimeou(double value){ + grabTimeout = value; + } + + public void capture() throws IOException, InterruptedException { + + } + + public void start() throws IOException, InterruptedException { + channelRun.write(-1); + } + + public void stop() throws IOException, InterruptedException { + channelRun.write(0); + } + + public void grabSingle() throws IOException, InterruptedException { + channelRun.write(1); + } + + public void latch() throws IOException, InterruptedException { + channelLatch.write(1); + } + + public void enableBackground(boolean value) throws IOException, InterruptedException { + bgEnable.write(value ? 1 : 0); + } + + public void captureBackground(int images) throws IOException, InterruptedException { + start(); + bgCapture.write(images); + Thread.sleep(200); + while( bgCaptureRemain.read() > 0){ + Thread.sleep(10); + } + } + + + //Statisticss pseudo devices + + ArrayList posXSamples; + ArrayList posYSamples; + + public void updateStats() throws IOException, InterruptedException { + posXSamples.clear(); + posYSamples.clear(); + for (int i=0; i samples){ + int count = 0; + double temp = 0; + for (Double n : samples) { + if (!Double.isNaN(n)){ + temp += n.doubleValue(); + count++; + } + } + return count==0 ? Double.NaN : temp/count; + } + + public double stdev(ArrayList samples){ + int count = 0; + double temp = 0; + double mean = mean(samples); + for (Double n : samples) { + if (!Double.isNaN(n)){ + temp += Math.pow((mean - n), 2); + } + } + return count==0 ? Double.NaN : temp / count; + } + } diff --git a/plugins/GunSolenoidAlignment.java b/plugins/GunSolenoidAlignment.java index f14719b..3a3dc1f 100644 --- a/plugins/GunSolenoidAlignment.java +++ b/plugins/GunSolenoidAlignment.java @@ -386,7 +386,7 @@ public class GunSolenoidAlignment extends Panel { args.put("number_backgrounds", spinnerNumBackgrounds.getValue()); args.put("use_background", checkBackground.isSelected()); args.put("multiple_background", radioBackMultiple.isSelected()); - args.put("do_elog", Boolean.FALSE); // checkElog.isSelected() + args.put("do_elog", checkElog.isSelected()); runAsync("Alignment/Gun_solenoid_alignment", args).thenAccept((Object ret) -> { List l = (List) ret; diff --git a/script/Alignment/Laser_gun_alignment.py b/script/Alignment/Laser_gun_alignment.py index 3eb0fcc..0e6a4f3 100755 --- a/script/Alignment/Laser_gun_alignment.py +++ b/script/Alignment/Laser_gun_alignment.py @@ -114,7 +114,7 @@ gsa_log_msg = gsa_log_msg + "\nImages: " + str(number_images) gsa_log_msg = gsa_log_msg + "\nBackground: enabled=" + str(use_background) + " multiple=" + str(multiple_background) + " number=" + str(number_backgrounds) gsa_log_msg = gsa_log_msg + "\n\n" + r.print() if do_elog: - elog("Gun solenoid current scan", gsa_log_msg , get_plot_snapshots()) + elog("Gun phasee scan", gsa_log_msg , get_plot_snapshots()) _=[r, hx, hy] set_return([r, hx, hy])