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