Drive position blending

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