1'''
2Motion - Motion_3axis_synchronous_move.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 threading
16import time
17import time
18## WPC
19
20from wpcsys import pywpc
21
22def Axis1_thread(handle, port, axis, delay=0.005):
23 move_status = 0
24 while move_status == 0:
25 move_status = handle.Motion_getMoveStatus(port, axis)
26 if move_status != 0:
27 print(f"Move completed axis {axis}...")
28 return move_status
29
30 ## Wait for seconds
31 time.sleep(delay) ## delay [s]
32
33def Axis2_thread(handle, port, axis, delay=0.005):
34 move_status = 0
35 while move_status == 0:
36 move_status = handle.Motion_getMoveStatus(port, axis)
37 if move_status != 0:
38 print(f"Move completed axis {axis}...")
39 return move_status
40
41 ## Wait for seconds
42 time.sleep(delay) ## delay [s]
43
44def Axis3_thread(handle, port, axis, delay=0.005):
45 move_status = 0
46 while move_status == 0:
47 move_status = handle.Motion_getMoveStatus(port, axis)
48 if move_status != 0:
49 print(f"Move completed axis {axis}...")
50 return move_status
51
52 ## Wait for seconds
53 time.sleep(delay) ## delay [s]
54
55def main():
56 ## Get Python driver version
57 print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
58
59 ## Create device handle
60 dev = pywpc.EMotion()
61
62 ## Connect to device
63 try:
64 dev.connect("192.168.1.110") ## Depend on your device
65 except Exception as err:
66 pywpc.printGenericError(err)
67 ## Release device handle
68 dev.close()
69 return
70
71 try:
72 ## Parameters setting
73 port = 0 ## Depend on your device
74 axis1 = 0
75 axis2 = 1
76 axis3 = 2
77 two_pulse_mode = 1
78 rel_posi_mode = 1
79 stop_decel = 0
80 timeout = 3 ## second
81
82 ## Axis and encoder parameters
83 axis_dir_cw = 0
84 encoder_dir_cw = 0
85
86 ## Polarity and enable parameters
87 active_low = 0
88 active_high = 1
89 forward_enable_false = 0
90 reverse_enable_false = 0
91
92 ## Define Axis1 ~ Axis3 thread
93 thread_1 = threading.Thread(target = Axis1_thread, args = [dev, port, axis1, 0.005])
94 thread_2 = threading.Thread(target = Axis2_thread, args = [dev, port, axis2, 0.005])
95 thread_3 = threading.Thread(target = Axis3_thread, args = [dev, port, axis3, 0.005])
96
97 ## Thread start
98 thread_1.start()
99 thread_2.start()
100 thread_3.start()
101
102 ## Get firmware model & version
103 driver_info = dev.Sys_getDriverInfo(timeout)
104 print("Model name: " + driver_info[0])
105 print("Firmware version: " + driver_info[-1])
106
107 ## Motion open
108 err = dev.Motion_open(port, timeout)
109 print(f"Motion_open in port {port}, status: {err}")
110
111 '''
112 ## Motion open configuration file
113 err = dev.Motion_openCfgFile('C:/Users/user/Desktop/3AxisStage_2P.ini')
114 print(f"openCfgFile, status: {err}")
115
116 ## Motion load configuration file
117 err = dev.Motion_loadCfgFile()
118 print(f"loadCfgFile, status: {err}")
119 '''
120
121 ## Motion configure for axis1
122 err = dev.Motion_cfgAxis(port, axis1, two_pulse_mode, axis_dir_cw, encoder_dir_cw, active_low, timeout)
123 print(f"Motion_cfgAxis in axis{axis1}, status: {err}")
124
125 err = dev.Motion_cfgLimit(port, axis1, forward_enable_false, reverse_enable_false, active_low, timeout)
126 print(f"Motion_cfgLimit in axis{axis1}, status: {err}")
127
128 err = dev.Motion_rstEncoderPosi(port, axis1, encoder_posi=0, timeout=timeout)
129 print(f"Motion_rstEncoderPosi in axis{axis1}, status: {err}")
130
131 err = dev.Motion_cfgAxisMove(port, axis1, rel_posi_mode, target_posi=1000, velo=10000, accel=100000, decel=100000, timeout)
132 print(f"Motion_cfgAxisMove in axis{axis1}, status: {err}")
133
134 err = dev.Motion_enableServoOn(port, axis1, timeout)
135 print(f"Motion_enableServoOn in axis{axis1}, status: {err}")
136
137 ## Motion configure for axis2
138 err = dev.Motion_cfgAxis(port, axis2, two_pulse_mode, axis_dir_cw, encoder_dir_cw, active_low, timeout)
139 print(f"Motion_cfgAxis in axis{axis2}, status: {err}")
140
141 err = dev.Motion_cfgLimit(port, axis2, forward_enable_false, reverse_enable_false, active_low, timeout)
142 print(f"cfgLimit in axis{axis2}, status: {err}")
143
144 err = dev.Motion_rstEncoderPosi(port, axis2, encoder_posi=0, timeout=timeout)
145 print(f"Motion_rstEncoderPosi in axis{axis2}, status: {err}")
146
147 err = dev.Motion_cfgAxisMove(port, axis2, rel_posi_mode, target_posi=1000, velo=10000, accel=100000, decel=100000, timeout=timeout)
148 print(f"Motion_cfgAxisMove in axis{axis2}, status: {err}")
149
150 err = dev.Motion_enableServoOn(port, axis2, timeout)
151 print(f"Motion_enableServoOn in axis{axis2}, status: {err}")
152
153 ## Motion configure for axis3
154 err = dev.Motion_cfgAxis(port, axis3, two_pulse_mode, axis_dir_cw, encoder_dir_cw, active_low, timeout)
155 print(f"Motion_cfgAxis in axis{axis3}, status: {err}")
156
157 err = dev.Motion_cfgLimit(port, axis3, forward_enable_false, reverse_enable_false, active_low, timeout)
158 print(f"Motion_cfgLimit in axis{axis3}, status: {err}")
159
160 err = dev.Motion_rstEncoderPosi(port, axis3, encoder_posi=0, timeout=timeout)
161 print(f"Motion_rstEncoderPosi in axis{axis3}, status: {err}")
162
163 err = dev.Motion_cfgAxisMove(port, axis3, rel_posi_mode, target_posi=-5000, velo=10000, accel=100000, decel=100000, timeout=timeout)
164 print(f"Motion_cfgAxisMove in axis{axis3}, status: {err}")
165
166 err = dev.Motion_enableServoOn(port, axis3, timeout)
167 print(f"Motion_enableServoOn in axis{axis3}, status: {err}")
168
169 ## Motion start
170 err = dev.Motion_startMultiAxisMove(port, [axis1, axis2, axis3], timeout)
171 print(f"Motion_startMultiAxisMove in port {port}, status: {err}")
172
173 ## Wait for thread completion
174 thread_1.join()
175 print("Axis1_Thread returned.")
176
177 thread_2.join()
178 print("Axis2_Thread returned.")
179
180 thread_3.join()
181 print("Axis3_Thread returned.")
182
183 for i in [axis1, axis2, axis3]:
184 err = dev.Motion_enableServoOff(port, i, timeout)
185 print(f"Motion_enableServoOff in axis{i}, status: {err}")
186
187 ## Motion stop
188 for i in [axis1, axis2, axis3]:
189 err = dev.Motion_stop(port, i, stop_decel, timeout)
190 print(f"Motion_stop in axis{i}, status: {err}")
191
192 ## Motion close
193 err = dev.Motion_close(port, timeout)
194 print(f"Motion_close in port {port}, status: {err}")
195 except Exception as err:
196 pywpc.printGenericError(err)
197
198 ## Disconnect device
199 dev.disconnect()
200
201 ## Release device handle
202 dev.close()
203
204 return
205
206if __name__ == '__main__':
207 main()