Turntable Calculations

Background

For those readers who want more information on the process I used to design the drive mechanism for my turntable project, read on.

roundhouse

Figure 1: KATO roundhouse, in and out of box

The KATO roundhouse has three stalls whose centerlines are spaced 10 degrees apart. We want the stepper mechanism to be able to precisely line up with these three tracks, but to do that the mechanism’s steps per revolution must be a multiple of (360° ⁄ 10°) or 36. None of the stepper motors’ step counts divide evenly by 36, so I need to use a gear or pulley mechanism to change the steps per revolution at the turntable side.

There are three variables which I can adjust to set up the gearing ratio:

  1. Number of steps per revolution of stepper motor
  2. Diameter of motor’s pulley or number of teeth in its gear
  3. Diameter of turntable’s pulley or number of teeth in its gear

To prevent slippage from causing errors in the turntable’s positioning, I am using a toothed belt to connect the motor and turntable, so I have to select the tooth counts of two gears. The belt is an MXL belt which has a pitch (distance between teeth) of 0.08 inches. I also have two small MXL-compatible gears to choose from for the motor side, with 18 or 32 teeth.

For the stepper motor, I have three different stepper motors on hand.

20180106_132442

Figure 2: Stepper motors and gears

From left to right in Figure 2:

  • An 8-wire geared stepper motor with 480 steps per revolution, with a pair of external gears I could use to change the effective resolution to 2400 steps per revolution, or 0.15 degrees per step. Unfortunately, I’ve had this motor for at least 35 years and no longer have the wiring diagram, and it’s too old to be found on the internet. It’s also quite heavy for its size.
  • A newer 4-wire NEMA-17 stepper motor with 200 steps per revolution. Also a bit large and heavy. This motor and the 8-wire one are both designed to be driven with 12 volts. NEMA-17 steppers are commonly used in 3D printers and CNC machines. I got mine from Adafruit.com.
  • A 5-wire geared stepper with 513(!) steps per revolution. This particular device is available both in 5 volt and 12 volt versions from Adafruit.com. Mine is the 5 volt unit.

That last one, with 513 steps per revolution, surprised me at first. 513 is one greater than 2 to the 9th power, and powers of 2 are near and dear to the hearts of many diehard computer geeks. At first I thought 513 was a prime number, but I was wrong. This turned out to be a good thing later on.

Calculations

To get the smallest steps possible on the turntable side, we want the motor resolution high, the motor’s drive gear small, and the turntable’s gear large. Let’s call the number of teeth in the motor’s small gear SG, and use LG for the turntable’s larger gear.

Obviously both SG and LG are whole numbers, because you can’t have fractional teeth in a gear. But the gear ratio GR = (LG SG) can be fractional; a 3:2 or 1.5 gear ratio would be perfectly reasonable. Let’s also use SC for the motor’s step count per revolution. So if we connect a gearing mechanism to our motor, we can move the turntable with a new step count TC = SC × GR = SC × LGSG. It’s TC that we now want to be a multiple of 36 to match the roundhouse dimensions.

I can’t find any larger gears for the turntable side which are compatible with the timing belt and have high enough tooth counts to give me a usable TC, so I will 3D-print a custom one with the number of teeth I want. So how many teeth do I want?

The step count SC is either 480, 2400, 200, or 513, depending on which motor I use, and in the case of the old 480-step motor, if I include the external 5:1 pair of gears. More steps is better, you would think. To get the highest gear ratio, I’ll use the smaller 18-tooth gear on the motor side, so let’s define SG to be 18. TC must be a multiple of 36, so I need to find suitable values for LG, the number of teeth in the turntable’s larger gear.

I have two more constraints I need to consider. First, my 3D printer’s print surface is 220 mm square, or about 8.7 inches in the X and Y directions. So I can’t create a large gear which won’t fit within this area. Also, I need the turntable’s step angle to be (much) smaller than the width of the rail heads at the ends of the turntable’s bridge, so that I can fine-tune the positions where the turntable will need to align with the tracks around its perimeter.

Most N-gauge track uses rails which are 0.025 inch or 0.635 mm thick at the top (the rail head). The turntable bridge is 151 mm long, so the radius is half that or 75.5 mm. So the end of each rail sweeps an angle of (0.635 ⁄ 75.5) ≅ 0.0084 radians ≅ 0.48°. I want the angle moved for each turntable step to be a fraction of that angle, say 0.10°. That will require a larger gear ratio to reduce the turntable step size, but not so large that the gear becomes too big for the printer.

