Show velocity from simulator trace file

Add a tool (tools/velocity_plot.sh) to read in a simulator trace
file, calculate the velocity of the X and Y axes, and show a plot
of these velocities against time along with the X and Y positions.
This commit is contained in:
Phil Hord 2013-12-05 14:02:42 -05:00 committed by Markus Hitter
parent d94e3c7258
commit 199d6d2bb4
2 changed files with 65 additions and 0 deletions

35
tools/deriv.awk Executable file
View File

@ -0,0 +1,35 @@
#!/usr/bin/awk -f
BEGIN { firstline = 1 }
# Calculates the first derivative of columns 2 and 3 wrt column 1
$0 !~ /^#/ {
t = $1
x = $2
y = $3
if (firstline == 1) {
old_tx = old_ty = t
old_x = x
old_y = y
dy_dt = dx_dt = 0
firstline = 0
} else {
dx = old_x - x
dy = old_y - y
if ( dx != 0) {
dt = old_tx - t
dx_dt = dx/dt
old_tx = t
old_x = x
}
if ( dy != 0) {
dt = old_ty - t
dy_dt = dy/dt
old_ty = t
old_y = y
}
if ( dx != 0 || dy != 0 ) {
print t, " ", x, " ", y, " ", dx_dt, " ", dy_dt
}
}
}

30
tools/velocity_plot.sh Executable file
View File

@ -0,0 +1,30 @@
#!/bin/sh
TMPDIR=/tmp
TOOLSDIR=$(dirname $0)
# Set this to your steps-per-mm value, or use 1 to keep results in steps
MM_PER_STEP=500.0
die() {
echo "$1"
exit 1
}
test -n "$1" || die "Usage: $0 <tracefile-name>"
test -f "$1" || die "Error: $1 does not exist or is not a regular file"
FILE="$1"
VELOC="$TMPDIR/$(basename "$FILE").velocity"
"${TOOLSDIR}/deriv.awk" "$FILE" > "$VELOC"
gnuplot --persist -e "
set ylabel 'Position';
set y2label 'Velocity (mm/minute)'; set ytics nomirror ; set y2tics;
set samples 10000 ;
plot '${VELOC}' u (\$1/1000000):(\$2/$MM_PER_STEP) with lines t \"X-position\" , '' u (\$1/1000000):(\$3/$MM_PER_STEP) with lines t \"Y-position\"
, '' u (\$1/1000000):(60000000.0*\$4/$MM_PER_STEP) with lines t \"X-velocity\" axes x1y2
, '' u (\$1/1000000):(60000000.0*\$5/$MM_PER_STEP) with lines t \"Y-velocity\" axes x1y2
"