# $URL: svn+ssh://mrwhat@ssh.boim.com/home/mrwhat/svn/Walker/trunk/motorMount.pl $
# $Id: motorMount.pl 414 2014-03-13 16:31:15Z mrwhat $
#
# main bar parts and motor mount tabs

sub printMainFlat() {
    local ($x0,$y0,$rot,$bx,$rx,$ay,$ry,$flags) = (@_,0);
    #local $doveTails  = $flags&2;
    local $bottomless = $flags&1;
    local $topless = $flags&2;
    local $motorTab   = $flags&4;
    #local $edgeLess   = $flags&8;
    local $partTab    = $flags&16;

    local $tabRad = 2;
    local $dY = 7.5;#8.3;#1.5*$lr;
    local $hr = $irS;  # alignment/spacer hole radius

    # move mounts to BELOW motor, to avoid getting in way of crank-links
    local $dYtab = $ay-$dA_Motor-$motorRad-$dHole/2;

    &startPart($x0,$y0,$rot);

    &drawCircle(-$bx,0,$rx,17);             #B-axle  hole
    &drawCircle(-$bx+1.5*$dHole,0,$hr,11);  #B-brace alignment hole
    &drawCircle(0, $ay,$ry,32);             #A-axle  hole
    &drawCircle( $bx-1.5*$dHole,0,$hr,11);  #B-brace hole
    &drawCircle( $bx,0,$rx,17);             #B-axle  hole

    local $mountWidth = 6;
    local $tabHoleY = $ay-$dA_Motor-3;
    local $tabHoleX = $motorRad+$mountWidth;
    if ($motorTab) {
	&drawCircle(-$tabHoleX,$tabHoleY,$hr,11);
	&drawCircle( $tabHoleX,$tabHoleY,$hr,11);

        # use motor-cut-out as a hub for the gear
        &drawDhole($rShaft,$dShaft,0,$ay-$dA_Motor);
        &drawCircle(0,$ay-$dA_Motor,$gearHeadRad,360/8);

	# extra cut(s) to make a little brace which can be glued under motor if desired.
	if (1) {  # minimalist cut
	    &drawArc('M',0,$tabHoleY+6*3,$motorRad+3.5*$mountWidth,119+180+6,61+180-6,-5);
	} else { # extra cuts to allow a little more slop on brace
	    printf("\nM%.2f,%.2f\n", $motorRad-1,$tabHoleY-1);
	    &drawArc('L', $tabHoleX,$tabHoleY,$mountWidth+0.3,190,270,12); #extra slop
	    &drawArc('L',0,$tabHoleY+6*3,$motorRad+3.5*$mountWidth,119+180,61+180,-5);
	    &drawArc('L',-$tabHoleX,$tabHoleY,$mountWidth+0.3,270,350,12);
	    printf("\nL%.2f,%.2f\n",-$motorRad+1,$tabHoleY-1);
	}

	print "\nM$bx,-$dY\n";
	local $cr = 10;
	&drawArc('L', 25,-20,$cr,-266,-175,10);
	&drawArc('L', $tabHoleX,$tabHoleY,$mountWidth,380,210,-11);
	printf("\nL$gearHeadRad,%.2f M-$gearHeadRad,%.2f\n",$ay-$dA_Motor,$ay-$dA_Motor);
	&drawArc('L',-$tabHoleX,$tabHoleY,$mountWidth,330,158,-11);
	&drawArc('L',-25,-20,$cr,-22,85,10);

    } else { print "\nM$bx,-$dY\n"; }

    local $lc = 0.5 * (-$dY + ($ay+$dY-($rx-$ry)));
    $lc = 0 if ($lc<0);  # never main main THINNER to accomodate a low $ay
#print STDERR "bx=$bx\tlc=$lc\tdY=$dY\n";
    &drawArc($bottomless?'M':'L',-$bx,$lc,$dY+$lc,-90,-270,-12);
    &drawArc($topless?'M':'L',$bx,$lc,$dY+$lc,90,-90,-12);
    print "\n$endPart\n";
}

sub printMotorStacker() {
    local ($x0,$y0,$rot,$hr) = @_;

    &startPart($x0,$y0,$rot);

    local $mountWidth = 6;
    local $tabHoleY = 3;
    local $tabHoleX = $motorRad+$mountWidth;
    &drawCircle(-$tabHoleX,0,$hr,11);
    &drawCircle( $tabHoleX,0,$hr,11);

    &drawArc('M', $tabHoleX,0,$mountWidth,362,200,-12);
    &drawArc('L',0,-$tabHoleY,$gearHeadRad+$fuzz*0.5,30,150,8);
    &drawArc('L',-$tabHoleX,0,$mountWidth,340,130,-12);
    &drawArc('L',0,-6*$tabHoleY,$motorRad+3.5*$mountWidth,125,55,-6);
    &drawArc('L', $tabHoleX,0,$mountWidth,50,0,-12);

    print "\n$endPart\n";
}

=begin comment

