Coder Social home page Coder Social logo

tigerasi's Introduction

TigerASI

a feature-rich Python interface for ASI Tiger Controllers.

This driver was written to simplify the serial api to ASI's Tiger Controllers while reducing reliance on the full documentation for most users. Many (but not all!) commands have been exposed and wrapped in a simplified, self-consistent interface and documented for easy usage.

Installation

To install this package from PyPI, invoke: pip install TigerASI.

To install this package from the Github in editable mode, from this directory invoke: pip install -e .

To install this package in editable mode and build the docs locally, invoke: pip install -e .[dev]

Intro and Basic Usage

from tigerasi.tiger_controller import TigerController

box = TigerController("COM4")

The basic command syntax looks like this:

box.zero_in_place('x', 'y')  # Zero out the specified axes at their current location.
box.move_absolute(x=1000, y=25)  # Move to an absolute location in "stage units" (tenths of microns).
box.move_relative(z=100) # Move z +100 stage units in the positive z direction.

Syntax Basics

All commands that reference stage axes accept a variable, optional number of arguments.

box.zero_in_place('x')  # only zeros the x axis. Other axes are ignored.

Stage axes are also case-insensitive,

box.zero_in_place('X', 'y', 'Z')  # also ok

and the order doesn't matter.

box.zero_in_place('y', 'z', 'x')  # also ok

All commands that query stage axes return a dict, keyed by upper-case stage axis.

box.get_position('x', 'z', 'y')
# {'X': 100.0, 'Y': 305.0, 'Z': 10000.0}

Some commands can take an axis setting to be "current value" and another axis setting to be a specified value. The syntax for these commands look like this:

box.set_home('x', 'z', y=100.0) # Set x and z axes homing location to current spot. Set y axis to specific spot.
box.set_home('z', 'y', 'x', m=100.0, n=200.0) # variable number of arguments ok! order and case don't matter.

Some commands assume all axes if none are specified.

box.zero_in_place()  # will zero ALL lettered axes.
box.reset_lower_travel_limits()  # will reset ALL lettered axes.

box.get_home()  # will get ALL lettered axis home positions.
box.get_lower_travel_limits() # will get ALL lettered axis lower travel limits.

For setting values, this might not be your desired behavior, so it is safer to default to passing in axes explicitly.

box.zero_in_place('x', 'y', 'z')  # will zero only x, y, and z axes.
box.reset_lower_travel_limits('x', 'y', 'z')  # will reset only x, y, and z axes.

When in doubt, check the docs.

Simulation

This package also features a simulated version of the TigerController

from tigerasi.sim_tiger_controller import SimTigerController

box = SimTigerController()  # OR
box = SimTigerController('COM4')  # com port is ignored. # OR
box = SimTigerController(build_config={'Motor Axes': ['X', 'Y', 'Z']})

# This object tracks its internal state for position and speed.
box.home_in_place('x', 'y', 'z')  # home mocked axes.
box.move_absolute(z=10)  # move mocked axis.

This feature can be useful for testing higher level code using the current api without the need to interact with real hardware.

Advanced Usage

Many (but not all!) of ASI's more advanced features have been made available via this simplified API. This list includes joystick enabling/disabling and remapping, setting stage travel limits, queuing moves into the hardware buffer, and many other more nuanced features. For a breakdown of what commands have been exposed, have a look at the examples folder and the docs.

Documentation

Docs can be generated via Sphinx but are also available on readthedocs.

Implementation Details

Blocking or Non-Blocking?

All commands to the Tigerbox return a reply. Commands that query the Tigerbox state will also return data with that reply.

Waiting for a reply introduces 10-20[ms] of execution time before the function returns an 'ACK'knowledgement. By default, methods will block until receiving this acknowledgement unless otherwise specified, like this:

box.move_absolute(x=1000, y=25, wait=False) # will not block.

This behavior can only be used for commands to change the Tigerbox state. Commands that query the Tigerbox state will always block until they receive a hardware reply.

tigerasi's People

Contributors

adamkglaser avatar github-actions[bot] avatar jtyoung84 avatar micahwoodard avatar poofjunior avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tigerasi's Issues

Update Ring Buffer funcs to keep up with ASI updates

ASI recently updated the RBMODE syntax recently to add some capabilities, but it changes the meaning of the arguments.

Note how enumerations were added to the bottom, and the previous enumeration values have now changed meaning.

Since it's not clear exactly what firmware version these changed, it's critical that we get these up-to-date with the latest ASI docs.

get_etl_temperature fails *sometimes*

Here's the stack trace:

