Drive find home

  1'''
  2Drive - Drive_find_home.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.EDriveST()
 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        searching_speed = 50000
 38        approaching_speed = 10000
 39        acceleration = 10000
 40        search_direction = 1  ## 1: pointing to forward, -1: pointing to reverse.
 41        approach_direction = 1  ## 1: pointing to forward, -1: pointing to reverse.
 42        offset = 0
 43        reset_position = False
 44        en_forward = 1
 45        en_reverse = 1
 46        active_high = 1
 47        timeout = 3  ## [sec]
 48
 49        ## Get firmware model & version
 50        driver_info = dev.Sys_getDriverInfo(timeout)
 51        print(f"Model name: {driver_info[0]}, Firmware version: {driver_info[-1]} ")
 52
 53        ## Motion open
 54        err = dev.Motion_open(port, timeout)
 55        print(f"Motion_open, status: {err}")
 56
 57        ## Motion configure
 58        err = dev.Motion_cfgLimit(port, en_forward, en_reverse, active_high, timeout)
 59        print(f"Motion_cfgLimit, status: {err}")
 60
 61        ## Motion reset
 62        err = dev.Motion_rstEncoderPosi(port, timeout)
 63        print(f"Motion_resetEncoderPosi, status: {err}")
 64
 65        ## Motion Servo on
 66        err = dev.Motion_enableServoOn(port, timeout)
 67        print(f"Motion_enableServoOn, status: {err}")
 68
 69        ## Motion find home
 70        err = dev.Motion_startFindHome(port, searching_speed, approaching_speed, acceleration, search_direction, approach_direction, offset, reset_position, timeout)
 71        print(f"Motion_startFindHome, status: {err}")
 72
 73        status = 1
 74        while status != 0:
 75            status = dev.Motion_getProcessState(port, timeout)
 76            if status == 0:
 77                print(f"Motion_getProcessState: {status}")
 78
 79        ## Motion get limit status
 80        state_list = dev.Motion_getLimitStatus(port, timeout)
 81        print(f"Forward limit status: {state_list[0]}")
 82        print(f"Reverse limit status: {state_list[1]}")
 83        print(f"Home status: {state_list[2]}")
 84
 85    except Exception as err:
 86        pywpc.printGenericError(err)
 87    except KeyboardInterrupt:
 88        print("Press keyboard")
 89    finally:
 90        ## Motion stop
 91        err = dev.Motion_stopProcess(port, timeout)
 92        print(f"Motion_stopProcess, status: {err}")
 93
 94        ## Motion Servo off
 95        err = dev.Motion_enableServoOff(port, timeout)
 96        print(f"Motion_enableServoOff, status: {err}")
 97
 98        ## Motion close
 99        err = dev.Motion_close(port, timeout)
100        print(f"Motion_close, status: {err}")
101
102        ## Disconnect device
103        dev.disconnect()
104
105        ## Release device handle
106        dev.close()
107
108
109if __name__ == '__main__':
110    main()