Last active
April 13, 2022 11:58
-
-
Save aquila12/b3979b97b468a174196214f2e0ec30ea to your computer and use it in GitHub Desktop.
Battery charging plotter for Roomba 400 serial logs in gnuplot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/gnuplot -c | |
# Plot battery charge graph | |
logfile=ARG1 | |
tmp=system("mktemp") | |
logname=system("basename '" .logfile. "'") | |
set terminal qt persist noraise size 400,600 | |
set datafile separator ' ' | |
set style data lines | |
quit=0 | |
bind all 'q' 'quit=1' | |
while(!quit) { | |
system "awk '/^bat:/ { \ | |
t1=60*$3+$5; (t==0) ? t0=t1 : t0=t; t=t1; dt=t-t0; \ | |
v=$7/1000; ma=$9; T=$11; mas+=ma*dt; \ | |
print t,v,v/12,ma,T,mas/3600; \ | |
}' \ | |
< '" .logfile. "' > '" .tmp. "'" | |
unset multiplot | |
set multiplot layout 3,1 title 'Battery Charging' | |
set lmargin at screen 0.15 | |
set rmargin at screen 0.85 | |
set grid x lt 1 lw .75 lc "gray" | |
set grid y lt 1 lw .75 lc "gray" | |
set tics nomirror | |
set border 3 | |
set timefmt "%s" | |
set xdata time | |
set format x "%h:%M" | |
set xtics rotate by -45 | |
unset mxtics | |
set title logname | |
set ytics 0.5 format " %0.1f" | |
set y2tics 100 format " %0.0f" | |
unset yrange | |
set y2range [0:] | |
set key Left right bottom reverse box samplen 2 width 2 | |
plot tmp using 1:2 axes x1y1 title 'Voltage', \ | |
tmp using 1:4 axes x1y2 title 'Current (mA)' | |
set title 'Temperature (C)' | |
set ytics 10 format " %0.0f" | |
unset y2tics | |
set yrange [10:70] | |
unset key | |
plot tmp using 1:5 axes x1y1 notitle | |
set title 'Cell Charge' | |
set ytics 0.05 format " %0.2f" | |
set y2tics 200 format " %0.0f" | |
set yrange [1.2:1.45] | |
unset y2range | |
set key Left right bottom reverse box samplen 2 width 2 | |
plot tmp using 1:3 axes x1y1 title 'Voltage', \ | |
tmp using 1:6 axes x1y2 title 'Charge (mAh)' | |
if(ARG2 eq '--live') { pause 5; } else { quit=1; } | |
} | |
system("rm '" .tmp. "'") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment