1'''
2Motion - Motion_2axis_circular_interpolation.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.EMotion()
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 axis = 0
41 stop_decel = 0
42 rel_posi_mode = 1
43 timeout = 3 ## second
44
45 ## Circular interpolation parameters
46 x_axis = 0
47 y_axis = 1
48 center_point_x = 2000
49 center_point_y = 2000
50 finish_point_x = 0
51 finish_point_y = 0
52 circular_dir_cw = 0
53
54 ## jerk and acceletation mode parameters setting
55 scurve = 1
56 jerk = 1
57
58 ## Get firmware model & version
59 driver_info = dev.Sys_getDriverInfo(timeout)
60 print("Model name: " + driver_info[0])
61 print("Firmware version: " + driver_info[-1])
62
63 ## Motion open
64 err = dev.Motion_open(port, timeout)
65 print(f"Motion_open in port {port}, status: {err}")
66
67 ## Motion open configuration file
68 err = dev.Motion_openCfgFile('C:/Users/user/Desktop/3AxisStage_2P.ini')
69 print(f"Motion_openCfgFile, status: {err}")
70
71 ## Motion load configuration file
72 err = dev.Motion_loadCfgFile(timeout)
73 print(f"Motion_loadCfgFile, status: {err}")
74
75 ## Motion configure
76 err = dev.Motion_cfgCircularInterpo(port, x_axis, y_axis, center_point_x, center_point_y, finish_point_x, finish_point_y, circular_dir_cw, speed=1000, accel=100000, decel=100000, timeout=timeout)
77 print(f"Motion_cfgCircularInterpo in port {port}, status: {err}")
78
79 err = dev.Motion_startCircularInterpo(port, timeout)
80 print(f"Motion_startCircularInterpo in axis{axis}, status: {err}")
81
82 err = dev.Motion_cfgAxisMove(port, axis, rel_posi_mode, target_posi=5000, velo=10000, accel=100000, decel=100000, timeout=timeout)
83 print(f"Motion_cfgAxisMove in axis{axis}, status: {err}")
84
85 err = dev.Motion_cfgJerkAndAccelMode(port, axis, jerk, scurve, timeout)
86 print(f"Motion_cfgJerkAndAccelMode in axis{axis}, status: {err}")
87
88 err = dev.Motion_rstEncoderPosi(port, axis, encoder_posi=0, timeout=timeout)
89 print(f"Motion_rstEncoderPosi in axis{axis}, status: {err}")
90
91 for i in range(4):
92 err = dev.Motion_enableServoOn(port, i, timeout)
93 print(f"Motion_enableServoOn in axis{i}, status: {err}")
94
95 ## Motion start
96 err = dev.Motion_startSingleAxisMove(port, axis, timeout)
97 print(f"Motion_startSingleAxisMove in axis{axis}, status: {err}")
98
99 move_status = 0
100 while move_status == 0:
101 x_axis_move_status = dev.Motion_getMoveStatus(port, x_axis, timeout)
102 y_axis_move_status = dev.Motion_getMoveStatus(port, y_axis, timeout)
103 move_status = x_axis_move_status & y_axis_move_status
104 if move_status == 0:
105 print("Moving......")
106 else:
107 print("Move completed")
108
109 ## Motion stop
110 err = dev.Motion_stop(port, axis, stop_decel, timeout)
111 print(f"Motion_stop in axis{axis}, status: {err}")
112
113 for i in range(4):
114 err = dev.Motion_enableServoOff(port, i, timeout)
115 print(f"Motion_enableServoOff in axis{i}, status: {err}")
116
117 ## Motion close
118 err = dev.Motion_close(port, timeout)
119 print(f"Motion_close in port {port}, status: {err}")
120 except Exception as err:
121 pywpc.printGenericError(err)
122
123 ## Disconnect device
124 dev.disconnect()
125
126 ## Release device handle
127 dev.close()
128
129 return
130
131if __name__ == '__main__':
132 main()