Motion 1axis move with breakpoint

  1'''
  2Motion - Motion_1axis_move_with_breakpoint.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-2025 WPC Systems Ltd. All rights reserved.
 12'''
 13
 14## WPC
 15from wpcsys import pywpc
 16
 17
 18def main():
 19    ## Get Python driver version
 20    print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
 21
 22    ## Create device handle
 23    dev = pywpc.EMotion()
 24
 25    ## Connect to device
 26    try:
 27        dev.connect("192.168.1.110")  ## Depend on your device
 28    except Exception as err:
 29        pywpc.printGenericError(err)
 30        ## Release device handle
 31        dev.close()
 32        return
 33
 34    try:
 35        ## Parameters setting
 36        port = 0  ## Depend on your device
 37        axis = 0
 38        rel_posi_mode = 1
 39        stop_decel = 0
 40        timeout = 3  ## [sec]
 41
 42        ## Polarity and enable parameters
 43        active_low = 0
 44        active_high = 1
 45
 46        ## Breakpoint parameters
 47        start_position = 100
 48        pulse_width = 100
 49        pulse_period = 100
 50        pulse_number = 100
 51
 52        ## Get firmware model & version
 53        driver_info = dev.Sys_getDriverInfo(timeout)
 54        print(f"Model name: {driver_info[0]}, Firmware version: {driver_info[-1]} ")
 55
 56        ## Motion open
 57        err = dev.Motion_open(port, timeout)
 58        print(f"Motion_open in port {port}, status: {err}")
 59
 60        ## Motion open configuration file
 61        err = dev.Motion_openCfgFile('C:/Users/user/Desktop/3AxisStage_2P.ini')
 62        print(f"Motion_openCfgFile, status: {err}")
 63
 64        ## Motion load configuration file
 65        err = dev.Motion_loadCfgFile(timeout)
 66        print(f"Motion_loadCfgFile, status: {err}")
 67
 68        ## Motion configure
 69        err = dev.Motion_cfgBreakPoint(port, axis, rel_posi_mode, active_high, start_position, pulse_width, pulse_period, pulse_number, timeout)
 70        print(f"Motion_cfgBreakPoint in axis{axis}, status: {err}")
 71
 72        err = dev.Motion_enableBreakPoint(port, axis, int(True), timeout)
 73        print(f"Motion_enableBreakPoint in axis{axis}, status: {err}")
 74
 75        err = dev.Motion_cfgAxisMove(port, axis, rel_posi_mode, target_posi=5000, velo=10000, accel=100000, decel=100000, timeout=timeout)
 76        print(f"Motion_cfgAxisMove in axis{axis}, status: {err}")
 77
 78        err = dev.Motion_rstEncoderPosi(port, axis, encoder_posi=0, timeout=timeout)
 79        print(f"Motion_rstEncoderPosi in axis{axis}, status: {err}")
 80
 81        ## Servo on
 82        err = dev.Motion_enableServoOn(port, axis, timeout)
 83        print(f"Motion_enableServoOn in axis{axis}, status: {err}")
 84
 85        ## Motion start
 86        err = dev.Motion_startSingleAxisMove(port, axis, timeout)
 87        print(f"Motion_startSingleAxisMove in axis{axis}, status: {err}")
 88
 89        move_status = 0
 90        while move_status == 0:
 91            move_status = dev.Motion_getMoveStatus(port, axis, timeout)
 92            print(f"Motion_getMoveStatus in axis{axis}: {move_status}")
 93
 94        ## Motion stop
 95        err = dev.Motion_stop(port, axis, stop_decel, timeout)
 96        print(f"Motion_stop in axis{axis}, status: {err}")
 97
 98        ## Servo off
 99        err = dev.Motion_enableServoOff(port, axis, timeout)
100        print(f"Motion_enableServoOff in axis{axis}, status: {err}")
101
102        ## Motion close
103        err = dev.Motion_close(port, timeout)
104        print(f"Motion_close in port {port}, status: {err}")
105    except Exception as err:
106        pywpc.printGenericError(err)
107
108    finally:
109        ## Disconnect device
110        dev.disconnect()
111
112        ## Release device handle
113        dev.close()
114
115
116if __name__ == '__main__':
117    main()