Skip to content

Commit 32c34bc

Browse files
committed
first commit
0 parents  commit 32c34bc

File tree

3 files changed

+1051
-0
lines changed

3 files changed

+1051
-0
lines changed

multi_curve.py

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import pyqtgraph as pg
2+
from pyqtgraph.Qt import QtGui, QtCore
3+
import numpy as np
4+
import csv
5+
6+
pg.setConfigOptions(antialias=True)
7+
8+
def read_imu_values():
9+
accX = []
10+
accY = []
11+
accZ = []
12+
gyrX = []
13+
gyrY = []
14+
gyrZ = []
15+
magX = []
16+
magY = []
17+
magZ = []
18+
firstrow = True
19+
20+
with open('/Users/chrestme/BerryIMU/python-LSM9DS0-gryo-accel-compass/test_raw.out') as f:
21+
imu_reader = csv.reader(f)
22+
for row in imu_reader:
23+
if firstrow:
24+
firstrow = False
25+
continue
26+
accX.append(int(row[2]))
27+
accY.append(int(row[3]))
28+
accZ.append(int(row[4]))
29+
30+
gyrX.append(int(row[5]))
31+
gyrY.append(int(row[6]))
32+
gyrZ.append(int(row[7]))
33+
34+
magX.append(int(row[8]))
35+
magY.append(int(row[8]))
36+
magZ.append(int(row[8]))
37+
38+
acc = {'x': accX,
39+
'y': accY,
40+
'z': accZ}
41+
gyr = {'x': gyrX,
42+
'y': gyrY,
43+
'z': gyrZ}
44+
mag = {'x': magX,
45+
'y': magY,
46+
'z': magZ}
47+
48+
return acc,gyr,mag
49+
50+
acc,gyr,mag = read_imu_values()
51+
LA_so = 0.732 #linear accel sensitivity for +/-16G scale
52+
53+
p1 = pg.plot()
54+
#plot.setAspectLocked()
55+
56+
p1.plot([ (x * LA_so)/1000 for x in acc['x']], pen=(255,0,0), name="Red curve")
57+
p1.plot([ (y * LA_so)/1000 for y in acc['y']], pen=(0,255,0), name="Blue curve")
58+
p1.plot([ (z * LA_so)/1000 for z in acc['z']], pen=(0,0,255), name="Green curve")
59+
60+
#cross hair
61+
vLine = pg.InfiniteLine(angle=90, movable=False)
62+
hLine = pg.InfiniteLine(angle=0, movable=False)
63+
p1.addItem(vLine, ignoreBounds=True)
64+
p1.addItem(hLine, ignoreBounds=True)
65+
label = pg.LabelItem(justify='right')
66+
p1.addItem(label)
67+
vb = p1.getViewBox()
68+
69+
def mouseMoved(evt):
70+
pos = evt[0] ## using signal proxy turns original arguments into a tuple
71+
if p1.sceneBoundingRect().contains(pos):
72+
mousePoint = vb.mapSceneToView(pos)
73+
index = int(mousePoint.x())
74+
if index > 0 and index < len(acc['x']):
75+
label.setText("<span style='font-size: 12pt'>x=%0.1f, <span style='color: red'>accX=%0.1f</span>, <span style='color: green'>accY=%0.1f</span>, <span style='color: blue'>accZ=%0.1f</span>" % (mousePoint.x(), acc['x'][index], acc['y'][index], acc['z'][index]))
76+
vLine.setPos(mousePoint.x())
77+
hLine.setPos(mousePoint.y())
78+
79+
proxy = pg.SignalProxy(p1.scene().sigMouseMoved, rateLimit=60, slot=mouseMoved)
80+
81+
#p2 = pg.plot()
82+
#p2.plot(gyr['x'], pen=(255,0,0), name="Red curve")
83+
#p2.plot(gyr['y'], pen=(0,255,0), name="Blue curve")
84+
#p2.plot(gyr['z'], pen=(0,0,255), name="Green curve")
85+
86+
87+
88+
if __name__ == '__main__':
89+
import sys
90+
if sys.flags.interactive != 1 or not hasattr(QtCore, 'PYQT_VERSION'):
91+
pg.QtGui.QApplication.exec_()

