diff --git a/tools/deriv.awk b/tools/deriv.awk new file mode 100755 index 0000000..5736b62 --- /dev/null +++ b/tools/deriv.awk @@ -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 + } + } +} diff --git a/tools/velocity_plot.sh b/tools/velocity_plot.sh new file mode 100755 index 0000000..e2d9fed --- /dev/null +++ b/tools/velocity_plot.sh @@ -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 " +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 +"