# Single-Stage Planetary Layout


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

## Executive Summary

**Purpose:** Turn a target ratio, a number of planets and a module into
a planetary gear set that meshes, assembles and fits: tooth counts,
profile shifts, centre distance, speeds, and the space left between the
planets and around the sun bore and ring.

**What it does:** `tooth_count_candidates` lists every sun/planet/ring
combination near the target ratio that satisfies the coaxial, assembly
and neighbour conditions. `PlanetarySet.build` picks profile shifts so
the sun is not undercut and both meshes share one centre distance, and
shortens the ring tips where they would dig into the planet roots.
`module_limits` turns the envelope diameter and the sun shaft into the
smallest and largest module that fit.

**Arrangement:** ring gear fixed, sun is the input, carrier is the
output (the usual single-stage reducer). Ratio
*i* = *n*<sub>*s*</sub>/*n*<sub>*c*</sub> = 1 + *z*<sub>*r*</sub>/*z*<sub>*s*</sub>.

## How It Fits Into the Gear Design Workflow

**Upstream:** `gears.involute` (`GearGeometry`, `mesh_check`, centre
distance and shift relations).

**Downstream:** `gears.rating` (loads and stresses of the two meshes),
`gears.components` (planet pin, bearing and carrier at the centre
distance and planet bore found here), `gears.design` (the search over
modules and tooth counts).

## Tooth Counts: Theory

With sun *z*<sub>*s*</sub>, planets *z*<sub>*p*</sub>, ring
*z*<sub>*r*</sub> and *N* equally spaced planets:

1.  **Ratio** (ring fixed):
    *i* = 1 + *z*<sub>*r*</sub>/*z*<sub>*s*</sub>.
2.  **Coaxial condition.** Both meshes must have the same centre
    distance. With unshifted gears that needs
    *z*<sub>*r*</sub> = *z*<sub>*s*</sub> + 2*z*<sub>*p*</sub>. Profile
    shift lets the ring differ by one tooth,
    *z*<sub>*r*</sub> = *z*<sub>*s*</sub> + 2*z*<sub>*p*</sub> + *δ*
    with *δ* = ±1, which opens up more ratios; the shifts then absorb
    the half-module mismatch.
3.  **Assembly condition.** *N* planets can be put in at equal angles
    only if (*z*<sub>*s*</sub> + *z*<sub>*r*</sub>)/*N* is a whole
    number.
4.  **Neighbour condition.** Adjacent planets must not touch:
    2*a*<sub>*w*</sub>sin (*π*/*N*) \> *d*<sub>*a*, *p*</sub> + *c*,
    where *c* is the gap you need for oil and for the carrier posts that
    pass between the planets.
5.  **Undercut.** A hobbed sun below about 17 teeth needs a positive
    shift; this module adds it automatically, so *z*<sub>*s*</sub> down
    to about 12 is allowed.
6.  **Hunting teeth** (preferred, not required): if *z*<sub>*s*</sub>
    and *z*<sub>*p*</sub> share no common factor, and neither do
    *z*<sub>*p*</sub> and *z*<sub>*r*</sub>, every tooth meets every
    mating tooth and wear evens out.

The figure shows these quantities on the 18/27/72 set with three
planets.

![](02_layout_files/figure-commonmark/cell-2-output-1.png)

**Candidate search.** `tooth_count_candidates` loops over the sun tooth
count *z*<sub>*s*</sub> in the allowed range and, for each one, over
ring counts *z*<sub>*r*</sub> near
(*i*<sub>*t**a**r**g**e**t*</sub> − 1) *z*<sub>*s*</sub>. A combination
is kept when

$$e = \frac{(1 + z_r/z_s) - i\_{target}}{i\_{target}},\quad |e| \le \text{tol};\qquad \frac{z_s + z_r}{N} \in \mathbb{Z};\qquad z_p = \frac{z_r - z_s - \delta}{2} \in \mathbb{Z},\\z_p \ge z\_{p,min},$$

