Thanks for the help. The following bash script will generate gCode for cutting a regular hexagon. The parameters should be obvious enough when you read it.
#!/bin/bash
if [[ $# -lt 8 ]];
then echo "$0 xstart ystart zstart zstep zend xyfeed z feed height"
exit 2;
fi
cat prolog.nc >hexagon.nc
xstart=$1
ystart=$2
zstart=$3
zstep=$4
zend=$5
xyfeed=$6
zfeed=$7
height=$8
halfheight=`echo "$height/2" | bc -l`
oneandonehalfheight=`echo "$height*1.5" | bc -l`
doubleheight=`echo "$height*2" | bc -l`
sqrt3div2=`echo "$height * .866" | bc -l`
sqrt3=`echo "$sqrt3div2*2" | bc -l`
cat prolog.nc >hexagon.nc
echo "g1 z1 f25" >>hexagon.nc
for z in $(seq $zstart $zstep $zend)
do
echo "g1 x$xstart y$ystart f$xyfeed" >>hexagon.nc
echo "g1 z$z f$zfeed" >>hexagon.nc
# First vertex
echo "g1 x$halfheight y$sqrt3div2 f$xyfeed" >>hexagon.nc
# second vertice
echo "g1 x$oneandonehalfheight y$sqrt3div2 f$xyfeed" >>hexagon.nc
# far (third) vertex
echo "g1 x$doubleheight y$ystart f$xyfeed" >>hexagon.nc
# fourth vertex
echo "g1 x$oneandonehalfheight y-$sqrt3div2 f$xyfeed" >>hexagon.nc
# fifth vertex
echo "g1 x$halfheight y-$sqrt3div2 f$xyfeed" >>hexagon.nc
# back to start of hexagon
done
echo "g1 z0 f25" >>hexagon.nc
cat epilog.nc >>hexagon.nc
The prolog amd epilog files are just to have consistent gCode files.
prolog.nc
%
g17 g20 g54
epilog.nc
m2
%
No comments:
Post a Comment