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