Skip to content

Move Stage

Controlling a motorized stage through the Inscoper API requires identifying the correct sub-devices within the loaded hardware configuration and issuing position commands through the bridge. This example demonstrates how to locate the stage control sub-devices and use them to read and update the stage position.

Prerequisites

This example builds on the device exploration pattern introduced in Explore Devices. The device map constructed in that example is reused here to locate the stage-specific sub-devices by their functional type.

Overview

Stage movement is controlled through three sub-device types:

Sub-device type Role
X_AXIS Holds and sets the position of the stage along the X axis (in nanometers)
Y_AXIS Holds and sets the position of the stage along the Y axis (in nanometers)
MOVE_AXIS Triggers the physical movement of the stage to the positions set on the axis sub-devices

The example iterates over the device map to locate sub-devices matching each of these types, then reads the current X and Y positions before issuing a new position command and triggering the move.

Note

This example uses a configuration named camera_and_microscope. Replace this value with the name defined in your own hardware configuration file. Stage control sub-devices must be present in that configuration, otherwise the example will raise an assertion error.

Stage control

# To move the stage we need to interact with the X_AXIS, Y_AXIS, and MOVE_XY sub-devices.
x_axis_sub_device_id = None
y_axis_sub_device_id = None
move_xy_sub_device_id = None
for device_id, device in device_map.items():
    for sub_device_tag, sub_device in device.sub_device_map.items():
        if sub_device.inscoper_type == "X_AXIS":
            x_axis_sub_device_id    = inscoper_api.SubDeviceId(device.name, sub_device.name)
        elif sub_device.inscoper_type == "Y_AXIS":
            y_axis_sub_device_id    = inscoper_api.SubDeviceId(device.name, sub_device.name)
        elif sub_device.inscoper_type == "MOVE_AXIS":
            move_xy_sub_device_id   = inscoper_api.SubDeviceId(device.name, sub_device.name)

# Check that stage control sub-devices were found in your config.
assert x_axis_sub_device_id is not None,"No X axis position sub-device was found. Check your configuration."
assert y_axis_sub_device_id is not None,"No Y axis position sub-device was found. Check your configuration."
assert move_xy_sub_device_id is not None,"No move action sub_device was found. Check your configuration."

# Read the current values for the x/y positions.
current_x = my_bridge.getIntValue(x_axis_sub_device_id)
current_y = my_bridge.getIntValue(y_axis_sub_device_id)

print(f"X axis position sub-device: {x_axis_sub_device_id.getName()}. Current value: {current_x} nm")
print(f"Y axis position sub-device: {y_axis_sub_device_id.getName()}. Current value: {current_y} nm")
print(f"Move action sub-device: {move_xy_sub_device_id.getName()}")

# Set a new x position and order the stage to move
new_x_value = current_x - 1_000_000 # offset x position by 1 mm
my_bridge.setValue(x_axis_sub_device_id, new_x_value)
my_bridge.setValue(move_xy_sub_device_id)

# Did you see your stage move?