Commit 87acb46adb6ae47675efcc8f4d08afe8c55f5eb5

Authored by Christopher Stone
1 parent 3ba04ab1
Exists in master

Added code to actually plot lines! Still very much an experimental arranagement,…

… but scale/limit calculation seems to be correct
robots/little_john/telemetry/code/monitor/version1/main.py
@@ -53,7 +53,7 @@ class Series: @@ -53,7 +53,7 @@ class Series:
53 self.title = title 53 self.title = title
54 self.xname = xname 54 self.xname = xname
55 self.yname = yname 55 self.yname = yname
56 - self.xlimits = (100, 0) 56 + self.xlimits = (0, 100)
57 self.ylimits = (0, 255) 57 self.ylimits = (0, 255)
58 self.data = [] 58 self.data = []
59 self.points = points 59 self.points = points
@@ -97,6 +97,7 @@ class Plot(pyglet.window.Window): @@ -97,6 +97,7 @@ class Plot(pyglet.window.Window):
97 self.drawHeading() 97 self.drawHeading()
98 self.drawAxis(0) 98 self.drawAxis(0)
99 self.drawAxis(1) 99 self.drawAxis(1)
  100 + self.drawLine(self.series)
100 101
101 def drawBackground(self): 102 def drawBackground(self):
102 """Draw the graph background, currently a plain colour""" 103 """Draw the graph background, currently a plain colour"""
@@ -110,10 +111,27 @@ class Plot(pyglet.window.Window): @@ -110,10 +111,27 @@ class Plot(pyglet.window.Window):
110 anchor_x='center', anchor_y='top') 111 anchor_x='center', anchor_y='top')
111 heading.draw() 112 heading.draw()
112 113
113 - def drawLine(self):  
114 - for n in range(len(data) - 1):  
115 - a, b = data[n], data[n+1]  
116 - pass 114 + def drawLine(self, series):
  115 + xscale = float(self.series.xlimits[1]-self.series.xlimits[0])/(self.bounds[0][1]-self.bounds[0][0])
  116 + yscale = float(self.series.ylimits[1]-self.series.ylimits[0])/(self.bounds[1][1]-self.bounds[1][0])
  117 + logging.debug("xscale = " + str(xscale) + ", yscale = " + str(yscale))
  118 + #xscale = 5
  119 + #xscale = self.series.xlimits[1] self.series.xlimits[0]
  120 + #yscale = 1
  121 + lmar = int(self.width * self.margins[0])
  122 + rmar = int(self.width * self.margins[1])
  123 + tmar = int(self.height * self.margins[0])
  124 + bmar = int(self.height * self.margins[1])
  125 + for n in range(len(series.data) - 1):
  126 + x1, y1, x2, y2 = series.data[n][0], series.data[n][1], series.data[n+1][0], series.data[n+1][1]
  127 + x1 = int((x1/xscale)+lmar)
  128 + y1 = int((y1/yscale)+bmar)
  129 + x2 = int((x2/xscale)+lmar)
  130 + y2 = int((y2/yscale)+bmar)
  131 + pyglet.graphics.draw(2, pyglet.gl.GL_LINES,
  132 + ('v2i', (x1, y1, x2, y2)),
  133 + ('c3B', (255, 0, 0, 255, 0, 0)))
  134 +
117 135
118 def drawAxis(self, axis): # axis=0 is x, 1 is y 136 def drawAxis(self, axis): # axis=0 is x, 1 is y
119 """Draw the gridlines and labels for one axis, specified in the last argument""" 137 """Draw the gridlines and labels for one axis, specified in the last argument"""
@@ -181,13 +199,14 @@ def pollSerial(elapsed): @@ -181,13 +199,14 @@ def pollSerial(elapsed):
181 values = values.split(b', ') 199 values = values.split(b', ')
182 for n, value in enumerate(values): 200 for n, value in enumerate(values):
183 values[n] = float(value) 201 values[n] = float(value)
184 - logging.info("Recieved data: " + str(values)) 202 + #logging.info("Recieved data: " + str(values))
185 testseries.addpoint(values) 203 testseries.addpoint(values)
186 204
187 def fakePollSerial(elapsed): 205 def fakePollSerial(elapsed):
188 """This function immitates the behaviour of pollSerial, for testing purposes""" 206 """This function immitates the behaviour of pollSerial, for testing purposes"""
189 - values = [time.time(), time.time()%10]  
190 - logging.info("Generated test data: " + str(values)) 207 + faketime = time.time() * 10
  208 + values = [(faketime%100), faketime%255]
  209 + #logging.info("Generated test data: " + str(values))
191 testseries.addpoint(values) 210 testseries.addpoint(values)
192 211
193 # Pyglet looks after the main event loop, but this ensures that data keeps being read in 212 # Pyglet looks after the main event loop, but this ensures that data keeps being read in