# this motor has a 10x12mm rectangular section on the front, where behind
# is a 6mm radius cylander, 12mm width one way, but truncated to 10mm width
# to match the front section the other way.
# Mounting holes on tab are centered $dHole/2 up from the bottom edge of the mounting tab
sub drawSmallGearheadMotorMount(){
    local ($flags) = (@_,0);
    local $edgeless = $flags & 1;
    local $rCorner = $dHole/3;

    &drawCircle(-$dHole/2,0,$rad4,12);
    &drawCircle( $dHole/2,0,$rad4,12);

    local $motorRad = 6-.07;  # with fuzz for laser cut width
    local $arcLim = 56.443; # arc part of motor can is +- $arcLim degrees
    #&drawArc('M',0,$dHole/2+5,$radQ,0,360,15); # make a convient spacer
    &drawArc('M',0,$dHole/2+5,$motorRad,-$arcLim+3,$arcLim,12);
    &drawArc('L',0,$dHole/2+5,$motorRad,180-$arcLim,180+$arcLim,12);
    &drawArc('L',0,$dHole/2+5,$motorRad,-$arcLim,-$arcLim+3,12);

    &drawArc('M',-$dHole+$rCorner,-$dHole/2   +$rCorner,$rCorner,-180,-90,12);
    &drawArc('L', $dHole-$rCorner,-$dHole/2   +$rCorner,$rCorner, -90,  0,12);
    &drawArc('L', $dHole-$rCorner, $dHole/2+15-$rCorner,$rCorner,   0, 90,12);
    &drawArc('L',-$dHole+$rCorner, $dHole/2+15-$rCorner,$rCorner,  90,180,12);
    printf(" L-$dHole,%.2f\n",-$dHole/2+$rCorner) if !($edgeless);
}

# this motor has a 15.5mm diameter cylander gearhead
# with a 15.5mm diameter motor housing behind, flattened to 12mm wide on the flat side
sub drawGA16gearheadMotorMount(){
    local ($flags) = (@_,0);
    local $edgeless = $flags & 1;
    local $round    = $flags & 2 ? 1 : 0;
    local $topless = $flags & 4;

    local $rCorner = $dHole/3;

    &drawCircle(-$dHole/2,0,$irS,12);
    &drawCircle( $dHole/2,0,$irS,12);

    # move to JansenDefs: local $motorRad = 7.75;  # no fuzz needed on Acrylic
    local $yc = $dHole/2+$motorRad;
    #&drawArc('M',0,$yc,$irB,0,360,15); # make a convient spacer
    &drawDhole($rShaft,$dShaft,0,$yc); # make a convient drive axle spacer
    if ($round) { &drawCircle(0,$yc,$motorRad,30); }
    else {
        local $arcLim = 90-37.747; # arc part of motor can is +- $arcLim degrees
        local $mr = $motorRad - $fuzz*.4;  # previous cut was a little tight on this side, the circular part was just about perfect.
        &drawArc('M',0,$yc,$mr,  3-$arcLim,    $arcLim,12);
        &drawArc('L',0,$yc,$mr,180-$arcLim,180+$arcLim,12);
        &drawArc('L',0,$yc,$mr,   -$arcLim,  3-$arcLim,2); # close the loop
    }
print STDERR "less small motor axis $yc below tab holes\n";

    local $dx = 13;
    &drawArc('M',-$dx+$rCorner,-$dHole/2   +$rCorner,$rCorner,-180,-90,12);
    &drawArc($topless?'M':'L', $dx-$rCorner,-$dHole/2   +$rCorner,$rCorner, -90,  0,12);
    &drawArc('L', 0, $yc,$dx,   0, 180,12);
    printf(" L-$dx,%.2f\n",-$dHole/2+$rCorner) if !($edgeless);
}
=end
=cut

# this motor has a 15.5mm diameter cylander gearhead
# with a 15.5mm diameter motor housing behind, flattened to 12mm wide on the flat side
sub printMotorTabGA16() {
    local ($x0,$y0,$rot,$dy,$hr,$tw) = @_;
    # dy -- offset of tab holes to motor axis
    # hr -- tab hole radius
    # tw -- tab width, nominal

    &startPart($x0,$y0,$rot);

    local $tabHoleX = $motorRad+$tw;
    &drawCircle(-$tabHoleX,0,$hr,11);
    &drawCircle( $tabHoleX,0,$hr,11);
    &drawDhole($rShaft,$dShaft,0,$dy); # make a convient drive axle spacer

    # cut out for flattened rear part of motor
    local $arcLim = 90-37.747; # arc part of motor can is +- $arcLim degrees
    local $mr = $motorRad - $fuzz*.2;
    &drawArc('M',0,$dy,$mr,  3-$arcLim,    $arcLim,12);
    &drawArc('L',0,$dy,$mr,180-$arcLim,180+$arcLim,12);
    &drawArc('L',0,$dy,$mr,   -$arcLim,  3-$arcLim,2); # close the loop

    # outside perimiter
    local $ro = $tabHoleX + 1.2*$tw;
    &drawArc('M', $tabHoleX,0,$tw,0,10,6);
    &drawArc('L',0,-0.8*$tw,$ro,25,155,6);
    &drawArc('L',-$tabHoleX,0,$tw,170,220,9);
    &drawArc('L',0,$dy*6,$motorRad+3.5*$tw,-125,-55,6);
    &drawArc('L', $tabHoleX,0,$tw,-30,0,9);

    print "\n$endPart\n";
}


1;
