Skip to content

Commit

Permalink
automate IMU data length calculation for data parser
Browse files Browse the repository at this point in the history
  • Loading branch information
corruptbear committed Jul 24, 2024
1 parent 9a883db commit edfcbe4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 398 deletions.
3 changes: 1 addition & 2 deletions software/management/dashboard/experimental_tottag.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import threading
import asyncio
import argparse
from load_imu_data import IMU_DATA_LEN


# CONSTANTS AND DEFINITIONS -------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -46,8 +47,6 @@
STORAGE_TYPE_RANGES = 4
STORAGE_TYPE_IMU = 5

IMU_DATA_LEN = 21

BATTERY_CODES = defaultdict(lambda: 'Unknown Battery Event')
BATTERY_CODES[1] = 'Plugged'
BATTERY_CODES[2] = 'Unplugged'
Expand Down
67 changes: 34 additions & 33 deletions software/management/dashboard/load_imu_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,38 +100,39 @@ def generate_headers_formats(data_types):
formats+=["%.14f"]*4
return headers,formats


#a = load_data("./0_Yankee_doodle_Saloon_style_padded_100.pkl")
a = load_data("./Unknown.pkl")
data_types = [STAT_DATA,LACC_DATA,GYRO_DATA,QUAT_DATA]
headers,formats = generate_headers_formats(data_types)

all_data = []
for segment in a.loc["i"]:
if not isinstance(segment, list):
print("NAN") # TODO: investigate why NAN shows up? it never happens in the past
continue
for ts, data in segment:
try:
unpacked = unpack_imu_data(data,data_types)
#print(ts, unpacked)
all_data.append([ts]+unpacked)
except:
print(ts)

all_data = np.array(all_data)
print(all_data)
np.savetxt("output.csv", all_data, delimiter=',', header=','.join(headers), comments='', fmt=formats)

timestamps = all_data[:, 0]
timestamps = timestamps - timestamps[0]
lacc_x =all_data[:, 5]
lacc_y =all_data[:, 6]
lacc_z =all_data[:, 7]
gyro_x =all_data[:, 8]
gyro_y =all_data[:, 9]
gyro_z =all_data[:, 10]

#plt.plot(timestamps, lacc_x)
plt.plot(timestamps, lacc_y)
plt.show()
IMU_DATA_LEN = sum([data_type_len[x] for x in data_types])

if __name__ == "__main__":
#a = load_data("./0_Yankee_doodle_Saloon_style_padded_100.pkl")
a = load_data("./Unknown.pkl")
all_data = []
for segment in a.loc["i"]:
if not isinstance(segment, list):
print("NAN") # TODO: investigate why NAN shows up? it never happens in the past
continue
for ts, data in segment:
try:
unpacked = unpack_imu_data(data,data_types)
#print(ts, unpacked)
all_data.append([ts]+unpacked)
except:
print(ts)

all_data = np.array(all_data)
print(all_data)
np.savetxt("output.csv", all_data, delimiter=',', header=','.join(headers), comments='', fmt=formats)

timestamps = all_data[:, 0]
timestamps = timestamps - timestamps[0]
lacc_x =all_data[:, 5]
lacc_y =all_data[:, 6]
lacc_z =all_data[:, 7]
gyro_x =all_data[:, 8]
gyro_y =all_data[:, 9]
gyro_z =all_data[:, 10]

#plt.plot(timestamps, lacc_x)
plt.plot(timestamps, lacc_y)
plt.show()
Loading

0 comments on commit edfcbe4

Please sign in to comment.