Commit 2bd76084f8bb6fbe9baf31161f6e56ea4609d890
1 parent
d9d09665
Exists in
master
Minor adjustments, cleaning up, and changes to the error-handling system in the …
…wake of the latest live-plot demo work
Showing
4 changed files
with
34 additions
and
13 deletions
Show diff stats
robots/little_john/telemetry/code/monitor/version1/main.py
| ... | ... | @@ -40,32 +40,46 @@ else: |
| 40 | 40 | os='Other' |
| 41 | 41 | logging.info('OS = ' + os) |
| 42 | 42 | |
| 43 | -testseries = Series(points=150, ylimits=(0, 1024), title="Data from serial", xname="Time (s)", yname="ADC output") | |
| 43 | + | |
| 44 | +testseries = Series(points=150, xauto=True, ylimits=(0, 1024), | |
| 45 | + title="Data from serial (time)", xname="Time (s)", yname="ADC output") | |
| 46 | +testseries2 = Series(points=150, xlimits=(0, 1024), ylimits=(0, 1024), | |
| 47 | + title="Data from serial (xy)", xname="ADC0 output", yname="ADC7 output") | |
| 48 | + | |
| 44 | 49 | plots = [] |
| 45 | 50 | plots.append(Plot(testseries)) |
| 51 | +plots.append(Plot(testseries2)) | |
| 52 | + | |
| 46 | 53 | |
| 47 | 54 | def pollSerial(elapsed): |
| 48 | 55 | """Check serial port for incoming data""" |
| 49 | 56 | # Note: 'elapsed' is time since last call of this function |
| 50 | 57 | # This works, but it might be better for performance to have two seperate functions, only one of which is run. |
| 51 | 58 | try: |
| 59 | + incoming = datafeed.readline() | |
| 60 | + except: | |
| 61 | + logging.error("Failed to read input data") | |
| 62 | + | |
| 63 | + try: | |
| 52 | 64 | if os=='Windows': |
| 53 | - values = datafeed.readline().strip().split(b", ") | |
| 65 | + values = incoming.strip().split(b", ") | |
| 54 | 66 | else: |
| 55 | - values = datafeed.readline().strip() | |
| 67 | + values = incoming.strip() | |
| 56 | 68 | values = values.split(b', ') |
| 57 | 69 | except: |
| 58 | - logging.error("Failed to recieve or parse input data") | |
| 70 | + logging.error("Failed to parse input data") | |
| 59 | 71 | return |
| 60 | 72 | |
| 61 | - for n, value in enumerate(values): | |
| 62 | - try: | |
| 73 | + try: | |
| 74 | + for n, value in enumerate(values): | |
| 63 | 75 | values[n] = float(value) |
| 64 | - except: | |
| 65 | - logging.error("Failed to convert input to float") | |
| 66 | - return | |
| 76 | + except: | |
| 77 | + logging.error("Failed to convert input to float") | |
| 78 | + return | |
| 67 | 79 | #logging.info("Recieved data: " + str(values)) |
| 68 | 80 | testseries.addpoint([time.time()-starttime] + values) |
| 81 | + testseries2.addpoint(values) | |
| 82 | + | |
| 69 | 83 | |
| 70 | 84 | def fakePollSerial(elapsed): |
| 71 | 85 | """This function immitates the behaviour of pollSerial, for testing purposes""" | ... | ... |
robots/little_john/telemetry/code/monitor/version1/plot.py
| ... | ... | @@ -64,7 +64,7 @@ class Plot(pyglet.window.Window): |
| 64 | 64 | |
| 65 | 65 | pyglet.gl.glLineWidth(2) |
| 66 | 66 | |
| 67 | - linecolours = [(255, 0, 0, 255, 0, 0), (0, 0, 255, 0, 0, 255)] | |
| 67 | + linecolours = [(255, 0, 0, 255, 0, 0), (0, 220, 0, 0, 220, 0), (0, 0, 255, 0, 0, 255)] | |
| 68 | 68 | |
| 69 | 69 | try: |
| 70 | 70 | for m in range(len(series.data[0])-1): | ... | ... |
robots/little_john/telemetry/code/monitor/version1/series.py
| ... | ... | @@ -5,7 +5,9 @@ |
| 5 | 5 | import logging |
| 6 | 6 | |
| 7 | 7 | class Series: |
| 8 | - def __init__(self, points=100, xlimits=(0, 100), ylimits=(0, 100), title="Series title", xname="x-axis name", yname="y-axis name"): | |
| 8 | + def __init__(self, points=100, xlimits=(0, 100), ylimits=(0, 100), | |
| 9 | + xauto=False, yauto=False, | |
| 10 | + title="Series title", xname="x-axis name", yname="y-axis name"): | |
| 9 | 11 | """Set up an object to store a 2D data series""" |
| 10 | 12 | # Proposal: |
| 11 | 13 | # In order to neatly handle multiple lines on the same graph |
| ... | ... | @@ -24,6 +26,8 @@ class Series: |
| 24 | 26 | self.ylimits = ylimits |
| 25 | 27 | self.data = [] |
| 26 | 28 | self.points = points |
| 29 | + self.xauto = xauto | |
| 30 | + self.yauto = yauto | |
| 27 | 31 | |
| 28 | 32 | logging.info("Created series: " + title) |
| 29 | 33 | |
| ... | ... | @@ -33,7 +37,10 @@ class Series: |
| 33 | 37 | if len(self.data) > self.points: |
| 34 | 38 | del self.data[0] |
| 35 | 39 | try: |
| 36 | - self.autoscale(0) | |
| 40 | + if self.xauto: | |
| 41 | + self.autoscale(0) | |
| 42 | + if self.yauto: | |
| 43 | + self.autoscale(1) | |
| 37 | 44 | except: |
| 38 | 45 | logging.error("Series autoscale failed") |
| 39 | 46 | ... | ... |