Commit ba381288d523ecdf39a9a3ae7cb6d529f975daf7

Authored by Christopher Stone
1 parent 7b2c967b
Exists in master

Demonstration of plotting data from serial

robots/little_john/telemetry/code/monitor/version1/main.py
@@ -40,7 +40,7 @@ else: @@ -40,7 +40,7 @@ else:
40 os='Other' 40 os='Other'
41 logging.info('OS = ' + os) 41 logging.info('OS = ' + os)
42 42
43 -testseries = Series(points=150, title="Sine wave demo", xname="Time (s)", yname="100sin(t)") 43 +testseries = Series(points=150, ylimits=(9, 1024), title="Sine wave demo", xname="Time (s)", yname="100sin(t)")
44 plots = [] 44 plots = []
45 plots.append(Plot(testseries)) 45 plots.append(Plot(testseries))
46 46
@@ -56,7 +56,7 @@ def pollSerial(elapsed): @@ -56,7 +56,7 @@ def pollSerial(elapsed):
56 for n, value in enumerate(values): 56 for n, value in enumerate(values):
57 values[n] = float(value) 57 values[n] = float(value)
58 #logging.info("Recieved data: " + str(values)) 58 #logging.info("Recieved data: " + str(values))
59 - testseries.addpoint(values) 59 + testseries.addpoint([time.time()-starttime] + values)
60 60
61 def fakePollSerial(elapsed): 61 def fakePollSerial(elapsed):
62 """This function immitates the behaviour of pollSerial, for testing purposes""" 62 """This function immitates the behaviour of pollSerial, for testing purposes"""
@@ -66,6 +66,6 @@ def fakePollSerial(elapsed): @@ -66,6 +66,6 @@ def fakePollSerial(elapsed):
66 testseries.addpoint(values) 66 testseries.addpoint(values)
67 67
68 # Pyglet looks after the main event loop, but this ensures that data keeps being read in 68 # Pyglet looks after the main event loop, but this ensures that data keeps being read in
69 -pyglet.clock.schedule_interval(fakePollSerial, 0.04) 69 +pyglet.clock.schedule_interval(pollSerial, 0.04)
70 70
71 pyglet.app.run() 71 pyglet.app.run()
robots/little_john/telemetry/code/monitor/version1/series.py
@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 import logging 5 import logging
6 6
7 class Series: 7 class Series:
8 - def __init__(self, points=100, title="Series title", xname="x-axis name", yname="y-axis name"): 8 + def __init__(self, points=100, xlimits=(0, 100), ylimits=(0, 100), title="Series title", xname="x-axis name", yname="y-axis name"):
9 """Set up an object to store a 2D data series""" 9 """Set up an object to store a 2D data series"""
10 # Proposal: 10 # Proposal:
11 # In order to neatly handle multiple lines on the same graph 11 # In order to neatly handle multiple lines on the same graph
@@ -20,8 +20,8 @@ class Series: @@ -20,8 +20,8 @@ class Series:
20 self.title = title 20 self.title = title
21 self.xname = xname 21 self.xname = xname
22 self.yname = yname 22 self.yname = yname
23 - self.xlimits = (0, 100)  
24 - self.ylimits = (-100, 100) 23 + self.xlimits = xlimits
  24 + self.ylimits = ylimits
25 self.data = [] 25 self.data = []
26 self.points = points 26 self.points = points
27 27