-
Notifications
You must be signed in to change notification settings - Fork 0
/
quadlive.py
103 lines (93 loc) · 2.66 KB
/
quadlive.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"""
author: Tim Leonard Straube
email: [email protected]
"""
import config
import numpy
from flask import Flask
from flask import render_template
from flask import request
from flask import jsonify
from quadtest import Testbench
from quadserial import Quadserial
from quaternion import Quaternion
deg2rad = numpy.pi / 180.0
app = Flask(__name__)
testbench = Testbench()
try:
sampleSerial = Quadserial()
quad_connected = True
except:
print("Für Quadtest Quadcopter verbinden.")
quad_connected = False
quaternion = Quaternion()
@app.route('/', methods=['GET', 'POST', 'HEAD'])
def home():
if request.method == 'POST':
# Winkel in rad
if config.model_id[1] == "P":
(
t,
north,
east,
down,
roll,
pitch,
yaw
) = testbench.testPID()
elif config.model_id[1] == "M":
(
t,
north,
east,
down,
roll,
pitch,
yaw
) = testbench.testModell()
else:
print("Invalid controller type.")
# t [s], NED [m], Attitude [rad]
quad_state = jsonify({
"t" : t,
"north" : north,
"east" : east,
"down" : down,
"roll" : roll,
"pitch" : pitch,
"yaw" : yaw
})
return quad_state
else:
testbench.reset()
return render_template('simulation.html')
@app.route('/sensortest/', methods=['GET', 'POST', 'HEAD'])
def sensortest():
if request.method == 'POST':
if quad_connected:
sampleSerial.startEinmalsampler()
samples = sampleSerial.sample_current.tolist()
else:
samples = numpy.array([[0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0]])
# kardan = quaternion.quaternion2cardan([
# samples[16][0],
# samples[17][0],
# samples[18][0],
# samples[19][0]
# ])
# Winkel in rad
quad_state = jsonify({
"t" : 0,
"north" : 0,
"east" : 0,
"down" : 0,
"roll" : float(samples[5][0]) * deg2rad,
"pitch" : float(samples[4][0]) * deg2rad,
"yaw" : float(samples[3][0]) * deg2rad
})
return quad_state
else:
testbench.reset()
return render_template('sensortest.html')
if __name__ == '__main__':
app.run(host="localhost", debug=True)