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 — Module
Interface for controlling a translation stage
MicroscopeControl.HardwareInterfaces.StageInterface.Stage — Type
'Stage' is an abstract type that represents a translation stage. Specific stage types should be defined as subtypes of Stage.
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.
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.
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.
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.
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.
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.
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.
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.
Simulated stages
MicroscopeControl.HardwareImplementations.SimulatedStage — Module
The simulated stages, SimStage1d, SimStage2d and SimStage3d, for tests and examples without hardware.
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.
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.
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.
initializeandshutdownsetconnectionstatus.move(stage, x, y, z)takesFloat64s 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 nextgetpositioncopies the targets intoreal_x,real_y,real_z.getrange(stage)returns(range_x, range_y, range_z).servoanddriftcorrectionrecord their flags inservostatusanddriftcorrectionstatus;stopmotiondoes nothing.- Every method logs a line describing what it did, at debug level (
@debug), so it prints nothing; setJULIA_DEBUG=MicroscopeControlto see the lines. [limitation]getpositionreturns onlyreal_z, not the(x, y, z)tuple theStageinterface describes; readreal_x,real_yandreal_zafter calling it.[limitation]homesetsreal_x,real_yandreal_zto 0 but leaves the targets, so the nextgetpositionreports the old target again.
See also SimStage2d, SimStage1d.
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.
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.
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.
Mad City Labs Nano-Drive
MicroscopeControl.HardwareImplementations.MadCityLabs — Module
The driver for Mad City Labs Nano-Drive piezo stages: MCLStage, its Stage interface methods, and bindings to the Madlib library.
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)takesFloat64s, 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 intoreal_x,real_y,real_zand 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]stopmotionis not implemented for this stage; it logs an error and does nothing.
MicroscopeControl.HardwareImplementations.MadCityLabs.get_z_position — Method
get_z_position(stage::MCLStage) -> Float64Read axis 3 (Z) with singleread, store it in stage.real_z, and return it (micrometers). A failed read throws an ErrorException naming the Madlib error.
MicroscopeControl.HardwareImplementations.MadCityLabs.getcalibration — Method
getcalibration(stage::MCLStage, axis::Int) -> Tuple{Float64,Float64} or falseRead 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.
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.
MicroscopeControl.HardwareImplementations.MadCityLabs.getserialnumber — Method
getserialnumber(stage::MCLStage) -> Int32Return the serial number of the Nano-Drive with handle stage.id (MCL_GetSerialNumber) as the library reports it. The value is not checked, so a library error code comes back as a number, not a throw.
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.
MicroscopeControl.HardwareImplementations.MadCityLabs.isdeviceattached — Method
isdeviceattached(stage::MCLStage) -> BoolAsk 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.
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.
MicroscopeControl.HardwareImplementations.MadCityLabs.move_to_z — Method
move_to_z(stage::MCLStage, z::Float64) -> StringWrite 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.
MicroscopeControl.HardwareImplementations.MadCityLabs.printdeviceinfo — Method
printdeviceinfo(stage::MCLStage) -> nothingHave the Madlib library print the device information of handle stage.id (MCL_PrintDeviceInfo). The text is written by the library, not returned to Julia, so it may not appear in a Julia session's output.
MicroscopeControl.HardwareImplementations.MadCityLabs.releaseallhandles — Method
releaseallhandles(stage::MCLStage) -> nothingRelease every Nano-Drive handle this process holds (MCL_ReleaseAllHandles) and set stage.connectionstatus to false. The library call is not limited to stage: other MCLStage objects lose their handles too but keep their own connectionstatus and id. releasehandle releases only stage.id.
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.
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.
MicroscopeControl.HardwareImplementations.MadCityLabs.singlereadZ — Method
singlereadZ(stage::MCLStage)
Reads the location of the Z axis
Arguments
stage::MCLStage: The stage whose handle is to be released.
Description
Updates the Z position only after a nonnegative, finite SDK result; a negative error code throws.
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.
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.
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.
PI C-867 (GCS2)
MicroscopeControl.HardwareImplementations.PI — Module
The driver for Physik Instrumente stages on a C-867 controller: PIStage, its Stage interface methods, and bindings to the PI GCS2 library.
MicroscopeControl.HardwareImplementations.PI.PIStage — Type
Structure for the PI stage
MicroscopeControl.HardwareImplementations.PI.PIStage — Method
Constructor for the PI Stage Type, allows for creation on "empty", disconnected stage
Initialize function must be called to connect to the stage, so the constructor just sets default values
MicroscopeControl.HardwareImplementations.PI.getxposition — Method
Function to update the x position of the PI Stage
MicroscopeControl.HardwareImplementations.PI.getyposition — Method
Function to update the y position of the PI Stage
MicroscopeControl.HardwareImplementations.PI.immediatestop — Method
Function call to immediately stop the PI Stage
MicroscopeControl.HardwareImplementations.PI.ismoving — Method
BOOL PI_IsMoving (int ID, const char* szAxes, BOOL* pbValueArray)
Function to check if the PI Stage is moving, both the x and y axis are checked
MicroscopeControl.HardwareImplementations.PI.moveandwait — Method
Function to move PI Stage, and wait for completion
MicroscopeControl.HardwareImplementations.PI.movex — Method
Function to move PI Stage X axis to a specific position
MicroscopeControl.HardwareImplementations.PI.movey — Method
Function to move PI Stage Y axis to a specific position
MicroscopeControl.HardwareImplementations.PI.referencemove — Method
Start the reference move (PI_FRF) on both axes and return the GCS BOOL, 1 if accepted. initialize waits for it to finish.
MicroscopeControl.HardwareImplementations.PI.servox — Method
Sets the servo state of the x axis
MicroscopeControl.HardwareImplementations.PI.servoy — Method
Sets the servo state of the y axis
MicroscopeControl.HardwareInterfaces.StageInterface.driftcorrection — Method
Function to toggel the drift correction of the stage. 1 is for on, 0 is for off.
MicroscopeControl.HardwareInterfaces.StageInterface.getposition — Method
Function to update the position of the PI Stage
MicroscopeControl.HardwareInterfaces.StageInterface.getrange — Method
Function to update the position range of the PI Stage
MicroscopeControl.HardwareInterfaces.StageInterface.home — Method
Move to home position
MicroscopeControl.HardwareInterfaces.StageInterface.move — Method
Function to move PI Stage to a specific position
MicroscopeControl.HardwareInterfaces.StageInterface.servo — Method
Sets the servo state of both the x and y axis
MicroscopeControl.HardwareInterfaces.StageInterface.stopmotion — Method
Function call to immediately stop motion of the PI Stage
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.
MicroscopeControl.initialize — Method
Initialize the PI stage; see initialize_original for the sequence and its failure behaviour.
PI N-472
MicroscopeControl.HardwareImplementations.PI_N472 — Module
The driver for the PI N-472 linear stage: N472, its Stage interface methods, and bindings to the PI GCS2 library.
MicroscopeControl.HardwareImplementations.PI_N472.N472 — Type
Struct for PI-N472 linear actuator (3 axes)MicroscopeControl.HardwareImplementations.PI_N472.setvel — Method
setvel(stage::N472, vel::Vector{Float64}) -> BOOLSet 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.
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.
SmarAct MCS2
MicroscopeControl.HardwareImplementations.MCS2Stage_mod — Module
The driver for SmarAct MCS2 positioners: MCS2Stage, its Stage interface methods, and bindings to the SmarAct MCS2 library.
MicroscopeControl.HardwareImplementations.MCS2Stage_mod.MCS2Stage — Method
MCS2Stage(; kwargs...) -> MCS2StageKeyword-argument constructor with safe defaults for a 3-channel MCS2. All positions default to 0; call initialize!(stage) to populate them from the device.
MicroscopeControl.HardwareImplementations.MCS2Stage_mod.find_reference! — Method
find_reference!(stage::MCS2Stage, ch_index::Int; timeout_s::Float64=60.0) -> nothingRun 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.
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.
MicroscopeControl.HardwareImplementations.MCS2Stage_mod.query_positions! — Method
query_positions!(stage::MCS2Stage) -> nothingRead 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.
MicroscopeControl.HardwareImplementations.MCS2Stage_mod.set_acceleration! — Method
set_acceleration!(stage::MCS2Stage, accel_pm_s2::Int64) -> nothingSet 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.
MicroscopeControl.HardwareImplementations.MCS2Stage_mod.set_velocity! — Method
set_velocity!(stage::MCS2Stage, vel_pm_s::Int64) -> nothingSet 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.
MicroscopeControl.HardwareImplementations.MCS2Stage_mod.stop_all! — Method
stop_all!(stage)Stops all CONNECTED channels.
MicroscopeControl.HardwareImplementations.MCS2Stage_mod.stop_channel! — Method
stop_channel!(stage, ch_index)Immediately stops motion on one channel (1-based index). No-op if the channel has no positioner attached.
MicroscopeControl.HardwareInterfaces.StageInterface.getposition — Method
StageInterface.getposition(stage::MCS2Stage)Refreshes stage.pos_pm from the hardware and mirrors channels 1/2 (and 3, if present) into real_x/real_y/real_z (µm).
MicroscopeControl.HardwareInterfaces.StageInterface.home — Method
StageInterface.home(stage::MCS2Stage)Thin wrapper around home!(stage); syncs targ_x/targ_y (and targ_z, if a third channel exists) to the configured home position afterwards.
MicroscopeControl.HardwareInterfaces.StageInterface.move — Method
StageInterface.move(stage::MCS2Stage, x::Float64, y::Float64, z::Float64)Used by gui3d (the one your 3-channel stage's gui actually calls, since stage.dimensions == 3 routes it through gui3d). x, y, z in micrometres. See _apply_move!.
MicroscopeControl.HardwareInterfaces.StageInterface.move — Method
StageInterface.move(stage::MCS2Stage, x::Float64, y::Float64)Used by gui2d. x, y in micrometres. See _apply_move!.
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.
MicroscopeControl.HardwareInterfaces.StageInterface.servo — Method
StageInterface.servo(stage::MCS2Stage, xtoggle::Bool, ytoggle::Bool)Used by gui2d. See _apply_servo! — channels with no positioner attached are skipped automatically.
MicroscopeControl.HardwareInterfaces.StageInterface.stopmotion — Method
StageInterface.stopmotion(stage::MCS2Stage)Thin wrapper around stopmotion!(stage).
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.
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.
MicroscopeControl.shutdown — Method
shutdown(stage::MCS2Stage)Generic-interface entry point; thin wrapper around shutdown!(stage).
Stage internals
Helpers the interface and the drivers define but do not export, including each driver's SDK bindings.
MicroscopeControl.HardwareInterfaces.StageInterface.StageFormat — Type
StageFormatGeneric 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.
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
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.
MicroscopeControl.HardwareImplementations.PI._waitforready — Method
Poll PI_IsControllerReady every 0.1 s until the controller reports ready; throw if the call fails or it is not ready within timeout seconds.
[limitation] Not yet run on hardware; the wait needs a rig check on the C-867.
MicroscopeControl.HardwareImplementations.PI._waitforreference — Method
Poll PI_qFRF until both axes report referenced; throw if that has not happened within timeout seconds or the query itself fails.
MicroscopeControl.HardwareImplementations.PI._waitforstop — Method
Poll PI_IsMoving every 0.1 s until neither axis is moving; throw if the query fails or motion has not stopped within timeout seconds. Query only: it sends no motion command.
MicroscopeControl.HardwareImplementations.PI.getposition — Method
Function to update the position of the PI Stage
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.
MicroscopeControl.HardwareImplementations.PI.move — Method
Function to move PI Stage to a specific position
MicroscopeControl.HardwareImplementations.PI.servo — Method
Sets the servo state of both the x and y axis
MicroscopeControl.HardwareImplementations.PI.shutdown_original — Method
Function to disconnect PI Stage
MicroscopeControl.HardwareImplementations.PI.stopmotion — Method
Function call to smoothly stop motion of the PI Stage
MicroscopeControl.HardwareImplementations.PI_N472._cstring — Method
_cstring(buf) -> StringThe bytes of buf up to its first NUL, as a String.
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.
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.
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.
MicroscopeControl.HardwareImplementations.MCS2Stage_mod.getposition! — Method
getposition!(stage) -> Vector{Int64}Queries the current position of all channels, updates stage.pos_pm, and returns the values in picometres.
MicroscopeControl.HardwareImplementations.MCS2Stage_mod.home! — Method
home!(stage)Moves all channels to stage.home_pm (default: all zeros).
MicroscopeControl.HardwareImplementations.MCS2Stage_mod.initialize! — Method
initialize!(stage::MCS2Stage)Discovers the first available MCS2 device, opens it, configures all channels (CLF, hold time, velocity, acceleration), and reads travel limits.
After this call, stage.connectionstatus == true and stage.pos_pm holds the current hardware positions.
MicroscopeControl.HardwareImplementations.MCS2Stage_mod.move! — Method
move!(stage, targets_pm::Vector{Int64})Moves all channels to absolute positions given in picometres, then refreshes stage.pos_pm.
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.
MicroscopeControl.HardwareImplementations.MCS2Stage_mod.move_um! — Method
move_um!(stage, targets_um::Vector{Float64})Convenience overload: supply positions in micrometres (Float64). Internally converts to Int64 picometres.
MicroscopeControl.HardwareImplementations.MCS2Stage_mod.shutdown! — Method
shutdown!(stage::MCS2Stage)Closes the device connection. Safe to call even if not connected.
MicroscopeControl.HardwareImplementations.MCS2Stage_mod.stopmotion! — Method
stopmotion!(stage)Immediately stops all channels.