1'''
2Motion - Motion_1axis_move_with_breakpoint.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 rel_posi_mode = 1
42 stop_decel = 0
43 timeout = 3 ## second
44
45 ## Polarity and enable parameters
46 active_low = 0
47 active_high = 1
48
49 ## Breakpoint parameters
50 start_position = 100
51 pulse_width = 100
52 pulse_period = 100
53 pulse_number = 100
54
55 ## Get firmware model & version
56 driver_info = dev.Sys_getDriverInfo(timeout)
57 print("Model name: " + driver_info[0])
58 print("Firmware version: " + driver_info[-1])
59
60 ## Motion open
61 err = dev.Motion_open(port, timeout)
62 print(f"Motion_open in port {port}, status: {err}")
63
64 ## Motion open configuration file
65 err = dev.Motion_openCfgFile('C:/Users/user/Desktop/3AxisStage_2P.ini')
66 print(f"Motion_openCfgFile, status: {err}")
67
68 ## Motion load configuration file
69 err = dev.Motion_loadCfgFile(timeout)
70 print(f"Motion_loadCfgFile, status: {err}")
71
72 ## Motion configure
73 err = dev.Motion_cfgBreakPoint(port, axis, rel_posi_mode, active_high, start_position, pulse_width, pulse_period, pulse_number, timeout)
74 print(f"Motion_cfgBreakPoint in axis{axis}, status: {err}")
75
76 err = dev.Motion_enableBreakPoint(port, axis, int(True), timeout)
77 print(f"Motion_enableBreakPoint in axis{axis}, status: {err}")
78
79 err = dev.Motion_cfgAxisMove(port, axis, rel_posi_mode, target_posi=5000, velo=10000, accel=100000, decel=100000, timeout=timeout)
80 print(f"Motion_cfgAxisMove in axis{axis}, status: {err}")
81
82 err = dev.Motion_rstEncoderPosi(port, axis, encoder_posi=0, timeout=timeout)
83 print(f"Motion_rstEncoderPosi in axis{axis}, status: {err}")
84
85 ## Servo on
86 err = dev.Motion_enableServoOn(port, axis, timeout)
87 print(f"Motion_enableServoOn in axis{axis}, status: {err}")
88
89 ## Motion start
90 err = dev.Motion_startSingleAxisMove(port, axis, timeout)
91 print(f"Motion_startSingleAxisMove in axis{axis}, status: {err}")
92
93 move_status = 0
94 while move_status == 0:
95 move_status = dev.Motion_getMoveStatus(port, axis, timeout)
96 print(f"Motion_getMoveStatus in axis{axis}: {move_status}")
97
98 ## Motion stop
99 err = dev.Motion_stop(port, axis, stop_decel, timeout)
100 print(f"Motion_stop in axis{axis}, status: {err}")
101
102 ## Servo off
103 err = dev.Motion_enableServoOff(port, axis, timeout)
104 print(f"Motion_enableServoOff in axis{axis}, status: {err}")
105
106 ## Motion close
107 err = dev.Motion_close(port, timeout)
108 print(f"Motion_close in port {port}, status: {err}")
109 except Exception as err:
110 pywpc.printGenericError(err)
111
112 ## Disconnect device
113 dev.disconnect()
114
115 ## Release device handle
116 dev.close()
117
118 return
119
120if __name__ == '__main__':
121 main()