After a few failed attempts at finding workable gear ratios caveman-style (pencil and paper), I finally wrote a Python program which lets me set the initial parameters, and it then searches for sizes of the large gear which meet all my constraints. You can find the source code at the bottom of this page.

First I ran the Python code using the 18-tooth small gear and the 200-step motor (middle one in Figure 2), and I found the following possible solutions.

large gear tooth count diameter (mm) steps between stalls rail width fraction
81 52.4 25 0.83
162 104.8 50 0.42
243 157.2 75 0.28

The 243-tooth gear looks like a good solution, where about 4 steps of the motor would be required to rotate the bridge ends the width of one rail.

Out of curiosity I ran the code again using the 18-tooth small gear but with the (what I thought was a prime number) 513-step motor. I’m still nursing a small bruise from where my jaw hit the tabletop.

large gear tooth count diameter (mm) steps between stalls rail width fraction
48 31.0 38 0.55
72 46.6 57 0.36
96 62.1 76 0.27
120 77.6 95 0.22
144 93.1 114 0.18
168 108.7 133 0.16
192 124.2 152 0.14
216 139.7 171 0.12
240 155.2 190 0.11
264 170.8 209 0.10
288 186.3 228 0.09

Eleven solutions?  That’s when I looked more closely at the number 513 and discovered it’s not prime at all, it’s equal to 3×3×3×19. (I should have realized that earlier, because its digits add up to 9, meaning 513 is a multiple of 9.) As a result, its much higher resolution gave me 11 solutions compared to the 200-step motor’s 3 solutions. This means I can use the more compact, lighter weight motor after all.  Woohoo!

Python code

Below is the Python 3 script I used to search for valid combinations of gear sizes and stepper motor step sizes to work on my railroad turntable project.

import math

# Script update 2018/9/21 by Thomas W Rackers
#   Improved formatting of results.

def millimeters(v):
    return v * 25.4
  
def inches(v):
    return v / 25.4
  
def make_gear(pitch):
    return lambda x : x * pitch / math.pi
    
# Adjustable parameters
stepper_count = 513 # stepper resolution, counts/revolution
small_gear = 18     # tooth count on small pulley

# Fixed values
roundhouse_delta = 10       # angle between roundhouse stalls, degrees
belt_pitch = millimeters(0.08)    # MXL belt pitch, mm
rail_width = millimeters(0.025)   # N gauge rail head width, mm
rail_length = 151           # rail length, mm
max_dia = 200               # max large gear diameter,
                            # limited by 3D printer print volume

# Define belt gear generator with known belt pitch.
gear_dia = make_gear(belt_pitch)
# gear_dia(teeth) will return diameter in mm.

# Angle between stepper steps, degrees
stepper_delta = 360 / stepper_count

# Effective diameter of small gear, mm
small_gear_dia = gear_dia(small_gear)

# Arc width of rail end, degrees
rail_arc = math.degrees(rail_width / (rail_length / 2))

# Try sizes for large gear from small gear's size up.
for large_gear in range(small_gear, 18 * small_gear):
    # Stop if we will exceed 3D printer capacity.
    large_gear_dia = gear_dia(large_gear)
    if large_gear_dia > max_dia:
        break
        
    # Calculate the gear ratio.
    gear_ratio = large_gear / small_gear
    # Calculate the turntable's step size (degrees).
    turntable_delta = stepper_delta / gear_ratio
    # If the turntable steps are not less than the arc of
    # the end of a rail head, skip this one.
    rail_widths = turntable_delta / rail_arc
    if rail_widths > 1:
        continue
        
    # Calculate number of steps between roundhouse stalls.
    roundhouse_steps = roundhouse_delta / turntable_delta
    # Number of steps must be a whole number.
    if roundhouse_steps == int(roundhouse_steps):
        print("Solution found, large gear has {} teeth"
              .format(large_gear))
        print("Large gear diameter is {:.1f} mm or {:.2f} in"
              .format(large_gear_dia, inches(large_gear_dia)))
        print("Gear ratio is {:.1f}"
              .format(gear_ratio))
        print("Turntable step is {:.4f} degrees"
              .format(turntable_delta))
        print("Steps between stalls is {}"
              .format(int(roundhouse_steps)))
        print("Turntable step is {:.4f} times rail width"
              .format(rail_widths))
        print()