From 2bd76084f8bb6fbe9baf31161f6e56ea4609d890 Mon Sep 17 00:00:00 2001 From: Christopher Stone Date: Fri, 9 Mar 2018 21:38:43 +0000 Subject: [PATCH] Minor adjustments, cleaning up, and changes to the error-handling system in the wake of the latest live-plot demo work --- robots/little_john/telemetry/code/monitor/version1/main.py | 32 +++++++++++++++++++++++--------- robots/little_john/telemetry/code/monitor/version1/plot.py | 2 +- robots/little_john/telemetry/code/monitor/version1/series.py | 11 +++++++++-- robots/little_john/telemetry/code/robot/analogread_demo/analogread_demo.ino | 2 +- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/robots/little_john/telemetry/code/monitor/version1/main.py b/robots/little_john/telemetry/code/monitor/version1/main.py index d5ad62c..cbb96c8 100755 --- a/robots/little_john/telemetry/code/monitor/version1/main.py +++ b/robots/little_john/telemetry/code/monitor/version1/main.py @@ -40,32 +40,46 @@ else: os='Other' logging.info('OS = ' + os) -testseries = Series(points=150, ylimits=(0, 1024), title="Data from serial", xname="Time (s)", yname="ADC output") + +testseries = Series(points=150, xauto=True, ylimits=(0, 1024), + title="Data from serial (time)", xname="Time (s)", yname="ADC output") +testseries2 = Series(points=150, xlimits=(0, 1024), ylimits=(0, 1024), + title="Data from serial (xy)", xname="ADC0 output", yname="ADC7 output") + plots = [] plots.append(Plot(testseries)) +plots.append(Plot(testseries2)) + def pollSerial(elapsed): """Check serial port for incoming data""" # Note: 'elapsed' is time since last call of this function # This works, but it might be better for performance to have two seperate functions, only one of which is run. try: + incoming = datafeed.readline() + except: + logging.error("Failed to read input data") + + try: if os=='Windows': - values = datafeed.readline().strip().split(b", ") + values = incoming.strip().split(b", ") else: - values = datafeed.readline().strip() + values = incoming.strip() values = values.split(b', ') except: - logging.error("Failed to recieve or parse input data") + logging.error("Failed to parse input data") return - for n, value in enumerate(values): - try: + try: + for n, value in enumerate(values): values[n] = float(value) - except: - logging.error("Failed to convert input to float") - return + except: + logging.error("Failed to convert input to float") + return #logging.info("Recieved data: " + str(values)) testseries.addpoint([time.time()-starttime] + values) + testseries2.addpoint(values) + def fakePollSerial(elapsed): """This function immitates the behaviour of pollSerial, for testing purposes""" diff --git a/robots/little_john/telemetry/code/monitor/version1/plot.py b/robots/little_john/telemetry/code/monitor/version1/plot.py index 2cf0056..c453357 100644 --- a/robots/little_john/telemetry/code/monitor/version1/plot.py +++ b/robots/little_john/telemetry/code/monitor/version1/plot.py @@ -64,7 +64,7 @@ class Plot(pyglet.window.Window): pyglet.gl.glLineWidth(2) - linecolours = [(255, 0, 0, 255, 0, 0), (0, 0, 255, 0, 0, 255)] + linecolours = [(255, 0, 0, 255, 0, 0), (0, 220, 0, 0, 220, 0), (0, 0, 255, 0, 0, 255)] try: for m in range(len(series.data[0])-1): diff --git a/robots/little_john/telemetry/code/monitor/version1/series.py b/robots/little_john/telemetry/code/monitor/version1/series.py index e54210f..0bfd962 100644 --- a/robots/little_john/telemetry/code/monitor/version1/series.py +++ b/robots/little_john/telemetry/code/monitor/version1/series.py @@ -5,7 +5,9 @@ import logging class Series: - def __init__(self, points=100, xlimits=(0, 100), ylimits=(0, 100), title="Series title", xname="x-axis name", yname="y-axis name"): + def __init__(self, points=100, xlimits=(0, 100), ylimits=(0, 100), + xauto=False, yauto=False, + 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 @@ -24,6 +26,8 @@ class Series: self.ylimits = ylimits self.data = [] self.points = points + self.xauto = xauto + self.yauto = yauto logging.info("Created series: " + title) @@ -33,7 +37,10 @@ class Series: if len(self.data) > self.points: del self.data[0] try: - self.autoscale(0) + if self.xauto: + self.autoscale(0) + if self.yauto: + self.autoscale(1) except: logging.error("Series autoscale failed") diff --git a/robots/little_john/telemetry/code/robot/analogread_demo/analogread_demo.ino b/robots/little_john/telemetry/code/robot/analogread_demo/analogread_demo.ino index ffdbf1a..91d592c 100644 --- a/robots/little_john/telemetry/code/robot/analogread_demo/analogread_demo.ino +++ b/robots/little_john/telemetry/code/robot/analogread_demo/analogread_demo.ino @@ -23,5 +23,5 @@ void loop() { Bluetooth.print(a0value); Bluetooth.print(", "); Bluetooth.println(a7value); - delay(100); + delay(180); } -- libgit2 0.21.2