2023-08-01,15:58:04.182 INFO spim_core.spim_base.Exaspim: tile: (0, 1); stage_position: (0.000[um], 0.000[um])
2023-08-01,15:58:04.645 INFO spim_core.spim_base.Exaspim: tile data
2023-08-01,15:58:04.987 DEBUG tigerasi.tiger_controller: Sending: 'PM V?\r'
2023-08-01,15:58:06.306 DEBUG tigerasi.tiger_controller: Reply: 'V=1 :A\r\n'
2023-08-01,15:58:06.924 DEBUG tigerasi.tiger_controller: Sending: 'PM V=2\r'
2023-08-01,15:58:07.484 DEBUG tigerasi.tiger_controller: Reply: ':A\r\n'
2023-08-01,15:58:07.965 DEBUG tigerasi.tiger_controller: Sending: '35PZINFO\r'
2023-08-01,15:58:09.564 DEBUG tigerasi.tiger_controller: Reply: 'Hdwr REV.C \rV0 :24.3 V\rI'
2023-08-01,15:58:10.155 DEBUG tigerasi.tiger_controller: Sending: 'PM V=1\r'
2023-08-01,15:58:11.637 DEBUG tigerasi.tiger_controller: Reply: '2C Check> HUB[OK]\rV Mode['
XY Tiling Progress:   0%|                                                                              | 0/3 [00:42<?, ?it/s]
2023-08-01,15:58:12.319 ERROR spim_core.spim_base.Exaspim: Error raised from the main acquisition loop.
Traceback (most recent call last):
  File "C:\Users\Administrator\Documents\Github\exa-spim-control\exaspim\exaspim.py", line 316, in collect_volumetric_image
    self.log_stack_acquisition_params(self.curr_tile_index,
  File "C:\Users\Administrator\Documents\Github\exa-spim-control\exaspim\exaspim.py", line 797, in log_stack_acquisition_params
    'etl_temperature': self.tigerbox.get_etl_temp('V'),  # FIXME: this is hardcoded as V axis
  File "C:\Users\Administrator\Documents\Github\TigerASI\src\tigerasi\tiger_controller.py", line 39, in inner
    return func(self, *args, **kwds)
  File "C:\Users\Administrator\Documents\Github\TigerASI\src\tigerasi\tiger_controller.py", line 1172, in get_etl_temp
    return temp
UnboundLocalError: local variable 'temp' referenced before assignment
2023-08-01,15:58:13.498 DEBUG spim_core.devices.tiger_components.SamplePose: Absolute move to: x=0.000 y=0.000 and waiting.
2023-08-01,15:58:14.070 DEBUG tigerasi.tiger_controller: Sending: 'M Y=0 Z=0\r'
2023-08-01,15:58:15.605 DEBUG tigerasi.tiger_controller: Reply: 'IN],Tc[22.750],TCOMP['
2023-08-01,15:58:16.258 DEBUG tigerasi.tiger_controller: Sending: '/\r'
2023-08-01,15:58:17.963 DEBUG tigerasi.tiger_controller: Reply: 'ON]\rW Mode[EXT],Tc[30.0'
2023-08-01,15:58:18.838 INFO spim_core.devices.tiger_components.SamplePose: Releasing joystick control.
2023-08-01,15:58:19.289 DEBUG tigerasi.tiger_controller: Sending: 'J X+ Y+ Z+ F+ R+ M+ N+ V+ W+\r'
2023-08-01,15:58:20.890 DEBUG tigerasi.tiger_controller: Reply: '00],TCOMP[OFF]\rV> IN:127,OUT'
2023-08-01,15:58:21.482 DEBUG tigerasi.tiger_controller: Sending: 'J X=0 Y=0 Z=0 F=0 R=0 M=0 N=0 V=0 W=0\r'
2023-08-01,15:58:22.862 DEBUG tigerasi.tiger_controller: Reply: ':128 \rW> IN:1,OUT:124'
---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
File ~\Documents\Github\exa-spim-control\exaspim\exaspim.py:316, in Exaspim.collect_volumetric_image(self=<exaspim.exaspim.Exaspim object>, volume_x_um=20000, volume_y_um=10000, volume_z_u
m=100, channels=[488], tile_overlap_x_percent=15, tile_overlap_y_percent=15, z_step_size_um=8, start_tile_index=0, end_tile_index=5, tile_prefix='', compressor_chunk_size=None, local_stora
ge_dir=None, img_storage_dir=None, deriv_storage_dir=None)
    315 # Log stack capture start state.
--> 316 self.log_stack_acquisition_params(self.curr_tile_index,
        self = <exaspim.exaspim.Exaspim object at 0x0000023AF4993FA0>
        self.curr_tile_index = 1
        stack_prefix = '_x_0000_y_0001_z_0000'
        z_step_size_um = 8
    317                                   stack_prefix,
    318                                   z_step_size_um)
    319 # TODO, should we do the arithmetic outside of the Camera class?
    320 # TODO, should we transfer this small file or just write directly over the network?

It looks like tigerasi is returning early, despite the read_until value being correctly set to '\r\n'.

reset travel limit without args

reset_lower_travel_limit() should reset all lower travel limits.

reset_upper_travel_limit() should reset all upper travel limits.

SCANR should take a length input instead of encoder ticks input

Currently scanr takes as input an argument pulse_interval_enc_ticks. There is a bit of mental overhead here, such that the user needs to know what length is reprsented by an encoder tick.

This is available in TigerASI via the command get_encoder_ticks_per_mm.

Proposed that within scanr we instead change to pulse_interval_um. Requires that:

  1. We ask scan what the fast axis id is (the one which will be scanned).
  2. We internally call get_encoder_ticks_per_mm for this axis.
  3. We use the output to convert the desired pulse interval rounded to a certain number of encoder ticks.
  4. We then feed in this encoder ticks to the Z argument of SCANR.

Update axis_check

The current axis_check decorator makes some hard-coded assumptions and may break in some versions of double-specifying parameters

We should rewrite this to possibly

  • not hardcode parameters to skip
  • ensure that args/kwargs aren't being skipped if double-specified in certain ways.
  • sanitize the input to all lowercase (or all uppercase??)

Here's a stab at this:

# Decorators
def axis_check(func, *args_to_skip: str):
    """Ensure that the axis (specified as an arg or kwarg) exists."""

    def inner(self, *args, **kwargs):
        # Sanitize input to all-lowercase.
        args = [a.lower() for a in args]
        kwargs = {k.lower(): v for k, v in kwargs.items()}
        # Combine args and kwarg names; skip double-adding params specified as
        # one or the other.
        iterable = [a for a in args if a not in kwargs] + list(kwargs.keys())
        for arg in iterable:
            # Skip pre-specified args.
            if arg in args_to_skip:
                continue
            assert arg.lower() not in self.stages, \
                f"Error. Axis '{arg.upper()}' does not exist"
        return func(self, *args, **kwargs)
    return inner

Add Github action to publish to PyPi

This is a low priority, but it would be great to use this package as a way to test automatically bumping our code to PyPi package by package.

Some notes:

  • might require repo to be public
  • version bumping should be automatic

Switching to pyproject.toml breaks version bumping

I think it's related to (1) folder structure being slightly different (we don't have a src folder) and (2) versioning is set to dynamic in pyproject.toml, which means it is specified in the init.py. I have removed this breaking section for now.

