TheDeanLab / navigate

navigate - open source light-sheet microscope controls
https://thedeanlab.github.io/navigate/
Other
18 stars 5 forks source link

New feature: WaitForExternalTrigger #937

Closed conorhughmcfadden closed 1 month ago

conorhughmcfadden commented 1 month ago

Put this feature in your feature list to wait for an external digital trigger before moving on to the next block.

Example feature list which worked:

[{"name": PrepareNextChannel,},({"name": WaitForExternalTrigger,"args": ("/PCIe-6738/PFI4",-1,),},({"name": MoveToNextPositionInMultiPositionTable,},{"name": ZStackAcquisition,"args": (True,True,),},{"name": WaitToContinue,},{"name": LoopByCount,"args": ("experiment.MicroscopeState.multiposition_count",),},),{"name": LoopByCount,"args": (5,),},),]

Option to set a timeout to break the loop if no trigger is incoming.

Tested with a function generator hooked up to PFI4 and it seemed to work well.

conorhughmcfadden commented 1 month ago

I found a bug...

In the proposed feature list using multiposition above, the stage will not go back to the first position after the first iteration. It just repeatedly stacks the last position.

I'll investigate why and report back.

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 9.09091% with 30 lines in your changes missing coverage. Please review.

Project coverage is 53.08%. Comparing base (4b37039) to head (cc2e20c).

Files Patch % Lines
src/navigate/model/devices/daq/ni.py 0.00% 18 Missing :warning:
src/navigate/model/features/common_features.py 20.00% 12 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #937 +/- ## =========================================== - Coverage 53.18% 53.08% -0.10% =========================================== Files 177 177 Lines 19020 19052 +32 =========================================== - Hits 10115 10114 -1 - Misses 8905 8938 +33 ``` | [Flag](https://app.codecov.io/gh/TheDeanLab/navigate/pull/937/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheDeanLab) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/TheDeanLab/navigate/pull/937/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheDeanLab) | `53.08% <9.09%> (-0.10%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheDeanLab#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

conorhughmcfadden commented 1 month ago

I found a bug...

In the proposed feature list using multiposition above, the stage will not go back to the first position after the first iteration. It just repeatedly stacks the last position.

I'll investigate why and report back.

I found the issue! There appears to have been a bug in MoveToNextPositionInMultiPositionTable. At least when I ran this feature list without my new triggering block, just a normal loop, I got the same issue:

[({"name": PrepareNextChannel, },({"name": MoveToNextPositionInMultiPositionTable, },{"name": ZStackAcquisition, "args": (False,False,"z-stack",),},{"name": WaitToContinue, },{"name": LoopByCount, "args": ("experiment.MicroscopeState.multiposition_count",),},),{"name": LoopByCount, "args": (3,),},),]

It turns out current_idx needs to be reset in the signal_func in order for it to work with LoopByCount. Making this bug fix allows it to return to the original position using a nested loop. I tested it with my WaitForExternalTrigger and it works properly now!

AdvancedImagingUTSW commented 1 month ago

This is a great addition. Before we merge, I think it would be a good idea to have the calls to the data acquisition card go through the device abstraction layer. This way, should we add additional ways to receive external signals (e.g., Tiger Controller, TriggerScope), it will be more modular.