Motion find index

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