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-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 searching_speed = 50000
41 approaching_speed = 10000
42 acceleration = 10000
43 search_direction = 1 ## 1: pointing to forward, -1: pointing to reverse.
44 approach_direction = 1 ## 1: pointing to forward, -1: pointing to reverse.
45 offset = 0
46 reset_position = False
47 en_forward = 1
48 en_reverse = 1
49 active_high = 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 find home
74 err = dev.Motion_startFindHome(port, searching_speed, approaching_speed, acceleration, search_direction, approach_direction, offset, reset_position, timeout)
75 print(f"Motion_startFindHome, 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 get limit status
84 state_list = dev.Motion_getLimitStatus(port, timeout)
85 print(f"Forward limit status: {state_list[0]}")
86 print(f"Reverse limit status: {state_list[1]}")
87 print(f"Home status: {state_list[2]}")
88
89 except Exception as err:
90 pywpc.printGenericError(err)
91 except KeyboardInterrupt:
92 print("Press keyboard")
93 finally:
94 ## Motion stop
95 err = dev.Motion_stopProcess(port, timeout)
96 print(f"Motion_stopProcess, status: {err}")
97
98 ## Motion Servo off
99 err = dev.Motion_enableServoOff(port, timeout)
100 print(f"Motion_enableServoOff, status: {err}")
101
102 ## Motion close
103 err = dev.Motion_close(port, timeout)
104 print(f"Motion_close, status: {err}")
105
106 ## Disconnect device
107 dev.disconnect()
108
109 ## Release device handle
110 dev.close()
111
112if __name__ == '__main__':
113 main()