diff --git a/telemetry/code/monitor/graph_plotter.py b/telemetry/code/monitor/graph_plotter.py index 202fe9b..4472aef 100755 --- a/telemetry/code/monitor/graph_plotter.py +++ b/telemetry/code/monitor/graph_plotter.py @@ -14,15 +14,19 @@ datafeed = serial.Serial( bytesize=serial.EIGHTBITS, timeout=1 ) + +red = [1, 0, 0] +green = [0, 1, 0] +blue = [0, 0, 1] window = pyglet.window.Window() -window.set_caption("Test graph") +window.set_caption("Raw data") starttime = time.time() def drawgrid(xlines, ylines, xlimits, ylimits): - pyglet.gl.glColor4f(0.5, 0.5, 0.5, 1.0) + pyglet.gl.glColor3f(0.5, 0.5, 0.5) for xpos in range(0, window.width, window.width/xlines): pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (xpos, 0, xpos, window.height))) tagtext = str(round((xlimits[1]-xlimits[0])*(float(xpos)/window.width) + xlimits[0], 1)) @@ -35,8 +39,8 @@ def drawgrid(xlines, ylines, xlimits, ylimits): tag.draw() -def plotline(xdata, ydata): - pyglet.gl.glColor4f(1, 0, 0, 1.0) +def plotline(xdata, ydata, colour): + pyglet.gl.glColor3f(colour[0], colour[1], colour[2]) points = [] for n in range(max(len(xdata), len(ydata))): try: @@ -56,19 +60,31 @@ def plotline(xdata, ydata): xdata = [0] ydata = [0] +ydatasmooth = [0] def poll_serial(foo): + max_points = 250 value = datafeed.readline() try: value = float(value) ydata.append(value) - - if len(ydata) > 300: + if len(ydata) > max_points: del ydata[0] + xdata.append(round(time.time() - starttime, 3)) - if len(xdata) > 300: + if len(xdata) > max_points: del xdata[0] + + avg = 0; + for n in range(0, len(ydata)): + weight = (1-float(n/len(ydata)))/max_points + avg += weight * ydata[n] + + ydatasmooth.append(avg) + if len(ydatasmooth) > max_points: + del ydatasmooth[0] + except: pass @@ -80,7 +96,7 @@ def on_draw(): window.clear() drawgrid(10, 10, [min(xdata), max(xdata)], [min(ydata), max(ydata)]) - plotline(xdata, ydata) + plotline(xdata, ydata, red) -- libgit2 0.21.2