Motion 2axis linear interpo

  1'''
  2Motion - Motion_2axis_linear_interpolation.py with synchronous mode.
  3
  4-------------------------------------------------------------------------------------
  5Please change correct serial number or IP and port number BEFORE you run example code.
  6
  7For other examples please check:
  8    https://github.com/WPC-Systems-Ltd/WPC_Python_driver_release/tree/main/examples
  9See README.md file to get detailed usage of this example.
 10
 11Copyright (c) 2022-2024 WPC Systems Ltd. All rights reserved.
 12'''
 13
 14## Python
 15import time
 16
 17## WPC
 18
 19from wpcsys import pywpc
 20
 21def main():
 22    ## Get Python driver version
 23    print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
 24
 25    ## Create device handle
 26    dev = pywpc.EMotion()
 27
 28    ## Connect to device
 29    try:
 30        dev.connect("192.168.1.110") ## Depend on your device
 31    except Exception as err:
 32        pywpc.printGenericError(err)
 33        ## Release device handle
 34        dev.close()
 35        return
 36
 37    try:
 38        ## Parameters setting
 39        port = 0 ## Depend on your device
 40        stop_decel = 0
 41        timeout = 3 ## second
 42
 43        ## Linear interpolation parameters
 44        axis1 = 0
 45        dest_posi1 = 2000
 46        axis2 = 1
 47        dest_posi2 = 2000
 48
 49        ## Get firmware model & version
 50        driver_info = dev.Sys_getDriverInfo(timeout)
 51        print("Model name: " + driver_info[0])
 52        print("Firmware version: " + driver_info[-1])
 53
 54        ## Motion open
 55        err = dev.Motion_open(port, timeout)
 56        print(f"Motion_open in port {port}, status: {err}")
 57
 58        ## Motion open configuration file
 59        err = dev.Motion_openCfgFile('C:/Users/user/Desktop/3AxisStage_2P.ini')
 60        print(f"Motion_openCfgFile, status: {err}")
 61
 62        ## Motion load configuration file
 63        err = dev.Motion_loadCfgFile(timeout)
 64        print(f"Motion_loadCfgFile, status: {err}")
 65
 66        ## Motion configure
 67        err = dev.Motion_cfg2AxisLinearInterpo(port, axis1, dest_posi1, axis2, dest_posi2, speed=2000, accel=100000, decel=100000, timeout)
 68        print(f"Motion_cfg2AxisLinearInterpo in axis{axis1} and {axis2}, status: {err}")
 69
 70        ## Motion start
 71        err = dev.Motion_startLinearInterpo(port, timeout)
 72        print(f"Motion_startLinearInterpo in port {port}, status: {err}")
 73
 74        move_status = 0
 75        while move_status == 0:
 76            axis1_move_status = dev.Motion_getMoveStatus(port, axis1, timeout)
 77            axis2_move_status = dev.Motion_getMoveStatus(port, axis2, timeout)
 78            move_status = axis1_move_status & axis2_move_status
 79            if move_status == 0:
 80                print("Moving......")
 81            else:
 82                print("Move completed")
 83
 84        ## Motion stop
 85        for i in [axis1, axis2]:
 86            err = dev.Motion_stop(port, i, stop_decel, timeout)
 87            print(f"Motion_stop in axis{i}, status: {err}")
 88
 89        ## Motion close
 90        err = dev.Motion_close(port, timeout)
 91        print(f"Motion_close in port {port}, status: {err}")
 92    except Exception as err:
 93        pywpc.printGenericError(err)
 94
 95    ## Disconnect device
 96    dev.disconnect()
 97
 98    ## Release device handle
 99    dev.close()
100
101    return
102
103if __name__ == '__main__':
104    main()