-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyze.py
152 lines (114 loc) · 4.38 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
#!/usr/bin/env python3
# coding: utf-8
# -*- coding: utf-8 -*-
# the script was written by Erik Blank
'''
This script shows 4 charts
The first three charts show the accelerometer values for x-,y- and z-axis
On the last chart you can see the rotation around the z-Axis
Usage: python3 analyze.py <PORT>
'''
from PyQt5 import QtGui, QtCore
import pyqtgraph as pg
from pyqtgraph.flowchart import Flowchart, Node
from DIPPID_pyqtnode import DIPPIDNode, BufferNode
import pyqtgraph.flowchart.library as fclib
import sys
import numpy as np
import NormalVectorNode
import LogNode
def create_plots(fc, layout):
# create plot widgets and adjust them on right position
channels = ["accelX", "accelY", "accelZ"]
plot_widgets = create_plot_widgets(channels, layout)
# create PlotWidget node and set associated plot
pw_nodes = init_plot_nodes(plot_widgets, fc)
# create dippidNode with 3 outputs
dippidNode = fc.createNode("DIPPID", pos=(-150, -100))
# create buffer nodes for each plot widget nodes
buffer_nodes = create_buffer_nodes(fc, pw_nodes)
create_normvec_plot(dippidNode)
connect_dippid_with_buffer(fc, dippidNode, channels, buffer_nodes)
# connect buffers with plot nodes
connect_buffer_with_plot(buffer_nodes, pw_nodes)
# create plot widgets for each channel of the dippid node
def create_plot_widgets(channels, layout):
list = []
for i in range(len(channels)):
list.append(create_plot_widget(channels[i], [0, i+1], layout))
return list
def create_plot_widget(name, pos, layout):
pw = pg.PlotWidget()
layout.addWidget(pw, pos[0], pos[1])
pw.setTitle(name)
pw.setYRange(-1, 1)
return pw
# init plot nodes and set according plot
def init_plot_nodes(pws, fc):
plot_nodes = []
for i in range(len(pws)):
plot_nodes.append(init_plot_node(pws[i], (150, -50 - i*50), fc))
return plot_nodes
def init_plot_node(plot, pos, fc):
pwNode = fc.createNode('PlotWidget', pos=pos)
pwNode.setPlot(plot)
return pwNode
# create as many buffernodes as plotnodes
def create_buffer_nodes(fc, pws):
buffer_nodes = []
for i in range(len(pws)):
buffer_nodes.append(fc.createNode('Buffer', pos=(0, -50 - i*50)))
return buffer_nodes
# create Normalvector plot widget, plotnode and node and connect terminals
def create_normvec_plot(dippidNode):
pw = create_normvec_pw()
plot_node = fc.createNode("PlotWidget", pos=(-200, -50))
plot_node.setPlot(pw)
normvec_node = fc.createNode("NormalVector", pos=(-100, -50))
fc.connectTerminals(dippidNode["accelX"], normvec_node["axisIn1"])
fc.connectTerminals(dippidNode["accelY"], normvec_node["axisIn2"])
fc.connectTerminals(normvec_node["dataOut"], plot_node["In"])
log_node = fc.createNode("LogNode", pos=(1000, 1000))
fc.connectTerminals(normvec_node["dataOut"], log_node["In"])
# create plotwidget of normalvector
def create_normvec_pw():
pw = pg.PlotWidget()
layout.addWidget(pw, 1, 2)
pw.setTitle("NormalVector")
pw.setYRange(-1, 1)
pw.setXRange(0, 1)
return pw
# connect the dippidNode with the bufferNodes
def connect_dippid_with_buffer(fc, dippidNode, channels, buffer_nodes):
for i in range(len(channels)):
fc.connectTerminals(dippidNode[channels[i]], buffer_nodes[i]['dataIn'])
# connect the bufferNodes with the dippidNodes
def connect_buffer_with_plot(buffer_nodes, plot_nodes):
if len(buffer_nodes) is not len(plot_nodes):
print("size of buffer_nodes and plot_nodes are not the same")
else:
for i in range(len(buffer_nodes)):
fc.connectTerminals(buffer_nodes[i]['dataOut'], plot_nodes[i]['In'])
def get_port():
if len(sys.argv) != 2:
print("Usage: python3 analyze.py <PORT>")
exit(1)
else:
# don't know how to implement port into dippid
port = sys.argv[1]
if __name__ == '__main__':
get_port()
app = QtGui.QApplication([])
win = QtGui.QMainWindow()
win.setWindowTitle('DIPPIDNode demo')
cw = QtGui.QWidget()
win.setCentralWidget(cw)
layout = QtGui.QGridLayout()
cw.setLayout(layout)
# Create an empty flowchart with a single input and output
fc = Flowchart(terminals={})
layout.addWidget(fc.widget(), 0, 0, 2, 1)
create_plots(fc, layout)
win.show()
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
sys.exit(QtGui.QApplication.instance().exec_())