From 09537b00a19f3bf7e8a822c2f193d21bfd8ef5f9 Mon Sep 17 00:00:00 2001 From: gac-x04sa Date: Thu, 25 Jan 2018 12:47:27 +0100 Subject: [PATCH] --- config/plugins.properties | 1 + plugins/SampleSearch.form | 374 +++++++++++++++++++++++++++++++++++ plugins/SampleSearch.java | 372 ++++++++++++++++++++++++++++++++++ script/scans/SampleSearch.py | 111 ++++++----- 4 files changed, 811 insertions(+), 47 deletions(-) create mode 100644 plugins/SampleSearch.form create mode 100644 plugins/SampleSearch.java diff --git a/config/plugins.properties b/config/plugins.properties index 18a681e..1d53e07 100644 --- a/config/plugins.properties +++ b/config/plugins.properties @@ -1,2 +1,3 @@ +SampleSearch.java=enabled Omega.java=enabled Pilatus.java=enabled diff --git a/plugins/SampleSearch.form b/plugins/SampleSearch.form new file mode 100644 index 0000000..c3f93df --- /dev/null +++ b/plugins/SampleSearch.form @@ -0,0 +1,374 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/plugins/SampleSearch.java b/plugins/SampleSearch.java new file mode 100644 index 0000000..6a6da87 --- /dev/null +++ b/plugins/SampleSearch.java @@ -0,0 +1,372 @@ +/* + * Copyright (c) 2014-2017 Paul Scherrer Institute. All rights reserved. + */ + +import ch.psi.pshell.device.Device; +import ch.psi.pshell.ui.Panel; +import ch.psi.utils.State; +import ch.psi.utils.swing.SwingUtils; +import java.util.HashMap; + +/** + * + */ +public class SampleSearch extends Panel { + + public SampleSearch() { + initComponents(); + } + + //Overridable callbacks + @Override + public void onInitialize(int runCount) { + panelX.setDevice((Device) getDevice("scx")); + panelY.setDevice((Device) getDevice("scy")); + panelZ.setDevice((Device) getDevice("scz")); + panelOmega.setDevice((Device) getDevice("scr")); + } + + @Override + public void onStateChange(State state, State former) { + buttonStart.setEnabled(state == State.Ready); + buttonAbort.setEnabled(state.isRunning()); + } + + @Override + public void onExecutedFile(String fileName, Object result) { + } + + + //Callback to perform update - in event thread + @Override + protected void doUpdate() { + } + + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jPanel1 = new javax.swing.JPanel(); + jLabel5 = new javax.swing.JLabel(); + spinnerXmin = new javax.swing.JSpinner(); + spinnerXmax = new javax.swing.JSpinner(); + spinnerSampleSize = new javax.swing.JSpinner(); + jLabel1 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + spinnerYmax = new javax.swing.JSpinner(); + jLabel3 = new javax.swing.JLabel(); + spinnerYmin = new javax.swing.JSpinner(); + jLabel4 = new javax.swing.JLabel(); + jLabel6 = new javax.swing.JLabel(); + spinnerResolution = new javax.swing.JSpinner(); + jLabel7 = new javax.swing.JLabel(); + spinnerOmegaStart = new javax.swing.JSpinner(); + jLabel12 = new javax.swing.JLabel(); + spinnerZStart = new javax.swing.JSpinner(); + checkSimulation = new javax.swing.JCheckBox(); + buttonStart = new javax.swing.JButton(); + buttonAbort = new javax.swing.JButton(); + jLabel8 = new javax.swing.JLabel(); + panelX = new ch.psi.pshell.swing.MotorReadoutPanel(); + jLabel9 = new javax.swing.JLabel(); + panelY = new ch.psi.pshell.swing.MotorReadoutPanel(); + jLabel10 = new javax.swing.JLabel(); + panelZ = new ch.psi.pshell.swing.MotorReadoutPanel(); + jLabel11 = new javax.swing.JLabel(); + panelOmega = new ch.psi.pshell.swing.MotorReadoutPanel(); + + jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Parameters")); + + jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel5.setText("Sample size(mm):"); + + spinnerXmin.setModel(new javax.swing.SpinnerNumberModel(-1.0d, -3.0d, 3.0d, 1.0d)); + + spinnerXmax.setModel(new javax.swing.SpinnerNumberModel(1.0d, -3.0d, 3.0d, 1.0d)); + + spinnerSampleSize.setModel(new javax.swing.SpinnerNumberModel(0.25d, 0.1d, 0.4d, 1.0d)); + + jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel1.setText("Xmin (mm):"); + + jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel2.setText("Xmax(mm):"); + + spinnerYmax.setModel(new javax.swing.SpinnerNumberModel(1.0d, -3.0d, 3.0d, 1.0d)); + + jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel3.setText("Ymin(mm):"); + + spinnerYmin.setModel(new javax.swing.SpinnerNumberModel(-1.0d, -3.0d, 3.0d, 1.0d)); + + jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel4.setText("Ymax(mm):"); + + jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel6.setText("Scan resolution(mm)"); + + spinnerResolution.setModel(new javax.swing.SpinnerNumberModel(0.01d, 0.001d, 0.2d, 0.01d)); + + jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel7.setText("Omega start(deg)"); + + spinnerOmegaStart.setModel(new javax.swing.SpinnerNumberModel(57.0d, -360.0d, 360.0d, 1.0d)); + + jLabel12.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel12.setText("Z start(mm)"); + + spinnerZStart.setModel(new javax.swing.SpinnerNumberModel(0.0d, -3.0d, 3.0d, 1.0d)); + + checkSimulation.setText("Diode simulated"); + + javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); + jPanel1.setLayout(jPanel1Layout); + jPanel1Layout.setHorizontalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addContainerGap() + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(jLabel2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(spinnerXmax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(jLabel3) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(spinnerYmin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(jLabel4) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(spinnerYmax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(jLabel5) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(spinnerSampleSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(spinnerXmin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(jLabel6) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(spinnerResolution, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(jLabel7) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(spinnerOmegaStart, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(jLabel12) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(spinnerZStart, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(checkSimulation)) + .addGap(31, 31, 31)) + ); + + jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel12, jLabel2, jLabel3, jLabel4, jLabel5, jLabel6, jLabel7}); + + jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerOmegaStart, spinnerResolution, spinnerSampleSize, spinnerXmax, spinnerXmin, spinnerYmax, spinnerYmin, spinnerZStart}); + + jPanel1Layout.setVerticalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addContainerGap() + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel1) + .addComponent(spinnerXmin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel2) + .addComponent(spinnerXmax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel3) + .addComponent(spinnerYmin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel4) + .addComponent(spinnerYmax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(18, 18, 18) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel5) + .addComponent(spinnerSampleSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel6) + .addComponent(spinnerResolution, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel7) + .addComponent(spinnerOmegaStart, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel12) + .addComponent(spinnerZStart, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 48, Short.MAX_VALUE) + .addComponent(checkSimulation) + .addContainerGap()) + ); + + buttonStart.setText("Start"); + buttonStart.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonStartActionPerformed(evt); + } + }); + + buttonAbort.setText("Abort"); + buttonAbort.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonAbortActionPerformed(evt); + } + }); + + jLabel8.setText("Sample X:"); + + panelX.setReadOnly(true); + + jLabel9.setText("Sample Y:"); + + panelY.setReadOnly(true); + + jLabel10.setText("Sample Z:"); + + panelZ.setReadOnly(true); + + jLabel11.setText("Omega:"); + + panelOmega.setReadOnly(true); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(32, 32, 32) + .addComponent(buttonStart, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(39, 39, 39) + .addComponent(buttonAbort, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(72, 72, 72) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel8) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(panelX, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel9) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(panelY, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel10) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(panelZ, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel11) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(panelOmega, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addGap(0, 62, Short.MAX_VALUE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(layout.createSequentialGroup() + .addGap(97, 97, 97) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(panelX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel8)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(panelY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel9)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(panelZ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel10)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(panelOmega, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel11)))) + .addGap(18, 18, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(buttonStart) + .addComponent(buttonAbort)) + .addContainerGap(15, Short.MAX_VALUE)) + ); + }// //GEN-END:initComponents + + private void buttonStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStartActionPerformed + try { + if ((Double)spinnerXmax.getValue() <= (Double)spinnerXmin.getValue()){ + throw new Exception ("Invalid range"); + } + HashMap pars = new HashMap<>(); + pars.put("X_MIN", spinnerXmin.getValue()); + pars.put("X_MAX", spinnerXmax.getValue()); + pars.put("Y_MIN", spinnerYmin.getValue()); + pars.put("Y_MAX", spinnerYmax.getValue()); + + pars.put("MIN_SAMPLE_SIZE", spinnerSampleSize.getValue()); + pars.put("SCAN_RESOLUTION", spinnerResolution.getValue()); + pars.put("OMEGA_START", spinnerOmegaStart.getValue()); + pars.put("Z_START", spinnerZStart.getValue()); + + pars.put("SIMULATION", checkSimulation.isSelected()); + + + this.runAsync("scans/SampleSearch", pars).handle((ok, ex) -> { + if (ex != null) { + showException((Exception) ex); + } else { + SwingUtils.showMessage(this, "Success", "Sample was successfully centered"); + } + return ok; + }); + + } catch (Exception ex) { + this.showException(ex); + } + }//GEN-LAST:event_buttonStartActionPerformed + + private void buttonAbortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAbortActionPerformed + try { + this.abort(); + } catch (Exception ex) { + this.showException(ex); + } + }//GEN-LAST:event_buttonAbortActionPerformed + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton buttonAbort; + private javax.swing.JButton buttonStart; + private javax.swing.JCheckBox checkSimulation; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel10; + private javax.swing.JLabel jLabel11; + private javax.swing.JLabel jLabel12; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JLabel jLabel4; + private javax.swing.JLabel jLabel5; + private javax.swing.JLabel jLabel6; + private javax.swing.JLabel jLabel7; + private javax.swing.JLabel jLabel8; + private javax.swing.JLabel jLabel9; + private javax.swing.JPanel jPanel1; + private ch.psi.pshell.swing.MotorReadoutPanel panelOmega; + private ch.psi.pshell.swing.MotorReadoutPanel panelX; + private ch.psi.pshell.swing.MotorReadoutPanel panelY; + private ch.psi.pshell.swing.MotorReadoutPanel panelZ; + private javax.swing.JSpinner spinnerOmegaStart; + private javax.swing.JSpinner spinnerResolution; + private javax.swing.JSpinner spinnerSampleSize; + private javax.swing.JSpinner spinnerXmax; + private javax.swing.JSpinner spinnerXmin; + private javax.swing.JSpinner spinnerYmax; + private javax.swing.JSpinner spinnerYmin; + private javax.swing.JSpinner spinnerZStart; + // End of variables declaration//GEN-END:variables +} diff --git a/script/scans/SampleSearch.py b/script/scans/SampleSearch.py index da85234..be51675 100644 --- a/script/scans/SampleSearch.py +++ b/script/scans/SampleSearch.py @@ -1,18 +1,20 @@ import mathutils import plotutils -SIMULATION = True - -X_MIN = scx.minValue / 2 -X_MAX = scx.maxValue / 2 -Y_MIN = scy.minValue / 2 -Y_MAX = scy.maxValue / 2 - +if get_exec_pars().source == CommandSource.ui: + SIMULATION = True + X_MIN = scx.minValue / 2 + X_MAX = scx.maxValue / 2 + Y_MIN = scy.minValue / 2 + Y_MAX = scy.maxValue / 2 + MIN_SAMPLE_SIZE = 0.25 + SCAN_RESOLUTION = 0.01 + OMEGA_START = 57.0 + Z_START = 0.0 + MAX_SAMPLE_SIZE = 0.4 -MIN_SAMPLE_SIZE = 0.25 -SCAN_RESOLUTION = 0.01 -OMEGA_START = 57.0 + y_step = MIN_SAMPLE_SIZE * 0.5 sensor = scd_sim if SIMULATION else scd @@ -25,64 +27,79 @@ def plot_fit(normalization, mean_val, sigma, xdata): plotutils.plot_function(get_plots(None)[0], gaussian, "Fit", xdata) scr.move(OMEGA_START) +scz.move(Z_START) step=0 for y in frange(Y_MIN, Y_MAX, y_step): - scy.move(y) scan_range = [X_MIN, X_MAX] if (step % 2==0) else [X_MAX, X_MIN] + scx.moveAsync(scan_range[0]) + scy.move(y) r = cscan(scx, sensor, scan_range[0], scan_range[1], SCAN_RESOLUTION, latency = DIODE_SETTLING_TIME) try: xdata,ydata = enforce_monotonic(r.getPositions(0)), r.getReadable(0) - (offset, normalization, mean_val, sigma) = mathutils.fit_gaussian_offset(ydata, xdata) + (offset, normalization, mean_val_x, sigma) = mathutils.fit_gaussian_offset(ydata, xdata) if ((normalization-offset) < offset * 1.20) or (sigma > 0.5): raise Exception("Invalid x fit") - plot_fit(normalization, mean_val, sigma, xdata) - print "Found x center at ", mean_val - scx.move(mean_val) + plot_fit(normalization, mean_val_x, sigma, xdata) + print "Found x center at ", mean_val_x + scx.move(mean_val_x) break except: print "Invalid x fit for y=", y, ": ", sys.exc_info()[0] step += 1 -r = cscan(scy, sensor, y-MAX_SAMPLE_SIZE/2, Y_MAX+MAX_SAMPLE_SIZE/2, SCAN_RESOLUTION, latency = DIODE_SETTLING_TIME) +r = cscan(scy, sensor, max(y-MAX_SAMPLE_SIZE/2, scy.minValue), min(Y_MAX+MAX_SAMPLE_SIZE/2, scy.maxValue), SCAN_RESOLUTION, latency = DIODE_SETTLING_TIME) xdata,ydata = enforce_monotonic(r.getPositions(0)), r.getReadable(0) -(offset, normalization, mean_val, sigma) = mathutils.fit_gaussian_offset(ydata, xdata) +try: + (offset, normalization, mean_val_y, sigma) = mathutils.fit_gaussian_offset(ydata, xdata) +except: + raise Exception ("Invalid y fit: ", sys.exc_info()[0]) if ((normalization-offset) < offset * 1.20) or (sigma > 0.5): - raise Exception("Invalid x fit") -plot_fit(normalization, mean_val, sigma, xdata) -print "Found y center at ", mean_val -scy.move(mean_val) + raise Exception("Invalid y fit") +plot_fit(normalization, mean_val_y, sigma, xdata) +print "Found y center at ", mean_val_y +scy.move(mean_val_y) -print "Success finding center at x=", scx.read(), " y=", scy.read() +print "Success finding center at x=", mean_val_x, " y=", mean_val_y -scr.move(OMEGA_START-15.0) -r = cscan(scx, sensor, X_MIN, X_MAX, SCAN_RESOLUTION, latency = DIODE_SETTLING_TIME) -xdata,ydata = enforce_monotonic(r.getPositions(0)), r.getReadable(0) -(offset, normalization, mean_minus_15, sigma) = mathutils.fit_gaussian_offset(ydata, xdata) -if ((normalization-offset) < offset * 1.20) or (sigma > 0.5): - raise Exception("Invalid x fit on z search -15deg") -plot_fit(normalization, mean_minus_15, sigma, xdata) -print "Found x center at -15deg at ", mean_minus_15 - - -scr.move(OMEGA_START+15.0) -r = cscan(scx, sensor, X_MIN, X_MAX, SCAN_RESOLUTION, latency = DIODE_SETTLING_TIME) -xdata,ydata = enforce_monotonic(r.getPositions(0)), r.getReadable(0) -(offset, normalization, mean_plus_15, sigma) = mathutils.fit_gaussian_offset(ydata, xdata) -if ((normalization-offset) < offset * 1.20) or (sigma > 0.5): - raise Exception("Invalid x fit on z search +15deg") -plot_fit(normalization, mean_minus_15, sigma, xdata) -print "Found x center at +15deg at ", mean_plus_15 - -scr.move(OMEGA_START) - -z_offset = 0.5 * (mean_minus_15 - mean_plus_15) / math.tan(math.radians(15.0)) -print "Calculated z offset = ", z_offset -scz.moveRel(z_offset) - +try: + scr.move(OMEGA_START-15.0) + r = cscan(scx, sensor, X_MIN, X_MAX, SCAN_RESOLUTION, latency = DIODE_SETTLING_TIME) + xdata,ydata = enforce_monotonic(r.getPositions(0)), r.getReadable(0) + try: + (offset, normalization, mean_minus_15, sigma) = mathutils.fit_gaussian_offset(ydata, xdata) + except: + raise Exception ("Invalid x fit on z search -15deg: ", sys.exc_info()[0]) + if ((normalization-offset) < offset * 1.20) or (sigma > 0.5): + raise Exception("Invalid x fit on z search -15deg") + plot_fit(normalization, mean_minus_15, sigma, xdata) + print "Found x center at -15deg at ", mean_minus_15 + + + scr.move(OMEGA_START+15.0) + r = cscan(scx, sensor, X_MAX, X_MIN, SCAN_RESOLUTION, latency = DIODE_SETTLING_TIME) + xdata,ydata = enforce_monotonic(r.getPositions(0)), r.getReadable(0) + try: + (offset, normalization, mean_plus_15, sigma) = mathutils.fit_gaussian_offset(ydata, xdata) + except: + raise Exception ("Invalid x fit on z search +15deg: ", sys.exc_info()[0]) + if ((normalization-offset) < offset * 1.20) or (sigma > 0.5): + raise Exception("Invalid x fit on z search +15deg") + plot_fit(normalization, mean_minus_15, sigma, xdata) + print "Found x center at +15deg at ", mean_plus_15 + + scr.move(OMEGA_START) + + z_offset = 0.5 * (mean_minus_15 - mean_plus_15) / math.tan(math.radians(15.0)) + print "Calculated z offset = ", z_offset + scz.moveRel(z_offset) +finally: + scx.move(mean_val_x) + scy.move(mean_val_y) + print "Centering successfull"