1'''
2Drive - Drive_velocity_blending_acceleration.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 speed = 50000
41 dir = 1
42 acceleration = 10000
43 deceleration = 10000
44 active_high = 1
45 en_forward = 1
46 en_reverse = 1
47 timeout = 3 ## second
48
49 ## Get firmware model & version
50 driver_info = dev.Sys_getDriverInfo(timeout)
51 print("Model name: " + driver_info[0])
52 print("Firmware version: " + driver_info[-1])
53
54 ## Motion open
55 err = dev.Motion_open(port, timeout)
56 print(f"Motion_open, status: {err}")
57
58 ## Motion configure
59 err = dev.Motion_cfgLimit(port, en_forward, en_reverse, active_high, timeout)
60 print(f"Motion_cfgLimit, status: {err}")
61
62 ## Motion reset
63 err = dev.Motion_rstEncoderPosi(port, timeout)
64 print(f"Motion_resetEncoderPosi, status: {err}")
65
66 ## Motion Servo on
67 err = dev.Motion_enableServoOn(port, timeout)
68 print(f"Motion_enableServoOn, status: {err}")
69
70 ## Motion start
71 err = dev.Motion_startVelocticyMove(port, speed, dir, acceleration, deceleration, timeout)
72 print(f"Motion_startVelocticyMove, status: {err}")
73
74 ## Wait for seconds for moving
75 time.sleep(3) ## delay [s]
76
77 ## Motion start
78 new_speed = 10000
79 new_dir = -1
80 new_acceleration = 20000
81 new_deceleration = 20000
82
83 err = dev.Motion_startVelocticyMove(port, new_speed, new_dir, new_acceleration, new_deceleration, timeout)
84 print(f"Motion_startVelocticyMove, status: {err}")
85
86 ## Wait for seconds for moving
87 time.sleep(3) ## delay [s]
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()