From 87acb46adb6ae47675efcc8f4d08afe8c55f5eb5 Mon Sep 17 00:00:00 2001 From: Christopher Stone Date: Fri, 9 Mar 2018 18:32:07 +0000 Subject: [PATCH] Added code to actually plot lines! Still very much an experimental arranagement, but scale/limit calculation seems to be correct --- robots/little_john/telemetry/code/monitor/version1/main.py | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/robots/little_john/telemetry/code/monitor/version1/main.py b/robots/little_john/telemetry/code/monitor/version1/main.py index e91b7d9..775a74b 100755 --- a/robots/little_john/telemetry/code/monitor/version1/main.py +++ b/robots/little_john/telemetry/code/monitor/version1/main.py @@ -53,7 +53,7 @@ class Series: self.title = title self.xname = xname self.yname = yname - self.xlimits = (100, 0) + self.xlimits = (0, 100) self.ylimits = (0, 255) self.data = [] self.points = points @@ -97,6 +97,7 @@ class Plot(pyglet.window.Window): self.drawHeading() self.drawAxis(0) self.drawAxis(1) + self.drawLine(self.series) def drawBackground(self): """Draw the graph background, currently a plain colour""" @@ -110,10 +111,27 @@ class Plot(pyglet.window.Window): anchor_x='center', anchor_y='top') heading.draw() - def drawLine(self): - for n in range(len(data) - 1): - a, b = data[n], data[n+1] - pass + def drawLine(self, series): + 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]) + 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 = int((x1/xscale)+lmar) + y1 = int((y1/yscale)+bmar) + x2 = int((x2/xscale)+lmar) + y2 = int((y2/yscale)+bmar) + pyglet.graphics.draw(2, pyglet.gl.GL_LINES, + ('v2i', (x1, y1, x2, y2)), + ('c3B', (255, 0, 0, 255, 0, 0))) + def drawAxis(self, axis): # axis=0 is x, 1 is y """Draw the gridlines and labels for one axis, specified in the last argument""" @@ -181,13 +199,14 @@ def pollSerial(elapsed): values = values.split(b', ') for n, value in enumerate(values): values[n] = float(value) - logging.info("Recieved data: " + str(values)) + #logging.info("Recieved data: " + str(values)) testseries.addpoint(values) def fakePollSerial(elapsed): """This function immitates the behaviour of pollSerial, for testing purposes""" - values = [time.time(), time.time()%10] - logging.info("Generated test data: " + str(values)) + faketime = time.time() * 10 + values = [(faketime%100), faketime%255] + #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 -- libgit2 0.21.2