PI-PhysikInstrumente / PIPython

Python Library for using PI controllers with GCS command language
27 stars 3 forks source link

Simultaneous connection to several controllers is impossible #19

Closed nfrik closed 21 hours ago

nfrik commented 1 month ago

I tried to connect to 3 mercury C-863.11 stages simultaneous for coordinated movement and the library doesn't handle it. Is there a way to allow coordinated movement with mercury or at least simultaneous movement for these controllers?


from pipython import GCSDevice, pitools

CONTROLLERNAME = 'C-863.11'
STAGES_X = ['623491001_NF', ]
STAGES_Y = ['623491002_NF', ]
STAGES_Z = ['623491003_NF', ]
REFMODES = ['FNL', ]

SERIAL_X = '1231'
SERIAL_Y = '1232'
SERIAL_Z = '1233'

def move_axis(pidevice, axis, target):
    print('move axis {} to {:.2f}'.format(axis, target))
    pidevice.MOV(axis, target)

def wait_for_all(pidevice_x, pidevice_y, pidevice_z):
    pitools.waitontarget(pidevice_x)
    pitools.waitontarget(pidevice_y)
    pitools.waitontarget(pidevice_z)
    print('All axes have reached their targets.')

def main():
    coordinates = [(0, 0, 0), (1, 1, 1), (2, 2, 2), (3, 3, 3)]  # Replace with your list of coordinates

    with GCSDevice(CONTROLLERNAME) as pidevice_x, \
            GCSDevice(CONTROLLERNAME) as pidevice_y, \
            GCSDevice(CONTROLLERNAME) as pidevice_z:

        # Connect to the devices
        pidevice_x.ConnectUSB(serialnum=SERIAL_X)
        pidevice_y.ConnectUSB(serialnum=SERIAL_Y)
        pidevice_z.ConnectUSB(serialnum=SERIAL_Z)

        print('connected X: {}'.format(pidevice_x.qIDN().strip()))
        print('connected Y: {}'.format(pidevice_y.qIDN().strip()))
        print('connected Z: {}'.format(pidevice_z.qIDN().strip()))

        if pidevice_x.HasqVER():
            print('X version info:\n{}'.format(pidevice_x.qVER().strip()))
        if pidevice_y.HasqVER():
            print('Y version info:\n{}'.format(pidevice_y.qVER().strip()))
        if pidevice_z.HasqVER():
            print('Z version info:\n{}'.format(pidevice_z.qVER().strip()))

        # Initialize connected stages
        pitools.startup(pidevice_x, stages=STAGES_X, refmodes=REFMODES)
        pitools.startup(pidevice_y, stages=STAGES_Y, refmodes=REFMODES)
        pitools.startup(pidevice_z, stages=STAGES_Z, refmodes=REFMODES)

        desired_speed = 5  # Set your desired speed here, units depending on your setup
        pidevice_x.VEL(axes=1, values=desired_speed)  # Set velocity limit for the X axis
        pidevice_y.VEL(axes=1, values=desired_speed)  # Set velocity limit for the Y axis
        pidevice_z.VEL(axes=1, values=desired_speed)  # Set velocity limit for the Z axis

        for coord in coordinates:
            x_target, y_target, z_target = coord
            if x_target is not None:
                move_axis(pidevice_x, 1, x_target)
            if y_target is not None:
                move_axis(pidevice_y, 1, y_target)
            if z_target is not None:
                move_axis(pidevice_z, 1, z_target)

            wait_for_all(pidevice_x, pidevice_y, pidevice_z)

        print('done')

if __name__ == '__main__':
    main()
DetlefMaurel commented 1 month ago

In general, PIPython is able to handle several simultaneous connections. Could you please enable log output, run your code again and provide us the output? To enable logging output, add the following lines before the call to the main-function

from pipython import PILogger, DEBUG, INFO, WARNING, ERROR, CRITICAL PILogger.setLevel(DEBUG)

DetlefMaurel commented 3 weeks ago

As long as all three stages are connected to different controllers and operated by a non real time operating system, precise simultaneous movement is not possible. However, the appropriate solution depends on your application and time requirements. Please refer to Physik Instrumente Service at service@pi.de for further recommendations.

Software-PhysikInstrumente commented 21 hours ago

Works as designed.