From 83fd6fb15f8ff68771166b3554513fceb6214969 Mon Sep 17 00:00:00 2001 From: Brandon Date: Wed, 24 Apr 2024 15:18:38 -0700 Subject: [PATCH] add seven channel shutter ttl + fix stage scan camera trigger --- .../lightsheetmanager/model/PLogicSCAPE.java | 56 ++++++++++++++++--- .../acquisitions/AcquisitionEngineSCAPE.java | 2 + .../model/devices/vendor/ASIPLogic.java | 3 +- 3 files changed, 53 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/micromanager/lightsheetmanager/model/PLogicSCAPE.java b/src/main/java/org/micromanager/lightsheetmanager/model/PLogicSCAPE.java index 98c1143..3f30384 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/model/PLogicSCAPE.java +++ b/src/main/java/org/micromanager/lightsheetmanager/model/PLogicSCAPE.java @@ -220,7 +220,9 @@ public boolean prepareControllerForAcquisition( if (isInterleaved) { numLines = 1; // assure in acquisition code that we can't have single-sided interleaved } - numLines *= (int)((double)settings.numChannels() / computeScanChannelsPerPass(settings)); + if (settings.isUsingChannels()) { + numLines = numLines * (settings.numChannels() / computeScanChannelsPerPass(settings)); + } xyStage_.setScanNumLines(numLines); final boolean isStageScan2Sided = (settings.acquisitionMode() == AcquisitionMode.STAGE_SCAN) @@ -611,7 +613,6 @@ private boolean cleanUpControllerAfterAcquisitionSide( // break; // } - //if (scanner_ != null && piezo_ != null) { // make sure SPIM state machine is stopped scanner_.setSPIMState(ASIScanner.SPIMState.IDLE); @@ -624,7 +625,7 @@ private boolean cleanUpControllerAfterAcquisitionSide( if (movePiezo) { piezo_.setPosition(piezoPosition); } - //} + // make sure we stop SPIM and SCAN state machines every time we trigger controller (in AcquisitionPanel code) return true; } @@ -692,11 +693,17 @@ public boolean setupHardwareChannelSwitching(final DefaultAcquisitionSettingsSCA plcLaser_.setCellInput(3, acquisitionFlagAddr + ASIPLogic.addrEdge); } - if (plcLaser_.getShutterMode() == ASIPLogic.ShutterMode.SEVEN_CHANNEL_SHUTTER) { - // special 7-channel case + // there are 2 separate 7-channel cases different in the property value for "PLogicMode" + // 1. (original) with 7-channel laser on own PLogic card, seems to have some odd things that I won't change including only uses 6 lasers + // 2. (newer) with 7-channel TTL-triggered on PLogic card shared with single camera trigger output (i.e. not dual-view system) + // however they share some things like using cells 17-24 and building a 3-input LUT which code is just copy/paste right now + final boolean isSevenChannelShutter = plcLaser_.getShutterMode() == ASIPLogic.ShutterMode.SEVEN_CHANNEL_SHUTTER; + final boolean isSevenChannelShutterTTL = plcLaser_.getShutterMode() == ASIPLogic.ShutterMode.SEVEN_CHANNEL_SHUTTER; + + if (isSevenChannelShutter) { + // original special 7-channel case if (plcLaser_.getNumCells() < 24) { - // restore update setting - plcLaser_.setAutoUpdateCells(editCellUpdates); + plcLaser_.setAutoUpdateCells(editCellUpdates); // restore update setting studio_.logs().showError("Require 24-cell PLC firmware to use hardware channel switching with 7-channel shutter"); return false; } @@ -722,6 +729,41 @@ public boolean setupHardwareChannelSwitching(final DefaultAcquisitionSettingsSCA plcLaser_.setCellInput(2, counterMSBAddr); plcLaser_.setCellInput(3, laserTriggerAddress); } + } else if (isSevenChannelShutterTTL) { + // new 7-channel case with camera trigger on BNC #8 + if (plcLaser_.getNumCells() < 24) { + plcLaser_.setAutoUpdateCells(editCellUpdates); // restore update setting + studio_.logs().showError("Require 24-cell PLC firmware to use hardware channel switching with 7-channel shutter"); + return false; + } + + // set cells 17-24 to control BNCs 1-8, but then immediately change BNC8 to reflect camera (firmware ensures all are set to push-pull outputs) + // note that the device adapter should have already set BNC8 to be the camera so this is just resetting it + plcLaser_.setPreset(ASIPLogic.Preset.BNC1_8_ON_17_24); + final int addrFrontPanel8 = 40; + final int addrInternalTTLCameraA = 41; + plcLaser_.setPointerPosition(addrFrontPanel8); // address 40 is front panel #8 + plcLaser_.setCellType(ASIPLogic.CellType.OUTPUT_PUSH_PULL); + plcLaser_.setCellConfig(addrInternalTTLCameraA); // address 41 is internal TTL0 signal for CameraA + + // now set cells 17-23, so they reflect the counter state used to track state as well as the global laser trigger + for (int laserNum = 1; laserNum <= 7; ++laserNum) { + plcLaser_.setPointerPosition(laserNum + 16); + plcLaser_.setCellType(ASIPLogic.CellType.LUT3); + int lutValue = 0; + // populate a 3-input lookup table with the combinations of lasers present + // the LUT "MSB" is the laserTrigger, then the counter MSB, then the counter LSB + for (int channelNum = 0; channelNum < settings.numChannels(); ++channelNum) { + if (doesPLogicChannelIncludeLaser(laserNum, settings.channels()[channelNum], settings.channelGroup())) { + // LUT adds 2^(code in decimal) for each setting, but trigger is MSB of this code + lutValue += (int) Math.pow(2, channelNum + 4); + } + } + plcLaser_.setCellConfig(lutValue); + plcLaser_.setCellInput(1, counterLSBAddr); + plcLaser_.setCellInput(2, counterMSBAddr); + plcLaser_.setCellInput(3, laserTriggerAddress); + } } else { // original 4-channel mode diff --git a/src/main/java/org/micromanager/lightsheetmanager/model/acquisitions/AcquisitionEngineSCAPE.java b/src/main/java/org/micromanager/lightsheetmanager/model/acquisitions/AcquisitionEngineSCAPE.java index 0e35f6f..d48f74e 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/model/acquisitions/AcquisitionEngineSCAPE.java +++ b/src/main/java/org/micromanager/lightsheetmanager/model/acquisitions/AcquisitionEngineSCAPE.java @@ -373,6 +373,8 @@ public AcquisitionEvent run(AcquisitionEvent event) { xyStage.setSpeedX(scanSpeedX_); xyStage.setAccelerationX(scanAccelX_); finalController.prepareStageScanForAcquisition(pos.x, pos.y, acqSettings_); + finalController.triggerControllerStartAcquisition(acqSettings_.acquisitionMode(), + acqSettings_.volumeSettings().firstView()); } return event; } diff --git a/src/main/java/org/micromanager/lightsheetmanager/model/devices/vendor/ASIPLogic.java b/src/main/java/org/micromanager/lightsheetmanager/model/devices/vendor/ASIPLogic.java index 4e8c253..cda7631 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/model/devices/vendor/ASIPLogic.java +++ b/src/main/java/org/micromanager/lightsheetmanager/model/devices/vendor/ASIPLogic.java @@ -326,7 +326,8 @@ public enum ShutterMode { NONE("None"), FOUR_CHANNEL_SHUTTER("Four-channel shutter"), DISPIM_SHUTTER("diSPIM Shutter"), - SEVEN_CHANNEL_SHUTTER("Seven-channel shutter"); + SEVEN_CHANNEL_SHUTTER("Seven-channel shutter"), + SEVEN_CHANNEL_TTL_SHUTTER("Seven-channel TTL shutter"); private final String text_;