-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
62 lines (45 loc) · 1.54 KB
/
app.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
import threading
import DobotDllType as dType
from flask import Flask
app = Flask(__name__)
#Load Dll
api = dType.load()
@app.route('/')
def index():
return 'Server Works!'
@app.route('/greet')
def say_hello():
return 'Hello from Server'
@app.route('/connect')
def connect_dobot():
CON_STR = {
dType.DobotConnect.DobotConnect_NoError: "DobotConnect_NoError",
dType.DobotConnect.DobotConnect_NotFound: "DobotConnect_NotFound",
dType.DobotConnect.DobotConnect_Occupied: "DobotConnect_Occupied"}
#Connect Dobot
state = dType.ConnectDobot(api, "", 115200)[0]
return "Connect status:" + CON_STR[state]
@app.route('/home')
def home_dobot():
#Clean Command Queued
dType.SetQueuedCmdClear(api)
#Async Motion Params Setting
dType.SetHOMEParams(api, 250, 0, 50, 0, isQueued = 1)
dType.SetPTPJointParams(api, 200, 200, 200, 200, 200, 200, 200, 200, isQueued = 1)
dType.SetPTPCommonParams(api, 100, 100, isQueued = 1)
#Async Home
lastIndex=dType.SetHOMECmd(api, temp = 0, isQueued = 1)[0]
lastIndex=lastIndex
#Start to Execute Command Queued
dType.SetQueuedCmdStartExec(api)
#Wait for Executing Last Command
while lastIndex > dType.GetQueuedCmdCurrentIndex(api)[0]:
dType.dSleep(100)
#Stop to Execute Command Queued
dType.SetQueuedCmdStopExec(api)
return 'Homing'
@app.route('/disconnect')
def disconnect_dobot():
#Disconnect Dobot
dType.DisconnectDobot(api)
return 'Disconnected'