Skip to content
Leeroy edited this page Jul 24, 2018 · 26 revisions

Stepper Motor Demo

In this tutorial, we'll model a NEMA 17 stepper motor. The Nema motor is a de facto standard for the reprap project and modeling it is a first step towards designing your own printer parts.

So let's start with the specs:

We need a box that's 42mm x 42mm in size.

box(42);

Stack on top of that a clearance for gears that's 22mm in diameter and set it to whatever height sounds reasonable.

box(42)
align(top)
rod(d=22,h=10);

Now the screws. Screws are set 31mm apart, so position a rod at half this distance from the center along the x and y axes. We'll use translated to do it in all four corners of the motor.

box(42)
align(top)
{
    rod(d=22,h=10);
    
    translated(31*y, [-1,1]/2) 
    translated(31*x, [-1,1]/2) 
    rod(d=3,h=7);
}

Screw Heads

We now have a pretty functional model for most practical purposes. Well, that was easy. Feels like this tutorial should have gone on longer. For the hell of it, let's put some heads on our screws.

box(42)
align(top)
{
    rod(d=22,h=10);
    
    translated(31*y, [-1,1]/2) 
    translated(31*x, [-1,1]/2) 
    rod(d=3,h=7)
    align(top)
    rod(d=6,h=2);
}

Add some screw slots, too. Here we need to perform a difference, but we can't just call difference because the screw slots are going to be the children of the screw heads. Instead, we'll assign the screw slots as negative space and use relativity's CSG operations to take the difference between positive and negative spaces.

box(42, $class="positive")
align(top)
{
    rod(d=22,h=10);
    
    translated(31*y, [-1,1]/2) 
    translated(31*x, [-1,1]/2) 
    rod(d=3,h=7)
    align(top)
    differed("negative", "positive")
    rod(d=6,h=2)
    align(top)
    box([4,1,1], anchor=top, $class="negative");
}

Let's make it a Philip's screw. We'll use rotated to take the slot above and apply it in two different directions.

box(42, $class="positive")
align(top)
{
    rod(d=22,h=10);
    
    translated(31*y, [-1,1]/2) 
    translated(31*x, [-1,1]/2) 
    rod(d=3,h=7)
    align(top)
    differed("negative", "positive")
    rod(d=6,h=2)
    align(top)
    rotated(90*z, [0,1])
    box([4,1,1], anchor=top, $class="negative");
}

Round out the screw heads. We'll split the screw head into two cylinders of different size, then use hulled("positive") to take the hull on just the positive space.

box(42, $class="positive")
align(top)
{
    rod(d=22,h=10);

    translated(31*y, [-1,1]/2) 
    translated(31*x, [-1,1]/2) 
    rod(d=3,h=7)
    align(top)
    differed("negative", "positive")
    
    hulled("positive")
    rod(d=6,h=1.5)
    align(top)
    rod(d=5,h=1)
    
    align(top)
    rotated(90*z, [0,1])
    box([4,1,1], anchor=top, $class="negative");
}

Rotor

Still not enough detail? Let's flesh out the rotor. Shorten the cylinder we modeled for the gear clearance and add a 5mm rotor shaft.

box(42, $class="positive")
align(top)
{
    rod(d=22,h=1)
    align(top)
    rod(d=5, h=20);
    
    translated(31*y, [-1,1]/2) 
    translated(31*x, [-1,1]/2) 
    rod(d=3,h=7)
    align(top)
    differed("negative", "positive")
    hulled("positive")
    rod(d=6,h=1.5)
    align(top)
    rod(d=5,h=1)
    align(top)
    rotated(90*z, [0,1])
    box([4,1,1], anchor=top, $class="negative");
}

Stick a gear on top.

box(42, $class="positive")
align(top)
{
    rod(d=22,h=1)
    align(top)
    rod(d=5, h=20)
    align(top)
    rod(d=15, h=8);
    
    translated(31*y, [-1,1]/2) 
    translated(31*x, [-1,1]/2) 
    rod(d=3,h=7)
    align(top)
    differed("negative", "positive")
    hulled("positive")
    rod(d=6,h=1.5)
    align(top)
    rod(d=5,h=1)
    align(top)
    rotated(90*z, [0,1])
    box([4,1,1], anchor=top, $class="negative");
}

