-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyze.py
174 lines (134 loc) · 5.42 KB
/
analyze.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/env python3
# coding: utf-8
# -*- coding: utf-8 -*-
import sys
import pyqtgraph as pg
import numpy as np
from numpy.core.function_base import logspace
import pyqtgraph.flowchart.library as fclib
from pyqtgraph.flowchart import Flowchart, Node
from pyqtgraph.flowchart.library.common import CtrlNode
from pyqtgraph.Qt import QtGui, QtCore
# import BufferNode and DIPPIDNode
from DIPPID_pyqtnode import BufferNode, DIPPIDNode
from DIPPID import SensorUDP, SensorSerial, SensorWiimote
'''
The script is implemented for the M5Stack and uses UDP port for connection.
Author: Jonas
Reviewer: Sarah
'''
# create NormalVectorNode
class NormalVectorNode(Node):
nodeName = "NormalVector"
def __init__(self, name):
terminals = {
'accel_x': dict(io='in'),
'accel_z': dict(io='in'),
'output_rotation': dict(io='out')
}
self.__output_vector = np.array([])
Node.__init__(self, name, terminals=terminals)
def process(self, **kwds):
normal_x = -kwds["accel_x"][0]
normal_z = kwds["accel_z"][0]
self.__output_vector = np.array(((0, 0), (normal_x, normal_z)))
return {'output_rotation': self.__output_vector}
fclib.registerNodeType(NormalVectorNode, [('Data', )])
# create LogNode
class LogNode(Node):
nodeName = "Log"
def __init__(self, name):
terminals = {
'accel_x': dict(io='in'),
'accel_y': dict(io='in'),
'accel_z': dict(io='in'),
'output': dict(io='out')
}
Node.__init__(self, name, terminals=terminals)
def process(self, **kwds):
log_data = {
"accel_x": kwds["accel_x"][0],
"accel_y": kwds["accel_y"][0],
"accel_z": kwds["accel_z"][0]
}
print(log_data)
return log_data
fclib.registerNodeType(LogNode, [('Log data', )])
def generate_plots():
win = QtGui.QMainWindow()
win.setWindowTitle('set title')
central_widget = QtGui.QWidget()
win.setCentralWidget(central_widget)
layout = QtGui.QGridLayout()
central_widget.setLayout(layout)
chart = Flowchart(terminals={'out': dict(io='out')})
layout.addWidget(chart.widget(), 0, 0, 2, 1)
# accelerometer_x
plot_widget_accel_x = pg.PlotWidget()
plot_widget_accel_x.setTitle('Plot for Accelerometer X')
plot_widget_accel_x.setYRange(-1, 1)
layout.addWidget(plot_widget_accel_x, 0, 1)
plot_widget_node_1 = chart.createNode('PlotWidget', pos=(300, -200))
plot_widget_node_1.setPlot(plot_widget_accel_x)
# accelerometer_y
plot_widget_accel_y = pg.PlotWidget()
layout.addWidget(plot_widget_accel_y, 0, 2)
plot_widget_accel_y.setTitle('Plot for Accelerometer Y')
plot_widget_accel_y.setYRange(-1, 1)
plot_widget_node_2 = chart.createNode('PlotWidget', pos=(300, -100))
plot_widget_node_2.setPlot(plot_widget_accel_y)
# accelerometer_z
plot_widget_accel_z = pg.PlotWidget()
layout.addWidget(plot_widget_accel_z, 1, 1)
plot_widget_accel_z.setTitle('Plot for Accelerometer Z')
plot_widget_accel_z.setYRange(-1, 1)
plot_widget_node_3 = chart.createNode('PlotWidget', pos=(300, 200))
plot_widget_node_3.setPlot(plot_widget_accel_z)
# normal vector
plot_widget_normal_vector = pg.PlotWidget()
layout.addWidget(plot_widget_normal_vector, 1, 2)
plot_widget_normal_vector.setTitle('Plot for NormalVectorNode')
plot_widget_normal_vector.setXRange(-1, 1)
plot_widget_normal_vector.setYRange(-1, 1)
plot_widget_node_4 = chart.createNode('PlotWidget', pos=(300, 100))
plot_widget_node_4.setPlot(plot_widget_normal_vector)
# create nodes
dippid_node = chart.createNode("DIPPID", pos=(0, 0))
buffer_node_accel_x = chart.createNode("Buffer", pos=(100, -200))
buffer_node_accel_y = chart.createNode("Buffer", pos=(130, -100))
buffer_node_accel_z = chart.createNode("Buffer", pos=(100, 200))
normal_vector_node = chart.createNode("NormalVector", pos=(130, 100))
log_node = chart.createNode("Log", pos=(150, 0))
# connect nodes
chart.connectTerminals(
dippid_node['accelX'], buffer_node_accel_x['dataIn'])
chart.connectTerminals(
dippid_node['accelY'], buffer_node_accel_y['dataIn'])
chart.connectTerminals(
dippid_node['accelZ'], buffer_node_accel_z['dataIn'])
chart.connectTerminals(
buffer_node_accel_x['dataOut'], plot_widget_node_1['In'])
chart.connectTerminals(
buffer_node_accel_y['dataOut'], plot_widget_node_2['In'])
chart.connectTerminals(
buffer_node_accel_z['dataOut'], plot_widget_node_3['In'])
chart.connectTerminals(
dippid_node['accelX'], normal_vector_node['accel_x'])
chart.connectTerminals(
dippid_node['accelZ'], normal_vector_node['accel_z'])
chart.connectTerminals(
normal_vector_node['output_rotation'], plot_widget_node_4['In'])
chart.connectTerminals(dippid_node['accelX'], log_node['accel_x'])
chart.connectTerminals(dippid_node['accelY'], log_node['accel_y'])
chart.connectTerminals(dippid_node['accelZ'], log_node['accel_z'])
win.show()
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
sys.exit(QtGui.QApplication.instance().exec_())
if __name__ == '__main__':
if len(sys.argv) < 2:
sys.stdout.write("Please specify port")
port_num = sys.argv[1]
print(port_num)
app = QtGui.QApplication([])
generate_plots()
sys.exit(app.exec_())