Here's the original tag_and_publish.yml for reference.

Add flag or ability for multi-line replies

Trying to use Tiger controller to read ETL temperature using the command:

[#]pzinfo
-> 5pzinfo for exaSPIM

Expected response is:
Hdwr REV.C
V0 :24.3 V
I2C Check> HUB[OK]
V Mode[EXT],Tc[30.000],TCOMP[OFF]
W Mode[EXT],Tc[30.000],TCOMP[OFF]
V> IN:125,OUT:127
W> IN:1,OUT:124
Power Good[YES]
V> Over Current[NO] Over Temp[NO]
W> Over Current[NO] Over Temp[NO]

Current behavior of send() is to only return the final line. Uncommenting line 185 shows that the full response is being received. Perhaps some form of concatenation for multi-line responses?

The Tc[30.000] -> 30.000 is what we would be wanting to grab out of the response.

Add a wait() command

For flow control purposes it would be nice to do something like this:

box = TigerController("COM4")

box.move_absolute(x=10, y=100, wait=False)
# do other stuff here
box.wait()  # blocks until the tigerbox is done moving or handling the last command.

Under the hood, wait would block until we got a reply from any previous command that was issued without waiting, and it would wait until the tigerbox was idle.

PM command isn't working

When calling tigerbox.pm(**externally_controlled_axes) bugs pop up. Will update with more specific when I can

Implement close() command

I am not sure if this is entirely necessary, but it seems like we should implement a close() command for any COM ports which we open for devices using pyserial. I think something along the lines of:

self.ser = Serial(...)

def close(self):
self.ser.close()

This might avoid hanging COM ports which linger depending on how the main code is terminated?

Simplify API

We use wait_for_output and wait_for_reply flags all over methods, but really we only set them as a group. Let's consolidate this into one wait--even if we split up the type of wait internally in the function.

We also call move_axes_absolute and move_axes_relative, when we could just say move_absolute and move_relative.

kwargs should also just be kwds.

joystick axis remapping

We need to remap axes to make "up" on the joystick either + or - in a particular axis direction.

TTL command not implemented correctly

This command explicitly needs the card address specified of the axis we are trying to enable external triggers on. To do that from software, we need to do an axis-to-card lookup.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.