diff --git a/robots/little_john/telemetry/code/monitor/version1/main.py b/robots/little_john/telemetry/code/monitor/version1/main.py index 775a74b..53979b0 100755 --- a/robots/little_john/telemetry/code/monitor/version1/main.py +++ b/robots/little_john/telemetry/code/monitor/version1/main.py @@ -7,7 +7,7 @@ # This code is incomplete, and is missing core features -#import math +import math import time #import serial @@ -24,6 +24,7 @@ from colours import * logging.basicConfig(format='%(levelname)s:\t%(message)s', level=logging.DEBUG) logging.info("Logging system active") +starttime = time.time() datafeed = selectserial() @@ -38,7 +39,7 @@ else: logging.info('OS = ' + os) class Series: - def __init__(self, points=100, title="Series title", xname="x-axis name", yname="y-axis name"): + def __init__(self, points=300, title="Series title", xname="x-axis name", yname="y-axis name"): """Set up an object to store a 2D data series""" # Proposal: # In order to neatly handle multiple lines on the same graph @@ -54,7 +55,7 @@ class Series: self.xname = xname self.yname = yname self.xlimits = (0, 100) - self.ylimits = (0, 255) + self.ylimits = (-100, 100) self.data = [] self.points = points @@ -63,6 +64,20 @@ class Series: self.data.append(point) if len(self.data) > self.points: del self.data[0] + self.autoscale(0) + + def autoscale(self, axis): # axis=0 is x, 1 is y + minval = self.data[0][axis] + maxval = self.data[0][axis] + for value in self.data: + if value[axis] < minval: + minval = value[axis] + if value[axis] > maxval: + maxval = value[axis] + if axis == 0: + self.xlimits = (minval, maxval) + else: + self.ylimits = (minval, maxval) class Plot(pyglet.window.Window): def __init__(self, series): @@ -115,15 +130,16 @@ class Plot(pyglet.window.Window): xscale = float(self.series.xlimits[1]-self.series.xlimits[0])/(self.bounds[0][1]-self.bounds[0][0]) yscale = float(self.series.ylimits[1]-self.series.ylimits[0])/(self.bounds[1][1]-self.bounds[1][0]) logging.debug("xscale = " + str(xscale) + ", yscale = " + str(yscale)) - #xscale = 5 - #xscale = self.series.xlimits[1] self.series.xlimits[0] - #yscale = 1 lmar = int(self.width * self.margins[0]) rmar = int(self.width * self.margins[1]) tmar = int(self.height * self.margins[0]) bmar = int(self.height * self.margins[1]) + + pyglet.gl.glLineWidth(2) + for n in range(len(series.data) - 1): - x1, y1, x2, y2 = series.data[n][0], series.data[n][1], series.data[n+1][0], series.data[n+1][1] + x1, y1 = series.data[n][0]-series.xlimits[0], series.data[n][1]-series.ylimits[0] + x2, y2 = series.data[n+1][0]-series.xlimits[0], series.data[n+1][1]-series.ylimits[0] x1 = int((x1/xscale)+lmar) y1 = int((y1/yscale)+bmar) x2 = int((x2/xscale)+lmar) @@ -131,6 +147,8 @@ class Plot(pyglet.window.Window): pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (x1, y1, x2, y2)), ('c3B', (255, 0, 0, 255, 0, 0))) + pyglet.gl.glLineWidth(1) + def drawAxis(self, axis): # axis=0 is x, 1 is y @@ -204,12 +222,12 @@ def pollSerial(elapsed): def fakePollSerial(elapsed): """This function immitates the behaviour of pollSerial, for testing purposes""" - faketime = time.time() * 10 - values = [(faketime%100), faketime%255] + timefromstart = (time.time()-starttime) + values = [timefromstart, 100*math.sin(25*math.radians(timefromstart))] #logging.info("Generated test data: " + str(values)) testseries.addpoint(values) # Pyglet looks after the main event loop, but this ensures that data keeps being read in -pyglet.clock.schedule_interval(fakePollSerial, 0.1) +pyglet.clock.schedule_interval(fakePollSerial, 0.04) pyglet.app.run() -- libgit2 0.21.2