Drive position move

  1'''
  2Drive - Drive_position_move.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.EDriveST()
 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        position = 50000
 41        speed = 50000
 42        acceleration = 10000
 43        deceleration = 10000
 44        mode = 1 ## 0: absolute, 1: relative.
 45        active_high = 1
 46        en_forward = 1
 47        en_reverse = 1
 48        timeout = 3 ## second
 49
 50        ## Get firmware model & version
 51        driver_info = dev.Sys_getDriverInfo(timeout)
 52        print("Model name: " + driver_info[0])
 53        print("Firmware version: " + driver_info[-1])
 54
 55        ## Motion open
 56        err = dev.Motion_open(port, timeout)
 57        print(f"Motion_open, status: {err}")
 58
 59        ## Motion configure
 60        err = dev.Motion_cfgLimit(port, en_forward, en_reverse, active_high, timeout)
 61        print(f"Motion_cfgLimit, status: {err}")
 62
 63        ## Motion reset
 64        err = dev.Motion_rstEncoderPosi(port, timeout)
 65        print(f"Motion_resetEncoderPosi, status: {err}")
 66
 67        ## Motion Servo on
 68        err = dev.Motion_enableServoOn(port, timeout)
 69        print(f"Motion_enableServoOn, status: {err}")
 70
 71        ## Motion start
 72        err = dev.Motion_startPositionMove(port, position, speed, acceleration, deceleration, mode, timeout)
 73        print(f"Motion_start, status: {err}")
 74
 75        status = 1
 76        while status != 0 :
 77            status = dev.Motion_getProcessState(port, timeout)
 78            if(status == 0):
 79                print(f"Motion_getProcessState: {status}")
 80    except Exception as err:
 81        pywpc.printGenericError(err)
 82    except KeyboardInterrupt:
 83        print("Press keyboard")
 84    finally:
 85        ## Motion stop
 86        err = dev.Motion_stopProcess(port, timeout)
 87        print(f"Motion_stopProcess, status: {err}")
 88
 89        ## Motion Servo off
 90        err = dev.Motion_enableServoOff(port, timeout)
 91        print(f"Motion_enableServoOff, status: {err}")
 92
 93        ## Motion close
 94        err = dev.Motion_close(port, timeout)
 95        print(f"Motion_close, status: {err}")
 96
 97    ## Disconnect device
 98    dev.disconnect()
 99
100    ## Release device handle
101    dev.close()
102
103if __name__ == '__main__':
104    main()