Skip to content

Commit f0a235a

Browse files
committed
add logging tool
1 parent 2c578d4 commit f0a235a

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

Diff for: tool/bin2csv.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import pandas as pd
2+
import numpy as np
3+
import struct, sys
4+
5+
COLS = ["ack","sec","ax","ay","az","gx","gy","gz","pitch","roll","yaw","ch1","ch2","co1","co2","pad"]
6+
NCOLS = len(COLS)
7+
8+
src = sys.argv[1]
9+
dst = sys.argv[1].replace(".bin",".csv")
10+
11+
with open(src,"rb") as f:
12+
df = pd.DataFrame(columns=COLS)
13+
n = 0
14+
while True:
15+
buf = f.read(4*NCOLS)
16+
if len(buf) > 0:
17+
row = struct.unpack("i"*2+"f"*(NCOLS-2), buf)
18+
df.loc[n] = row
19+
n = n + 1
20+
else:
21+
break
22+
df["sec"] = df["sec"]/1000. #convert msec to sec
23+
df.to_csv(dst,index=False)
24+
print("\nconverted", src, "to", dst, "[",NCOLS,"x",n,"]")
25+

Diff for: tool/csv2plot.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import pandas as pd
2+
import numpy as np
3+
import struct, sys
4+
import matplotlib.pyplot as plt
5+
6+
RENAME = {}
7+
8+
try:
9+
src = sys.argv[1]
10+
dst = sys.argv[1].replace(".csv","-plot.png")
11+
df = pd.read_csv(src,index_col="sec")
12+
df = df.rename(columns=RENAME)
13+
except OSError as e:
14+
print(e)
15+
else:
16+
## summary
17+
NR = len(df)
18+
TD = df.index[-1] - df.index[0]
19+
COLS = df.columns[1:-1]
20+
print("NR:","%d(samples)"%NR)
21+
print("TD:","%.1f(sec)"%TD)
22+
print("CL:",COLS)
23+
## plot
24+
LOC = "upper right"
25+
LABEL = ["accl (G)", "gyro (dps)", "ahrs (deg)", "pwm (usec)"]
26+
NP = len(LABEL)
27+
#
28+
fig,axs = plt.subplots(NP,1,sharex=True)
29+
for n in range(0,NP):
30+
pl = axs[n]
31+
if n==0: pl.set_title("Samples(%.1fsec@%.fHz): "%(TD,NR/TD) + src)
32+
for c in COLS[3*n:3*(n+1)]: df[c].plot(ax=pl,label=c)
33+
pl.set_ylabel(LABEL[n])
34+
pl.legend(loc=LOC)
35+
pl.grid()
36+
#
37+
plt.savefig(dst)
38+

0 commit comments

Comments
 (0)