plotting
This commit is contained in:
@ -6,6 +6,9 @@ import numpy as np
|
|||||||
from bleak import BleakClient, BleakScanner
|
from bleak import BleakClient, BleakScanner
|
||||||
from matplotlib import pyplot as plt
|
from matplotlib import pyplot as plt
|
||||||
|
|
||||||
|
# NOTE: this must be run in Jupyter. I rely on the Jupyter run loop for async
|
||||||
|
|
||||||
|
|
||||||
# %%
|
# %%
|
||||||
devices = await BleakScanner.discover()
|
devices = await BleakScanner.discover()
|
||||||
for d in devices:
|
for d in devices:
|
||||||
@ -24,7 +27,7 @@ async with BleakClient(address) as client:
|
|||||||
# print("Model Number: {0}".format("".join(map(chr, model_number))))
|
# print("Model Number: {0}".format("".join(map(chr, model_number))))
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
print("Starting capture...")
|
print("Starting capture...")
|
||||||
while time.time() < start_time + 20:
|
while time.time() < start_time + 3:
|
||||||
buffer = await client.read_gatt_char(SENSORS_UUID)
|
buffer = await client.read_gatt_char(SENSORS_UUID)
|
||||||
sensor_values = np.frombuffer(bytes(buffer), dtype=np.double)
|
sensor_values = np.frombuffer(bytes(buffer), dtype=np.double)
|
||||||
timeseries.append(sensor_values)
|
timeseries.append(sensor_values)
|
||||||
@ -33,7 +36,36 @@ async with BleakClient(address) as client:
|
|||||||
timeseries = np.array(timeseries)
|
timeseries = np.array(timeseries)
|
||||||
|
|
||||||
# %%
|
# %%
|
||||||
plt.plot(timeseries)
|
plt.plot(timeseries, marker=".")
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
# %%
|
||||||
|
a_x, a_y, a_z, g_x, g_y, g_z, m_x, m_y, m_z = timeseries.T
|
||||||
|
t = np.linspace(0, 2, len(timeseries))
|
||||||
|
a = np.sqrt(a_x**2 + a_y**2 + a_z**2)
|
||||||
|
g = 9.81 # acceleration due to gravity
|
||||||
|
h = np.array([0, *np.cumsum((a - g)[1:] * np.diff(t))])
|
||||||
|
|
||||||
|
# %%
|
||||||
|
plt.plot(t, a_x, label="$A_x$")
|
||||||
|
plt.plot(t, a_y, label="$A_y$")
|
||||||
|
plt.plot(t, a_z, label="$A_z$")
|
||||||
|
plt.plot(t, a, color="k", label="$A_{total}$")
|
||||||
|
plt.ylabel("Acceleration [m/s^2]")
|
||||||
|
plt.xlabel("Time [s]")
|
||||||
|
plt.xlim(t[0], t[-1])
|
||||||
|
plt.legend()
|
||||||
|
plt.grid(True)
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
# %%
|
||||||
|
plt.plot(t, h, label="$Z$")
|
||||||
|
plt.ylabel("Displacement [m]")
|
||||||
|
plt.title("Displacement assuming only vertical motion")
|
||||||
|
plt.xlabel("Time [s]")
|
||||||
|
plt.xlim(t[0], t[-1])
|
||||||
|
plt.legend()
|
||||||
|
plt.grid(True)
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
# %%
|
# %%
|
||||||
|
Reference in New Issue
Block a user