Commit ba381288d523ecdf39a9a3ae7cb6d529f975daf7
1 parent
7b2c967b
Exists in
master
Demonstration of plotting data from serial
Showing
2 changed files
with
6 additions
and
6 deletions
Show diff stats
robots/little_john/telemetry/code/monitor/version1/main.py
| ... | ... | @@ -40,7 +40,7 @@ else: |
| 40 | 40 | os='Other' |
| 41 | 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 | 44 | plots = [] |
| 45 | 45 | plots.append(Plot(testseries)) |
| 46 | 46 | |
| ... | ... | @@ -56,7 +56,7 @@ def pollSerial(elapsed): |
| 56 | 56 | for n, value in enumerate(values): |
| 57 | 57 | values[n] = float(value) |
| 58 | 58 | #logging.info("Recieved data: " + str(values)) |
| 59 | - testseries.addpoint(values) | |
| 59 | + testseries.addpoint([time.time()-starttime] + values) | |
| 60 | 60 | |
| 61 | 61 | def fakePollSerial(elapsed): |
| 62 | 62 | """This function immitates the behaviour of pollSerial, for testing purposes""" |
| ... | ... | @@ -66,6 +66,6 @@ def fakePollSerial(elapsed): |
| 66 | 66 | testseries.addpoint(values) |
| 67 | 67 | |
| 68 | 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 | 71 | pyglet.app.run() | ... | ... |
robots/little_john/telemetry/code/monitor/version1/series.py
| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | import logging |
| 6 | 6 | |
| 7 | 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 | 9 | """Set up an object to store a 2D data series""" |
| 10 | 10 | # Proposal: |
| 11 | 11 | # In order to neatly handle multiple lines on the same graph |
| ... | ... | @@ -20,8 +20,8 @@ class Series: |
| 20 | 20 | self.title = title |
| 21 | 21 | self.xname = xname |
| 22 | 22 | self.yname = yname |
| 23 | - self.xlimits = (0, 100) | |
| 24 | - self.ylimits = (-100, 100) | |
| 23 | + self.xlimits = xlimits | |
| 24 | + self.ylimits = ylimits | |
| 25 | 25 | self.data = [] |
| 26 | 26 | self.points = points |
| 27 | 27 | ... | ... |