polar_plot.py

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import pyqtgraph as pg
2+
from pyqtgraph.Qt import QtGui, QtCore
3+
import numpy as np
4+
5+
#QtGui.QApplication.setGraphicsSystem('raster')
6+
app = QtGui.QApplication([])
7+
#mw = QtGui.QMainWindow()
8+
#mw.resize(800,800)
9+
10+
win = pg.GraphicsWindow(title="Basic plotting examples")
11+
win.resize(1000,600)
12+
win.setWindowTitle('pyqtgraph example: Plotting')
13+
14+
15+
# Enable antialiasing for prettier plots
16+
pg.setConfigOptions(antialias=True)
17+
p1 = win.addPlot(title="Polar Plot")
18+
#plot = pg.plot(pen='y')
19+
#plot.setAspectLocked()
20+
21+
# Add polar grid lines
22+
p1.addLine(x=0, pen=0.2)
23+
p1.addLine(y=0, pen=0.2)
24+
for r in range(0, 2, 1):
25+
circle = pg.QtGui.QGraphicsEllipseItem(-r, -r, r*2, r*2)
26+
circle.setPen(pg.mkPen(0.2))
27+
p1.addItem(circle)
28+
29+
# make polar data
30+
#theta = np.linspace(0,np.pi,100) #[0,np.pi/4] #np.linspace(0, 2*np.pi, 100)
31+
#radius = 10 #np.random.normal(loc=10, size=100)
32+
33+
# Transform to cartesiani and plot
34+
#x = radius * np.cos(theta)
35+
#y = radius * np.sin(theta)
36+
37+
import csv
38+
with open('test_raw.out') as f:
39+
imu_data = csv.reader(f)
40+
first_row = True
41+
x = []
42+
y = []
43+
for row in imu_data:
44+
if first_row:
45+
first_row = False
46+
continue
47+
48+
x.append((int(row[2]) * .762)/1000)
49+
y.append((int(row[3]) * .762)/1000)
50+
51+
p1.plot(x, y)
52+
53+
import math
54+
p2 = win.addPlot()
55+
s1 = pg.ScatterPlotItem(pxMode = True) #size=10, pen=pg.mkPen(None), brush=pg.mkBrush(255, 255, 255, 20))
56+
spots = []
57+
ptr = 0
58+
#for i in range(len(x)):
59+
def update():
60+
global s1,x,y,p2,ptr
61+
s1.clear()
62+
if ptr == 0:
63+
p2.enableAutoRange('xy', False)
64+
spots = [{'pos': (x[ptr], y[ptr]), 'size': 1, 'pen': {'color': 'w', 'width': 6}, 'brush':pg.mkBrush(255, 255, 0, 100)}]
65+
s1.addPoints(spots)
66+
p2.addItem(s1)
67+
ptr += 1
68+
#s4.sigClicked.connect(clicked)
69+
70+
71+
#curve = p6.plot(pen='y')
72+
#data = np.random.normal(size=(10,1000))
73+
#ptr = 0
74+
#def update():
75+
# global curve, data, ptr, plot
76+
#while ptr < 100:
77+
# plot.setData(radius * np.cos(theta[ptr]),radius * np.sin(theta[ptr]))
78+
# if ptr == 0:
79+
# plot.enableAutoRange('xy', False) ## stop auto-scaling after the first data set is plotted
80+
# ptr += 1
81+
82+
timer = QtCore.QTimer()
83+
timer.timeout.connect(update)
84+
timer.start(38)
85+
86+
if __name__ == '__main__':
87+
import sys
88+
if sys.flags.interactive != 1 or not hasattr(QtCore, 'PYQT_VERSION'):
89+
pg.QtGui.QApplication.exec_()

0 commit comments

Comments
 (0)