Commit 637ab4252f02499ffe9d9fac70fdbb02cc17e857

Authored by Hugo Stephens
2 parents f2e29c3f f838feeb
Exists in master

sorting out merge

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