1
Fork 0

working with real data

This commit is contained in:
Julian Gaal 2019-04-17 19:36:27 +02:00
parent 64e83d288e
commit 2473fa6964
2 changed files with 17 additions and 5 deletions

View file

@ -14,6 +14,11 @@ Accepted file format from data recording, e.g.
10,7 10,7
``` ```
"rate" defines the number of steps from one data point to the next. I.e. if the sensor pumps out 100 measurements a second, it takes way too long to visualize like this. Adjust rate to e.g. 25 to do 25% faster run:
```
$ python3 viz.py 25
```
For requirements, see [requirements.txt](requirements.txt) For requirements, see [requirements.txt](requirements.txt)
On linux, you need to install `tkinter` with On linux, you need to install `tkinter` with

View file

@ -1,3 +1,5 @@
#!/usr/bin/env python3
import numpy as np import numpy as np
import sys import sys
import math import math
@ -7,7 +9,7 @@ import random
import time import time
fig = plt.figure() fig = plt.figure()
iteration = 0
ax1 = plt.subplot(211) ax1 = plt.subplot(211)
ax2 = plt.subplot(212) ax2 = plt.subplot(212)
@ -19,11 +21,15 @@ class RegrMagic(object):
self.angles = raw_data.split('\n') self.angles = raw_data.split('\n')
self.num_data = len(self.angles) self.num_data = len(self.angles)
self.run_index = 0 self.run_index = 0
self.rate = 1
if len(sys.argv) > 1 and len(sys.argv) < 3:
self.rate = int(sys.argv[1])
print("Rate set to", self.rate)
def __call__(self) -> float: def __call__(self) -> float:
if self.run_index < self.num_data-1: if self.run_index < self.num_data-1:
x,y = self.angles[self.run_index].split(',') x,y = self.angles[self.run_index].split(',')
self.run_index += 1 self.run_index += 100
return float(x), float(y) return float(x), float(y)
else: else:
sys.exit(0) sys.exit(0)
@ -34,7 +40,6 @@ def frames():
while True: while True:
yield regr_magic() yield regr_magic()
def get_start_end(point: (float, float), length: float, angle: float): def get_start_end(point: (float, float), length: float, angle: float):
x, y = point x, y = point
# find the end point # find the end point
@ -55,11 +60,13 @@ def plot_line(args):
Will plot the line on a 5 x 5 plot. Will plot the line on a 5 x 5 plot.
''' '''
global iteration
# unpack the first point # unpack the first point
x, y = (2., 0.) x, y = (2., 0.)
length = 5.0 length = 5.0
roll_angle = args[0] roll_angle = args[0] * 180.0 / math.pi
pitch_angle = args[1] pitch_angle = args[1] * 180.0 / math.pi
print(roll_angle, pitch_angle) print(roll_angle, pitch_angle)
ax1.clear() ax1.clear()