Stages

A stage is a subtype of Stage. move commands a position, getposition reads it, getrange reports the travel of each axis, and stopmotion halts a move where the driver implements it (MCLStage's only logs an error). The number of axes, the position units and whether move waits for the stage to arrive differ between drivers; each driver's docstrings below state its own. A stage's export_state records position_fresh::Bool: on a hardware stage, true when the export read every axis from the hardware; on a simulated stage, always true.

Stage interface

MicroscopeControl.HardwareInterfaces.StageInterface.driftcorrection — Method
driftcorrection(stage::Stage, xtoggle::Bool, ytoggle::Bool, ztoggle::Bool)

Sets the drift correction state of the given stage. This function is expected to be implemented for each specific stage type.

Arguments

  • stage::Stage: The stage whose drift correction state is to be set.
  • xtoggle::Bool: The desired drift correction state for the x-axis.
  • ytoggle::Bool: The desired drift correction state for the y-axis.
  • ztoggle::Bool: The desired drift correction state for the z-axis.

Description

This function is responsible for setting the drift correction state of the stage. The drift correction state controls whether the stage automatically corrects for any drift in its position over time. The specific method of setting the drift correction state may vary depending on the specific type of stage.

source
MicroscopeControl.HardwareInterfaces.StageInterface.getposition — Method
getposition(stage::Stage)

Gets the current position of the given stage. This function is expected to be implemented for each specific stage type.

Arguments

  • stage::Stage: The stage whose position is to be retrieved.

Returns

  • A tuple (x::Float64, y::Float64, z::Float64) representing the current position of the stage. 2D stages will return a tuple with (x,y), and 1D stages will return a tuple with (x).

Description

This function is responsible for retrieving the current position of the stage. The specific method of retrieving the position may vary depending on the specific type of stage.

source
MicroscopeControl.HardwareInterfaces.StageInterface.getrange — Method
getrange(stage::Stage)

Gets the range of motion of the given stage. This function is expected to be implemented for each specific stage type.

Arguments

  • stage::Stage: The stage whose range of motion is to be retrieved.

Returns

  • A tuple (x_range::Tuple{Float64, Float64}, y_range::Tuple{Float64, Float64}, z_range::Tuple{Float64, Float64}) representing the range of motion of the stage in each dimension. For 2D stages, the zrange should be (0.0, 0.0) or unspecified. For 1D stages, both the yrange and z_range should be (0.0, 0.0) or unspecified.

Description

This function is responsible for retrieving the range of motion of the stage. The specific method of retrieving the range may vary depending on the specific type of stage.

source
MicroscopeControl.HardwareInterfaces.StageInterface.home — Method
home(stage::Stage)

Moves the given stage to its home position. This function is expected to be implemented for each specific stage type.

Arguments

  • stage::Stage: The stage to be moved to its home position.

Description

This function is responsible for moving the stage to its home position. The home position is typically a predefined position that is used as a reference point for other movements. The specific method of moving to the home position may vary depending on the specific type of stage.

source
MicroscopeControl.HardwareInterfaces.StageInterface.move — Method
move(stage::Stage, x::Float64, y::Float64, z::Float64)

Moves the given stage to the specified position. This function is expected to be implemented for each specific stage type. 2D stages should ignore the z-coordinate. 1D stages should ignore the y- and z-coordinates.

Arguments

  • stage::Stage: The stage to be moved.
  • x::Float64: The target x-coordinate for the stage.
  • y::Float64: The target y-coordinate for the stage.
  • z::Float64: The target z-coordinate for the stage.

Description

This function is responsible for moving the stage to a specified position. The specific actions taken during the move operation may vary depending on the specific type of stage.

source
MicroscopeControl.HardwareInterfaces.StageInterface.servo — Method
servo(stage::Stage, xtoggle::Bool, ytoggle::Bool, ztoggle::Bool)

Sets the servo state of the given stage. This function is expected to be implemented for each specific stage type.

Arguments

  • stage::Stage: The stage whose servo state is to be set.
  • xtoggle::Bool: The desired servo state for the x-axis.
  • ytoggle::Bool: The desired servo state for the y-axis.
  • ztoggle::Bool: The desired servo state for the z-axis.

Description

This function is responsible for setting the servo state of the stage. The specific method of setting the servo state may vary depending on the specific type of stage.

source
MicroscopeControl.HardwareInterfaces.StageInterface.stopmotion — Method
stopmotion(stage::Stage)

Stops any ongoing motion of the given stage. This function is expected to be implemented for each specific stage type.

Arguments

  • stage::Stage: The stage whose motion is to be stopped.

Description

This function is responsible for stopping any ongoing motion of the stage. The specific method of stopping the motion may vary depending on the specific type of stage.

source
MicroscopeControl.gui — Method
# Arguments
- `stage::Stage`: The stage for which the GUI is to be created. The stage must have a `dimensions` field that indicates the number of dimensions it operates in (1, 2, or 3).

# Returns
- The function returns the created GUI. The specific type of the GUI depends on the dimensions of the stage.

# Errors
- If the stage's dimensions are not 1, 2, or 3, an error is thrown.

# Description
 - Function to create GUI for general stage format:
    - Target Position Textbox
    - X and Y Axis Control Arrows (right now implemented for 2D only, but should be extended to support 1 and 3 axis stages)
    - Query Position Button
    - Buttons to turn stage on and off
    - Stop Motion Button
    - Display for current position (can be text for now)

    - Servo Control Button (if servo is present)
    - Drift Correction Control Button (if drift correction is present)

[limitation] The panel reads stage.stagelabel for its window title, a field the simulated stages (SimStage1d, SimStage2d, SimStage3d) do not have, so gui throws on them.

source

Simulated stages

MicroscopeControl.HardwareImplementations.SimulatedStage.SimStage1d — Type
SimStage1d(; label="Simulated 1D Stage", range_x=(0, 100), kwargs...)

A simulated single-axis stage. It behaves as SimStage3d with one axis: move(stage, x) takes a Float64, getposition returns real_x as a number (not a one-element tuple), and getrange returns range_x. servostatus and driftcorrectionstatus are single Bools. home zeroes the position but not the target, as on SimStage3d.

source
MicroscopeControl.HardwareImplementations.SimulatedStage.SimStage2d — Type
SimStage2d(; label="Simulated 2D Stage", range_x=(0, 100), range_y=(0, 100), kwargs...)

A simulated two-axis stage. It behaves as SimStage3d without the z axis: move(stage, x, y) takes Float64s, and getrange returns (range_x, range_y).

[limitation] getposition returns only real_y; read real_x and real_y after calling it. home zeroes the positions but not the targets, as on SimStage3d.

source
MicroscopeControl.HardwareImplementations.SimulatedStage.SimStage3d — Type
SimStage3d(; label="Simulated 3D Stage", range_x=(0, 100), range_y=(0, 100), range_z=(0, 100), kwargs...)

A simulated three-axis stage, for tests, examples and system code run without hardware. Every field is a keyword with the default shown in the struct; positions are plain numbers in whatever unit the caller uses.

  • initialize and shutdown set connectionstatus.
  • move(stage, x, y, z) takes Float64s and stores them as the target (targ_x, targ_y, targ_z); it does not check them against the range. The stage arrives at once: the next getposition copies the targets into real_x, real_y, real_z.
  • getrange(stage) returns (range_x, range_y, range_z).
  • servo and driftcorrection record their flags in servostatus and driftcorrectionstatus; stopmotion does nothing.
  • Every method logs a line describing what it did, at debug level (@debug), so it prints nothing; set JULIA_DEBUG=MicroscopeControl to see the lines.
  • [limitation] getposition returns only real_z, not the (x, y, z) tuple the Stage interface describes; read real_x, real_y and real_z after calling it.
  • [limitation] home sets real_x, real_y and real_z to 0 but leaves the targets, so the next getposition reports the old target again.

See also SimStage2d, SimStage1d.

source
MicroscopeControl.export_state — Method
export_state(stage::SimStage1d)

Refresh the simulated position through getposition and export it. position_fresh::Bool is always true, including when the simulated stage is disconnected; no hardware is involved.

source
MicroscopeControl.export_state — Method
export_state(stage::SimStage2d)

Refresh the simulated position through getposition and export it. position_fresh::Bool is always true, including when the simulated stage is disconnected; no hardware is involved.

source
MicroscopeControl.export_state — Method
export_state(stage::SimStage3d)

Refresh the simulated position through getposition and export it. position_fresh::Bool is always true, including when the simulated stage is disconnected; no hardware is involved.

source

Mad City Labs Nano-Drive

MicroscopeControl.HardwareImplementations.MadCityLabs.MCLStage — Type
MCLStage(; stagelabel="MCL-NanoXYZ", units="Microns", kwargs...)

A Mad City Labs Nano-Drive three-axis piezo stage, driven through the Madlib library (libmadlib, resolved at load time; set MICROSCOPECONTROL_LIBMADLIB to override the path). Every field is a keyword with the default shown in the struct; positions are in micrometers.

The constructor does not touch the hardware. initialize takes the first available Nano-Drive handle (MCL_InitHandle) into id, sets connectionstatus, reads each axis's calibrated range into range_x, range_y, range_z, and sets the targets to the current position; it returns the handle, and when none is found it logs an error and returns 0 without throwing. shutdown releases the handle.

  • move(stage, x, y, z) takes Float64s, writes each axis, records the targets, and returns ("MCL_SUCCESS", "MCL_SUCCESS", "MCL_SUCCESS"); a write the library refuses throws, naming the Madlib error. move_to_z(stage, z) writes the z axis alone.
  • getposition(stage) reads the three axes into real_x, real_y, real_z and returns (x, y, z); get_z_position(stage) reads z alone. A failed read throws.
  • getrange(stage) reads the calibration of each axis and returns (range_x, range_y, range_z).
  • home(stage) moves to (0, 0, 0).
  • [limitation] stopmotion is not implemented for this stage; it logs an error and does nothing.
source
MicroscopeControl.HardwareImplementations.MadCityLabs.getcalibration — Method
getcalibration(stage::MCLStage, axis::Int) -> Tuple{Float64,Float64} or false

Read the calibration (maximum travel) of axis axis (1 = X, 2 = Y, 3 = Z) with MCL_GetCalibration, store (0.0, calibration) in stage.range_x, range_y or range_z, and return that tuple. An axis outside 1 to 3 logs an error and returns false. A negative integer library result throws an ErrorException naming the Madlib error when the code is a known one ("unknown error" otherwise); a non-finite result throws one saying the value is invalid.

source
MicroscopeControl.HardwareImplementations.MadCityLabs.getcommandedposition — Method
getcommandedposition(stage::MCLStage) -> (x, y, z)

Return the position last commanded to the controller (MCL_GetCommandedPosition) as three Float64s, in the stage's units (micrometers per MCLStage). Unlike getposition, it asks for the commanded position rather than a measured one, and it does not update real_x, real_y, real_z or the targets. The call's status is not checked.

source
MicroscopeControl.HardwareImplementations.MadCityLabs.inithandle — Method
inithandle(stage::MCLStage)

Initializes the handle for the given stage. This function is specific to stages of type MCLStage.

Arguments

  • stage::MCLStage: The stage whose handle is to be initialized.

Returns

  • The handle for the stage as an integer. If the stage is not found, the handle is 0 and an error is logged.

Description

This function is responsible for initializing the handle for the stage. The handle is used to identify the stage in subsequent operations. If the stage is not found, the function logs an error and sets the connection status of the stage to false.

source
MicroscopeControl.HardwareImplementations.MadCityLabs.isdeviceattached — Method
isdeviceattached(stage::MCLStage) -> Bool

Ask the Madlib library whether the Nano-Drive with handle stage.id is attached (MCL_DeviceAttached, waiting up to 500 ms), set stage.connectionstatus to the answer, log it, and return it. It does not throw when the device is absent. It uses the handle already in stage.id, so call it after initialize.

source
MicroscopeControl.HardwareImplementations.MadCityLabs.monitorZ — Method

monitorZ(stage::MCLStage)

Sets the position of the Z axis

Arguments

  • stage::MCLStage: The stage whose handle is to be released.
  • position::Float64: The position to move to.

Description

Commands the Nano-Drive to move the Z axis to a position and then reads the current position of the axis.

source
MicroscopeControl.HardwareImplementations.MadCityLabs.move_to_z — Method
move_to_z(stage::MCLStage, z::Float64) -> String

Write axis 3 (Z) to z (micrometers) with singlewrite, leaving X and Y alone, and return the status string "MCL_SUCCESS". The Z target stage.targ_z is recorded only on success; a write the library refuses throws an ErrorException naming the Madlib error.

source
MicroscopeControl.HardwareImplementations.MadCityLabs.releasehandle — Method

releasehandle(stage::MCLStage)

Closes the connection to a given stage

Arguments

  • stage::MCLStage: The stage whose handle is to be released.

Description

This function is responsible for releasing the handle for the stage. After the handle is released, the connection status of the stage is set to false.

source
MicroscopeControl.HardwareImplementations.MadCityLabs.singleread — Method

singleread(stage::MCLStage)

Reads the location of specific axis

Arguments

  • stage::MCLStage: The stage whose handle is to be released.
  • axis::Int: The axis to read from.

Description

Updates the axis position only after a nonnegative, finite SDK result; a negative error code throws.

source
MicroscopeControl.HardwareImplementations.MadCityLabs.singlewrite — Method

singlewrite(stage::MCLStage, axis::Int, position::Float64)

Moves the stage to a given location on a specific axis

Arguments

  • stage::MCLStage: The stage to move.
  • axis::Int: The axis to move.
  • position::Float64: The position to move to.

Description

This function moves the stage to the given position on the specified axis. It records the accepted target only on MCL_SUCCESS and returns that status string. A refused write throws before changing the target.

source
MicroscopeControl.HardwareImplementations.MadCityLabs.singlewriteZ — Method

singlewriteZ(stage::MCLStage)

Sets the position of the Z axis

Arguments

  • stage::MCLStage: The stage whose handle is to be released.
  • position::Float64: The position to move to.

Description

Records the Z target only on MCL_SUCCESS; a refused write throws and preserves the previous target.

source
MicroscopeControl.export_state — Method
export_state(stage::MCLStage)

Read the connected stage's position through getposition, without moving it. position_fresh::Bool is true only when this read succeeds. If disconnected or the read throws, warn once with the error and export the last-read position; an acquisition save is not interrupted.

source

PI C-867 (GCS2)

MicroscopeControl.export_state — Method
export_state(stage::PIStage)

Read the connected stage's position through getposition, without moving it. position_fresh::Bool is true only when this read succeeds. If disconnected or the read throws, warn once with the error and export the last-read position; an acquisition save is not interrupted.

source

PI N-472

MicroscopeControl.HardwareImplementations.PI_N472.setvel — Method
setvel(stage::N472, vel::Vector{Float64}) -> BOOL

Set the closed-loop move velocity of all axes with the GCS2 PI_VEL call, one value per axis in the order of stage.axes, then read the velocities back with PI_qVEL into stage.velocity (so the field holds what the controller reports, not what was requested). vel is passed to the controller unchanged; the code states no unit, and the default stage.velocity is [0.01, 0.01, 0.01] (one per axis) for units="mm". Returns FALSE if the set failed, otherwise the result of the read-back (TRUE or FALSE); a failure is also logged with @error, never thrown. initialize calls it with stage.velocity. Needs an open connection.

source
MicroscopeControl.export_state — Method
export_state(stage::N472)

Read the connected stage through getposition without moving it. position_fresh::Bool is true only on a successful GCS2 read. If disconnected or the read fails or throws, warn once with the error and export the last-read position; an acquisition save is not interrupted.

source

SmarAct MCS2

MicroscopeControl.HardwareImplementations.MCS2Stage_mod.find_reference! — Method
find_reference!(stage::MCS2Stage, ch_index::Int; timeout_s::Float64=60.0) -> nothing

Run the controller's referencing (homing) move on channel ch_index (1-based index into stage.channel_ids) with default referencing options (0), then poll the channel state every 0.1 s until it is no longer referencing. A channel with no positioner attached logs a warning and returns. Sets stage.is_referenced[ch_index] = true when the poll ends without reading the referenced bit back. Throws an ErrorException if the start command fails or if timeout_s seconds (default 60) pass; on timeout the referencing move is not stopped.

source
MicroscopeControl.HardwareImplementations.MCS2Stage_mod.find_travel_range! — Method
find_travel_range!(stage, ch_index; overshoot_pm=70_000_000_000, timeout_s=60.0)

Discovers the PHYSICAL travel range of one channel by driving it to each mechanical end stop and recording where it actually stops.

This is different from stage.min_pm / stage.max_pm, which are SOFTWARE limits (see SACTLPKEYRANGELIMITMIN/MAX in the manual). By default those are 0/0 — "no software limit configured" — NOT "zero physical range". The MCS2 has no limit-switch property to query directly; instead the controller detects a mechanical end stop while moving and sets the ENDSTOP_REACHED state bit.

source
MicroscopeControl.HardwareImplementations.MCS2Stage_mod.query_positions! — Method
query_positions!(stage::MCS2Stage) -> nothing

Read the current position of every connected channel from the controller (property POSITION, picometers) into stage.pos_pm and log them in micrometers. Channels with stage.connected[i] == false are skipped. Throws an ErrorException carrying the SDK message if a read fails.

source
MicroscopeControl.HardwareImplementations.MCS2Stage_mod.set_acceleration! — Method
set_acceleration!(stage::MCS2Stage, accel_pm_s2::Int64) -> nothing

Set the move acceleration of every connected channel to accel_pm_s2 picometers per second squared (1 mm/s^2 is 1_000_000_000) and record it in stage.accel_pm_s2. One value is applied to all channels; it is not range-checked here. Throws an ErrorException carrying the SDK message if the controller rejects it.

source
MicroscopeControl.HardwareImplementations.MCS2Stage_mod.set_velocity! — Method
set_velocity!(stage::MCS2Stage, vel_pm_s::Int64) -> nothing

Set the move velocity of every connected channel to vel_pm_s picometers per second (1 mm/s is 1_000_000_000) and record it in stage.velocity_pm_s. One value is applied to all channels; it is not range-checked here. Throws an ErrorException carrying the SDK message if the controller rejects it.

source
MicroscopeControl.HardwareInterfaces.StageInterface.servo — Method
StageInterface.servo(stage::MCS2Stage, xtoggle::Bool, ytoggle::Bool, ztoggle::Bool)

Used by gui3d (this is the one your 3-channel stage's gui actually calls, since stage.dimensions == 3 routes it through gui3d). See _apply_servo! — channels with no positioner attached are skipped automatically.

source
MicroscopeControl.export_state — Method
export_state(stage::MCS2Stage) -> (attributes, data, children)

Returns a tuple of (Dict, nothing, Dict) for compatibility with the MicroscopeControl state serialisation convention used by the PI module. Read the connected stage through getposition!, without moving it. position_fresh::Bool is true only when every exported channel was read. If the controller or any exported channel is disconnected, or a read throws, warn once with the error and export the last-read position; a save is not interrupted. Reads still query any connected channels.

source
MicroscopeControl.initialize — Method
initialize(stage::MCS2Stage)

Generic-interface entry point. Calls the existing initialize!(stage), then populates the Float64 µm fields (real_x/y, targ_x/y, range_x/y) that the shared gui expects.

source

Stage internals

Helpers the interface and the drivers define but do not export, including each driver's SDK bindings.

MicroscopeControl.HardwareInterfaces.StageInterface.StageFormat — Type
StageFormat

Generic properties for a translation stage.

Fields

  • label::String: The label of the stage.
  • units::String: The units of the stage.
  • id::Int: The ID of the stage.
  • dimensions::Int: The number of dimensions of the stage.
  • connectionstatus::Bool: Whether the stage is connected.
  • real_x::Float64: The real x position of the stage.
  • real_y::Float64: The real y position of the stage.
  • real_z::Float64: The real z position of the stage.
  • targ_x::Float64: The target x position of the stage.
  • targ_y::Float64: The target y position of the stage.
  • targ_z::Float64: The target z position of the stage.
  • range_x::Tuple{Float64, Float64}: The range of motion of the stage in the x dimension.
  • range_y::Tuple{Float64, Float64}: The range of motion of the stage in the y dimension.
  • range_z::Tuple{Float64, Float64}: The range of motion of the stage in the z dimension.
  • servostatus::Tuple{Bool, Bool, Bool}: The status of the servo motors in each dimension.
  • driftcorrectionstatus::Tuple{Bool, Bool, Bool}: The status of the drift correction in each dimension.
source
MicroscopeControl.HardwareImplementations.MadCityLabs.monitor — Method

monitor(stage::MCLStage, axis::Int, position::Float64)

Arguments

  • stage::MCLStage: The stage to move.
  • axis::Int: The axis to move.
  • position::Float64: The position to move to.

Returns

  • The location of the stage after movement.

Description

This function moves the stage to a given position then reads the location after movement

source
MicroscopeControl.HardwareImplementations.PI.REFERENCE_TIMEOUT_S — Constant

How long each of initialize's three waits may take, in seconds: for the controller to report ready, for both axes to report referenced, and for motion to stop. The budgets are separate, so initialize can wait up to three times this in all. A Ref so tests can shorten it.

source
MicroscopeControl.HardwareImplementations.PI.initialize_original — Method

Initialize the PI stage. Connects to the first PI C-867 the GCS2 library enumerates, turns both servos on, starts the reference move, waits for the controller and for both axes to report referenced, reads the travel range, waits for motion to stop, sets stage.velocity, and reads the position into real_x/real_y and the targets targ_x/targ_y.

connectionstatus becomes true only when all of that succeeded. A failure after the connect closes the connection and throws. Enumeration and connect failures log @error and return with connectionstatus == false.

[limitation] Not yet run on hardware; the wait for PI_IsControllerReady needs a rig check on the C-867. The stage needs calibration using PiMikroMove to work correctly; there is no documentation on how to calibrate using the PI_GCS2 library.

source
MicroscopeControl.HardwareImplementations.MCS2Stage_mod._apply_move! — Method
_apply_move!(stage::MCS2Stage, targets_um::Vector{Float64})

Shared implementation behind both StageInterface.move methods below. targets_um[i] corresponds to stage.channel_ids[i], in micrometres. Channels with no positioner attached (stage.connected[i] == false) keep their current position — same "skip disconnected channels" convention as _apply_servo! and the rest of helper_smaract.jl.

source
MicroscopeControl.HardwareImplementations.MCS2Stage_mod._apply_servo! — Method
_apply_servo!(stage::MCS2Stage, toggles::Vector{Bool})

Shared implementation behind both StageInterface.servo methods below. toggles[i] corresponds to stage.channel_ids[i]. Channels with no positioner physically attached (stage.connected[i] == false, populated from the real CHANNELSTATE query during initialize!) are silently skipped — same "skip disconnected channels" convention already used throughout helpersmaract.jl (moveall!, stopall!, etc.), rather than forcing a fixed dimensionality on the stage.

source
MicroscopeControl.HardwareImplementations.MCS2Stage_mod._drive_to_endstop! — Method
_drive_to_endstop!(stage, ch, target_pm, timeout_s)

Internal helper for find_travel_range!. Sends an absolute move to target_pm (deliberately beyond the real travel range) and waits until the channel stops — either because it arrived (won't happen here) or because ENDSTOPREACHED / MOVEMENT_FAILED was set.

Unlike move_abs!, this does NOT treat a stopped/failed move as an error — hitting the end stop is the expected and desired outcome.

source
MicroscopeControl.HardwareImplementations.MCS2Stage_mod.move_all! — Method
move_all!(stage, targets_pm)

Sends absolute move commands to all CONNECTED channels simultaneously, then waits for all of them to finish. targets_pm is a vector of Int64 positions, one per channel — entries for disconnected channels (e.g. channel 2 on an XY-only stage) are simply ignored.

source