|
| 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_() |
0 commit comments