Motion 1axis move with capture

  1'''
  2Motion - Motion_1axis_move_with_capture.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        axis = 0
 41        rel_posi_mode = 1
 42        stop_decel = 0
 43        timeout = 3 ## second
 44
 45        ## Get firmware model & version
 46        driver_info = dev.Sys_getDriverInfo(timeout)
 47        print("Model name: " + driver_info[0])
 48        print("Firmware version: " + driver_info[-1])
 49
 50        ## Capture parameters setting
 51        rising_edge = 0
 52        capture_logical_position = 0
 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_cfgCapture(port, axis, rising_edge, capture_logical_position, timeout)
 68        print(f"Motion_cfgCapture in axis{axis}, status: {err}")
 69
 70        err = dev.Motion_enableCapture(port, axis, int(True), timeout)
 71        print(f"Motion_enableCapture in axis{axis}, status: {err}")
 72
 73        err = dev.Motion_cfgAxisMove(port, axis, rel_posi_mode, target_posi=5000, velo=10000, accel=100000, decel=100000, timeout=timeout)
 74        print(f"Motion_cfgAxisMove in axis{axis}, status: {err}")
 75
 76        err = dev.Motion_rstEncoderPosi(port, axis, encoder_posi=0, timeout=timeout)
 77        print(f"Motion_rstEncoderPosi in axis{axis}, status: {err}")
 78
 79        ## Servo on
 80        err = dev.Motion_enableServoOn(port, axis, timeout)
 81        print(f"Motion_enableServoOn in axis{axis}, status: {err}")
 82
 83        ## Motion start
 84        err = dev.Motion_startSingleAxisMove(port, axis, timeout)
 85        print(f"Motion_startSingleAxisMove in axis{axis}, status: {err}")
 86
 87        move_status = 0
 88        while move_status == 0:
 89            move_status = dev.Motion_getMoveStatus(port, axis, timeout)
 90            print(f"Motion_getMoveStatus in axis{axis}: {move_status}")
 91
 92            capture_points = dev.Motion_readCapturePoint(port, axis, timeout)
 93            print(f"Motion_readCapturePoint in axis{axis}: {capture_points}")
 94
 95        ## Motion stop
 96        err = dev.Motion_stop(port, axis, stop_decel, timeout)
 97        print(f"Motion_stop in axis{axis}, status: {err}")
 98
 99        ## Servo off
100        err = dev.Motion_enableServoOff(port, axis, timeout)
101        print(f"Motion_enableServoOff in axis{axis}, status: {err}")
102
103        ## Motion close
104        err = dev.Motion_close(port, timeout)
105        print(f"Motion_close in port {port}, status: {err}")
106    except Exception as err:
107        pywpc.printGenericError(err)
108
109    ## Disconnect device
110    dev.disconnect()
111
112    ## Release device handle
113    dev.close()
114
115    return
116
117if __name__ == '__main__':
118    main()