diff --git a/robots/little_john/telemetry/code/monitor/version1/main.py b/robots/little_john/telemetry/code/monitor/version1/main.py index 53979b0..b544933 100755 --- a/robots/little_john/telemetry/code/monitor/version1/main.py +++ b/robots/little_john/telemetry/code/monitor/version1/main.py @@ -21,6 +21,7 @@ import logging from serialselect import selectserial from colours import * +from series import Series logging.basicConfig(format='%(levelname)s:\t%(message)s', level=logging.DEBUG) logging.info("Logging system active") @@ -38,47 +39,6 @@ else: os='Other' logging.info('OS = ' + os) -class Series: - 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 - # a series is not so much a set of 2D data points, but a number - # of series sharing an x axis. For example - # (time, temperature) - # (time, xaccel, yaccel, zaccel) - # The latter seta of points much be of like nature and share an axis - # (time, temperature, xaccel) - # would be a meaningless thing to plot on a single graph anyway - - self.title = title - self.xname = xname - self.yname = yname - self.xlimits = (0, 100) - self.ylimits = (-100, 100) - 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] - 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): """Setup a the details of a plot, and create a corresponding window""" diff --git a/robots/little_john/telemetry/code/monitor/version1/series.py b/robots/little_john/telemetry/code/monitor/version1/series.py new file mode 100644 index 0000000..517a26a --- /dev/null +++ b/robots/little_john/telemetry/code/monitor/version1/series.py @@ -0,0 +1,45 @@ +# Class to store data for a live graph +# Written as a telemetry tool by: +# The UoN Robot Wars Project, 2018 + + +class Series: + 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 + # a series is not so much a set of 2D data points, but a number + # of series sharing an x axis. For example + # (time, temperature) + # (time, xaccel, yaccel, zaccel) + # The latter seta of points much be of like nature and share an axis + # (time, temperature, xaccel) + # would be a meaningless thing to plot on a single graph anyway + + self.title = title + self.xname = xname + self.yname = yname + self.xlimits = (0, 100) + self.ylimits = (-100, 100) + 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] + 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) -- libgit2 0.21.2