-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessIMU.py
More file actions
54 lines (40 loc) · 1.21 KB
/
processIMU.py
File metadata and controls
54 lines (40 loc) · 1.21 KB
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
47
48
49
50
51
52
53
54
import json
import argparse
import numpy as np
def readIMU(infile):
t = []
ax = []
ay = []
az = []
wx = []
wy = []
wz = []
file = open(infile, 'r')
while True:
line = file.readline()
if not line:
break
try:
data = json.loads(line)
except:
continue
if not "msg" in data:
continue
if data["msg"] == "imu_raw":
t.append(float(data["stamp"]))
ax.append(float(data["ax"]))
ay.append(float(data["ay"]))
az.append(float(data["az"]))
wx.append(float(data["wx"]))
wy.append(float(data["wy"]))
wz.append(float(data["wz"]))
return np.array(t), np.array(ax), np.array(ay), np.array(az), np.array(wx), np.array(wy), np.array(wz)
parser = argparse.ArgumentParser(description='Process IMU log.')
parser.add_argument(dest='file', type=str, help='Input file with IMU JSON messages.')
args = parser.parse_args()
t, ax, ay, az, wx, wy, wz = readIMU(args.file)
print('Loaded ' + str(len(t)) + ' IMU messages.')
# process IMU data
# compute norm of the acceleration vector
a = np.sqrt(ax*ax + ay*ay + az*az)
print("a = " + str(a))