forked from Jarvis-K/wechat_jump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
play_dobot.py
65 lines (50 loc) · 2.17 KB
/
play_dobot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import time
from DobotDll import DobotDllType as dType
CON_STR = {
dType.DobotConnect.DobotConnect_NoError: "DobotConnect_NoError",
dType.DobotConnect.DobotConnect_NotFound: "DobotConnect_NotFound",
dType.DobotConnect.DobotConnect_Occupied: "DobotConnect_Occupied"}
api = dType.load() # Load Dll
postion = [237.7514, 49.2358, -25.7501, 7.1569]
def init(speed=100, coordinate=4000):
dType.SetQueuedCmdClear(api)
dType.SetPTPJointParams(api, 200, 200, 200, 200, 200, 200, 200, 200, isQueued=1)
# dType.SetPTPJointParams(api, speed, speed, speed, speed, speed, speed, speed, speed, isQueued=1)
dType.SetPTPCoordinateParams(api, coordinate, coordinate, coordinate, coordinate, isQueued=1)
def press_screen(press_time):
dType.SetQueuedCmdClear(api)
init() if press_time > 450 else init(coordinate=9000)
waiting_time = press_time * 0.001
for i in range(0, 2):
offset = 20 if i % 2 == 0 else 0
last_index = dType.SetPTPCmd(api, dType.PTPMode.PTPMOVLXYZMode, postion[0], postion[1], postion[2]-offset, postion[3])[0]
dType.SetWAITCmd(api, waiting_time)
dType.SetQueuedCmdStartExec(api)
while last_index > dType.GetQueuedCmdCurrentIndex(api)[0]:
dType.dSleep(0)
dType.SetQueuedCmdStopExec(api)
dType.SetQueuedCmdClear(api)
def moveForward(offset=0):
"""
default offset = 0 means above the phone screen
when offset = -70, it means moveBackward, (to let the camera get the image)
"""
dType.SetQueuedCmdClear(api)
init()
last_index = dType.SetPTPCmd(api, dType.PTPMode.PTPMOVLXYZMode,postion[0]+offset,postion[1],postion[2],postion[3])[0] # 移动
dType.SetQueuedCmdStartExec(api)
while last_index > dType.GetQueuedCmdCurrentIndex(api)[0]:
dType.dSleep(0)
dType.SetQueuedCmdStopExec(api)
dType.SetQueuedCmdClear(api)
def play_1_loop(press_time):
dobot_state = dType.ConnectDobot(api, "", 115200)[0]
if dobot_state == dType.DobotConnect.DobotConnect_NoError:
moveForward()
press_screen(press_time)
time.sleep(1.7)
moveForward(offset=-70)
dType.DisconnectDobot(api)
time.sleep(4)
if __name__ == '__main__':
play_1_loop(555)