Commit 637ab4252f02499ffe9d9fac70fdbb02cc17e857
Exists in
master
sorting out merge
Showing
6 changed files
with
51 additions
and
70 deletions
Show diff stats
robots/little_john/telemetry/code/monitor/version1/colours.py
robots/little_john/telemetry/code/monitor/version1/getdata.py
... | ... | @@ -7,7 +7,6 @@ import os |
7 | 7 | import time |
8 | 8 | import math |
9 | 9 | |
10 | - | |
11 | 10 | def getData(starttime, datafeed, testseries, testseries2, fake=False): |
12 | 11 | """Check serial port for incoming data""" |
13 | 12 | # Note: 'elapsed' is time since last call of this function |
... | ... | @@ -16,7 +15,7 @@ def getData(starttime, datafeed, testseries, testseries2, fake=False): |
16 | 15 | if fake: |
17 | 16 | timefromstart = (time.time()-starttime) |
18 | 17 | values = [timefromstart, 100*math.sin(timefromstart)] |
19 | - # logging.info("Generated test data: " + str(values)) | |
18 | + #logging.info("Generated test data: " + str(values)) | |
20 | 19 | testseries.addpoint(values) |
21 | 20 | testseries2.addpoint(values) |
22 | 21 | else: |
... | ... | @@ -24,9 +23,9 @@ def getData(starttime, datafeed, testseries, testseries2, fake=False): |
24 | 23 | incoming = datafeed.readline() |
25 | 24 | except: |
26 | 25 | logging.error("Failed to read input data") |
27 | - | |
26 | + | |
28 | 27 | try: |
29 | - if os == 'Windows': | |
28 | + if os=='Windows': | |
30 | 29 | values = incoming.strip().split(b", ") |
31 | 30 | else: |
32 | 31 | values = incoming.strip() |
... | ... | @@ -34,13 +33,15 @@ def getData(starttime, datafeed, testseries, testseries2, fake=False): |
34 | 33 | except: |
35 | 34 | logging.error("Failed to parse input data") |
36 | 35 | return |
37 | - | |
36 | + | |
38 | 37 | try: |
39 | 38 | for n, value in enumerate(values): |
40 | 39 | values[n] = float(value) |
41 | 40 | except: |
42 | 41 | logging.error("Failed to convert input to float") |
43 | 42 | return |
44 | - # logging.info("Recieved data: " + str(values)) | |
43 | + #logging.info("Recieved data: " + str(values)) | |
45 | 44 | testseries.addpoint([time.time()-starttime] + values) |
46 | 45 | 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 is None: | |
34 | +if datafeed == None: | |
35 | 35 | logging.critical("Failed to open serial port") |
36 | 36 | sys.exit() |
37 | 37 | |
... | ... | @@ -43,11 +43,9 @@ 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)", | |
47 | - xname="Time (s)", yname="ADC output") | |
46 | + title="Data from serial (time)", xname="Time (s)", yname="ADC output") | |
48 | 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 | 50 | plots = [] |
53 | 51 | plots.append(Plot(testseries)) | ... | ... |
robots/little_john/telemetry/code/monitor/version1/plot.py
... | ... | @@ -8,27 +8,24 @@ import logging |
8 | 8 | from colours import * |
9 | 9 | import sys |
10 | 10 | |
11 | - | |
12 | 11 | class Plot(pyglet.window.Window): |
13 | 12 | def __init__(self, series): |
14 | 13 | """Setup a the details of a plot, and create a corresponding window""" |
15 | 14 | pyglet.window.Window.__init__(self, resizable=True) |
16 | 15 | self.set_icon(pyglet.image.load('32x32.png')) |
17 | - self.set_minimum_size(320, 320) | |
16 | + self.set_minimum_size(320,320) | |
18 | 17 | self.series = series |
19 | 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 | 20 | self.lines = (10, 8) |
22 | - # self.resizable = True | |
21 | + #self.resizable = True | |
23 | 22 | self.set_caption(self.series.title) |
24 | 23 | |
25 | 24 | def on_resize(self, width, height): |
26 | 25 | """Handle a resize event from the pyglet event loop""" |
27 | 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 | 29 | except Exception as e: |
33 | 30 | logging.critical(str(e)) |
34 | 31 | self.close() |
... | ... | @@ -57,13 +54,11 @@ class Plot(pyglet.window.Window): |
57 | 54 | self.width, self.height).blit(0, 0) |
58 | 55 | |
59 | 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 | 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 | 62 | heading.draw() |
68 | 63 | |
69 | 64 | def drawLines(self, series): |
... | ... | @@ -83,20 +78,18 @@ class Plot(pyglet.window.Window): |
83 | 78 | try: |
84 | 79 | for m in range(len(series.data[0])-1): |
85 | 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 | 83 | x1 = int((x1/xscale)+lmar) |
91 | 84 | y1 = int((y1/yscale)+bmar) |
92 | 85 | x2 = int((x2/xscale)+lmar) |
93 | 86 | y2 = int((y2/yscale)+bmar) |
94 | 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 | 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 | 93 | pyglet.gl.glLineWidth(1) |
101 | 94 | |
102 | 95 | def drawAxis(self, axis): # axis=0 is x, 1 is y |
... | ... | @@ -115,34 +108,27 @@ class Plot(pyglet.window.Window): |
115 | 108 | stop-start) |
116 | 109 | tagvalue = ((pos-start) * scale) + self.series.xlimits[0] |
117 | 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 | 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 | 115 | x=pos, y=self.height*self.margins[1], |
125 | 116 | anchor_x='left', anchor_y='top') |
126 | 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 | 121 | axistitle.draw() |
133 | 122 | if axis == 1: # y axis, horizontal lines |
134 | 123 | scale = float(self.series.ylimits[1]-self.series.ylimits[0])/( |
135 | 124 | stop-start) |
136 | 125 | tagvalue = ((pos-start) * scale) + self.series.ylimits[0] |
137 | 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 | 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 | 132 | anchor_x='right', anchor_y='center') |
147 | 133 | axistitle = pyglet.text.Label(self.series.yname, color=BLACK, |
148 | 134 | font_name=self.font, | ... | ... |
robots/little_john/telemetry/code/monitor/version1/serialselect.py
... | ... | @@ -2,29 +2,27 @@ |
2 | 2 | # Written as a telemetry tool by: |
3 | 3 | # The UoN Robot Wars Project, 2018 |
4 | 4 | |
5 | - | |
6 | 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 | 7 | import platform |
10 | 8 | import serial |
11 | 9 | import os |
12 | 10 | import easygui |
13 | 11 | import logging |
14 | - | |
12 | + | |
15 | 13 | devpatterns = ['ttyACM', 'ttyUSB', 'rfcomm'] |
16 | 14 | targetdevs = [] |
17 | - if platform.system() == 'Windows': | |
15 | + if platform.system()=='Windows': | |
18 | 16 | com_ports = ['COM%s' % (i + 1) for i in range(256)] |
19 | 17 | for port in com_ports: |
20 | 18 | try: |
21 | 19 | s = serial.Serial(port) |
22 | 20 | s.close() |
23 | 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 | 24 | pass |
27 | - os = 'Windows' # may be useful | |
25 | + os='Windows' #may be useful | |
28 | 26 | else: |
29 | 27 | alldevs = os.listdir("/dev/") |
30 | 28 | targetdevs = [] |
... | ... | @@ -32,7 +30,7 @@ def selectserial(): |
32 | 30 | for pattern in devpatterns: |
33 | 31 | if pattern in dev: |
34 | 32 | targetdevs.append("/dev/" + dev) |
35 | - os = 'Other' # may be useful | |
33 | + os='Other' #may be useful | |
36 | 34 | |
37 | 35 | if len(targetdevs) == 0: |
38 | 36 | logging.info("No serial device found.") |
... | ... | @@ -44,13 +42,13 @@ def selectserial(): |
44 | 42 | message = "Please choose a serial port to recieve data through:" |
45 | 43 | title = "Found multiple serial ports!" |
46 | 44 | serialport = easygui.choicebox(message, title, targetdevs) |
47 | - if serialport is None: | |
45 | + if serialport == None: | |
48 | 46 | logging.info("User cancelled selection dialogue") |
49 | 47 | return None |
50 | 48 | else: |
51 | 49 | logging.info("Only found one likely serial device: " + targetdevs[0]) |
52 | 50 | serialport = targetdevs[0] |
53 | - | |
51 | + | |
54 | 52 | try: |
55 | 53 | datafeed = serial.Serial( |
56 | 54 | port=serialport, | ... | ... |
robots/little_john/telemetry/code/monitor/version1/series.py
... | ... | @@ -4,12 +4,10 @@ |
4 | 4 | |
5 | 5 | import logging |
6 | 6 | |
7 | - | |
8 | 7 | class Series: |
9 | 8 | def __init__(self, points=100, xlimits=(0, 100), ylimits=(0, 100), |
10 | 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 | 11 | """Set up an object to store a 2D data series""" |
14 | 12 | # Proposal: |
15 | 13 | # In order to neatly handle multiple lines on the same graph |
... | ... | @@ -30,9 +28,9 @@ class Series: |
30 | 28 | self.points = points |
31 | 29 | self.xauto = xauto |
32 | 30 | self.yauto = yauto |
33 | - | |
31 | + | |
34 | 32 | logging.info("Created series: " + title) |
35 | - | |
33 | + | |
36 | 34 | def addpoint(self, point): |
37 | 35 | """Add a point to the dataset, and remove the oldest, if necessary""" |
38 | 36 | self.data.append(point) |
... | ... | @@ -45,15 +43,15 @@ class Series: |
45 | 43 | self.autoscale(1) |
46 | 44 | except: |
47 | 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 | 48 | minval = self.data[0][axis] |
51 | 49 | maxval = self.data[0][axis] |
52 | 50 | for value in self.data: |
53 | 51 | if value[axis] < minval: |
54 | 52 | minval = value[axis] |
55 | 53 | if value[axis] > maxval: |
56 | - maxval = value[axis] | |
54 | + maxval = value[axis] | |
57 | 55 | if axis == 0: |
58 | 56 | self.xlimits = (minval, maxval) |
59 | 57 | else: | ... | ... |