@rulecad/gears 0.3.2 → 0.3.4
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/CHANGELOG.md +44 -0
- package/README.md +28 -1
- package/contact.mjs +1 -1
- package/core.d.mts +419 -0
- package/core.mjs +698 -0
- package/diagram.mjs +1 -1
- package/gears.d.mts +2 -420
- package/gears.mjs +5 -685
- package/package.json +4 -1
- package/planetary.d.mts +38 -2
- package/planetary.mjs +67 -6
- package/tooth.mjs +1 -1
- package/worm.mjs +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulecad/gears",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
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,18 +15,21 @@
|
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
17
|
"gears.mjs",
|
|
18
|
+
"core.mjs",
|
|
18
19
|
"planetary.mjs",
|
|
19
20
|
"contact.mjs",
|
|
20
21
|
"tooth.mjs",
|
|
21
22
|
"worm.mjs",
|
|
22
23
|
"diagram.mjs",
|
|
23
24
|
"gears.d.mts",
|
|
25
|
+
"core.d.mts",
|
|
24
26
|
"planetary.d.mts",
|
|
25
27
|
"contact.d.mts",
|
|
26
28
|
"tooth.d.mts",
|
|
27
29
|
"worm.d.mts",
|
|
28
30
|
"diagram.d.mts",
|
|
29
31
|
"README.md",
|
|
32
|
+
"CHANGELOG.md",
|
|
30
33
|
"LICENSE"
|
|
31
34
|
],
|
|
32
35
|
"license": "MIT",
|
package/planetary.d.mts
CHANGED
|
@@ -66,9 +66,16 @@ export function compoundEfficiency({ planet: P1, planet2: P2, ring: R1, ring2: R
|
|
|
66
66
|
* what printed robot joints use. Stepped planets (P2 = P1 + the rings' difference) keep one centre distance with no
|
|
67
67
|
* profile shift: a single planet on two rings can't, at sizes that print, without a shift far past what a tooth takes.
|
|
68
68
|
* Every tooth count is a multiple of the planets, so identical planets go in evenly and in phase on both rings.
|
|
69
|
-
*
|
|
69
|
+
*
|
|
70
|
+
* Printed in place (printInPlace: true), the gearbox comes off the bed in one piece with nothing to assemble but the
|
|
71
|
+
* motor: every gap is widened to the print gap (gap, mm each side, default DEFAULTS.printGap), so the backlash is
|
|
72
|
+
* the one that leaves that gap normal to every flank, 2 gap / (cos α cos β_b), and the dedendum leaves it under every
|
|
73
|
+
* tip; the teeth are herringbones (helix, default DEFAULTS.helix), the sun's one hand and the planets' and rings' the
|
|
74
|
+
* other, so the rings can't walk off the planets; and there is no carrier: the two rings hold the planets.
|
|
75
|
+
* @param {{ module: number, ratio: number, planets?: number, size?: number, least?: number, most?: number, step?: number, pressureAngle?: number, backlash?: number, printInPlace?: boolean, gap?: number, helix?: number }} spec
|
|
70
76
|
* ratio: turns of the sun for one of the output ring, in size (a negative one turns the other way); step: the rings' difference, in planets (default tries 1 and 2)
|
|
71
|
-
* @returns {{ best: object, others: object[], findings: object[] }}
|
|
77
|
+
* @returns {{ best: object, others: object[], findings: object[] }} best.play: the output ring's free turn with the
|
|
78
|
+
* sun and the held ring still (compoundPlay); best.printInPlace: the gap, backlash, dedendum and helix it was drawn to
|
|
72
79
|
*/
|
|
73
80
|
export function compoundPlanetary(spec: {
|
|
74
81
|
module: number;
|
|
@@ -80,8 +87,37 @@ export function compoundPlanetary(spec: {
|
|
|
80
87
|
step?: number;
|
|
81
88
|
pressureAngle?: number;
|
|
82
89
|
backlash?: number;
|
|
90
|
+
printInPlace?: boolean;
|
|
91
|
+
gap?: number;
|
|
92
|
+
helix?: number;
|
|
83
93
|
}): {
|
|
84
94
|
best: object;
|
|
85
95
|
others: object[];
|
|
86
96
|
findings: object[];
|
|
87
97
|
};
|
|
98
|
+
/**
|
|
99
|
+
* How far a compound planetary's output ring turns with the sun and the held ring still: the three meshes' backlash
|
|
100
|
+
* taken up all one way. With stepped planets of pitch radii r1 (on the sun and the held ring) and r2 (on the output
|
|
101
|
+
* ring), the planets float on their two meshes (no carrier), and the output ring's travel at its pitch circle is
|
|
102
|
+
* j_sun |1 − r2/r1| / 2 + j_ring (1 + r2/r1) / 2 + j_ring2. Worked out from the three contacts' slips along the pitch
|
|
103
|
+
* circles; a play, not a twist: the teeth bending under load add to it.
|
|
104
|
+
* @param {{ sun: number, planet: number, planet2: number, ring: number, ring2: number, module: number }} t
|
|
105
|
+
* @param {{ sun: number, ring: number, ring2: number }} backlash each mesh's, mm at the pitch circle
|
|
106
|
+
* @returns {{ mm: number, degrees: number, radians: number }} mm at the output ring's pitch circle
|
|
107
|
+
*/
|
|
108
|
+
export function compoundPlay({ planet: P1, planet2: P2, ring2: R2, module: m }: {
|
|
109
|
+
sun: number;
|
|
110
|
+
planet: number;
|
|
111
|
+
planet2: number;
|
|
112
|
+
ring: number;
|
|
113
|
+
ring2: number;
|
|
114
|
+
module: number;
|
|
115
|
+
}, backlash: {
|
|
116
|
+
sun: number;
|
|
117
|
+
ring: number;
|
|
118
|
+
ring2: number;
|
|
119
|
+
}): {
|
|
120
|
+
mm: number;
|
|
121
|
+
degrees: number;
|
|
122
|
+
radians: number;
|
|
123
|
+
};
|
package/planetary.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// −R / S). planetary() finds the teeth for a wanted ratio that also put together: the ring is the sun and two planets
|
|
4
4
|
// across (R = S + 2P), the planets go in evenly spaced ((S + R) a whole number of times the planets), and they clear
|
|
5
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 './
|
|
6
|
+
import { gearModel, internalModel, mesh, phase, DEFAULTS } from './core.mjs';
|
|
7
7
|
|
|
8
8
|
const DEG = Math.PI / 180;
|
|
9
9
|
const MEMBERS = ['sun', 'carrier', 'ring'];
|
|
@@ -103,9 +103,16 @@ export function compoundEfficiency({ planet: P1, planet2: P2, ring: R1, ring2: R
|
|
|
103
103
|
* what printed robot joints use. Stepped planets (P2 = P1 + the rings' difference) keep one centre distance with no
|
|
104
104
|
* profile shift: a single planet on two rings can't, at sizes that print, without a shift far past what a tooth takes.
|
|
105
105
|
* Every tooth count is a multiple of the planets, so identical planets go in evenly and in phase on both rings.
|
|
106
|
-
*
|
|
106
|
+
*
|
|
107
|
+
* Printed in place (printInPlace: true), the gearbox comes off the bed in one piece with nothing to assemble but the
|
|
108
|
+
* motor: every gap is widened to the print gap (gap, mm each side, default DEFAULTS.printGap), so the backlash is
|
|
109
|
+
* the one that leaves that gap normal to every flank, 2 gap / (cos α cos β_b), and the dedendum leaves it under every
|
|
110
|
+
* tip; the teeth are herringbones (helix, default DEFAULTS.helix), the sun's one hand and the planets' and rings' the
|
|
111
|
+
* other, so the rings can't walk off the planets; and there is no carrier: the two rings hold the planets.
|
|
112
|
+
* @param {{ module: number, ratio: number, planets?: number, size?: number, least?: number, most?: number, step?: number, pressureAngle?: number, backlash?: number, printInPlace?: boolean, gap?: number, helix?: number }} spec
|
|
107
113
|
* ratio: turns of the sun for one of the output ring, in size (a negative one turns the other way); step: the rings' difference, in planets (default tries 1 and 2)
|
|
108
|
-
* @returns {{ best: object, others: object[], findings: object[] }}
|
|
114
|
+
* @returns {{ best: object, others: object[], findings: object[] }} best.play: the output ring's free turn with the
|
|
115
|
+
* sun and the held ring still (compoundPlay); best.printInPlace: the gap, backlash, dedendum and helix it was drawn to
|
|
109
116
|
*/
|
|
110
117
|
export function compoundPlanetary(spec) {
|
|
111
118
|
const what = 'compoundPlanetary';
|
|
@@ -115,7 +122,8 @@ export function compoundPlanetary(spec) {
|
|
|
115
122
|
if (!(typeof ratio === 'number' && Number.isFinite(ratio) && Math.abs(ratio) > 1)) throw new Error(`${what}: ratio is turns of the sun for one of the output, more than 1 either way (got ${JSON.stringify(ratio)})`);
|
|
116
123
|
if (!(Number.isInteger(n) && n >= 2 && n <= 6)) throw new Error(`${what}: planets is a whole number from 2 to 6 (got ${JSON.stringify(n)})`);
|
|
117
124
|
const least = spec.least ?? 17, most = spec.most ?? 90, pa = spec.pressureAngle ?? 20, steps = spec.step != null ? [spec.step] : [1, -1, 2, -2];
|
|
118
|
-
const
|
|
125
|
+
const inPlace = printedInPlace(what, spec, m, pa);
|
|
126
|
+
const common = { module: m, pressureAngle: pa, ...(inPlace ? { backlash: inPlace.backlash, dedendum: inPlace.dedendum, helix: inPlace.helix, herringbone: true } : spec.backlash != null ? { backlash: spec.backlash } : {}) };
|
|
119
127
|
const multiple = (x, k) => Math.ceil(x / k) * k, sets = [];
|
|
120
128
|
for (let S = multiple(least, n); S <= most; S += n) for (let P1 = multiple(least, n); P1 <= most; P1 += n) {
|
|
121
129
|
const R1 = S + 2 * P1;
|
|
@@ -131,13 +139,66 @@ export function compoundPlanetary(spec) {
|
|
|
131
139
|
}
|
|
132
140
|
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, or a smaller module`);
|
|
133
141
|
sets.sort((x, y) => x.off - y.off || x.rim - y.rim);
|
|
134
|
-
|
|
142
|
+
// (helical teeth: two outer gears in mesh are of opposite hands, a ring and its pinion of the same)
|
|
143
|
+
const hand = (h) => (inPlace ? { hand: h } : {});
|
|
144
|
+
const b = sets[0], sun = gearModel({ ...common, ...hand('right'), teeth: b.sun }), planet = gearModel({ ...common, ...hand('left'), teeth: b.planet }), planet2 = gearModel({ ...common, ...hand('left'), teeth: b.planet2 }), ring = internalModel({ ...common, ...hand('left'), teeth: b.ring }), ring2 = internalModel({ ...common, ...hand('left'), teeth: b.ring2 });
|
|
135
145
|
const sunMesh = mesh(sun, planet), ringMesh = mesh(planet, ring), ring2Mesh = mesh(planet2, ring2), a = sunMesh.centre, out = [], f = (level, text, code, values) => out.push({ level, text, code, ...(values ? { values } : {}) });
|
|
136
146
|
const planets = Array.from({ length: n }, (_, k) => { const at = (360 * k) / n; return { at: [a * Math.cos(at * DEG), a * Math.sin(at * DEG)], angle: phase(sun, planet, at), place: at }; });
|
|
137
147
|
const ringAngle = (b.planet / b.ring) * planets[0].angle + phase(planet, ring, 180), ring2Angle = (b.planet2 / b.ring2) * planets[0].angle + phase(planet2, ring2, 180);
|
|
148
|
+
// Each planet's second step in phase with the output ring. The rings are set from the first planet; another planet
|
|
149
|
+
// meshes the sun and the held ring as well a whole tooth of its first step on (360 / P1 degrees), and that turns its
|
|
150
|
+
// second step too, so it takes the first such tooth that also puts its second step in a space of the output ring,
|
|
151
|
+
// whose angle for a planet at place θ turned ψ is (P2 / R2) ψ + phase(planet2, ring2, θ + 180), to a whole pitch
|
|
152
|
+
// (360 / R2). Every tooth count a multiple of the planets puts some in phase as they stand (chapter 11's 18/21 and
|
|
153
|
+
// 54/57 all are) and others not: 57/39/36/135/132's second planet stood 0.11 mm from the output ring at a 0.3 mm gap.
|
|
154
|
+
const pitch2 = 360 / b.ring2, missAt = (p, t) => { const d = (b.planet2 / b.ring2) * (p.angle + (360 * t) / b.planet) + phase(planet2, ring2, p.place + 180) - ring2Angle; return ((((d % pitch2) + pitch2 * 1.5) % pitch2) - pitch2 / 2); };
|
|
155
|
+
for (const p of planets.slice(1)) {
|
|
156
|
+
const t = Array.from({ length: b.planet }, (_, i) => i).find((i) => Math.abs(missAt(p, i)) < 1e-6);
|
|
157
|
+
if (t == null) f('fail', `the planet at ${fmt(p.place, 1)}° can't mesh with the output ring, whichever tooth of its first step meets the sun`, 'compound.phase', { place: p.place });
|
|
158
|
+
else p.angle += (360 * t) / b.planet;
|
|
159
|
+
}
|
|
138
160
|
f(b.off < 0.05 ? 'pass' : b.off < 0.2 ? 'warn' : 'fail', `${fmt(b.ratio, 2)} : 1 (sun to the output ring, the other ring held), ${b.off < 0.01 ? 'as asked' : `${fmt(b.off * 100, 1)}% from the ${fmt(ratio)} asked`}: sun ${b.sun}, stepped planets ${b.planet}/${b.planet2} × ${n}, rings ${b.ring} and ${b.ring2}`, 'compound.ratio', { ratio: b.ratio, asked: ratio });
|
|
139
161
|
f('info', `about ${fmt(b.efficiency * 100, 0)}% efficient (an estimate): ${b.efficiency <= 0.5 ? 'under 50%, so it can\'t be driven backwards' : 'it can be driven backwards'}`, 'compound.efficiency', { efficiency: b.efficiency });
|
|
140
162
|
if (Math.abs(ring2Mesh.centre - a) > 1e-9) f('fail', `the output ring's centre distance is ${fmt(ring2Mesh.centre)} mm and the planets' ${fmt(a)} mm: the rings' difference must equal the planets'`, 'compound.centre');
|
|
141
163
|
for (const [pair, ms] of [['sun and planet', sunMesh], ['planet and held ring', ringMesh], ['planet and output ring', ring2Mesh]]) for (const x of ms.findings) out.push({ ...x, text: `${pair}: ${x.text}` });
|
|
142
|
-
|
|
164
|
+
const play = compoundPlay({ sun: b.sun, planet: b.planet, planet2: b.planet2, ring: b.ring, ring2: b.ring2, module: m }, { sun: sunMesh.backlash, ring: ringMesh.backlash, ring2: ring2Mesh.backlash });
|
|
165
|
+
if (inPlace) f('info', `printed in place: ${fmt(inPlace.gap)} mm clear normal to every flank and under every tip (a backlash of ${fmt(inPlace.backlash)} mm and a dedendum of ${fmt(inPlace.dedendum)} modules), herringbone teeth at ${fmt(inPlace.helix)}° so the rings stay on the planets, and no carrier: the rings hold the planets`, 'compound.inPlace', { gap: inPlace.gap, backlash: inPlace.backlash, dedendum: inPlace.dedendum, helix: inPlace.helix });
|
|
166
|
+
f('info', `the output ring turns ${fmt(play.degrees, 2)}° (${fmt(play.mm)} mm at its pitch circle) with the sun and the held ring still: its play, from the three meshes' backlash`, 'compound.play', { degrees: play.degrees, mm: play.mm });
|
|
167
|
+
return { best: { sun: { teeth: b.sun, model: sun }, planet: { teeth: b.planet, model: planet }, planet2: { teeth: b.planet2, model: planet2 }, ring: { teeth: b.ring, model: ring, angle: ringAngle }, ring2: { teeth: b.ring2, model: ring2, angle: ring2Angle }, planets, centre: a, ratio: b.ratio, efficiency: b.efficiency, rim: Math.max(ring.rim, ring2.rim), module: m, play, ...(inPlace ? { printInPlace: inPlace } : {}) }, others: sets.slice(1, 6).map(({ off, ...x }) => x), findings: out };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Printed in place: the gap, checked by name, and the backlash, dedendum and helix it sets
|
|
171
|
+
function printedInPlace(what, spec, m, pa) {
|
|
172
|
+
if (spec.printInPlace == null || spec.printInPlace === false) {
|
|
173
|
+
for (const k of ['gap', 'helix']) if (spec[k] != null) throw new Error(`${what}: ${k} is for a gearbox printed in place: add printInPlace: true, or leave ${k} out`);
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
if (spec.printInPlace !== true) throw new Error(`${what}: printInPlace is true or false (got ${JSON.stringify(spec.printInPlace)})`);
|
|
177
|
+
if (spec.backlash != null) throw new Error(`${what}: printed in place, the backlash comes from the gap (2 gap / (cos α cos β_b)): give gap, the print gap each side in mm, not backlash`);
|
|
178
|
+
const gap = spec.gap ?? DEFAULTS.printGap.value, helix = spec.helix ?? DEFAULTS.helix.value;
|
|
179
|
+
if (!(typeof gap === 'number' && gap > 0 && gap < m / 2)) throw new Error(`${what}: gap is the print gap each side, above 0 and under half the module (${fmt(m / 2)} mm) (got ${JSON.stringify(spec.gap)})`);
|
|
180
|
+
if (!(typeof helix === 'number' && helix >= 10 && helix <= 45)) throw new Error(`${what}: helix is the herringbone's angle, from 10 to 45° (got ${JSON.stringify(spec.helix)})`);
|
|
181
|
+
// The gap normal to a flank: the transverse backlash j_t at the pitch circle, times cos α_t across the involute,
|
|
182
|
+
// times cos β_b along the helix (ISO/TR 10064-2: j_bn = j_t cos α_t cos β_b), shared by the two flanks of a space
|
|
183
|
+
const a = pa * DEG, betaB = Math.atan(Math.tan(helix * DEG) * Math.cos(a)), backlash = (2 * gap) / (Math.cos(a) * Math.cos(betaB));
|
|
184
|
+
// Under each tip: the dedendum less the addendum, in modules
|
|
185
|
+
const dedendum = Math.max(DEFAULTS.dedendum.value, DEFAULTS.addendum.value + gap / m);
|
|
186
|
+
return { gap, helix, backlash, dedendum, carrier: false };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* How far a compound planetary's output ring turns with the sun and the held ring still: the three meshes' backlash
|
|
191
|
+
* taken up all one way. With stepped planets of pitch radii r1 (on the sun and the held ring) and r2 (on the output
|
|
192
|
+
* ring), the planets float on their two meshes (no carrier), and the output ring's travel at its pitch circle is
|
|
193
|
+
* j_sun |1 − r2/r1| / 2 + j_ring (1 + r2/r1) / 2 + j_ring2. Worked out from the three contacts' slips along the pitch
|
|
194
|
+
* circles; a play, not a twist: the teeth bending under load add to it.
|
|
195
|
+
* @param {{ sun: number, planet: number, planet2: number, ring: number, ring2: number, module: number }} t
|
|
196
|
+
* @param {{ sun: number, ring: number, ring2: number }} backlash each mesh's, mm at the pitch circle
|
|
197
|
+
* @returns {{ mm: number, degrees: number, radians: number }} mm at the output ring's pitch circle
|
|
198
|
+
*/
|
|
199
|
+
export function compoundPlay({ planet: P1, planet2: P2, ring2: R2, module: m }, backlash) {
|
|
200
|
+
for (const k of ['sun', 'ring', 'ring2']) if (!(typeof backlash?.[k] === 'number' && backlash[k] >= 0)) throw new Error(`compoundPlay: backlash.${k} is the ${k === 'sun' ? 'sun\'s' : k === 'ring' ? 'held ring\'s' : 'output ring\'s'} mesh's, 0 or more mm (got ${JSON.stringify(backlash?.[k])})`);
|
|
201
|
+
if (!(typeof m === 'number' && m > 0)) throw new Error(`compoundPlay: module is a size above 0 (got ${JSON.stringify(m)})`);
|
|
202
|
+
const k = P2 / P1, mm = (backlash.sun * Math.abs(1 - k)) / 2 + (backlash.ring * (1 + k)) / 2 + backlash.ring2, radians = mm / ((m * R2) / 2);
|
|
203
|
+
return { mm, radians, degrees: radians / DEG };
|
|
143
204
|
}
|
package/tooth.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// stress), the rim's cut edges held, the load at the tip along the line of action. The peak stress at the root, with
|
|
3
3
|
// the fillet and the printed shape as they are, against Lewis's number, which leaves the fillet's concentration out.
|
|
4
4
|
import { grid, analyse, positions } from '@rulecad/fea';
|
|
5
|
-
import { gearModel, spurProfile, lewisFactor } from './
|
|
5
|
+
import { gearModel, spurProfile, lewisFactor } from './core.mjs';
|
|
6
6
|
|
|
7
7
|
const fmt = (x, d = 1) => String(+x.toFixed(d));
|
|
8
8
|
const inside = ([x, y], pts) => { let c = false; for (let i = 0, j = pts.length - 1; i < pts.length; j = i++) { const [xi, yi] = pts[i], [xj, yj] = pts[j]; if ((yi > y) !== (yj > y) && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi) c = !c; } return c; };
|
package/worm.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// printed teeth, a little soft, spread). One turn of a worm of s starts moves its wheel s teeth. With a lead angle
|
|
4
4
|
// under the friction angle it locks: the wheel can't turn the worm.
|
|
5
5
|
import jscad from '@jscad/modeling';
|
|
6
|
-
import { rackProfile, helical, gearModel } from './
|
|
6
|
+
import { rackProfile, helical, gearModel } from './core.mjs';
|
|
7
7
|
|
|
8
8
|
const { extrudeFromSlices, slice } = jscad.extrusions;
|
|
9
9
|
const { mat4 } = jscad.maths;
|