Home - derangedhk417/MicroscopeControl GitHub Wiki

Welcome to the MicroscopeControl wiki!

If you don't know where to go, start Here

This wiki is primarily concerned with documenting all of the quirks and unexpected behaviors encountered in the hardware during the development of this code. It is divided into one page per code file (for the most part).

Note: There is a program called MicroscopeShell.py in the src/ folder that provides a simple command line interface for controlling the microscope.

Available Functions

What follows is a list of available functions exposed by the MicroscopeController class. Many of these functions take a significant amount of time to execute because they do not return until the physical device has stopped moving. These functions provide an asynchronous callback functionality. See below for details.

Camera Functions

camera.startCapture()

This needs to be called to put the camera driver in a state where it can take images.


camera.endCapture()

Call this when you're done taking images. I'm not certain whether or not this is important.


camera.enableAutoExposure()

This will cause the camera to automatically adjust its exposure time until the image is not excessively bright or dark.


camera.disableAutoExposure()

This will turn off the automatic exposure adjustment. I still need to implement manual exposure adjustment.


camera.setExposure(float exposure)

This will set the exposure time to the specified value in milliseconds.


float camera.getExposure()

This will return the current exposure time of the camera in milliseconds.


NumPy.ndarray camera.getFrame(convert=False)

Retrieves a frame from the camera as a NumPy ndarray. This will have shape (height, width, 3). By default, the channels will be ordered BGR. If you pass convert=True as an argument, this function will return an array with channels ordered RGB.


Stage Functions

bool stage.getAxisStatus(str axis)

Returns True if the specified axis is moving and False if it is idle. Axis must be "x" or "y".


stage.moveTo(int x, int y, fn callback=None)

Moves the stage to the specified x and y coordinate in millimeters. If a callback function is specified, this function will return immediately and will call the specified callback with no arguments when the stage finishes moving. If no callback is specified, this function will not return until the stage finished moving.


stage.moveDelta(int x, int y, fn callback=None)

Moves the stage relative to its current position. Input values should be in millimeters. The callback function should take no arguments, if specified.


stage.setAcceleration(int x, int y)

Sets the amount of time in milliseconds that each axis should take to accelerate to its maximum velocity when a move is executed. This function returns quickly and does not have a callback option.


stage.setJoystickSensitivity(float coarse, float fine)

Sets the sensitivity of the physical joystick on the axis controller. The specified values should be between 0.1 and 100. They represent a percentage of the default values for the joystick. The coarse argument will apply when the joystick's fine adjustment mode has not been toggled on with the button on it. The fine argument applies otherwise.


stage.setMaxSpeed(float x, float y)

Sets the maximum speed of the x and y axes in millimeters per second. The maximum value is 7.5 for both axes. This appears to be the top speed that the stage accelerates to when it starts moving.


stage.setLimits([int, int] x, [int, int] y)

Sets the motion limits on the stage, in millimeters. The first argument should be a list where the first element is the minimum value on the x-axis and the second element is the maximum value on the x-axis. The second argument is in the same format, except that it applies to the y-axis. When this function is called, the limits will be saved into permanent memory on the stage controller. From then on, it will enforce these limits until they are reset. This applies regardless of whether or not you power cycle the controller and whether or not it is connected to the computer.

Note: As of this writing, these limits are set when the MicroscopeController object is instantiated. They default to [-50, 50], [-50, 37], which is sufficient to prevent the stage from running into the supports that hold up the optics.


stage.home(fn callback=None)

Moves the stage back to position 0, 0.


(float, float) stage.getPosition()

Returns the position in millimeters of both stage axes in the order x, y.


Focus/Zoom Functions

(int, int) focus.getLimits()

Returns the position limits of the zoom and focus motors in order. These values are integers in some arbitrary units. I am assuming that these are motor steps.


int focus.getZoomAcceleration()

Returns the acceleration value for the zoom motor in arbitrary integer units. This is probably in motor steps per second squared, but I have not confirmed this.


int focus.getZoomInitialVelocity()

Returns the initial velocity of the zoom motor (when it starts moving). This is also in unknown integer units.


int focus.getZoomMaxVelocity()

Returns the maximum velocity that the zoom motor reaches at its fastest. This is also in unknown integer units.


int focus.setZoomAcceleration(int value)

Sets the acceleration of the zoom motor in the same arbitrary units.


int focus.setZoomInitialVelocity(int value)

Sets the acceleration of the zoom motor in the same arbitrary units.


int focus.setZoomMaxVelocity(int value)

Sets the maximum value for the velocity of the zoom motor in arbitrary units.

Note: The six functions listed above also exist for the focus motor, just replace Zoom with Focus in the function name.


float focus.getZoom()

Returns the current position of the zoom motor in units where 0.0 is the minimum value for the motor and 1.0 is the maximum value for the motor.


float focus.getFocus()

Returns the current position of the focus motor in units where 0.0 is the minimum value for the motor and 1.0 is the maximum value for the motor.


int focus.incrementZoom(float value, fn callback=None)

Increment the current position of the zoom motor by this value [0.0, 1.0]. This function can take some time to execute because it physically moves the motor. This function will return the number of arbitrary units that it moved by. If you specify a callback function it will return immediately and will pass the number of units that it moved by to the callback function.


int focus.incrementFocus(float value, fn callback=None)

Increment the current position of the focus motor by this value [0.0, 1.0]. This function can take some time to execute because it physically moves the motor. This function will return the number of arbitrary units that it moved by. If you specify a callback function it will return immediately and will pass the number of units that it moved by to the callback function.


focus.setZoom(float value, corrected=True, fn callback=None)

Sets the current position of the zoom motor in units where 0.0 is the minimum value and 1.0 is the maximum value. If corrected=True, this function will move the motor to its home position (0.0), before moving to the specified position. This results in better repeatability than simply moving directly to that position.


focus.setFocus(float value, corrected=True, fn callback=None)

Sets the current position of the focus motor in units where 0.0 is the minimum value and 1.0 is the maximum value. If corrected=True, this function will move the motor to its home position (0.0), before moving to the specified position. This results in better repeatability than simply moving directly to that position.