/
live-from-ios.py
46 lines (35 loc) · 1.26 KB
/
live-from-ios.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import time
from mock import fetchLiveMpuReadings, BASE_URL
FREQ = 100
CURRENT_TEST_KEY = "demo-3-test"
MPU1_RESOURCE_PATH = "ios/accel-jake1?format=ALL"
MPU2_RESOURCE_PATH = "ios/accel-jake2?format=ALL"
def receivedSensorReading(o, t):
print("")
print("###")
print("Time = " + str(t) + " (" + str(t/1000) + "s)")
print("MPU1 = x={x:.5f}, y={y:.5f}, z={z:.5f}".format(x=o[0].x, y=o[0].y, z=o[0].z))
print("MPU2 = x={x:.5f}, y={y:.5f}, z={z:.5f}".format(x=o[1].x, y=o[1].y, z=o[1].z))
print('Reading mock MPU1 and MPU2 ...\n')
print('... from ' + BASE_URL + MPU1_RESOURCE_PATH)
print('... from ' + BASE_URL + MPU2_RESOURCE_PATH)
print('')
app_readings = []
timestamp = 0 # ms
while True:
mpu1_readings = fetchLiveMpuReadings(MPU1_RESOURCE_PATH)
mpu2_readings = fetchLiveMpuReadings(MPU2_RESOURCE_PATH)
results = list(zip(mpu1_readings, mpu2_readings))
for mpu1, mpu2 in results:
diff = abs(float(mpu1.timestamp) - float(mpu2.timestamp))
if diff > 50:
continue
receivedSensorReading([mpu1, mpu2], timestamp)
timestamp += FREQ
time.sleep(FREQ / 1000)
if len(results) == 0:
print("")
print("###")
print("No updates...")
timestamp += 1000
time.sleep(1)