@rulecad/gears 0.3.1 → 0.3.3
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 +17 -0
- package/README.md +11 -0
- package/contact.mjs +1 -1
- package/core.d.mts +419 -0
- package/core.mjs +696 -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 +51 -0
- package/planetary.mjs +67 -1
- 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.3",
|
|
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
|
@@ -34,3 +34,54 @@ export function planetary(spec: {
|
|
|
34
34
|
others: object[];
|
|
35
35
|
findings: object[];
|
|
36
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* The turns of the sun for one of the output ring, in a compound planetary with one ring held: its planets stepped,
|
|
39
|
+
* P1 teeth on the held ring and the sun, P2 on the ring that turns. The ring turns the sun's way when the result is positive.
|
|
40
|
+
* @param {{ sun: number, planet: number, planet2: number, ring: number, ring2: number }} t
|
|
41
|
+
*/
|
|
42
|
+
export function compoundRatio({ sun: S, planet: P1, planet2: P2, ring: R1, ring2: R2 }: {
|
|
43
|
+
sun: number;
|
|
44
|
+
planet: number;
|
|
45
|
+
planet2: number;
|
|
46
|
+
ring: number;
|
|
47
|
+
ring2: number;
|
|
48
|
+
}): number;
|
|
49
|
+
/**
|
|
50
|
+
* The share of the power a compound planetary passes on (printed teeth): the sun's mesh, and the rings', where the
|
|
51
|
+
* carrier-relative power is the output's times rho / |1 - rho|, rho being the rings' ratio through the planets: all of
|
|
52
|
+
* it rubbing, for a small movement out, which is why a high ratio is so much less efficient than its gears look.
|
|
53
|
+
* @param {{ sun: number, planet: number, planet2: number, ring: number, ring2: number }} t
|
|
54
|
+
* @param {number} [each] the share per mesh (default 0.95, an estimate)
|
|
55
|
+
*/
|
|
56
|
+
export function compoundEfficiency({ planet: P1, planet2: P2, ring: R1, ring2: R2 }: {
|
|
57
|
+
sun: number;
|
|
58
|
+
planet: number;
|
|
59
|
+
planet2: number;
|
|
60
|
+
ring: number;
|
|
61
|
+
ring2: number;
|
|
62
|
+
}, each?: number): number;
|
|
63
|
+
/**
|
|
64
|
+
* Teeth for a compound (split-ring) planetary: the held ring and the sun mesh the planets' P1 teeth, the output ring
|
|
65
|
+
* their P2. Two rings a few teeth apart give ratios of 30 to 200 in one stage, input and output on one axis, which is
|
|
66
|
+
* what printed robot joints use. Stepped planets (P2 = P1 + the rings' difference) keep one centre distance with no
|
|
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
|
+
* Every tooth count is a multiple of the planets, so identical planets go in evenly and in phase on both rings.
|
|
69
|
+
* @param {{ module: number, ratio: number, planets?: number, size?: number, least?: number, most?: number, step?: number, pressureAngle?: number, backlash?: number }} spec
|
|
70
|
+
* 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[] }}
|
|
72
|
+
*/
|
|
73
|
+
export function compoundPlanetary(spec: {
|
|
74
|
+
module: number;
|
|
75
|
+
ratio: number;
|
|
76
|
+
planets?: number;
|
|
77
|
+
size?: number;
|
|
78
|
+
least?: number;
|
|
79
|
+
most?: number;
|
|
80
|
+
step?: number;
|
|
81
|
+
pressureAngle?: number;
|
|
82
|
+
backlash?: number;
|
|
83
|
+
}): {
|
|
84
|
+
best: object;
|
|
85
|
+
others: object[];
|
|
86
|
+
findings: object[];
|
|
87
|
+
};
|
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 } from './core.mjs';
|
|
7
7
|
|
|
8
8
|
const DEG = Math.PI / 180;
|
|
9
9
|
const MEMBERS = ['sun', 'carrier', 'ring'];
|
|
@@ -75,3 +75,69 @@ function layout({ sun: S, planet: P, ring: R, ratio }, { n, m, common, held, inp
|
|
|
75
75
|
return { sun: { teeth: S, model: sun }, planet: { teeth: P, model: planet }, ring: { teeth: R, model: ring, angle: ringAngle },
|
|
76
76
|
planets, centre: a, ratio, held, input, output, rim: ring.rim, module: m, sunMesh, ringMesh };
|
|
77
77
|
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The turns of the sun for one of the output ring, in a compound planetary with one ring held: its planets stepped,
|
|
81
|
+
* P1 teeth on the held ring and the sun, P2 on the ring that turns. The ring turns the sun's way when the result is positive.
|
|
82
|
+
* @param {{ sun: number, planet: number, planet2: number, ring: number, ring2: number }} t
|
|
83
|
+
*/
|
|
84
|
+
export function compoundRatio({ sun: S, planet: P1, planet2: P2, ring: R1, ring2: R2 }) {
|
|
85
|
+
return ((S + R1) / S) / (1 - (R1 * P2) / (P1 * R2));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The share of the power a compound planetary passes on (printed teeth): the sun's mesh, and the rings', where the
|
|
90
|
+
* carrier-relative power is the output's times rho / |1 - rho|, rho being the rings' ratio through the planets: all of
|
|
91
|
+
* it rubbing, for a small movement out, which is why a high ratio is so much less efficient than its gears look.
|
|
92
|
+
* @param {{ sun: number, planet: number, planet2: number, ring: number, ring2: number }} t
|
|
93
|
+
* @param {number} [each] the share per mesh (default 0.95, an estimate)
|
|
94
|
+
*/
|
|
95
|
+
export function compoundEfficiency({ planet: P1, planet2: P2, ring: R1, ring2: R2 }, each = 0.95) {
|
|
96
|
+
const rho = (R1 * P2) / (P1 * R2), lost = 1 - each ** 2;
|
|
97
|
+
return each / (1 + (lost * rho) / Math.abs(1 - rho));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Teeth for a compound (split-ring) planetary: the held ring and the sun mesh the planets' P1 teeth, the output ring
|
|
102
|
+
* their P2. Two rings a few teeth apart give ratios of 30 to 200 in one stage, input and output on one axis, which is
|
|
103
|
+
* what printed robot joints use. Stepped planets (P2 = P1 + the rings' difference) keep one centre distance with no
|
|
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
|
+
* Every tooth count is a multiple of the planets, so identical planets go in evenly and in phase on both rings.
|
|
106
|
+
* @param {{ module: number, ratio: number, planets?: number, size?: number, least?: number, most?: number, step?: number, pressureAngle?: number, backlash?: number }} spec
|
|
107
|
+
* 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[] }}
|
|
109
|
+
*/
|
|
110
|
+
export function compoundPlanetary(spec) {
|
|
111
|
+
const what = 'compoundPlanetary';
|
|
112
|
+
if (!spec || typeof spec !== 'object') throw new Error(`${what}: give it { module, ratio, planets, size }`);
|
|
113
|
+
const { module: m, ratio } = spec, n = spec.planets ?? 3;
|
|
114
|
+
if (!(typeof m === 'number' && m > 0)) throw new Error(`${what}: module is a size above 0 (got ${JSON.stringify(m)})`);
|
|
115
|
+
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
|
+
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
|
+
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 common = { module: m, pressureAngle: pa, ...(spec.backlash != null ? { backlash: spec.backlash } : {}) };
|
|
119
|
+
const multiple = (x, k) => Math.ceil(x / k) * k, sets = [];
|
|
120
|
+
for (let S = multiple(least, n); S <= most; S += n) for (let P1 = multiple(least, n); P1 <= most; P1 += n) {
|
|
121
|
+
const R1 = S + 2 * P1;
|
|
122
|
+
if (R1 - P1 < 12) continue;
|
|
123
|
+
if (2 * ((m * (S + P1)) / 2) * Math.sin(Math.PI / n) < m * (P1 + 2) + m) continue; // the planets' tips a module apart
|
|
124
|
+
for (const k of steps) {
|
|
125
|
+
const j = k * n, P2 = P1 + j, R2 = R1 + j;
|
|
126
|
+
if (P2 < least) continue;
|
|
127
|
+
const set = { sun: S, planet: P1, planet2: P2, ring: R1, ring2: R2 }, i = compoundRatio(set), rim = m * (Math.max(R1, R2) + 2.5) + 6 * m;
|
|
128
|
+
if (spec.size != null && rim > spec.size) continue;
|
|
129
|
+
sets.push({ ...set, ratio: i, efficiency: compoundEfficiency(set), off: Math.abs(i - ratio) / Math.abs(ratio), rim });
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
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
|
+
sets.sort((x, y) => x.off - y.off || x.rim - y.rim);
|
|
134
|
+
const b = sets[0], sun = gearModel({ ...common, teeth: b.sun }), planet = gearModel({ ...common, teeth: b.planet }), planet2 = gearModel({ ...common, teeth: b.planet2 }), ring = internalModel({ ...common, teeth: b.ring }), ring2 = internalModel({ ...common, teeth: b.ring2 });
|
|
135
|
+
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
|
+
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
|
+
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);
|
|
138
|
+
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
|
+
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
|
+
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
|
+
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
|
+
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 }, others: sets.slice(1, 6).map(({ off, ...x }) => x), findings: out };
|
|
143
|
+
}
|
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;
|