Sunday, April 20, 2025

Improved Circle Script

Fixes starting Y math error.  Also it now writes to stdout instead of a fixed file name.  This makes it easier to create multiple command sets for common pieces.

#!/bin/bash
# Cut an interior circle starting at xStartBB yStartBB xEndBB yEndBB zStart zStep zEnd feedRate holeDiameter endMillDiameter
# BB is short for BoundingBox
if [ "$#" -eq 0 ];
    then echo "$0 xBB yBB xEndBB yEndBB zStart stepZ endZ feedRate holeDiameter endMillDiameter"
else
    xStartBB=$1
    yStartBB=$2
    xEndBB=$3
    yEndBB=$4
    startZ=$5
    stepZ=$6
    endZ=$7
    feedRate=$8
    holeDiameter=$9
    endMillDiameter=${10}
    millRadius=`echo "$endMillDiameter/2"|bc -l`
    # Calculate starting cut points
    echo $xEndBB $xStartBB $holeDiameter
    center=`echo "(($xEndBB-$xStartBB)/2)"|bc -l`
    echo "centerx = $center"
    offset=`echo "((($xEndBB-$xStartBB)-($holeDiameter))/2)"|bc -l`
    echo "offset = $offset"
        startXCut=`echo "$xStartBB+$offset+$millRadius"|bc -l`
    echo "startXCut = $startXCut"
    startYCut=`echo "($yEndBB-$yStartBB)/2+$offset"|bc -l`
    echo "startYCut = $startYCut"
    endYCut=$startYCut
    echo "endYCut = $endYCut"
    endXCut=`echo "$yEndBB-$offset-$millRadius"|bc -l`
    echo "endXCut = $endXCut"
    # calculate radius for i
    i=`echo "($center-$startXCut)"|bc -l`
    echo "i = $i"
    cat prolog.nc >rotate.nc
    echo "g1 z1.0 f$feedRate" >>rotate.nc
    echo "g1 x$startXCut y$startYCut f$feedRate" >>rotate.nc
    echo "g1 z$startZ y$startYCut f$feedRate" >>rotate.nc
    newstartZ=`echo "$startZ+$stepZ"|bc -l`
    for curZ in `seq $newstartZ $stepZ $endZ`
    do
        echo "g1 z$curZ f$feedRate"    >>rotate.nc
        echo "g2 x$endXCut y$endYCut i$i j0 f$feedRate" >>rotate.nc
        echo "x$startXCut y$startYCut j0 i-$i" >>rotate.nc
    done
    echo "g1 z3.0 f$feedRate" >>rotate.nc
    cat epilog.nc >>rotate.nc
fi


No comments:

Post a Comment