Motion position blending

  1'''
  2Motion - Motion_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.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        two_pulse_mode = 1
 42        rel_posi_mode = 1
 43        stop_decel = 0
 44        new_position = 0
 45        timeout = 3 ## second
 46
 47        ## Axis and encoder parameters
 48        axis_dir_cw = 0
 49        encoder_dir_cw = 0
 50
 51        ## Polarity and enable parameters
 52        active_low = 0
 53        active_high = 1
 54        forward_enable_true = 1
 55        reverse_enable_true = 1
 56        home_enable_false = 0
 57
 58        ## Get firmware model & version
 59        driver_info = dev.Sys_getDriverInfo(timeout)
 60        print("Model name: " + driver_info[0])
 61        print("Firmware version: " + driver_info[-1])
 62
 63        ## Motion open
 64        err = dev.Motion_open(port, timeout)
 65        print(f"Motion_open in port {port}, status: {err}")
 66
 67        '''
 68        ## Motion open configuration file
 69        err = dev.Motion_openCfgFile('C:/Users/user/Desktop/3AxisStage_2P.ini')
 70        print(f"openCfgFile, status: {err}")
 71
 72        ## Motion load configuration file
 73        err = dev.Motion_loadCfgFile()
 74        print(f"loadCfgFile, status: {err}")
 75        '''
 76
 77        ## Motion configure
 78        err = dev.Motion_cfgAxis(port, axis, two_pulse_mode, axis_dir_cw, encoder_dir_cw, active_low, timeout)
 79        print(f"Motion_cfgAxis in axis{axis}, status: {err}")
 80
 81        err = dev.Motion_cfgLimit(port, axis, forward_enable_true, reverse_enable_true, active_low, timeout)
 82        print(f"Motion_cfgLimit in axis{axis}, status: {err}")
 83
 84        err = dev.Motion_cfgHome(port, axis, home_enable_false, active_low, timeout)
 85        print(f"Motion_cfgHome in axis{axis}, status: {err}")
 86
 87        err = dev.Motion_cfgAxisMove(port, axis, rel_posi_mode, target_posi=5000, velo=10000, accel=100000, decel=100000, timeout=timeout)
 88        print(f"Motion_cfgAxisMove in axis{axis}, status: {err}")
 89
 90        err = dev.Motion_rstEncoderPosi(port, axis, encoder_posi=0, timeout=timeout)
 91        print(f"Motion_rstEncoderPosi in axis{axis}, status: {err}")
 92
 93        ## Servo on
 94        err = dev.Motion_enableServoOn(port, axis, timeout)
 95        print(f"Motion_enableServoOn in axis{axis}, status: {err}")
 96
 97        ## Motion start
 98        err = dev.Motion_startSingleAxisMove(port, axis, timeout)
 99        print(f"Motion_startSingleAxisMove in axis{axis}, status: {err}")
100
101        move_status = 0
102        while move_status == 0:
103            err = dev.Motion_overrideAxisPosi(port, axis, new_position, timeout)
104            # print(f"Motion_overrideAxisPosi in axis{axis}, status: {err}")
105            move_status = dev.Motion_getMoveStatus(port, axis, timeout)
106            logical_posi = dev.Motion_getLogicalPosi(port, axis, timeout)
107            encoder_posi = dev.Motion_getEncoderPosi(port, axis, timeout)
108            print(f"logical_posi: {logical_posi}, encoder_posi: {encoder_posi}")
109
110        ## Motion stop
111        err = dev.Motion_stop(port, axis, stop_decel, timeout)
112        print(f"Motion_stop in axis{axis}, status: {err}")
113
114        ## Servo off
115        err = dev.Motion_enableServoOff(port, axis, timeout)
116        print(f"Motion_enableServoOff in axis{axis}, status: {err}")
117
118        ## Motion close
119        err = dev.Motion_close(port, timeout)
120        print(f"Motion_close in port {port}, status: {err}")
121    except Exception as err:
122        pywpc.printGenericError(err)
123
124    ## Disconnect device
125    dev.disconnect()
126
127    ## Release device handle
128    dev.close()
129
130    return
131
132if __name__ == '__main__':
133    main()