and the neighbour condition holds with unshifted tip diameters
*d*<sub>*a*, *p*</sub> = (*z*<sub>*p*</sub> + 2) *m* and the centre
distance *a* = (*z*<sub>*s*</sub> + *z*<sub>*p*</sub>) *m*/2, both
divided by *m*:

(*z*<sub>*s*</sub> + *z*<sub>*p*</sub>)sin (*π*/*N*) ≥ *z*<sub>*p*</sub> + 2 + *c*<sup>\*</sup>,

with *c*<sup>\*</sup> the required gap in modules (`neighbour_gap`,
default 1). `PlanetarySet` repeats the neighbour check with the final
shifts. Candidates are sorted by |*e*| in steps of 0.5 %, then unshifted
sets (*δ* = 0) first, then hunting-tooth sets, then the smaller sun.

**Speeds.** The Willis equation relates the speeds of sun, ring and
carrier:

$$\frac{n_s - n_c}{n_r - n_c} = -\frac{z_r}{z_s}.$$

With the ring fixed (*n*<sub>*r*</sub> = 0) this gives

$$i = \frac{n_s}{n_c} = 1 + \frac{z_r}{z_s},\qquad n\_{p/c} = -(n_s - n_c)\\\frac{z_s}{z_p},\qquad n_p = n\_{p/c} + n_c,$$

where *n*<sub>*p*/*c*</sub> is the planet speed on its pin (relative to
the carrier, which sets the bearing speed) and *n*<sub>*p*</sub> its
absolute speed. Both meshes run at the tooth-mesh frequency

$$f_z = \frac{\lvert n_s - n_c\rvert\\ z_s}{60}\\\text{\[Hz\]}.$$

The speed (Kutzbach) diagram shows where these come from: tangential
speed grows linearly with radius on each member, and the planet has zero
speed where it touches the fixed ring, so its centre (and the carrier
pin) moves at half the speed of the sun’s pitch point.

![](02_layout_files/figure-commonmark/cell-3-output-1.png)

------------------------------------------------------------------------

### tooth_count_candidates

``` python
def tooth_count_candidates(
    ratio:float, n_planets:int, tol:float=0.02, zs_range:tuple[int, int]=(12, 40), zp_min:int=12,
    deltas:tuple[int, ...]=(0, -1, 1), neighbour_gap:float=1.0
)->list[ToothCounts]:
```

*All tooth counts within `tol` of the target ratio that assemble with
`n_planets` equally spaced* planets and leave a gap of at least
`neighbour_gap` modules between neighbouring planet tips.

Sorted by ratio error in 0.5 % steps, then unshifted sets (δ = 0) first,
hunting teeth first, smaller sun first. The neighbour check uses
unshifted tip diameters; `PlanetarySet` repeats it with the final
shifts.

------------------------------------------------------------------------

### ToothCounts

``` python
def ToothCounts(
    zs:int, zp:int, zr:int, n_planets:int, ratio:float, error:float, hunting:bool, delta:int
)->None:
```

*One sun/planet/ring combination.*

zs, zp, zr : int Tooth counts n_planets : int Number of planets N ratio
: float i = 1 + zr/zs error : float Relative error to the target ratio
hunting : bool zs,zp and zp,zr have no common factor delta : int zr −
(zs + 2 zp): 0 for an unshifted set, ±1 needs profile shift

### Example

A ratio of 5 with three planets. The list does not depend on the module,
so it cannot tell which sun size is best; the design search in
`gears.design` rates each candidate at each module. Here we take the
first one with at least 17 sun teeth.

``` python
cands = tooth_count_candidates(5.0, 3)
print(len(cands), "candidates")
for c in cands[:10]:
    print(f"zs={c.zs:2d} zp={c.zp:2d} zr={c.zr:3d}  i={c.ratio:.4f} ({c.error*100:+.2f} %)  "
          f"hunting={c.hunting}  δ={c.delta:+d}")
best = next(c for c in cands if c.zs >= 17)
print('chosen:', best)
assert (best.zs + best.zr) % 3 == 0 and best.zr == best.zs + 2 * best.zp + best.delta
```

    77 candidates
    zs=12 zp=18 zr= 48  i=5.0000 (+0.00 %)  hunting=False  δ=+0
    zs=18 zp=27 zr= 72  i=5.0000 (+0.00 %)  hunting=False  δ=+0
    zs=24 zp=36 zr= 96  i=5.0000 (+0.00 %)  hunting=False  δ=+0
    zs=30 zp=45 zr=120  i=5.0000 (+0.00 %)  hunting=False  δ=+0
    zs=36 zp=54 zr=144  i=5.0000 (+0.00 %)  hunting=False  δ=+0
    zs=15 zp=23 zr= 60  i=5.0000 (+0.00 %)  hunting=True  δ=-1
    zs=21 zp=31 zr= 84  i=5.0000 (+0.00 %)  hunting=True  δ=+1
    zs=27 zp=41 zr=108  i=5.0000 (+0.00 %)  hunting=True  δ=-1
    zs=33 zp=49 zr=132  i=5.0000 (+0.00 %)  hunting=True  δ=+1
    zs=39 zp=59 zr=156  i=5.0000 (+0.00 %)  hunting=True  δ=-1
    chosen: ToothCounts(zs=18, zp=27, zr=72, n_planets=3, ratio=5.0, error=0.0, hunting=False, delta=0)

## Profile Shifts: Theory

The sun is the smallest gear and carries the highest bending stress, so
it gets a positive shift and the planet the opposite (a *zero-sum* pair
keeps *a*<sub>*w*</sub> = *a*):

*x*<sub>*s*</sub> = max (0.02 (30 − *z*<sub>*s*</sub>), *x*<sub>*s*, *m**i**n*</sub> + 0.05) clipped to \[0, 0.6\],   *x*<sub>*p*</sub> = max (−*x*<sub>*s*</sub>, *x*<sub>*p*, *m**i**n*</sub> + 0.05),

where
$x\_{min} = h\_{fP}^\* - \rho\_{fP}^\*(1-\sin\alpha) - \tfrac{z}{2}\sin^2\alpha$
is the undercut limit. The first term is a common rule for small pinions
(it moves the start of active profile away from the weak root of a small
gear) and is a starting point, not an optimum; you can always pass your
own shifts.

The sun–planet mesh then fixes the centre distance *a*<sub>*w*</sub>.
The ring shift follows from requiring the planet–ring mesh to have the
same *a*<sub>*w*</sub> (`shift_sum_for_centre_distance`). When the
sun–planet shift sum is positive, both tips are shortened by the ISO
21771 amount
*k*<sup>\*</sup> = (*x*<sub>*s*</sub> + *x*<sub>*p*</sub>) − (*a*<sub>*w*</sub> − *a*)/*m*
to keep the standard tip clearance. Finally, if the ring tip would dig
into the planet fillet, or the ring tip circle falls inside its base
circle, the ring tip is shortened in steps of 0.05 *m* until the mesh
checks pass:

*k*<sub>*r*</sub><sup>\*</sup> = 0, 0.05, 0.10, …, 1.0: the first value with *d*<sub>*a*, *r*</sub> ≥ *d*<sub>*b*, *r*</sub> + 0.02 *m* that passes the planet–ring mesh check.

The figure shows the sun shift chosen for each sun tooth count, against
the undercut limit.

![](02_layout_files/figure-commonmark/cell-7-output-1.png)

------------------------------------------------------------------------

### default_shifts

``` python
def default_shifts(
    zs:int, zp:int
)->tuple[float, float]:
```

*Starting profile shifts (x_sun, x_planet) for a planetary set; see the
theory above.*

------------------------------------------------------------------------

### undercut_shift

``` python
def undercut_shift(
    z:int, hf:float=1.25, rho_f:float=0.38, alpha:float=0.3490658503988659
)->float:
```

*Smallest profile shift that avoids undercut of a rack-generated
external gear with z teeth.*

``` python
for zs in (12, 15, 17, 21, 30):
    print(zs, [round(v, 3) for v in default_shifts(zs, 25)], "undercut limit", round(undercut_shift(zs), 3))
assert default_shifts(12, 25)[0] > undercut_shift(12)
```

    12 [0.36, -0.36] undercut limit 0.298
    15 [0.3, -0.3] undercut limit 0.123
    17 [0.26, -0.26] undercut limit 0.006
    21 [0.18, -0.18] undercut limit -0.228
    30 [0.0, -0.0] undercut limit -0.755

## `PlanetarySet`: Theory

`PlanetarySet.build(zs, zp, zr, m, N, b)` puts the steps above together:

1.  Profile shifts *x*<sub>*s*</sub>, *x*<sub>*p*</sub> from
    `default_shifts` (or your own).
2.  Sun–planet centre distance *a*<sub>*w*</sub> from
    inv *α*<sub>*w*</sub> = inv *α* + 2tan *α* (*x*<sub>*s*</sub> + *x*<sub>*p*</sub>)/(*z*<sub>*s*</sub> + *z*<sub>*p*</sub>)
    (`gears.involute`).
3.  Tip shortening
    *k*<sup>\*</sup> = (*x*<sub>*s*</sub> + *x*<sub>*p*</sub>) − (*a*<sub>*w*</sub> − *a*)/*m*
    on sun and planet if it is positive.
4.  Ring shift *x*<sub>*r*</sub> so that the planet–ring mesh has the
    same *a*<sub>*w*</sub>:
    *x*<sub>*r*</sub> = *Σ**x*(*z*<sub>*p*</sub>, −*z*<sub>*r*</sub>, *a*<sub>*w*</sub>) − *x*<sub>*p*</sub>,
    with *Σ**x* from `shift_sum_for_centre_distance`.
5.  Ring tip reduction *k*<sub>*r*</sub><sup>\*</sup> by the step search
    above.

The set then reports its ratio
*i* = 1 + *z*<sub>*r*</sub>/*z*<sub>*s*</sub>, the speeds and mesh
frequency above, and the **neighbour gap** between planet tip circles,

*g*<sub>*N*</sub> = 2*a*<sub>*w*</sub>sin (*π*/*N*) − *d*<sub>*a*, *p*</sub>.

`PlanetarySet.ok` is true only when all of these hold:

- (*z*<sub>*s*</sub> + *z*<sub>*r*</sub>)/*N* is a whole number
  (assembly);
- both meshes pass `MeshCheck.ok` (*ε*<sub>*α*</sub> ≥ 1.2, no
  interference, positive tip clearance);
- *g*<sub>*N*</sub> \> 0;
- neither the sun nor the planet is undercut;
- tip thickness *s*<sub>*a*</sub> \> 0.25 *m* on the sun and the planet
  (thinner tips through-harden and chip).

------------------------------------------------------------------------

### PlanetarySet

``` python
def PlanetarySet(
    sun:GearGeometry, planet:GearGeometry, ring:GearGeometry, n_planets:int, sun_planet:MeshCheck,
    planet_ring:MeshCheck
)->None:
```

*A ring-fixed single-stage planetary gear set (sun in, carrier out).*

## Attributes

sun, planet, ring : GearGeometry n_planets : int sun_planet : MeshCheck
Checks of the sun–planet mesh planet_ring : MeshCheck Checks of the
planet–ring mesh

### Example

The best ratio-5 candidate above, module 1.5, three planets, 20 mm face
width:

``` python
ps = PlanetarySet.build(best.zs, best.zp, best.zr, m=1.5, n_planets=3, b=20)
print(ps.summary())
print({k: round(v, 1) for k, v in ps.speeds(3000).items()}, f"mesh frequency {ps.mesh_frequency(3000):.0f} Hz")
assert ps.ok and math.isclose(ps.planet_ring.a_w, ps.a_w, rel_tol=1e-12)
```

    i = 5.0000, N = 3, m = 1.5 mm, a_w = 33.7500 mm
      gear       z       x     k*         d        da        df      b
      sun       18  +0.240  0.000    27.000    30.720    23.970   20.0
      planet    27  -0.240  0.000    40.500    42.780    36.030   20.0
      ring      72  +0.240  0.200   108.000   104.880   111.030   20.0
      ε_α sun–planet 1.555, planet–ring 1.825, α_w 20.000° / 20.000°, planet tip gap 15.68 mm
      checks: all pass
    {'sun': 3000, 'carrier': 600.0, 'planet_rel': -1600.0, 'planet_abs': -1000.0} mesh frequency 720 Hz

A set with δ = ±1 (ring one tooth off the unshifted coaxial count) still
builds on one centre distance, through the shifts:

``` python
odd = next(c for c in tooth_count_candidates(5.6, 3, tol=0.03) if c.delta != 0)
ps_odd = PlanetarySet.build(odd.zs, odd.zp, odd.zr, m=1.0, n_planets=3, b=12)
print(odd)
print(ps_odd.summary())
assert math.isclose(ps_odd.planet_ring.a_w, ps_odd.a_w, rel_tol=1e-12)
```

    ToothCounts(zs=22, zp=39, zr=101, n_planets=3, ratio=5.590909090909091, error=-0.0016233766233765745, hunting=True, delta=1)
    i = 5.5909, N = 3, m = 1.0 mm, a_w = 30.5000 mm
      gear       z       x     k*         d        da        df      b
      sun       22  +0.160  0.000    22.000    24.320    19.820   12.0
      planet    39  -0.160  0.000    39.000    40.680    36.180   12.0
      ring     101  +0.628  0.200   101.000    98.145   102.245   12.0
      ε_α sun–planet 1.627, planet–ring 1.819, α_w 20.000° / 17.235°, planet tip gap 12.15 mm
      checks: all pass

## Module Limits From the Envelope and the Sun Shaft: Theory

The module is squeezed between two radial stacks: from the shaft out to
the sun root, and from the ring root out to the envelope.

![](02_layout_files/figure-commonmark/cell-14-output-1.png)

**Largest module (envelope).** If the ring gear is also the outer wall,
its outside diameter is the root diameter plus two rim thicknesses
*s*<sub>*R*</sub>:

*D*<sub>*r**i**n**g*</sub> ≈ *m* (*z*<sub>*r*</sub> + 2*h*<sub>*f**P*</sub><sup>\*</sup>) + 2*s*<sub>*R*</sub> ≤ *D*<sub>*e**n**v*</sub> − 2*t*<sub>*h**o**u**s**i**n**g*</sub>.

ISO 6336-3 applies no rim penalty to an internal gear when
*s*<sub>*R*</sub> ≥ 3.5 *m*, so with
*s*<sub>*R*</sub> = *c*<sub>*R*</sub> *m*

$$m\_{max} = \frac{D\_{env} - 2t\_{housing}}{z_r + 2h\_{fP}^\* + 2c_R}.$$

**Smallest module (sun bore).** The sun sits on the input shaft of
diameter *d*<sub>*s**h*</sub> with a key whose hub groove is
*t*<sub>2</sub> deep (DIN 6885-1). The rim between the sun root and the
bottom of the key groove must be at least *c*<sub>*s*</sub> tooth depths
*h*<sub>*t*</sub> = (*h*<sub>*a**P*</sub><sup>\*</sup> + *h*<sub>*f**P*</sub><sup>\*</sup>)*m*:

$$\frac{d\_{f,s}}{2} - \frac{d\_{sh}}{2} - t_2 \ge c_s h_t,\qquad m\_{min} = \frac{d\_{sh}/2 + t_2}{z_s/2 - h\_{fP}^\* - c_s (h\_{aP}^\* + h\_{fP}^\*)}.$$

*c*<sub>*s*</sub> = 1.2 gives no rim penalty for an external gear;
values down to 0.5 are allowed by ISO 6336-3 with a rim factor
*Y*<sub>*B*</sub> \> 1 on the bending stress (`gears.rating` applies
it). A positive sun shift raises *d*<sub>*f*, *s*</sub> and helps here;
the formula ignores it and so errs on the safe side. When no module
satisfies both limits, the sun has to be cut on the shaft itself (pinion
shaft) or the shaft–hub joint changed (spline instead of key).

------------------------------------------------------------------------

### module_limits

``` python
def module_limits(
    envelope_d:float, shaft_d:float, zs:int, zr:int, t2:float=0.0, housing_wall:float=0.0, ring_rim:float=3.5,
    sun_rim:float=1.2, ha:float=1.0, hf:float=1.25
)->tuple[float, float]:
```

*(m_min, m_max) \[mm\] from the sun bore and the envelope, see the
theory above.*

envelope_d : outside diameter available for the ring (or ring + housing)
\[mm\] shaft_d : shaft diameter in the sun bore \[mm\] t2 : hub
key-groove depth \[mm\] (0 for a plain or splined bore) housing_wall :
housing wall thickness outside the ring \[mm\] (0 if the ring is the
housing) ring_rim : ring rim thickness under the tooth roots, in modules
sun_rim : sun rim thickness above the key groove, in tooth depths

### Example

A 120 mm envelope and a 14 mm keyed input shaft (DIN 6885-1 key 5 × 5,
hub groove *t*<sub>2</sub> = 2.3 mm). For a ratio of 5 the ring has
about four times the sun’s teeth, so a small sun leaves no room for the
key and a large one pushes the ring past the envelope. Only sets with
enough sun teeth leave a window, and the window has to contain a
standard module:

``` python
from emachines.gears.involute import standard_modules
```

``` python
feasible, shown = [], 0
for c in cands:
    m_lo, m_hi = module_limits(envelope_d=120, shaft_d=14, zs=c.zs, zr=c.zr, t2=2.3)
    ms = standard_modules(m_lo, m_hi, series_ii=True)
    if shown < 12 and (c.zs in (15, 18, 21, 24) or ms):
        shown += 1
        print(f"zs={c.zs:2d} zp={c.zp:2d} zr={c.zr:3d}: m from {m_lo:.3f} to {m_hi:.3f} mm  standard: {ms}")
    if ms:
        feasible.append((c, ms))
print(f'{len(feasible)} of {len(cands)} candidates fit')
assert feasible and all(module_limits(120, 14, c.zs, c.zr, 2.3)[0] <= ms[0] for c, ms in feasible)
```

    zs=18 zp=27 zr= 72: m from 1.842 to 1.472 mm  standard: []
    zs=24 zp=36 zr= 96: m from 1.155 to 1.137 mm  standard: []
    zs=30 zp=45 zr=120: m from 0.842 to 0.927 mm  standard: [0.9]
    zs=36 zp=54 zr=144: m from 0.662 to 0.782 mm  standard: [0.7]
    zs=15 zp=23 zr= 60: m from 2.620 to 1.727 mm  standard: []
    zs=21 zp=31 zr= 84: m from 1.420 to 1.283 mm  standard: []
    zs=27 zp=41 zr=108: m from 0.974 to 1.021 mm  standard: [1.0]
    zs=33 zp=49 zr=132: m from 0.741 to 0.848 mm  standard: [0.8]
    zs=39 zp=59 zr=156: m from 0.598 to 0.725 mm  standard: [0.6, 0.7]
    zs=15 zp=22 zr= 60: m from 2.620 to 1.727 mm  standard: []
    zs=21 zp=32 zr= 84: m from 1.420 to 1.283 mm  standard: []
    zs=27 zp=40 zr=108: m from 0.974 to 1.021 mm  standard: [1.0]
    45 of 77 candidates fit

------------------------------------------------------------------------

## Tests

## References

- Müller, H.W. (1982). *Epicyclic Drive Trains*. Wayne State University
  Press — Willis equation, assembly and neighbour conditions.
- ISO 21771:2007 — tip shortening for gear pairs with a positive shift
  sum.
- ISO 6336-3:2019, rim thickness factor *Y*<sub>*B*</sub> — limits on
  the rim thickness of the sun and ring.
- DIN 3992:1964 — choice of profile shift coefficients for external
  gears.