Drill a hole in the gear and slide the shaft through it

box(42, $class="positive")
align(top)
{
    rod(d=22,h=1)
    align(top)
    rod(d=5, h=20)
    align(top)
    translate(2*up)
    differed("negative", "positive")
    rod(d=15, h=8, anchor=$outward)
    rod(d=5, $class="negative");
    
    translated(31*y, [-1,1]/2) 
    translated(31*x, [-1,1]/2) 
    rod(d=3,h=7)
    align(top)
    differed("negative", "positive")
    hulled("positive")
    rod(d=6,h=1.5)
    align(top)
    rod(d=5,h=1)
    align(top)
    rotated(90*z, [0,1])
    box([4,1,1], anchor=top, $class="negative");
}

Now add some gear teeth and a belt catch

box(42, $class="positive")
align(top)
{
    rod(d=22,h=1)
    align(top)
    rod(d=5, h=10)
    align(top)
    translate(2*up)
    differed("negative", "positive")
    rod(d=15, h=8, anchor=$outward){
        rod(d=5, $class="negative");
        
        align(bottom)
        rod(d=17, h=1);
        
        rotated(360/20*z, [1:20])
        align(x)
        align(bottom)
        rod(d=1.75, anchor=$outward, $class="negative");
        
    }
    
    translated(31*y, [-1,1]/2) 
    translated(31*x, [-1,1]/2) 
    rod(d=3,h=7)
    align(top)
    differed("negative", "positive")
    hulled("positive")
    rod(d=6,h=1.5)
    align(top)
    rod(d=5,h=1)
    align(top)
    rotated(90*z, [0,1])
    box([4,1,1], anchor=top, $class="negative");
}

Decorations

Some models have a shallow well around the rotor. Let's draw that!

differed("negative", "positive")
box(42, $class="positive")
align(top)
{
    rod(d=35,h=0.25, anchor=$outward, $class="negative")
    align(bottom)
    rod(d=22,h=2, anchor=$outward, $class="positive")
    align(top)
    rod(d=5, h=10)
    align(top)
    translate(2*up)
    differed("negative", "positive")
    rod(d=15, h=8, anchor=$outward){
        rod(d=5, $class="negative");
    
        align(bottom)
        rod(d=17, h=1);
        
        rotated(360/20*z, [1:20])
        align(x)
        align(bottom)
        rod(d=1.75, anchor=$outward, $class="negative");
    }
    
    translated(31*y, [-1,1]/2) 
    translated(31*x, [-1,1]/2) 
    rod(d=3,h=7)
    align(top)
    differed("negative", "positive")
    hulled("positive")
    rod(d=6,h=1.5)
    align(top)
    rod(d=5,h=1)
    align(top)
    rotated(90*z, [0,1])
    box([4,1,1], anchor=top, $class="negative");
}

Other models have a chamfer on their sides, so we'll add that too.

differed("negative", "positive")
box(42, $class="positive"){
    
    align([-y,y])
    align([-x,x])
    rotate(45*z)
    box([5,5,indeterminate], $class="negative", anchor=center)
    box([10,10,20], anchor=center);
    
    align(top)
    {

        rod(d=35,h=0.25, anchor=$outward, $class="negative")
        align(bottom)
        rod(d=22,h=2, anchor=$outward, $class="positive")
        align(top)
        rod(d=5, h=10)
        align(top)
        translate(2*up)
        differed("negative", "positive")
        rod(d=15, h=8, anchor=$outward){
        rod(d=5, $class="negative");

        align(bottom)
        rod(d=17, h=1);

        rotated(360/20*z, [1:20])
        align(x)
        align(bottom)
        rod(d=1.75, anchor=$outward, $class="negative");
        }

        translated(31*y, [-1,1]/2) 
        translated(31*x, [-1,1]/2) 
        rod(d=3,h=7)
        align(top)
        differed("negative", "positive")
        hulled("positive")
        rod(d=6,h=1.5)
        align(top)
        rod(d=5,h=1)
        align(top)
        rotated(90*z, [0,1])
        box([4,1,1], anchor=top, $class="negative");
    }
}

And there we have it - a finely detailed motor in under 50 lines of code.

Oh, you want more? Why not make a motor mount?

Clone this wiki locally