Motion 3axis helical interpo

  1'''
  2Motion - Motion_3axis_helical_interpolation.py with asynchronous 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 asyncio
 16
 17## WPC
 18
 19from wpcsys import pywpc
 20
 21async def 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        axis = 0
 41        stop_decel = 0
 42
 43        ## Helical parameters
 44        center_x = 0
 45        center_y = 0
 46        finish_x = 100
 47        finish_y = 100
 48        pitch_axis3 = 0
 49        pitch_axis4 = 0
 50        rotation_num = 0
 51        speed = 0
 52        cal_timeout = 1000
 53        helical_dir_cw = 0
 54
 55        ## Get firmware model & version
 56        driver_info = await dev.Sys_getDriverInfo_async()
 57        print("Model name: " + driver_info[0])
 58        print("Firmware version: " + driver_info[-1])
 59
 60        ## Motion open
 61        err = await dev.Motion_open_async(port)
 62        print(f"open_async in port {port}, status: {err}")
 63
 64        ## Motion open configuration file
 65        err = await dev.Motion_openCfgFile_async('C:/Users/user/Desktop/3AxisStage_2P.ini')
 66        print(f"openCfgFile_async, status: {err}")
 67
 68        ## Motion load configuration file
 69        err = await dev.Motion_loadCfgFile_async()
 70        print(f"loadCfgFile_async, status: {err}")
 71
 72        ## Motion configure
 73        err = await dev.Motion_cfgHelicalInterpo_async(port, center_x, center_y, finish_x, finish_y, int(False), pitch_axis3, int(False), pitch_axis4, rotation_num,
 74        speed, helical_dir_cw, cal_timeout)
 75        print(f"cfgHelicalInterpo_async in axis{axis}, status: {err}")
 76
 77        ## Motion start
 78        err = await dev.Motion_startHelicalInterpo_async(port)
 79        print(f"startHelicalInterpo_async in axis{axis}, status: {err}")
 80
 81        move_status = 0
 82        while move_status == 0:
 83            move_status = await dev.Motion_getMoveStatus_async(port, axis)
 84            print(f"getMoveStatus_async in axis{axis}: {move_status}")
 85
 86        ## Motion stop
 87        err = await dev.Motion_stop_async(port, axis, stop_decel)
 88        print(f"stop_async in axis{axis}, status: {err}")
 89
 90        ## Motion close
 91        err = await dev.Motion_close_async(port)
 92        print(f"close_async in port {port}, status: {err}")
 93    except Exception as err:
 94        pywpc.printGenericError(err)
 95
 96    ## Disconnect device
 97    dev.disconnect()
 98
 99    ## Release device handle
100    dev.close()
101
102    return
103
104def main_for_spyder(*args):
105    if asyncio.get_event_loop().is_running():
106        return asyncio.create_task(main(*args)).result()
107    else:
108        return asyncio.run(main(*args))
109
110if __name__ == '__main__':
111    asyncio.run(main()) ## Use terminal
112    # await main() ## Use Jupyter or IPython(>=7.0)
113    # main_for_spyder() ## Use Spyder