Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.micromanager.lightsheetmanager.model.devices.vendor.SingleAxis;
import org.micromanager.lightsheetmanager.model.utils.GeometryUtils;
import org.micromanager.lightsheetmanager.model.utils.NumberUtils;
import org.micromanager.lightsheetmanager.model.utils.StageScanUtils;

import java.awt.geom.Point2D;
import java.util.Objects;
Expand Down Expand Up @@ -201,7 +202,7 @@ public boolean prepareControllerForAcquisition(
final double actualMotorSpeed = xyStage_.getSpeedXUm() / 1000;

// set the acceleration to a reasonable value for the (usually very slow) scan speed
xyStage_.setAccelerationX(computeScanAcceleration(actualMotorSpeed,
xyStage_.setAccelerationX(StageScanUtils.computeScanAcceleration(actualMotorSpeed,
xyStage_.getMaxSpeedX(), settings.stageScan().accelerationFactor()));

// set the scan pattern and number of scans appropriately
Expand All @@ -210,7 +211,7 @@ public boolean prepareControllerForAcquisition(
numLines = 1; // assure in acquisition code that we can't have single-sided interleaved
}
if (settings.channels().enabled()) {
numLines = numLines * (settings.channels().count() / computeScanChannelsPerPass(settings));
numLines = numLines * (settings.channels().count() / StageScanUtils.computeScanChannelsPerPass(settings));
}
xyStage_.setScanNumLines(numLines);

Expand Down Expand Up @@ -264,47 +265,7 @@ public boolean prepareControllerForAcquisition(

// Compute appropriate motor speed in mm/s for the given stage scanning settings
public double computeScanSpeed(final ScapeAcquisitionSettings settings) {
double sliceDurationMs = settings.timing().sliceDurationMs();
if (settings.acquisitionMode() == AcquisitionMode.STAGE_SCAN_INTERLEAVED) {
// pretend like our slice takes twice as long so that we move the correct speed
// this has the effect of halving the motor speed, but keeping the scan distance the same
sliceDurationMs *= 2;
}
final int channelsPerPass = computeScanChannelsPerPass(settings);
final double speedFactor = GeometryUtils.getStageGeometricSpeedFactor(
settings.stageScan().firstViewAngle(), settings.volume().firstView() == 1);
return settings.volume().sliceStepSize() * speedFactor / sliceDurationMs / channelsPerPass;
}

// compute how many channels we do in each one-way scan, at least 1 so the speed and the scan
// line count never divide by 0 when channels are enabled but none is used
private int computeScanChannelsPerPass(ScapeAcquisitionSettings settings) {
return settings.channels().mode() == ChannelMode.SLICE_HW
? Math.max(1, settings.channels().count()) : 1;
}

/**
* Compute appropriate acceleration time in ms for the specified motor speed.
* Set to be 10ms + 0-100ms depending on relative speed to max, all scaled by factor specified on the settings panel
* @param motorSpeed
* @return
*/
public double computeScanAcceleration(final double motorSpeed, final ScapeAcquisitionSettings settings) {
return (10 + 100 * (motorSpeed / xyStage_.getMaxSpeedX())) * settings.stageScan().accelerationFactor();
}

/**
* Compute appropriate acceleration time in ms for the specified motor speed.
* Set to be 10ms + 0-100ms depending on relative speed to max, all scaled by factor specified on the settings panel
*
* @param motorSpeed
* @return
*/
public double computeScanAcceleration(final double motorSpeed, final double maxMotorSpeed, final double stageScanAccelFactor) {
// final double maxMotorSpeed = props_.getPropValueFloat(Devices.Keys.XYSTAGE, Properties.Keys.STAGESCAN_MAX_MOTOR_SPEED_X);
// final double accelFactor = props_.getPropValueFloat(Devices.Keys.PLUGIN, Properties.Keys.PLUGIN_STAGESCAN_ACCEL_FACTOR);
// return (10 + 100 * (motorSpeed / maxMotorSpeed) ) * accelFactor;
return (10 + 100 * (motorSpeed / maxMotorSpeed)) * stageScanAccelFactor;
return StageScanUtils.computeScanSpeed(settings);
}

public boolean prepareStageScanForAcquisition(final double x, final double y, ScapeAcquisitionSettings settings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.micromanager.lightsheetmanager.model.utils.FileUtils;
import org.micromanager.lightsheetmanager.model.utils.GeometryUtils;
import org.micromanager.lightsheetmanager.model.utils.NumberUtils;
import org.micromanager.lightsheetmanager.model.utils.StageScanUtils;

import javax.swing.JLabel;
import javax.swing.SwingUtilities;
Expand Down Expand Up @@ -2230,12 +2231,10 @@ private double getStageRampDuration(final ScapeAcquisitionSettings settings) {
}

private double getScanStageAcceleration(final ScapeAcquisitionSettings settings) {
// TODO: remove this and find a better way
if (controller_ == null) {
controller_ = new PLogicScape(model_);
}
final ASIXYStage stage = model_.devices().device("SampleXY");
// extra 1 for rounding up that often happens in controller
return controller_.computeScanAcceleration(controller_.computeScanSpeed(settings), settings) + 1;
return StageScanUtils.computeScanAcceleration(StageScanUtils.computeScanSpeed(settings),
stage.getMaxSpeedX(), settings.stageScan().accelerationFactor()) + 1;
}

private double getStageRetraceDuration(final ScapeAcquisitionSettings settings) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.micromanager.lightsheetmanager.model.utils;

import org.micromanager.lightsheetmanager.api.data.AcquisitionMode;
import org.micromanager.lightsheetmanager.api.data.ChannelMode;
import org.micromanager.lightsheetmanager.api.internal.ScapeAcquisitionSettings;

public final class StageScanUtils {

/** This class should not be instantiated. */
private StageScanUtils() {
throw new AssertionError("Utility class; do not instantiate.");
}

// Compute appropriate motor speed in mm/s for the given stage scanning settings
public static double computeScanSpeed(final ScapeAcquisitionSettings settings) {
double sliceDurationMs = settings.timing().sliceDurationMs();
if (settings.acquisitionMode() == AcquisitionMode.STAGE_SCAN_INTERLEAVED) {
// pretend like our slice takes twice as long so that we move the correct speed
// this has the effect of halving the motor speed, but keeping the scan distance the same
sliceDurationMs *= 2;
}
final int channelsPerPass = computeScanChannelsPerPass(settings);
final double speedFactor = GeometryUtils.getStageGeometricSpeedFactor(
settings.stageScan().firstViewAngle(), settings.volume().firstView() == 1);
return settings.volume().sliceStepSize() * speedFactor / sliceDurationMs / channelsPerPass;
}

// compute how many channels we do in each one-way scan, at least 1 so the speed and the scan
// line count never divide by 0 when channels are enabled but none is used
public static int computeScanChannelsPerPass(final ScapeAcquisitionSettings settings) {
return settings.channels().mode() == ChannelMode.SLICE_HW
? Math.max(1, settings.channels().count()) : 1;
}

/**
* Compute appropriate acceleration time in ms for the specified motor speed.
* Set to be 10ms + 0-100ms depending on relative speed to max, all scaled by factor specified on the settings panel
*
* @param motorSpeed
* @return
*/
public static double computeScanAcceleration(final double motorSpeed, final double maxMotorSpeed, final double stageScanAccelFactor) {
return (10 + 100 * (motorSpeed / maxMotorSpeed)) * stageScanAccelFactor;
}

}
Loading