Skip to content

Instantly share code, notes, and snippets.

@snajpa
Created August 4, 2016 16:44
Show Gist options
  • Save snajpa/198289ca8776becf6f8e5526f5aa2080 to your computer and use it in GitHub Desktop.
Save snajpa/198289ca8776becf6f8e5526f5aa2080 to your computer and use it in GitHub Desktop.
snajpa@snajpabook:~/Documents/eagle/espbreakout12e$ cat gcode-multiply.sh
#!/bin/bash
ADD_X=$2
ADD_Y=$3
PLACE_XTIMES=${4:-0}
PLACE_YTIMES=${5:-0}
for x in $(seq 0 $PLACE_XTIMES); do
for y in $(seq 0 $PLACE_YTIMES); do
RUNADD_X=$(($ADD_X * $x))
RUNADD_Y=$(($ADD_Y * $y))
# Here be dragons
echo "run x $x y $y" 1>&2
cat $1 | while read line; do
set $line
ignore=true
for i in $(seq 1 $#); do
if [[ ${!i} =~ M0?2$ ]]; then
param="( ${!i} )"
else
param=${!i}
fi
firstchar=${param:0:1}
case "$firstchar" in
X | Y )
value=${param:1}
echo -en $firstchar
addvar="RUNADD_${firstchar}"
echo -en $(echo "scale=4; $value + ${!addvar}" | bc)
;;
*)
echo -en $param
;;
esac
echo -en " "
done;
echo
done
done
done
echo M02
snajpa@snajpabook:~/Documents/eagle/espbreakout12e$ cat gcode-outline.sh
#!/bin/bash
X_EDGE=$1
Y_EDGE=$2
Z_SAFE=3
DEPTH=-2
STEP=0.3
TOOL_DIA=0
CORNER=$(perl -e "print 0.0 - $TOOL_DIA")
echo F300
echo G90
echo S1000
echo G00 Z$Z_SAFE
echo G00 X$CORNER Y$CORNER
echo M03
echo G04 P10.000000
echo G01 Z0
z=0.0
while [ "$(echo "$z > $DEPTH" | bc)" == "1" ]; do
z=$(perl -e "print $z - $STEP")
echo G01 Z$z
echo G01 X$(perl -e "print $X_EDGE + $TOOL_DIA") Y$CORNER
echo G01 X$(perl -e "print $X_EDGE + $TOOL_DIA") Y$(perl -e "print $Y_EDGE + $TOOL_DIA")
echo G01 X$CORNER Y$(perl -e "print $Y_EDGE + $TOOL_DIA")
echo G01 X$CORNER Y$CORNER
done
echo G00 Z$Z_SAFE
echo M05
echo M02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment