@rulecad/gears 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -1
- package/gears.d.mts +47 -1
- package/gears.mjs +119 -15
- package/package.json +3 -1
- package/planetary.d.mts +36 -0
- package/planetary.mjs +77 -0
package/README.md
CHANGED
|
@@ -47,6 +47,8 @@ its numbers come from.
|
|
|
47
47
|
| Spur gear | Teeth on the outside, straight across. Prints flat on the bed with no supports, its teeth in the layers. | `spur({ module, teeth, width, bore?, flat? })` |
|
|
48
48
|
| Rack | A gear of infinite radius: straight teeth on a bar, for a slide driven by a pinion. | `rack({ module, teeth, width, height? })` |
|
|
49
49
|
| Ring gear | Teeth on the inside of a ring, for a pinion turning within it (planetary gearboxes). Turns the same way as its pinion. | `internal({ module, teeth, width, rim? })` |
|
|
50
|
+
| Helical gear | A spur gear's teeth turned along the width by the helix angle: smoother and quieter, more teeth in mesh, but it pushes along its axis. | `helical({ module, teeth, width, helix, hand? })` |
|
|
51
|
+
| Herringbone | Helical one way to the middle and back: no push along the axis, it stays on its shaft and centres itself. Prints with no supports. | `herringbone({ module, teeth, width, helix? })` (30° by default) |
|
|
50
52
|
|
|
51
53
|
Each has a model with its numbers (`gearModel`, `rackModel`, `internalModel`) and an outline in 2D (`spurProfile`,
|
|
52
54
|
`rackProfile`, `internalProfile`: loops of `[x, y]` points). A spur gear's first tooth is on +x, its axis along z. A
|
|
@@ -64,6 +66,7 @@ What every gear takes:
|
|
|
64
66
|
| `width` | (required for a solid) | Up z. A whole number of layers prints as drawn. |
|
|
65
67
|
| `chamfer` | 0.3 mm, at most a quarter module | Round the bed face, so the first layer's squish doesn't widen the teeth there. `[bed, top]` for both faces. |
|
|
66
68
|
| `bore`, `flat` | none | A hole for a shaft, and the depth of a flat across it (a D shaft). |
|
|
69
|
+
| `helix`, `hand`, `herringbone` | 0°, right, no | Helical teeth: the angle (up to 45°), which way they turn (`"right"` turns anticlockwise up z), and whether they turn back at the middle. Racks and rings take them too. `module` and `pressureAngle` stay the transverse ones, so the centre distance is a spur gear's. |
|
|
67
70
|
|
|
68
71
|
## How a pair meshes
|
|
69
72
|
|
|
@@ -75,12 +78,30 @@ What every gear takes:
|
|
|
75
78
|
- **`contact`**: the contact ratio, how many pairs of teeth share the load on average. Under 1 the drive jumps; under
|
|
76
79
|
1.2 it is rough.
|
|
77
80
|
- **`backlash`**: the play, with the centre you gave.
|
|
81
|
+
- **`overlap`** and **`thrust`**: for helical gears, with `width` given, how much the twist adds to the contact ratio, and the push along the axis for each newton driven (none for a herringbone).
|
|
78
82
|
- **`findings`**: `mesh.contact`, `mesh.centre` (axes too close jam the teeth; too far knock), `mesh.module` and
|
|
79
|
-
`mesh.pressure` (gears that can't mesh), `mesh.interference` (a ring too near its pinion's size).
|
|
83
|
+
`mesh.pressure` (gears that can't mesh), `mesh.interference` (a ring too near its pinion's size), `mesh.helix` (helical
|
|
84
|
+
gears that cross: outer gears that mesh are of opposite hands; a pinion and its ring or rack, of the same hand).
|
|
80
85
|
|
|
81
86
|
`phase(a, b, angle)` is the turn that puts a tooth of a in a space of b: b's angle is `ratio × a's angle + phase`,
|
|
82
87
|
with `angle` the direction from a's centre to b's. `rackPhase(pinion, at)` does the same for a rack.
|
|
83
88
|
|
|
89
|
+
## Planetary gearboxes
|
|
90
|
+
|
|
91
|
+
A sun in the middle, planets round it on a carrier, and a ring round them all. Hold one of the three and the other two
|
|
92
|
+
turn at a ratio set by the teeth alone. `planetary({ module, ratio, planets, held, input, output, size })` finds the
|
|
93
|
+
teeth for a ratio that also put together, nearest the ratio first and then the smallest:
|
|
94
|
+
|
|
95
|
+
- the ring is the sun and two planets across: R = S + 2P;
|
|
96
|
+
- the planets go in evenly spaced: S + R a whole number of times the number of planets;
|
|
97
|
+
- the planets' tips clear each other by a module, and the ring has at least 12 teeth more than a planet;
|
|
98
|
+
- the sun and planets have 17 teeth or more (`least`), so none is undercut; the rim fits `size` if given.
|
|
99
|
+
|
|
100
|
+
`best` holds the teeth (ring held, sun in, carrier out, 5:1: a sun of 18, three planets of 27, a ring of 72), each
|
|
101
|
+
planet's place round the carrier and the turn that puts it in phase with the sun, and the ring's turn. When no set
|
|
102
|
+
gives the ratio exactly, the nearest is returned and `planetary.ratio` says how far off it is (a fail past 5%).
|
|
103
|
+
`planetaryRatio({ sun, ring }, { held, input, output })` is the ratio of any teeth, any way round.
|
|
104
|
+
|
|
84
105
|
## How it prints
|
|
85
106
|
|
|
86
107
|
`printable(model, printer, width)` reads the gear against the printer (`{ line, layer, nozzle, wall_min }`, as in
|
|
@@ -90,6 +111,7 @@ with `angle` the direction from a's centre to b's. `rackPhase(pinion, at)` does
|
|
|
90
111
|
- `gear.root`: a tooth narrower at its root than the thinnest wall.
|
|
91
112
|
- `gear.tip`: tips narrower than a line print as one bead.
|
|
92
113
|
- `gear.layers`: a width that isn't a whole number of layers.
|
|
114
|
+
- `gear.helix`: helical teeth lean most at their tips; past 45° the flanks sag. `gear.thrust` says the push along the axis.
|
|
93
115
|
|
|
94
116
|
Spur gears, racks and rings all print flat, with no supports: the teeth are in the layers, where the filament is
|
|
95
117
|
strongest. Every tooth has a round at its root (the commonest place a tooth cracks) and at its tip.
|
|
@@ -97,6 +119,23 @@ strongest. Every tooth has a round at its root (the commonest place a tooth crac
|
|
|
97
119
|
The defaults, each with its rule, are in `DEFAULTS`. The backlash, the chamfer, the tip round and the smallest module
|
|
98
120
|
are estimates until a printed sampler measures them.
|
|
99
121
|
|
|
122
|
+
## How strong it is
|
|
123
|
+
|
|
124
|
+
`strength(model, { width, material, torque?, safety?, speed? })` reads the teeth by the Lewis equation: the bending
|
|
125
|
+
stress at a tooth's root with the whole load at its tip, σ = F_t / (b m Y), Y the Lewis form factor for its teeth
|
|
126
|
+
(`lewisFactor(z)`). Given a torque (N·mm), it says the stress and how far under the material's strength
|
|
127
|
+
(`gear.strength`: a warn under the safety factor, 2 by default; a fail past the strength). Without one, it says the
|
|
128
|
+
torque the gear carries at the safety factor. Helical teeth are read in their normal section; a speed (rpm) adds
|
|
129
|
+
Barth's velocity factor.
|
|
130
|
+
|
|
131
|
+
```js
|
|
132
|
+
strength(gearModel({ module: 1, teeth: 18 }), { width: 6, material: { strength: 39, name: 'PLA' }, torque: 500 });
|
|
133
|
+
// at 0.5 N·m the teeth see 30 MPa at their roots (Lewis, Y 0.309): 1.3× under PLA's 39 MPa, under the 2× asked
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
It is a first number. A printed tooth is weaker than a moulded one where its layers and voids are, and stronger than
|
|
137
|
+
Lewis says where the root fillet and its neighbours share the load. Where it matters, print one and load it.
|
|
138
|
+
|
|
100
139
|
## What isn't refused, and what is
|
|
101
140
|
|
|
102
141
|
A model or a solid refuses what isn't a gear, by name, before any maths: `gearModel: teeth is a whole number of 6 or
|
|
@@ -118,7 +157,15 @@ a point.
|
|
|
118
157
|
| Contact ratio | (√(r_a1² − r_b1²) + √(r_a2² − r_b2²) − a sin α_w) / (π m cos α) | Dudley (1984); KHK |
|
|
119
158
|
| Rack contact | (√(r_a² − r_b²) − r sin α + m (h_a − x) / sin α) / (π m cos α) | KHK |
|
|
120
159
|
| Root fillet | 0.38 m | ISO 53 profile A |
|
|
160
|
+
| Helical twist | the profile turns z tan β / r up the width | ISO 21771 (transverse module) |
|
|
161
|
+
| Overlap ratio | ε_β = b tan β / π m (each half of a herringbone on its own) | ISO 21771 |
|
|
162
|
+
| Thrust | F_a = F_t tan β | Dudley (1984) |
|
|
163
|
+
| Flank lean at the tip | tan β_a = tan β · r_a / r | ISO 21771 |
|
|
121
164
|
| Ring and pinion | at least 10 teeth apart (12 to be safe) at 20° | KHK, internal gears |
|
|
165
|
+
| Planetary ratio | (ω_s − ω_c) / (ω_r − ω_c) = −R / S; ring held, sun in: 1 + R / S | Willis; Dudley (1984), ch. 3 |
|
|
166
|
+
| Planetary assembly | R = S + 2P; (S + R) / n whole; 2a sin(π / n) > d_a,planet | KHK, planetary gears |
|
|
167
|
+
| Tooth bending (Lewis) | σ = K_v F_t / (b m Y); helical: m cos β, z / cos³β teeth | Budynas and Nisbett, Shigley's Mechanical Engineering Design, 10th ed., §14-1 and Table 14-2 |
|
|
168
|
+
| Velocity factor (Barth, cut profile) | K_v = (3.05 + V) / 3.05, V in m/s | Shigley, eq. 14-4b |
|
|
122
169
|
|
|
123
170
|
## Words used
|
|
124
171
|
|
|
@@ -133,7 +180,10 @@ a point.
|
|
|
133
180
|
| Contact ratio | The path of contact over the base pitch: how many pairs of teeth share the load on average. |
|
|
134
181
|
| Profile shift | Moving the teeth outwards (or in) by a fraction of the module, without changing the module or the teeth. |
|
|
135
182
|
| Backlash | Play between mating teeth, so they don't bind as printed parts vary. |
|
|
183
|
+
| Helix angle | How far helical teeth lean from straight across, at the pitch circle. |
|
|
184
|
+
| Hand | Which way helical teeth turn. Two outer gears that mesh are of opposite hands. |
|
|
136
185
|
| Undercut | A pinion of few teeth having its flank cut away under the base circle, or its mate's tip fouling there. |
|
|
186
|
+
| Sun, planets, carrier, ring | A planetary gearbox's parts: the middle gear, the gears round it, what holds the planets' axles, and the ring gear round them all. |
|
|
137
187
|
|
|
138
188
|
## Sources
|
|
139
189
|
|
|
@@ -141,3 +191,4 @@ a point.
|
|
|
141
191
|
- ISO 21771:2007, *Gears: cylindrical involute gears and gear pairs, concepts and geometry*.
|
|
142
192
|
- D. W. Dudley, *Handbook of Practical Gear Design*, McGraw-Hill, 1984.
|
|
143
193
|
- KHK, *Gear Technical Reference* (khkgears.net): undercut, profile shift, internal gears.
|
|
194
|
+
- R. G. Budynas and J. K. Nisbett, *Shigley's Mechanical Engineering Design*, 10th ed., McGraw-Hill, 2015: the Lewis equation and form factors.
|
package/gears.d.mts
CHANGED
|
@@ -33,6 +33,10 @@ export function rackModel(p: GearSpec & {
|
|
|
33
33
|
backlash: any;
|
|
34
34
|
height: any;
|
|
35
35
|
thickness: number;
|
|
36
|
+
helix: any;
|
|
37
|
+
hand: any;
|
|
38
|
+
herringbone: boolean;
|
|
39
|
+
thrust: number;
|
|
36
40
|
length: number;
|
|
37
41
|
tipLine: number;
|
|
38
42
|
rootLine: number;
|
|
@@ -87,6 +91,10 @@ export function rackProfile(p: any, grow?: number): {
|
|
|
87
91
|
backlash: any;
|
|
88
92
|
height: any;
|
|
89
93
|
thickness: number;
|
|
94
|
+
helix: any;
|
|
95
|
+
hand: any;
|
|
96
|
+
herringbone: boolean;
|
|
97
|
+
thrust: number;
|
|
90
98
|
length: number;
|
|
91
99
|
tipLine: number;
|
|
92
100
|
rootLine: number;
|
|
@@ -110,6 +118,15 @@ export function rackProfile(p: any, grow?: number): {
|
|
|
110
118
|
* @returns {object} a JSCAD geom3
|
|
111
119
|
*/
|
|
112
120
|
export function spur(p: GearSpec & Solid): object;
|
|
121
|
+
/** A helical gear: a spur gear's profile turned along its width by the helix angle. Meshes with one of the opposite hand. @param {GearSpec & Solid & { helix: number, hand?: 'right' | 'left' }} p */
|
|
122
|
+
export function helical(p: GearSpec & Solid & {
|
|
123
|
+
helix: number;
|
|
124
|
+
hand?: "right" | "left";
|
|
125
|
+
}): any;
|
|
126
|
+
/** A herringbone gear: helical one way to the middle of its width and back, so it pushes no thrust along its axis and stays on its shaft. Prints with no supports. @param {GearSpec & Solid & { helix?: number }} p */
|
|
127
|
+
export function herringbone(p: GearSpec & Solid & {
|
|
128
|
+
helix?: number;
|
|
129
|
+
}): any;
|
|
113
130
|
/** An internal (ring) gear, its rim round it. @param {GearSpec & Solid & { rim?: number }} p */
|
|
114
131
|
export function internal(p: GearSpec & Solid & {
|
|
115
132
|
rim?: number;
|
|
@@ -125,7 +142,7 @@ export function rack(p: GearSpec & Solid & {
|
|
|
125
142
|
* a centre distance checked: closer than needed jams the teeth, further adds backlash.
|
|
126
143
|
* @param {GearModel} a @param {GearModel} b @param {{ centre?: number }} [o]
|
|
127
144
|
*/
|
|
128
|
-
export function mesh(a: GearModel, b: GearModel, { centre }?: {
|
|
145
|
+
export function mesh(a: GearModel, b: GearModel, { centre, width }?: {
|
|
129
146
|
centre?: number;
|
|
130
147
|
}): any;
|
|
131
148
|
/**
|
|
@@ -153,6 +170,34 @@ export function printable(g: GearModel, printer: {
|
|
|
153
170
|
nozzle?: number;
|
|
154
171
|
wall_min?: number;
|
|
155
172
|
}, width?: number): any[];
|
|
173
|
+
/** The Lewis form factor Y for z teeth (20° full depth); Infinity for a rack. @param {number} z */
|
|
174
|
+
export function lewisFactor(z: number): number;
|
|
175
|
+
/**
|
|
176
|
+
* How strong a gear's teeth are by the Lewis equation: the bending stress at the root of a tooth carrying the whole
|
|
177
|
+
* load at its tip, σ = F_t / (b m Y), against the material's strength. Give a torque (N·mm) for the stress and safety
|
|
178
|
+
* factor at it; give a safety factor for the torque the gear carries at it. Helical teeth are read in their normal
|
|
179
|
+
* section (m cos β, z / cos³β teeth). A speed (rpm) adds Barth's velocity factor, (3.05 + V) / 3.05 for a cut (here a
|
|
180
|
+
* printed) profile. A first number: the root fillet and a tooth's neighbours help, a printed tooth's layers and
|
|
181
|
+
* voids hurt. Where it matters, measure it, or analyse the tooth (fea).
|
|
182
|
+
* @param {GearModel} g
|
|
183
|
+
* @param {{ width: number, material: { strength: number, name?: string }, torque?: number, safety?: number, speed?: number }} o
|
|
184
|
+
*/
|
|
185
|
+
export function strength(g: GearModel, o?: {
|
|
186
|
+
width: number;
|
|
187
|
+
material: {
|
|
188
|
+
strength: number;
|
|
189
|
+
name?: string;
|
|
190
|
+
};
|
|
191
|
+
torque?: number;
|
|
192
|
+
safety?: number;
|
|
193
|
+
speed?: number;
|
|
194
|
+
}): {
|
|
195
|
+
Y: number;
|
|
196
|
+
velocity: number;
|
|
197
|
+
force: number;
|
|
198
|
+
torque: number;
|
|
199
|
+
findings: any[];
|
|
200
|
+
};
|
|
156
201
|
/**
|
|
157
202
|
* The defaults, each with the rule it comes from. Coefficients are times the module.
|
|
158
203
|
* @type {Record<string, { value: number, unit: string, rule: string, kind: string }>}
|
|
@@ -247,3 +292,4 @@ export type GearModel = {
|
|
|
247
292
|
};
|
|
248
293
|
};
|
|
249
294
|
import jscad from '@jscad/modeling';
|
|
295
|
+
export { planetary, planetaryRatio } from "./planetary.mjs";
|
package/gears.mjs
CHANGED
|
@@ -52,7 +52,13 @@ function common(what, p) {
|
|
|
52
52
|
const dedendum = between(what, 'dedendum', p.dedendum ?? D('dedendum'), addendum, 2, ' (times the module, at least the addendum)');
|
|
53
53
|
const rootFillet = between(what, 'rootFillet', p.rootFillet ?? D('rootFillet'), 0, 0.6, ' (times the module)');
|
|
54
54
|
const tipRound = between(what, 'tipRound', p.tipRound ?? D('tipRound'), 0, 0.4, ' (times the module)');
|
|
55
|
-
|
|
55
|
+
// Helical teeth: the spur profile turned along the width by the helix angle (the module and pressure angle are the
|
|
56
|
+
// transverse ones, in the gear's own plane, so a helical gear's centre distance is a spur gear's)
|
|
57
|
+
const helix = between(what, 'helix', p.helix ?? 0, 0, 45, '°');
|
|
58
|
+
if (p.hand != null && p.hand !== 'right' && p.hand !== 'left') throw new Error(`${what}: hand is "right" or "left" (got ${shown(p.hand)})`);
|
|
59
|
+
if (p.herringbone != null && typeof p.herringbone !== 'boolean') throw new Error(`${what}: herringbone is true or false (got ${shown(p.herringbone)})`);
|
|
60
|
+
if (p.herringbone && !helix) throw new Error(`${what}: a herringbone needs a helix angle (say helix: 30)`);
|
|
61
|
+
return { module, pressureAngle, shift, backlash, addendum, dedendum, rootFillet, tipRound, helix, hand: p.hand ?? 'right', herringbone: !!p.herringbone };
|
|
56
62
|
}
|
|
57
63
|
|
|
58
64
|
// ---------- the numbers ----------
|
|
@@ -97,6 +103,7 @@ export function gearModel(p) {
|
|
|
97
103
|
const rootHalf = halfAt(s, r, rb, Math.max(rf, rb));
|
|
98
104
|
return {
|
|
99
105
|
kind: 'external', module: m, teeth, pressureAngle, shift: x, backlash,
|
|
106
|
+
helix: c.helix, hand: c.hand, herringbone: c.herringbone, thrust: c.herringbone ? 0 : Math.tan(c.helix * DEG),
|
|
100
107
|
pitch: 2 * r, base: 2 * rb, tip: 2 * ra, root: 2 * rf, thickness: s,
|
|
101
108
|
circularPitch: Math.PI * m, basePitch: Math.PI * m * Math.cos(a),
|
|
102
109
|
topLand: 2 * ra * Math.sin(tipHalf), rootThickness: 2 * Math.max(rf, rb) * Math.sin(rootHalf),
|
|
@@ -124,6 +131,7 @@ export function internalModel(p) {
|
|
|
124
131
|
if (!(toothHalf(ra) > 0)) throw new Error(`${what}: the teeth come to a point at the tip circle: less profile shift`);
|
|
125
132
|
return {
|
|
126
133
|
kind: 'internal', module: m, teeth, pressureAngle, shift: x, backlash,
|
|
134
|
+
helix: c.helix, hand: c.hand, herringbone: c.herringbone, thrust: c.herringbone ? 0 : Math.tan(c.helix * DEG),
|
|
127
135
|
pitch: 2 * r, base: 2 * rb, tip: 2 * ra, root: 2 * rf, thickness: s, space: e, rim,
|
|
128
136
|
circularPitch: Math.PI * m, basePitch: Math.PI * m * Math.cos(a),
|
|
129
137
|
topLand: 2 * Math.max(ra, rb) * Math.sin(toothHalf(Math.max(ra, rb))), rootThickness: 2 * rf * Math.sin(toothHalf(rf)),
|
|
@@ -147,6 +155,7 @@ export function rackModel(p) {
|
|
|
147
155
|
if (!(tipHalf > 0)) throw new Error(`${what}: the teeth come to a point: a smaller addendum or pressure angle`);
|
|
148
156
|
return {
|
|
149
157
|
kind: 'rack', module: m, teeth, pressureAngle, shift: 0, backlash, height, thickness: s,
|
|
158
|
+
helix: c.helix, hand: c.hand, herringbone: c.herringbone, thrust: c.herringbone ? 0 : Math.tan(c.helix * DEG),
|
|
150
159
|
length: teeth * Math.PI * m, tipLine: m * c.addendum, rootLine: -m * c.dedendum,
|
|
151
160
|
circularPitch: Math.PI * m, basePitch: Math.PI * m * Math.cos(a),
|
|
152
161
|
topLand: 2 * tipHalf, rootThickness: s + 2 * m * c.dedendum * Math.tan(a),
|
|
@@ -315,20 +324,23 @@ export function rackProfile(p, grow = 0) {
|
|
|
315
324
|
|
|
316
325
|
// A solid from loops at heights: each slice is the loops at a height, grown (a chamfer: drawn smaller there) and turned
|
|
317
326
|
// (a helix), all with the same points, so the walls join point to point. Caps are triangulated with their holes.
|
|
318
|
-
function loft(profile, width, { chamfer, twist }) {
|
|
327
|
+
function loft(profile, width, { chamfer, twist, slide }) {
|
|
319
328
|
const [bottom, top] = Array.isArray(chamfer) ? chamfer : [chamfer, 0];
|
|
320
329
|
if (bottom + top >= width) throw new Error(`the chamfers (${bottom} and ${top} mm) are as tall as the gear (${width} mm)`);
|
|
321
330
|
// heights: the chamfers' ends, and for a twist enough between that no slice turns more than a degree or so
|
|
322
331
|
const zs = [0, ...(bottom > 0 ? [bottom] : []), ...(top > 0 ? [width - top] : []), width];
|
|
323
332
|
if (twist) {
|
|
324
|
-
const most = Math.max(...
|
|
333
|
+
const most = Math.max(...[0, 0.25, 0.5, 0.75, 1].map((f) => Math.abs(twist(width * f)))), n = Math.ceil(most / (1.5 * DEG));
|
|
325
334
|
for (let i = 1; i < n; i++) zs.push((width * i) / n);
|
|
335
|
+
zs.push(width / 2); // (a herringbone's apex)
|
|
326
336
|
}
|
|
337
|
+
if (slide) { const n = Math.ceil(width / 0.5); for (let i = 1; i < n; i++) zs.push((width * i) / n); zs.push(width / 2); }
|
|
327
338
|
const heights = [...new Set(zs.map((z) => +z.toFixed(9)))].sort((x, y) => x - y);
|
|
328
339
|
const slices = heights.map((z) => {
|
|
329
340
|
const grow = z < bottom ? -(bottom - z) : z > width - top ? -(z - (width - top)) : 0;
|
|
330
|
-
const loops = profile(grow), turn = twist ? twist(z) : 0, c = Math.cos(turn), s = Math.sin(turn);
|
|
331
|
-
const
|
|
341
|
+
const loops = profile(grow), turn = twist ? twist(z) : 0, c = Math.cos(turn), s = Math.sin(turn), dx = slide ? slide(z) : 0;
|
|
342
|
+
const at = (p) => [p[0] * c - p[1] * s + dx, p[0] * s + p[1] * c];
|
|
343
|
+
const sides = loops.flatMap((pts) => pts.map((p, i) => [at(p), at(pts[(i + 1) % pts.length])]));
|
|
332
344
|
return slice.transform(mat4.fromTranslation(mat4.create(), [0, 0, z]), slice.fromSides(sides));
|
|
333
345
|
});
|
|
334
346
|
return extrudeFromSlices({ numberOfSlices: slices.length, repair: false, callback: (t, i) => slices[i] }, slices[0]);
|
|
@@ -343,22 +355,42 @@ function loft(profile, width, { chamfer, twist }) {
|
|
|
343
355
|
*/
|
|
344
356
|
export function spur(p) {
|
|
345
357
|
const width = size('spur', 'width', p?.width), chamfer = chamfers('spur', p, width);
|
|
346
|
-
spurProfile(p); // (refuses here, before any slicing)
|
|
347
|
-
return loft((grow) => spurProfile(p, grow).loops, width, { chamfer });
|
|
358
|
+
const { model: g } = spurProfile(p); // (refuses here, before any slicing)
|
|
359
|
+
return loft((grow) => spurProfile(p, grow).loops, width, { chamfer, twist: twistOf(g, width) });
|
|
348
360
|
}
|
|
349
361
|
|
|
362
|
+
// How far a helical gear's profile has turned at height z: z tan β / r, the right hand turning anticlockwise up z; a
|
|
363
|
+
// herringbone turns to the middle and back. Gears that mesh outside each other are of opposite hands; a pinion and its
|
|
364
|
+
// ring, or its rack, of the same hand.
|
|
365
|
+
function twistOf(g, width) {
|
|
366
|
+
if (!g.helix) return null;
|
|
367
|
+
const k = (g.hand === 'left' ? -1 : 1) * Math.tan(g.helix * DEG) / (g.pitch / 2);
|
|
368
|
+
return g.herringbone ? (z) => k * Math.min(z, width - z) : (z) => k * z;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/** A helical gear: a spur gear's profile turned along its width by the helix angle. Meshes with one of the opposite hand. @param {GearSpec & Solid & { helix: number, hand?: 'right' | 'left' }} p */
|
|
372
|
+
export function helical(p) {
|
|
373
|
+
if (!(p?.helix > 0)) throw new Error(`helical: give a helix angle above 0° (got ${shown(p?.helix)}); 15° to 30° print well`);
|
|
374
|
+
return spur({ ...p, herringbone: false });
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/** A herringbone gear: helical one way to the middle of its width and back, so it pushes no thrust along its axis and stays on its shaft. Prints with no supports. @param {GearSpec & Solid & { helix?: number }} p */
|
|
378
|
+
export function herringbone(p) { return spur({ ...p, helix: p?.helix ?? 30, herringbone: true }); }
|
|
379
|
+
|
|
350
380
|
/** An internal (ring) gear, its rim round it. @param {GearSpec & Solid & { rim?: number }} p */
|
|
351
381
|
export function internal(p) {
|
|
352
382
|
const width = size('internal', 'width', p?.width), chamfer = chamfers('internal', p, width);
|
|
353
|
-
internalProfile(p);
|
|
354
|
-
return loft((grow) => internalProfile(p, grow).loops, width, { chamfer });
|
|
383
|
+
const { model: g } = internalProfile(p);
|
|
384
|
+
return loft((grow) => internalProfile(p, grow).loops, width, { chamfer, twist: twistOf(g, width) });
|
|
355
385
|
}
|
|
356
386
|
|
|
357
387
|
/** A rack along x, its teeth up +y, its width up z. @param {GearSpec & Solid & { height?: number }} p */
|
|
358
388
|
export function rack(p) {
|
|
359
389
|
const width = size('rack', 'width', p?.width), chamfer = chamfers('rack', p, width);
|
|
360
|
-
rackProfile(p);
|
|
361
|
-
|
|
390
|
+
const { model: g } = rackProfile(p);
|
|
391
|
+
// a helical rack's teeth slide along it with height as its pinion's turn: z tan β, the same hand as the pinion
|
|
392
|
+
const k = g.helix ? (g.hand === 'left' ? -1 : 1) * Math.tan(g.helix * DEG) : 0;
|
|
393
|
+
return loft((grow) => rackProfile(p, grow).loops, width, { chamfer, ...(k ? { slide: g.herringbone ? (z) => k * Math.min(z, width - z) : (z) => k * z } : {}) });
|
|
362
394
|
}
|
|
363
395
|
|
|
364
396
|
function chamfers(what, p, width) {
|
|
@@ -386,14 +418,22 @@ function working(a, sum, zs) {
|
|
|
386
418
|
* a centre distance checked: closer than needed jams the teeth, further adds backlash.
|
|
387
419
|
* @param {GearModel} a @param {GearModel} b @param {{ centre?: number }} [o]
|
|
388
420
|
*/
|
|
389
|
-
export function mesh(a, b, { centre } = {}) {
|
|
421
|
+
export function mesh(a, b, { centre, width } = {}) {
|
|
390
422
|
const out = [], f = (level, text, code, values) => out.push({ level, text, code, ...(values ? { values } : {}) });
|
|
391
423
|
for (const [k, g] of [['a', a], ['b', b]]) if (!g || !['external', 'internal', 'rack'].includes(g.kind)) throw new Error(`mesh: ${k} is a gear's model (gearModel, internalModel or rackModel), not ${shown(g)}`);
|
|
392
424
|
if (a.kind !== 'external' && b.kind !== 'external') throw new Error(`mesh: a ${a.kind} and a ${b.kind} don't mesh: one of them is an outer gear`);
|
|
393
|
-
if (b.kind === 'external' && a.kind !== 'external') return flip(mesh(b, a, { centre }));
|
|
425
|
+
if (b.kind === 'external' && a.kind !== 'external') return flip(mesh(b, a, { centre, width }));
|
|
394
426
|
if (Math.abs(a.module - b.module) > 1e-9) f('fail', `modules differ (${a.module} and ${b.module} mm): teeth of different sizes don't mesh`, 'mesh.module');
|
|
395
427
|
if (Math.abs(a.pressureAngle - b.pressureAngle) > 1e-9) f('fail', `pressure angles differ (${a.pressureAngle}° and ${b.pressureAngle}°): the flanks don't roll on each other`, 'mesh.pressure');
|
|
396
428
|
const m = a.module, al = a.pressureAngle * DEG, pb = Math.PI * m * Math.cos(al);
|
|
429
|
+
// Helical teeth: the same angle, opposite hands outside each other, the same hand on a ring or a rack
|
|
430
|
+
const ha = a.helix ?? 0, hb = b.helix ?? 0;
|
|
431
|
+
if (Math.abs(ha - hb) > 1e-9) f('fail', `helix angles differ (${ha}° and ${hb}°): the teeth cross each other`, 'mesh.helix');
|
|
432
|
+
else if (ha > 0) {
|
|
433
|
+
const same = b.kind !== 'external';
|
|
434
|
+
if ((a.hand === b.hand) !== same) f('fail', `both are ${a.hand}-handed: ${same ? `a pinion and its ${b.kind === 'rack' ? 'rack' : 'ring'} are of the same hand` : 'outer gears that mesh are of opposite hands'}`, 'mesh.helix');
|
|
435
|
+
if (!!a.herringbone !== !!b.herringbone) f('fail', 'a herringbone meshes only with a herringbone', 'mesh.helix');
|
|
436
|
+
}
|
|
397
437
|
const ra1 = a.tip / 2, rb1 = a.base / 2, r1 = a.pitch / 2;
|
|
398
438
|
let need, ratio, contact, aw = al;
|
|
399
439
|
if (b.kind === 'external') {
|
|
@@ -418,10 +458,14 @@ export function mesh(a, b, { centre } = {}) {
|
|
|
418
458
|
ratio = Math.PI * a.pitch; // mm a turn
|
|
419
459
|
contact = (Math.sqrt(ra1 ** 2 - rb1 ** 2) - r1 * Math.sin(al) + (m * (b.rack.addendum - a.shift)) / Math.sin(al)) / pb;
|
|
420
460
|
}
|
|
461
|
+
// the overlap ratio: how far a tooth's own twist carries the contact on across the width (εβ = b tan β / π m, each
|
|
462
|
+
// half of a herringbone on its own)
|
|
463
|
+
const overlap = ha > 0 && width !== undefined ? ((a.herringbone ? width / 2 : width) * Math.tan(ha * DEG)) / (Math.PI * m) : 0;
|
|
464
|
+
if (overlap) contact += overlap;
|
|
421
465
|
const sense = b.kind === 'rack' ? `${fmt(ratio)} mm of rack a turn (${fmt(ratio / 360, 4)} mm a degree)` : `${fmt(Math.abs(ratio), 4)} turns of the second for each turn of the first (${a.teeth}:${b.teeth}), ${ratio < 0 ? 'turning opposite ways' : 'the same way'}`;
|
|
422
466
|
if (contact < 1) f('fail', `contact ratio ${fmt(contact)}: under 1, a pair of teeth lets go before the next takes up, and the drive jumps: more teeth, or a longer addendum`, 'mesh.contact', { contact });
|
|
423
467
|
else if (contact < 1.2) f('warn', `contact ratio ${fmt(contact)}: under 1.2 the drive is rough, and a printed tooth's errors can make it jump`, 'mesh.contact', { contact });
|
|
424
|
-
else f('pass', `contact ratio ${fmt(contact)}: ${fmt(contact)} pairs of teeth share the load on average`, 'mesh.contact', { contact });
|
|
468
|
+
else f('pass', `contact ratio ${fmt(contact)}${overlap ? ` (${fmt(contact - overlap)} across the teeth and ${fmt(overlap)} along their twist)` : ''}: ${fmt(contact)} pairs of teeth share the load on average`, 'mesh.contact', { contact });
|
|
425
469
|
let backlash = a.backlash / 2 + b.backlash / 2;
|
|
426
470
|
if (centre !== undefined) {
|
|
427
471
|
if (!isNum(centre)) throw new Error(`mesh: centre is a distance in mm (got ${shown(centre)})`);
|
|
@@ -433,7 +477,8 @@ export function mesh(a, b, { centre } = {}) {
|
|
|
433
477
|
else if (backlash > 0.4) f('warn', `the axes are ${fmt(off, 3)} mm further apart than these gears need (${fmt(need, 3)} mm): ${fmt(backlash, 2)} mm of backlash, loose enough to knock`, 'mesh.centre', { centre, need });
|
|
434
478
|
else f('pass', `centre distance ${fmt(centre, 3)} mm, as they need${Math.abs(off) > 0.005 ? ` (${off > 0 ? '+' : ''}${fmt(off, 3)})` : ''}: ${fmt(backlash, 2)} mm of backlash`, 'mesh.centre', { centre, need });
|
|
435
479
|
}
|
|
436
|
-
|
|
480
|
+
const thrust = a.herringbone || !ha ? 0 : Math.tan(ha * DEG);
|
|
481
|
+
return { kind: b.kind, centre: need, ratio, contact, overlap, thrust, pressureAngle: aw / DEG, backlash, text: sense, findings: out };
|
|
437
482
|
}
|
|
438
483
|
const flip = (r) => ({ ...r, ratio: r.kind === 'rack' ? r.ratio : 1 / r.ratio });
|
|
439
484
|
const fmt = (x, d = 2) => String(+x.toFixed(d));
|
|
@@ -490,9 +535,68 @@ export function printable(g, printer, width) {
|
|
|
490
535
|
if (g.rootThickness < least - 1e-9) f('fail', `a tooth is ${fmt(g.rootThickness)} mm across at its root, under the thinnest wall (${fmt(least)} mm): a larger module`, 'gear.root', rootAt);
|
|
491
536
|
else f('pass', `a tooth is ${fmt(g.rootThickness)} mm across at its root, ${fmt(rootLines, 1)} lines`, 'gear.root', rootAt);
|
|
492
537
|
if (g.topLand < line) f('warn', `the tips are ${fmt(g.topLand)} mm across, under a line (${line} mm): they print as one bead, rounded off; fine for meshing, but don't count on the tip`, 'gear.tip', tipAt);
|
|
538
|
+
if (g.helix > 0) {
|
|
539
|
+
// the flank leans most at the tip: tan β_a = tan β × r_a / r
|
|
540
|
+
const ra = g.kind === 'rack' ? 1 : g.tip / (g.kind === 'internal' ? g.root : g.pitch), lean = Math.atan(Math.tan(g.helix * DEG) * Math.max(1, ra)) / DEG;
|
|
541
|
+
if (lean > 45) f('warn', `the teeth lean ${fmt(lean, 1)}° from upright at their tips: past 45° the flanks sag as they print; a smaller helix angle`, 'gear.helix', tipAt);
|
|
542
|
+
else f('pass', `the teeth lean ${fmt(lean, 1)}° from upright at their tips: prints with no supports`, 'gear.helix');
|
|
543
|
+
if (!g.herringbone) f('info', `a helix of ${g.helix}° pushes ${fmt(Math.tan(g.helix * DEG), 2)} N along the axis for each newton it drives: hold the gear on its shaft, or make it a herringbone`, 'gear.thrust');
|
|
544
|
+
}
|
|
493
545
|
if (width !== undefined) {
|
|
494
546
|
const layers = width / layer;
|
|
495
547
|
if (Math.abs(layers - Math.round(layers)) > 0.05) f('warn', `${width} mm wide is ${fmt(layers)} layers of ${layer} mm: a whole number prints as drawn`, 'gear.layers');
|
|
496
548
|
}
|
|
497
549
|
return out;
|
|
498
550
|
}
|
|
551
|
+
|
|
552
|
+
// Planetary gearboxes: the teeth for a ratio, laid out in phase
|
|
553
|
+
export { planetary, planetaryRatio } from './planetary.mjs';
|
|
554
|
+
|
|
555
|
+
// ---------- strength ----------
|
|
556
|
+
|
|
557
|
+
// The Lewis form factor for 20° full-depth teeth, by number of teeth (Budynas and Nisbett, Shigley's Mechanical
|
|
558
|
+
// Engineering Design, 10th ed., Table 14-2); a rack is 0.485. Between rows, read along a straight line.
|
|
559
|
+
const LEWIS = [[12, 0.245], [13, 0.261], [14, 0.277], [15, 0.290], [16, 0.296], [17, 0.303], [18, 0.309], [19, 0.314], [20, 0.322], [21, 0.328], [22, 0.331], [24, 0.337], [26, 0.346], [28, 0.353], [30, 0.359], [34, 0.371], [38, 0.384], [43, 0.397], [50, 0.409], [60, 0.422], [75, 0.435], [100, 0.447], [150, 0.460], [300, 0.472], [400, 0.480]];
|
|
560
|
+
/** The Lewis form factor Y for z teeth (20° full depth); Infinity for a rack. @param {number} z */
|
|
561
|
+
export function lewisFactor(z) {
|
|
562
|
+
if (z === Infinity) return 0.485;
|
|
563
|
+
if (z <= LEWIS[0][0]) return LEWIS[0][1];
|
|
564
|
+
if (z >= LEWIS.at(-1)[0]) return LEWIS.at(-1)[1] + ((0.485 - LEWIS.at(-1)[1]) * (1 - 400 / z));
|
|
565
|
+
const i = LEWIS.findIndex(([n]) => n >= z), [n0, y0] = LEWIS[i - 1], [n1, y1] = LEWIS[i];
|
|
566
|
+
return y0 + ((y1 - y0) * (z - n0)) / (n1 - n0);
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* How strong a gear's teeth are by the Lewis equation: the bending stress at the root of a tooth carrying the whole
|
|
571
|
+
* load at its tip, σ = F_t / (b m Y), against the material's strength. Give a torque (N·mm) for the stress and safety
|
|
572
|
+
* factor at it; give a safety factor for the torque the gear carries at it. Helical teeth are read in their normal
|
|
573
|
+
* section (m cos β, z / cos³β teeth). A speed (rpm) adds Barth's velocity factor, (3.05 + V) / 3.05 for a cut (here a
|
|
574
|
+
* printed) profile. A first number: the root fillet and a tooth's neighbours help, a printed tooth's layers and
|
|
575
|
+
* voids hurt. Where it matters, measure it, or analyse the tooth (fea).
|
|
576
|
+
* @param {GearModel} g
|
|
577
|
+
* @param {{ width: number, material: { strength: number, name?: string }, torque?: number, safety?: number, speed?: number }} o
|
|
578
|
+
*/
|
|
579
|
+
export function strength(g, o = {}) {
|
|
580
|
+
if (!g || !['external', 'internal', 'rack'].includes(g.kind)) throw new Error(`strength: give a gear's model, not ${shown(g)}`);
|
|
581
|
+
const width = size('strength', 'width', o.width), sigma = o.material?.strength;
|
|
582
|
+
if (!(isNum(sigma) && sigma > 0)) throw new Error(`strength: the material needs a strength above 0 MPa (got ${shown(sigma)})`);
|
|
583
|
+
if (o.torque !== undefined) size('strength', 'torque', o.torque);
|
|
584
|
+
const safety = o.safety === undefined ? 2 : size('strength', 'safety', o.safety);
|
|
585
|
+
const beta = (g.helix ?? 0) * DEG, mn = g.module * Math.cos(beta);
|
|
586
|
+
const teeth = g.kind === 'rack' ? Infinity : g.teeth / Math.cos(beta) ** 3;
|
|
587
|
+
// an internal gear's teeth are stouter at the root than an outer gear's of as many teeth: read as a rack's, a little kind
|
|
588
|
+
const Y = g.kind === 'internal' ? lewisFactor(Infinity) : lewisFactor(teeth);
|
|
589
|
+
const r = g.kind === 'rack' ? null : g.pitch / 2;
|
|
590
|
+
const V = o.speed !== undefined && r ? (size('strength', 'speed', o.speed) * 2 * Math.PI * r) / 60000 : 0, Kv = (3.05 + V) / 3.05;
|
|
591
|
+
const perNewton = Kv / (width * mn * Y); // MPa for each newton at the pitch circle
|
|
592
|
+
const out = [], f = (level, text, code, values) => out.push({ level, text, code, ...(values ? { values } : {}) });
|
|
593
|
+
const name = o.material.name ?? 'the material';
|
|
594
|
+
const result = { Y, velocity: Kv, force: (sigma / safety) / perNewton, torque: r ? ((sigma / safety) / perNewton) * r : null, findings: out };
|
|
595
|
+
if (o.torque !== undefined) {
|
|
596
|
+
if (!r) throw new Error('strength: a rack takes a force, not a torque (the torque is its pinion\'s)');
|
|
597
|
+
const F = o.torque / r, stress = F * perNewton, n = sigma / stress;
|
|
598
|
+
Object.assign(result, { stress, safety: n });
|
|
599
|
+
f(n >= safety ? 'pass' : n >= 1 ? 'warn' : 'fail', `at ${fmt(o.torque / 1000, 3)} N·m the teeth see ${fmt(stress, 1)} MPa at their roots (Lewis, Y ${fmt(Y, 3)}${Kv > 1 ? `, ×${fmt(Kv, 2)} for speed` : ''}): ${fmt(n, 1)}× under ${name}'s ${sigma} MPa${n >= safety ? '' : n >= 1 ? `, under the ${safety}× asked` : ': they break'}`, 'gear.strength', { stress, safety: n });
|
|
600
|
+
} else if (r) f('info', `the teeth carry ${fmt(result.torque / 1000, 3)} N·m at ${safety}× under ${name}'s ${sigma} MPa (Lewis, Y ${fmt(Y, 3)})`, 'gear.strength', { torque: result.torque });
|
|
601
|
+
return result;
|
|
602
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulecad/gears",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Gears for printed parts: involute spur gears, racks and ring gears drawn from their rules, with their numbers, how a pair meshes (centre distance, ratio, contact ratio, phase) and how they print.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -15,8 +15,10 @@
|
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
17
|
"gears.mjs",
|
|
18
|
+
"planetary.mjs",
|
|
18
19
|
"diagram.mjs",
|
|
19
20
|
"gears.d.mts",
|
|
21
|
+
"planetary.d.mts",
|
|
20
22
|
"diagram.d.mts",
|
|
21
23
|
"README.md",
|
|
22
24
|
"LICENSE"
|
package/planetary.d.mts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turns of the input for one of the output, with one member held: the planetary's ratio, by Willis's relation.
|
|
3
|
+
* @param {{ sun: number, ring: number }} teeth @param {{ held: string, input: string, output: string }} how
|
|
4
|
+
*/
|
|
5
|
+
export function planetaryRatio({ sun: S, ring: R }: {
|
|
6
|
+
sun: number;
|
|
7
|
+
ring: number;
|
|
8
|
+
}, { held, input, output }: {
|
|
9
|
+
held: string;
|
|
10
|
+
input: string;
|
|
11
|
+
output: string;
|
|
12
|
+
}): number;
|
|
13
|
+
/**
|
|
14
|
+
* Teeth for a planetary gearbox: the sets that put together, nearest the wanted ratio first (then the smallest).
|
|
15
|
+
* @param {{ module: number, ratio: number, planets?: number, held?: 'sun' | 'carrier' | 'ring', input?: 'sun' | 'carrier' | 'ring',
|
|
16
|
+
* output?: 'sun' | 'carrier' | 'ring', size?: number, least?: number, most?: number, pressureAngle?: number, backlash?: number }} spec
|
|
17
|
+
* size: the most the ring's rim may be across (mm); least: the fewest teeth on the sun and planets (17 at 20°, so none is undercut)
|
|
18
|
+
* @returns {{ best: object, others: object[], findings: object[] }}
|
|
19
|
+
*/
|
|
20
|
+
export function planetary(spec: {
|
|
21
|
+
module: number;
|
|
22
|
+
ratio: number;
|
|
23
|
+
planets?: number;
|
|
24
|
+
held?: "sun" | "carrier" | "ring";
|
|
25
|
+
input?: "sun" | "carrier" | "ring";
|
|
26
|
+
output?: "sun" | "carrier" | "ring";
|
|
27
|
+
size?: number;
|
|
28
|
+
least?: number;
|
|
29
|
+
most?: number;
|
|
30
|
+
pressureAngle?: number;
|
|
31
|
+
backlash?: number;
|
|
32
|
+
}): {
|
|
33
|
+
best: object;
|
|
34
|
+
others: object[];
|
|
35
|
+
findings: object[];
|
|
36
|
+
};
|
package/planetary.mjs
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Planetary gearboxes: a sun in the middle, planets round it on a carrier, and a ring round them all. Hold one of the
|
|
2
|
+
// three and the other two turn at a ratio set by the teeth alone (Willis: (ω_sun − ω_carrier) / (ω_ring − ω_carrier) =
|
|
3
|
+
// −R / S). planetary() finds the teeth for a wanted ratio that also put together: the ring is the sun and two planets
|
|
4
|
+
// across (R = S + 2P), the planets go in evenly spaced ((S + R) a whole number of times the planets), and they clear
|
|
5
|
+
// each other. It lays the gearbox out with every planet in phase with the sun and the ring.
|
|
6
|
+
import { gearModel, internalModel, mesh, phase } from './gears.mjs';
|
|
7
|
+
|
|
8
|
+
const DEG = Math.PI / 180;
|
|
9
|
+
const MEMBERS = ['sun', 'carrier', 'ring'];
|
|
10
|
+
const fmt = (x, d = 3) => String(+x.toFixed(d));
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Turns of the input for one of the output, with one member held: the planetary's ratio, by Willis's relation.
|
|
14
|
+
* @param {{ sun: number, ring: number }} teeth @param {{ held: string, input: string, output: string }} how
|
|
15
|
+
*/
|
|
16
|
+
export function planetaryRatio({ sun: S, ring: R }, { held, input, output }) {
|
|
17
|
+
// ω for each member with the held one at 0, from ω_s − ω_c = −(R/S)(ω_r − ω_c)
|
|
18
|
+
const w = held === 'ring' ? { ring: 0, carrier: 1, sun: 1 + R / S } : held === 'carrier' ? { carrier: 0, ring: 1, sun: -R / S } : { sun: 0, carrier: 1, ring: (R + S) / R };
|
|
19
|
+
return w[input] / w[output];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Teeth for a planetary gearbox: the sets that put together, nearest the wanted ratio first (then the smallest).
|
|
24
|
+
* @param {{ module: number, ratio: number, planets?: number, held?: 'sun' | 'carrier' | 'ring', input?: 'sun' | 'carrier' | 'ring',
|
|
25
|
+
* output?: 'sun' | 'carrier' | 'ring', size?: number, least?: number, most?: number, pressureAngle?: number, backlash?: number }} spec
|
|
26
|
+
* size: the most the ring's rim may be across (mm); least: the fewest teeth on the sun and planets (17 at 20°, so none is undercut)
|
|
27
|
+
* @returns {{ best: object, others: object[], findings: object[] }}
|
|
28
|
+
*/
|
|
29
|
+
export function planetary(spec) {
|
|
30
|
+
const what = 'planetary';
|
|
31
|
+
if (!spec || typeof spec !== 'object') throw new Error(`${what}: give it { module, ratio, planets, held, input, output }`);
|
|
32
|
+
const { module: m, ratio } = spec, n = spec.planets ?? 3, held = spec.held ?? 'ring', input = spec.input ?? 'sun';
|
|
33
|
+
if (!(typeof m === 'number' && m > 0)) throw new Error(`${what}: module is a size above 0 (got ${JSON.stringify(m)})`);
|
|
34
|
+
if (!(typeof ratio === 'number' && Number.isFinite(ratio) && ratio !== 0)) throw new Error(`${what}: ratio is turns of the input for one of the output, a number (got ${JSON.stringify(ratio)})`);
|
|
35
|
+
if (!(Number.isInteger(n) && n >= 2 && n <= 8)) throw new Error(`${what}: planets is a whole number from 2 to 8 (got ${JSON.stringify(n)})`);
|
|
36
|
+
for (const [k, v] of [['held', held], ['input', input]]) if (!MEMBERS.includes(v)) throw new Error(`${what}: ${k} is one of ${MEMBERS.join(', ')} (got ${JSON.stringify(v)})`);
|
|
37
|
+
const output = spec.output ?? MEMBERS.find((x) => x !== held && x !== input);
|
|
38
|
+
if (!MEMBERS.includes(output) || new Set([held, input, output]).size !== 3) throw new Error(`${what}: held, input and output are the sun, the carrier and the ring, one each (got ${held}, ${input}, ${output})`);
|
|
39
|
+
const least = spec.least ?? 17, most = spec.most ?? 150, pa = spec.pressureAngle ?? 20;
|
|
40
|
+
const common = { module: m, pressureAngle: pa, ...(spec.backlash != null ? { backlash: spec.backlash } : {}) };
|
|
41
|
+
// Every set that puts together, scored by how near its ratio is
|
|
42
|
+
const sets = [];
|
|
43
|
+
for (let S = least; S <= most; S++) for (let P = least; P <= most; P++) {
|
|
44
|
+
const R = S + 2 * P;
|
|
45
|
+
if ((S + R) % n) continue; // the planets go in evenly spaced
|
|
46
|
+
if (R - P < 12) continue; // a ring at least 12 teeth more than its planets, or their tips foul (KHK)
|
|
47
|
+
const a = (m * (S + P)) / 2, tip = m * (P + 2);
|
|
48
|
+
if (n > 1 && 2 * a * Math.sin(Math.PI / n) < tip + m) continue; // the planets' tips a module apart
|
|
49
|
+
const rim = m * (R + 2.5) + 6 * m;
|
|
50
|
+
if (spec.size != null && rim > spec.size) continue;
|
|
51
|
+
const i = planetaryRatio({ sun: S, ring: R }, { held, input, output });
|
|
52
|
+
sets.push({ sun: S, planet: P, ring: R, ratio: i, off: Math.abs(i - ratio) / Math.abs(ratio), rim });
|
|
53
|
+
}
|
|
54
|
+
if (!sets.length) throw new Error(`${what}: no teeth put together${spec.size != null ? ` within a rim of ${spec.size} mm` : ''} with ${n} planets of ${least} teeth or more: a larger size, fewer planets, or a smaller module`);
|
|
55
|
+
sets.sort((x, y) => x.off - y.off || x.rim - y.rim);
|
|
56
|
+
const best = layout(sets[0], { n, m, common, held, input, output });
|
|
57
|
+
const out = [], f = (level, text, code, values) => out.push({ level, text, code, ...(values ? { values } : {}) });
|
|
58
|
+
const off = sets[0].off;
|
|
59
|
+
f(off < 0.005 ? 'pass' : off < 0.05 ? 'warn' : 'fail', `${fmt(best.ratio)} : 1 (${input} to ${output}, ${held} held), ${off < 0.005 ? 'as asked' : `${fmt(off * 100, 1)}% from the ${fmt(ratio)} asked: the nearest that puts together`}: sun ${best.sun.teeth}, planets ${best.planet.teeth} × ${n}, ring ${best.ring.teeth}`, 'planetary.ratio', { ratio: best.ratio, asked: ratio });
|
|
60
|
+
for (const [pair, ms] of [['sun and planet', best.sunMesh], ['planet and ring', best.ringMesh]]) for (const x of ms.findings) out.push({ ...x, text: `${pair}: ${x.text}` });
|
|
61
|
+
return { best, others: sets.slice(1, 6).map((x) => ({ sun: x.sun, planet: x.planet, ring: x.ring, ratio: x.ratio, rim: x.rim })), findings: out };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// The gearbox laid out: the sun at the centre, its first tooth on +x; each planet at its place round the carrier,
|
|
65
|
+
// turned so a tooth sits in a gap of the sun and of the ring; the ring turned to suit
|
|
66
|
+
function layout({ sun: S, planet: P, ring: R, ratio }, { n, m, common, held, input, output }) {
|
|
67
|
+
const sun = gearModel({ ...common, teeth: S }), planet = gearModel({ ...common, teeth: P }), ring = internalModel({ ...common, teeth: R });
|
|
68
|
+
const sunMesh = mesh(sun, planet), ringMesh = mesh(planet, ring), a = sunMesh.centre;
|
|
69
|
+
const planets = Array.from({ length: n }, (_, k) => {
|
|
70
|
+
const at = (360 * k) / n;
|
|
71
|
+
return { at: [a * Math.cos(at * DEG), a * Math.sin(at * DEG)], angle: phase(sun, planet, at), place: at };
|
|
72
|
+
});
|
|
73
|
+
// the ring, from the first planet: the line from that planet to the ring's centre points back along 180°
|
|
74
|
+
const ringAngle = (P / R) * planets[0].angle + phase(planet, ring, 180);
|
|
75
|
+
return { sun: { teeth: S, model: sun }, planet: { teeth: P, model: planet }, ring: { teeth: R, model: ring, angle: ringAngle },
|
|
76
|
+
planets, centre: a, ratio, held, input, output, rim: ring.rim, module: m, sunMesh, ringMesh };
|
|
77
|
+
}
|