-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
77 lines (63 loc) · 1.64 KB
/
main.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
66
67
68
69
70
71
72
73
74
75
76
77
# import eventlet
# eventlet.monkey_patch()
from flask import Flask, render_template, Response
from flask_socketio import SocketIO
from flask_socketio import emit
from TankController import *
from XYZController import *
from imutils.video import VideoStream
import imutils
import threading
import json
import cv2
import argparse
from imutils.video import FPS
from flask import render_template
app = Flask(__name__)
outputFrame = None
# app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app,cors_allowed_origins='*')
#BootStrap
# Start Tank
motor_init()
#Start Servos
# initializeServos()
time.sleep(2)
@socketio.on('command')
def commandFunction(payload):
command = payload["actionType"]
print(command)
if command == "moveUp":
run(1)
elif command == "moveDown" :
back(1)
elif command == "moveRight" :
right(1)
elif command == "moveLeft" :
left(1)
pass
elif command == "stopTankMovement" :
brake(1)
pass
elif command == "spinTankRight" :
spin_right(1)
pass
elif command == "spinTankLeft" :
spin_left(1)
pass
@socketio.on('connect')
def handle_connection():
print('Connected')
#For Servos to move by degrees
@socketio.on('moveServos')
def doMoveServos(payload):
print("Received Payload")
print( payload )
axis = payload.axis
direction = payload.direction
# moveServos(axis,direction)
if __name__ == '__main__':
# socketio.start_background_task(gen)
socketio.run(app,debug=True, use_reloader=False,host="0.0.0.0")
# app.run(host='0.0.0.0', port =8000, debug=False, threaded=True)
# vs.stop()