Compare View
Commits (2)
Showing
6 changed files
Show diff stats
robots/little_john/telemetry/code/monitor/version1/colours.py
robots/little_john/telemetry/code/monitor/version1/getdata.py
| ... | ... | @@ -7,6 +7,7 @@ import os |
| 7 | 7 | import time |
| 8 | 8 | import math |
| 9 | 9 | |
| 10 | + | |
| 10 | 11 | def getData(starttime, datafeed, testseries, testseries2, fake=False): |
| 11 | 12 | """Check serial port for incoming data""" |
| 12 | 13 | # Note: 'elapsed' is time since last call of this function |
| ... | ... | @@ -15,7 +16,7 @@ def getData(starttime, datafeed, testseries, testseries2, fake=False): |
| 15 | 16 | if fake: |
| 16 | 17 | timefromstart = (time.time()-starttime) |
| 17 | 18 | values = [timefromstart, 100*math.sin(timefromstart)] |
| 18 | - #logging.info("Generated test data: " + str(values)) | |
| 19 | + # logging.info("Generated test data: " + str(values)) | |
| 19 | 20 | testseries.addpoint(values) |
| 20 | 21 | testseries2.addpoint(values) |
| 21 | 22 | else: |
| ... | ... | @@ -23,9 +24,9 @@ def getData(starttime, datafeed, testseries, testseries2, fake=False): |
| 23 | 24 | incoming = datafeed.readline() |
| 24 | 25 | except: |
| 25 | 26 | logging.error("Failed to read input data") |
| 26 | - | |
| 27 | + | |
| 27 | 28 | try: |
| 28 | - if os=='Windows': | |
| 29 | + if os == 'Windows': | |
| 29 | 30 | values = incoming.strip().split(b", ") |
| 30 | 31 | else: |
| 31 | 32 | values = incoming.strip() |
| ... | ... | @@ -33,15 +34,13 @@ def getData(starttime, datafeed, testseries, testseries2, fake=False): |
| 33 | 34 | except: |
| 34 | 35 | logging.error("Failed to parse input data") |
| 35 | 36 | return |
| 36 | - | |
| 37 | + | |
| 37 | 38 | try: |
| 38 | 39 | for n, value in enumerate(values): |
| 39 | 40 | values[n] = float(value) |
| 40 | 41 | except: |
| 41 | 42 | logging.error("Failed to convert input to float") |
| 42 | 43 | return |
| 43 | - #logging.info("Recieved data: " + str(values)) | |
| 44 | + # logging.info("Recieved data: " + str(values)) | |
| 44 | 45 | testseries.addpoint([time.time()-starttime] + values) |
| 45 | 46 | testseries2.addpoint(values) |
| 46 | - | |
| 47 | - | ... | ... |
robots/little_john/telemetry/code/monitor/version1/main.py
| ... | ... | @@ -31,7 +31,7 @@ starttime = time.time() |
| 31 | 31 | |
| 32 | 32 | datafeed = selectserial() |
| 33 | 33 | |
| 34 | -if datafeed == None: | |
| 34 | +if datafeed is None: | |
| 35 | 35 | logging.critical("Failed to open serial port") |
| 36 | 36 | sys.exit() |
| 37 | 37 | |
| ... | ... | @@ -43,9 +43,11 @@ logging.info('OS = ' + os) |
| 43 | 43 | |
| 44 | 44 | |
| 45 | 45 | testseries = Series(points=150, xauto=True, ylimits=(0, 1024), |
| 46 | - title="Data from serial (time)", xname="Time (s)", yname="ADC output") | |
| 46 | + title="Data from serial (time)", | |
| 47 | + xname="Time (s)", yname="ADC output") | |
| 47 | 48 | testseries2 = Series(points=150, xlimits=(0, 1024), ylimits=(0, 1024), |
| 48 | - title="Data from serial (xy)", xname="ADC0 output", yname="ADC7 output") | |
| 49 | + title="Data from serial (xy)", | |
| 50 | + xname="ADC0 output", yname="ADC7 output") | |
| 49 | 51 | |
| 50 | 52 | plots = [] |
| 51 | 53 | plots.append(Plot(testseries)) | ... | ... |
robots/little_john/telemetry/code/monitor/version1/plot.py
| ... | ... | @@ -8,24 +8,27 @@ import logging |
| 8 | 8 | from colours import * |
| 9 | 9 | import sys |
| 10 | 10 | |
| 11 | + | |
| 11 | 12 | class Plot(pyglet.window.Window): |
| 12 | 13 | def __init__(self, series): |
| 13 | 14 | """Setup a the details of a plot, and create a corresponding window""" |
| 14 | 15 | pyglet.window.Window.__init__(self, resizable=True) |
| 15 | 16 | self.set_icon(pyglet.image.load('32x32.png')) |
| 16 | - self.set_minimum_size(320,320) | |
| 17 | + self.set_minimum_size(320, 320) | |
| 17 | 18 | self.series = series |
| 18 | 19 | self.font = 'Arkhip' |
| 19 | - self.margins = (0.09, 0.08) # Fractions of window size | |
| 20 | + self.margins = (0.09, 0.08) # Fractions of window size | |
| 20 | 21 | self.lines = (10, 8) |
| 21 | - #self.resizable = True | |
| 22 | + # self.resizable = True | |
| 22 | 23 | self.set_caption(self.series.title) |
| 23 | 24 | |
| 24 | 25 | def on_resize(self, width, height): |
| 25 | 26 | """Handle a resize event from the pyglet event loop""" |
| 26 | 27 | try: |
| 27 | - self.bounds = ((int(self.width * self.margins[0]), int(self.width * (1 - self.margins[0]))), | |
| 28 | - (int(self.height * self.margins[1]), int(self.height * (1 - self.margins[1])))) | |
| 28 | + self.bounds = ((int(self.width * self.margins[0]), | |
| 29 | + int(self.width * (1 - self.margins[0]))), | |
| 30 | + (int(self.height * self.margins[1]), | |
| 31 | + int(self.height * (1 - self.margins[1])))) | |
| 29 | 32 | except Exception as e: |
| 30 | 33 | logging.critical(str(e)) |
| 31 | 34 | self.close() |
| ... | ... | @@ -54,11 +57,13 @@ class Plot(pyglet.window.Window): |
| 54 | 57 | self.width, self.height).blit(0, 0) |
| 55 | 58 | |
| 56 | 59 | def drawHeading(self): |
| 57 | - """Draw a title for the graph (duplicated in the window titlebar, if present""" | |
| 60 | + """Draw a title for the graph (duplicated in the window titlebar""" | |
| 58 | 61 | heading = pyglet.text.Label(self.series.title, color=BLACK, |
| 59 | - font_name=self.font, font_size=self.height*self.margins[0]*0.5, | |
| 60 | - x=self.width/2, y=self.height-(self.margins[1]), | |
| 61 | - anchor_x='center', anchor_y='top') | |
| 62 | + font_name=self.font, | |
| 63 | + font_size=self.height*self.margins[0]*0.5, | |
| 64 | + x=self.width/2, | |
| 65 | + y=self.height-(self.margins[1]), | |
| 66 | + anchor_x='center', anchor_y='top') | |
| 62 | 67 | heading.draw() |
| 63 | 68 | |
| 64 | 69 | def drawLines(self, series): |
| ... | ... | @@ -78,18 +83,20 @@ class Plot(pyglet.window.Window): |
| 78 | 83 | try: |
| 79 | 84 | for m in range(len(series.data[0])-1): |
| 80 | 85 | for n in range(len(series.data) - 1): |
| 81 | - x1, y1 = series.data[n][0]-series.xlimits[0], series.data[n][m+1]-series.ylimits[0] | |
| 82 | - x2, y2 = series.data[n+1][0]-series.xlimits[0], series.data[n+1][m+1]-series.ylimits[0] | |
| 86 | + x1 = series.data[n][0]-series.xlimits[0] | |
| 87 | + y1 = series.data[n][m+1]-series.ylimits[0] | |
| 88 | + x2 = series.data[n+1][0]-series.xlimits[0] | |
| 89 | + y2 = series.data[n+1][m+1]-series.ylimits[0] | |
| 83 | 90 | x1 = int((x1/xscale)+lmar) |
| 84 | 91 | y1 = int((y1/yscale)+bmar) |
| 85 | 92 | x2 = int((x2/xscale)+lmar) |
| 86 | 93 | y2 = int((y2/yscale)+bmar) |
| 87 | 94 | pyglet.graphics.draw(2, pyglet.gl.GL_LINES, |
| 88 | - ('v2i', (x1, y1, x2, y2)), | |
| 89 | - ('c3B', linecolours[m])) | |
| 95 | + ('v2i', (x1, y1, x2, y2)), | |
| 96 | + ('c3B', linecolours[m])) | |
| 90 | 97 | except: |
| 91 | - logging.error("Failed to plot lines, possibly due to corrupt/missing data. (This happens at startup)") | |
| 92 | - | |
| 98 | + logging.error("Failed to plot lines: corrupt/missing data?") | |
| 99 | + | |
| 93 | 100 | pyglet.gl.glLineWidth(1) |
| 94 | 101 | |
| 95 | 102 | def drawAxis(self, axis): # axis=0 is x, 1 is y |
| ... | ... | @@ -108,27 +115,34 @@ class Plot(pyglet.window.Window): |
| 108 | 115 | stop-start) |
| 109 | 116 | tagvalue = ((pos-start) * scale) + self.series.xlimits[0] |
| 110 | 117 | tagtext = str(int(tagvalue)) |
| 111 | - pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (pos, limita, pos, limitb)), | |
| 112 | - ('c3B', (0, 0, 0, 0, 0, 0))) | |
| 118 | + pyglet.graphics.draw(2, pyglet.gl.GL_LINES, | |
| 119 | + ('v2i', (pos, limita, pos, limitb)), | |
| 120 | + ('c3B', (0, 0, 0, 0, 0, 0))) | |
| 113 | 121 | tag = pyglet.text.Label(tagtext, color=BLACK, |
| 114 | - font_name=self.font, font_size=self.tag_size, | |
| 122 | + font_name=self.font, | |
| 123 | + font_size=self.tag_size, | |
| 115 | 124 | x=pos, y=self.height*self.margins[1], |
| 116 | 125 | anchor_x='left', anchor_y='top') |
| 117 | 126 | axistitle = pyglet.text.Label(self.series.xname, color=BLACK, |
| 118 | - font_name=self.font, font_size=self.tag_size, | |
| 119 | - x=self.width/2, y=0, | |
| 120 | - anchor_x='center', anchor_y='bottom') | |
| 127 | + font_name=self.font, | |
| 128 | + font_size=self.tag_size, | |
| 129 | + x=self.width/2, y=0, | |
| 130 | + anchor_x='center', | |
| 131 | + anchor_y='bottom') | |
| 121 | 132 | axistitle.draw() |
| 122 | 133 | if axis == 1: # y axis, horizontal lines |
| 123 | 134 | scale = float(self.series.ylimits[1]-self.series.ylimits[0])/( |
| 124 | 135 | stop-start) |
| 125 | 136 | tagvalue = ((pos-start) * scale) + self.series.ylimits[0] |
| 126 | 137 | tagtext = str(int(tagvalue)) |
| 127 | - pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (limita, pos, limitb, pos)), | |
| 128 | - ('c3B', (0, 0, 0, 0, 0, 0))) | |
| 138 | + pyglet.graphics.draw(2, pyglet.gl.GL_LINES, | |
| 139 | + ('v2i', (limita, pos, limitb, pos)), | |
| 140 | + ('c3B', (0, 0, 0, 0, 0, 0))) | |
| 129 | 141 | tag = pyglet.text.Label(tagtext, color=BLACK, |
| 130 | - font_name=self.font, font_size=self.tag_size, | |
| 131 | - x=self.width*self.margins[0]*0.9, y=pos, | |
| 142 | + font_name=self.font, | |
| 143 | + font_size=self.tag_size, | |
| 144 | + x=self.width*self.margins[0]*0.9, | |
| 145 | + y=pos, | |
| 132 | 146 | anchor_x='right', anchor_y='center') |
| 133 | 147 | axistitle = pyglet.text.Label(self.series.yname, color=BLACK, |
| 134 | 148 | font_name=self.font, | ... | ... |
robots/little_john/telemetry/code/monitor/version1/serialselect.py
| ... | ... | @@ -2,27 +2,29 @@ |
| 2 | 2 | # Written as a telemetry tool by: |
| 3 | 3 | # The UoN Robot Wars Project, 2018 |
| 4 | 4 | |
| 5 | + | |
| 5 | 6 | def selectserial(): |
| 6 | - """Cross-platform function to find appropriate serial ports, query the user if necessary, and open one of them""" | |
| 7 | + """Cross-platform function to find appropriate serial ports, query the | |
| 8 | + user if necessary, and open one of them""" | |
| 7 | 9 | import platform |
| 8 | 10 | import serial |
| 9 | 11 | import os |
| 10 | 12 | import easygui |
| 11 | 13 | import logging |
| 12 | - | |
| 14 | + | |
| 13 | 15 | devpatterns = ['ttyACM', 'ttyUSB', 'rfcomm'] |
| 14 | 16 | targetdevs = [] |
| 15 | - if platform.system()=='Windows': | |
| 17 | + if platform.system() == 'Windows': | |
| 16 | 18 | com_ports = ['COM%s' % (i + 1) for i in range(256)] |
| 17 | 19 | for port in com_ports: |
| 18 | 20 | try: |
| 19 | 21 | s = serial.Serial(port) |
| 20 | 22 | s.close() |
| 21 | 23 | targetdevs.append(port) |
| 22 | - # Temporarily broadened exception in attempt to make this work on uni PCs | |
| 23 | - except: # (OSError, serial.SerialException): | |
| 24 | + # Temporarily broadened exception to make this work on uni PCs | |
| 25 | + except: # (OSError, serial.SerialException): | |
| 24 | 26 | pass |
| 25 | - os='Windows' #may be useful | |
| 27 | + os = 'Windows' # may be useful | |
| 26 | 28 | else: |
| 27 | 29 | alldevs = os.listdir("/dev/") |
| 28 | 30 | targetdevs = [] |
| ... | ... | @@ -30,7 +32,7 @@ def selectserial(): |
| 30 | 32 | for pattern in devpatterns: |
| 31 | 33 | if pattern in dev: |
| 32 | 34 | targetdevs.append("/dev/" + dev) |
| 33 | - os='Other' #may be useful | |
| 35 | + os = 'Other' # may be useful | |
| 34 | 36 | |
| 35 | 37 | if len(targetdevs) == 0: |
| 36 | 38 | logging.info("No serial device found.") |
| ... | ... | @@ -42,13 +44,13 @@ def selectserial(): |
| 42 | 44 | message = "Please choose a serial port to recieve data through:" |
| 43 | 45 | title = "Found multiple serial ports!" |
| 44 | 46 | serialport = easygui.choicebox(message, title, targetdevs) |
| 45 | - if serialport == None: | |
| 47 | + if serialport is None: | |
| 46 | 48 | logging.info("User cancelled selection dialogue") |
| 47 | 49 | return None |
| 48 | 50 | else: |
| 49 | 51 | logging.info("Only found one likely serial device: " + targetdevs[0]) |
| 50 | 52 | serialport = targetdevs[0] |
| 51 | - | |
| 53 | + | |
| 52 | 54 | try: |
| 53 | 55 | datafeed = serial.Serial( |
| 54 | 56 | port=serialport, | ... | ... |
robots/little_john/telemetry/code/monitor/version1/series.py
| ... | ... | @@ -4,10 +4,12 @@ |
| 4 | 4 | |
| 5 | 5 | import logging |
| 6 | 6 | |
| 7 | + | |
| 7 | 8 | class Series: |
| 8 | 9 | def __init__(self, points=100, xlimits=(0, 100), ylimits=(0, 100), |
| 9 | 10 | xauto=False, yauto=False, |
| 10 | - title="Series title", xname="x-axis name", yname="y-axis name"): | |
| 11 | + title="Series title", | |
| 12 | + xname="x-axis name", yname="y-axis name"): | |
| 11 | 13 | """Set up an object to store a 2D data series""" |
| 12 | 14 | # Proposal: |
| 13 | 15 | # In order to neatly handle multiple lines on the same graph |
| ... | ... | @@ -28,9 +30,9 @@ class Series: |
| 28 | 30 | self.points = points |
| 29 | 31 | self.xauto = xauto |
| 30 | 32 | self.yauto = yauto |
| 31 | - | |
| 33 | + | |
| 32 | 34 | logging.info("Created series: " + title) |
| 33 | - | |
| 35 | + | |
| 34 | 36 | def addpoint(self, point): |
| 35 | 37 | """Add a point to the dataset, and remove the oldest, if necessary""" |
| 36 | 38 | self.data.append(point) |
| ... | ... | @@ -43,15 +45,15 @@ class Series: |
| 43 | 45 | self.autoscale(1) |
| 44 | 46 | except: |
| 45 | 47 | logging.error("Series autoscale failed") |
| 46 | - | |
| 47 | - def autoscale(self, axis): # axis=0 is x, 1 is y | |
| 48 | + | |
| 49 | + def autoscale(self, axis): # axis=0 is x, 1 is y | |
| 48 | 50 | minval = self.data[0][axis] |
| 49 | 51 | maxval = self.data[0][axis] |
| 50 | 52 | for value in self.data: |
| 51 | 53 | if value[axis] < minval: |
| 52 | 54 | minval = value[axis] |
| 53 | 55 | if value[axis] > maxval: |
| 54 | - maxval = value[axis] | |
| 56 | + maxval = value[axis] | |
| 55 | 57 | if axis == 0: |
| 56 | 58 | self.xlimits = (minval, maxval) |
| 57 | 59 | else: | ... | ... |