diff --git a/telemetry/code/monitor/graph_plotter_rewrite.py b/telemetry/code/monitor/graph_plotter_rewrite.py index e054e08..d9b23b7 100755 --- a/telemetry/code/monitor/graph_plotter_rewrite.py +++ b/telemetry/code/monitor/graph_plotter_rewrite.py @@ -1,5 +1,11 @@ #!/usr/bin/env python +# Tool to draw live graphs of data coming in from serial port +# Written as a telemetry tool by: +# The UoN Robot Wars Project, 2018 + +# This code is incomplete, and is missing core features + import pyglet #import math #import time @@ -19,12 +25,14 @@ timeout=1 class Series: def __init__(self, points=100, title="Series title", xname="x-axis name", yname="y-axis name"): + """Set up an object to store a 2D data series""" self.title = title self.xname = xname self.yname = yname self.data = [] self.points = points def addpoint(self, point): + """Add a point to the dataset, and remove the oldest, if necessary""" self.data.append(point) if len(self.data) > self.points: del self.data[0] @@ -41,6 +49,7 @@ class Plot(pyglet.window.Window): self.set_caption(self.series.title) def on_resize(self, width, height): + """Handle a resize event from the pyglet event loop""" self.bounds = ((int(self.width * self.margins[0]), int(self.width * (1 - self.margins[0]))), (int(self.height * self.margins[1]), int(self.height * (1 - self.margins[1])))) pyglet.window.Window.on_resize(self, width, height) @@ -66,6 +75,7 @@ class Plot(pyglet.window.Window): heading.draw() def drawAxis(self, axis): # axis=0 is x, 1 is y + """Draw the gridlines and labels for one axis, specified in the last argument""" limita = self.bounds[1-axis][1] limitb = self.bounds[1-axis][0] start = self.bounds[axis][0] @@ -97,23 +107,17 @@ class Plot(pyglet.window.Window): font_name=self.font, font_size=self.height*self.margins[axis]*0.3, x=0, y=self.height/2, anchor_x='center', anchor_y='top') - pyglet.gl.glPushMatrix() + pyglet.gl.glPushMatrix() # Set up a new context to avoid confusing the main one + # Tranformation to rotate label, and ensure it ends up in the right place pyglet.gl.glTranslatef(self.height//2, self.height//2, 0.0) - pyglet.gl.glRotatef(90.0, 0.0, 0.0, 1.0) + pyglet.gl.glRotatef(90.0, 0.0, 0.0, 1.0) + # Draw the axis title using the rotated coordinate system axistitle.draw() + # Return everything to its previous state pyglet.gl.glPopMatrix() - #pyglet.gl.glRotatef(-90.0, 0.0, 0.0, 1.0) - #pyglet.gl.glTranslatef(-self.width//2, -self.height//2, 0.0) tag.draw() - - - - - - - testseries = Series() plots = [] @@ -121,10 +125,11 @@ plots.append(Plot(testseries)) def pollSerial(elapsed): """Check serial port for incoming data""" - # Note, elapsed is time since last call of this function + # Note: 'elapsed' is time since last call of this function values = datafeed.readline().strip().split(", ") testseries.addpoint(values) +# Pyglet looks after the main event loop, but this ensures that data keeps being read in pyglet.clock.schedule_interval(pollSerial, 0.1) pyglet.app.run() \ No newline at end of file -- libgit2 0.21.2