Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add setup and cleanup code for stage scanning #262

Merged
merged 1 commit into from
Apr 12, 2024
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 @@ -1120,6 +1120,25 @@ public void setPathPreset(int side) {

public void stopSPIMStateMachines() {
scanner_.setSPIMState(ASIScanner.SPIMState.IDLE);
if (acqSettings_.isUsingStageScanning()) {
// give the stage scan 5 seconds to clean itself up, after which we stop it
// once all images come in there is still a time when stage is moving back to its start/center position
final int timeoutStageScanCleanupMs = 5000;
final long deadline = System.currentTimeMillis() + timeoutStageScanCleanupMs;
while (xyStage_.getScanState() == ASIXYStage.ScanState.IDLE) {
if (System.currentTimeMillis() > deadline) {
xyStage_.setScanState(ASIXYStage.ScanState.IDLE); // force-set to idle
studio_.logs().logError("Force-set XY stage scan to IDLE state with stage speed "
+ xyStage_.getSpeedX() + ".");
} else {
try {
Thread.sleep(25); // still waiting...
} catch (InterruptedException e) {
// ignore => only need to busy wait
}
}
}
}
}

// private void stopSPIMStateMachines(DefaultAcquisitionSettingsDISPIM acqSettings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.micromanager.lightsheetmanager.model.utils.FileUtils;
import org.micromanager.lightsheetmanager.model.utils.NumberUtils;

import java.awt.geom.Point2D;
import java.io.IOException;
import java.util.ArrayList;

Expand Down Expand Up @@ -79,25 +80,38 @@ boolean run() {

final boolean isUsingPLC = model_.devices().isUsingPLogic();

// initialize stage scanning so we can restore state
Point2D.Double xyPosUm = new Point2D.Double();
double xSupPosUm = 0.0;
double origXSpeed = 1.0; // don't want 0 in case something goes wrong
double origXAccel = 1.0; // don't want 0 in case something goes wrong

// make sure stage scan is supported if selected
if (isUsingPLC) {
if (acqSettings_.isUsingStageScanning()) {
final ASIXYStage xyStage = model_.devices().getDevice("SampleXY");
if (xyStage != null) {
if (!xyStage.hasProperty(ASIXYStage.Properties.SCAN_NUM_LINES)) {
studio_.logs().showError("Must have stage with scan-enabled firmware for stage scanning.");
return false;
}
if (acqSettings_.acquisitionMode() == AcquisitionMode.STAGE_SCAN_INTERLEAVED) {
if (acqSettings_.volumeSettings().numViews() < 2) {
studio_.logs().showError("Interleaved stage scan requires two sides.");
}
return false;
if (acqSettings_.isUsingStageScanning()) {
final ASIXYStage xyStage = model_.devices().getDevice("SampleXY");
if (xyStage != null) {
if (!xyStage.hasProperty(ASIXYStage.Properties.SCAN_NUM_LINES)) {
studio_.logs().showError("Must have stage with scan-enabled firmware for stage scanning.");
return false;
}
if (acqSettings_.acquisitionMode() == AcquisitionMode.STAGE_SCAN_INTERLEAVED) {
if (acqSettings_.volumeSettings().numViews() < 2) {
studio_.logs().showError("Interleaved stage scan requires two sides.");
}
return false;
}

// second part: initialize stage scanning so we can restore state
xyPosUm = xyStage.getXYPosition();
origXSpeed = xyStage.getSpeedX();
origXAccel = xyStage.getAccelerationX();

// TODO: add more checks from orignal plugin here...
// if (origXSpeed < 0.2 && resetXaxisSpeed_) { etc...
}
}


PLogicSCAPE controller = null;

// Assume demo mode if default camera is DemoCamera
Expand Down Expand Up @@ -557,6 +571,23 @@ public void close() {
controller.stopSPIMStateMachines();
}

// if we did stage scanning restore the original position and speed
if (acqSettings_.isUsingStageScanning()) {
final ASIXYStage xyStage = model_.devices().getDevice("SampleXY");
final boolean returnToOriginalPosition =
acqSettings_.scanSettings().scanReturnToOriginalPosition();

// make sure stage scanning state machine is stopped,
// otherwise setting speed/position won't take
xyStage.setScanState(ASIXYStage.ScanState.IDLE);
xyStage.setSpeedX(origXSpeed);
xyStage.setAccelerationX(origXAccel);

if (returnToOriginalPosition) {
xyStage.setXYPosition(xyPosUm.x, xyPosUm.y);
}
}

// Restore shutter/autoshutter to original state
try {
core_.setShutterOpen(isShutterOpen);
Expand Down Expand Up @@ -775,6 +806,12 @@ private boolean doHardwareCalculations(PLogicSCAPE plc) {
"with software channels (need to use PLogic channel switching).");
return false;
}
if (acqSettings_.isUsingStageScanning()) {
// stage scanning needs to be triggered for each time point
studio_.logs().showError("Cannot use hardware time points (small time point interval) "
+ "with stage scanning.");
return false;
}
}

double extraChannelOffset = 0.0;
Expand Down
Loading