@rulecad/frames 0.0.1 → 0.1.8
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 +23 -0
- package/README.md +1182 -21
- package/beam.d.mts +145 -0
- package/beam.mjs +201 -0
- package/bought.d.mts +60 -0
- package/bought.mjs +195 -0
- package/catalogue.d.mts +20 -0
- package/catalogue.mjs +268 -0
- package/cutlist.d.mts +88 -0
- package/cutlist.mjs +199 -0
- package/cutsheet.d.mts +23 -0
- package/cutsheet.mjs +118 -0
- package/door.d.mts +127 -0
- package/door.mjs +254 -0
- package/ends.d.mts +130 -0
- package/ends.mjs +290 -0
- package/fitting.d.mts +262 -0
- package/fitting.mjs +535 -0
- package/frames.d.mts +18 -9
- package/frames.mjs +43 -10
- package/guide.d.mts +140 -0
- package/guide.mjs +269 -0
- package/jig.d.mts +146 -0
- package/jig.mjs +332 -0
- package/join.d.mts +244 -0
- package/join.mjs +257 -0
- package/ops.d.mts +44 -0
- package/ops.mjs +324 -0
- package/package.json +75 -8
- package/panel.d.mts +225 -0
- package/panel.mjs +374 -0
- package/profile.d.mts +268 -0
- package/profile.mjs +462 -0
- package/rods.d.mts +195 -0
- package/rods.mjs +475 -0
- package/section.d.mts +43 -0
- package/section.mjs +140 -0
- package/services.d.mts +335 -0
- package/services.mjs +486 -0
- package/slotnut.d.mts +210 -0
- package/slotnut.mjs +394 -0
- package/square.d.mts +23 -0
- package/square.mjs +42 -0
- package/wheels.d.mts +141 -0
- package/wheels.mjs +337 -0
package/rods.mjs
ADDED
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
// Guides on smooth rods, and what drives them: two rods along a beam's face in printed holders at the ends of a stretch,
|
|
2
|
+
// a printed carriage riding them on linear bearings (rod-8 and lm8uu, or what their sets name), and for a screw drive a
|
|
3
|
+
// printed motor plate holding the catalogue's motor on its own mounting rules, a coupler to the lead screw, a bearing for
|
|
4
|
+
// the screw in each holder, and the lead nut on the carriage. An endstop's printed mount goes on a side face of the beam
|
|
5
|
+
// by an address, its lever where a flag on the carriage meets it.
|
|
6
|
+
//
|
|
7
|
+
// The holders and the motor plate are saddles: a plate standing across the beam, its legs down both side faces and a
|
|
8
|
+
// screw through each leg into the side face's slot, so the face the rods run over stays clear for the carriage, the
|
|
9
|
+
// coupler and the screw. Each part is drawn as it prints and turned into its fitted frame.
|
|
10
|
+
//
|
|
11
|
+
// A part's fitted frame is a mount's: x along the beam, y across it, z out of the face (0 on it), its origin on the
|
|
12
|
+
// address it is placed at (the face's first slot). A holder's outer face is at x = 0, its legs reaching in (+x); the
|
|
13
|
+
// motor plate's outer face, where the motor's mounting face lies, is at x = 0, the motor outside it (-x) and its shaft
|
|
14
|
+
// in. A carriage's frame: x along the beam about its middle, y and z as a holder's. Units: mm, N, N m, kg, grams.
|
|
15
|
+
import jscad from '@jscad/modeling';
|
|
16
|
+
import { hole, holeModel, fixingModel, engagement, counterbore, DEFAULTS as FIX } from '@rulecad/fixings';
|
|
17
|
+
import { SETS } from './catalogue.mjs';
|
|
18
|
+
import { FITTING_DEFAULTS, options, profileOf, printerOf, slotSide, roundConcave, ccw, combine, screwOf, sold } from './fitting.mjs';
|
|
19
|
+
import { partSetup, weigh, closingFindings, bendT, bendMargin } from './panel.mjs';
|
|
20
|
+
|
|
21
|
+
const { cylinder, polygon } = jscad.primitives, { extrudeLinear } = jscad.extrusions;
|
|
22
|
+
const { translate, transform } = jscad.transforms;
|
|
23
|
+
const CHECKED = '2026-11-17';
|
|
24
|
+
const isNum = (x) => typeof x === 'number' && Number.isFinite(x);
|
|
25
|
+
const shown = (v) => { const s = v === undefined ? 'nothing' : JSON.stringify(v) ?? String(v); return s.length > 80 ? `${s.slice(0, 77)}...` : s; };
|
|
26
|
+
const mm = (x) => String(+Number(x).toFixed(2));
|
|
27
|
+
const r3 = (x) => +x.toFixed(3);
|
|
28
|
+
const up = (x, step) => Math.ceil(x / step - 1e-9) * step;
|
|
29
|
+
const finding = (level, text, code, extra = {}) => ({ level, text, code, ...extra });
|
|
30
|
+
const rule = (value, unit, text, kind, source) => ({ value, ...(unit ? { unit } : {}), rule: text, kind, source, checked: CHECKED });
|
|
31
|
+
const short = (n) => String(n).replace(/^profile-/, '');
|
|
32
|
+
const want = () => FITTING_DEFAULTS.margin.value;
|
|
33
|
+
const fig = (s, k) => s.rules[k]?.value;
|
|
34
|
+
|
|
35
|
+
/** The working figures of rod guides and their drives, each with what it rests on. */
|
|
36
|
+
export const ROD_DEFAULTS = {
|
|
37
|
+
gap: rule(1, 'mm', 'Room between a moving part and a still one beside it: the carriage and a holder, a coupler and a plate', 'default', 'A working figure of @rulecad/frames'),
|
|
38
|
+
wall: rule(2, 'mm', 'A printed part\'s least wall round a rod, a bearing or a nut', 'default', 'A working figure of @rulecad/frames: five of the X1C\'s 0.42 mm lines'),
|
|
39
|
+
web: rule(1.5, 'mm', 'Plastic between a linear bearing\'s pocket and the lead nut\'s flange in the carriage', 'estimate', 'A working figure of @rulecad/frames: the wrist Z axis of the worked examples\' chapter 13 stands its rods 20 mm off the screw with this'),
|
|
40
|
+
floor: rule(3, 'mm', 'A carriage\'s floor under a linear bearing\'s pocket, which holds the bearing from sliding through', 'default', 'A working figure of @rulecad/frames'),
|
|
41
|
+
press: rule(0.1, 'mm', 'How much a printed pocket for a bought bearing is drawn under the bearing\'s diameter, for a light press', 'estimate', 'A working figure of @rulecad/frames, to be checked by a test print: a printer\'s holes come out small by about its hole compensation, which is added back'),
|
|
42
|
+
load: rule(50, 'N', 'The design load on a holder, a motor plate or a carriage where none is given: a hand pushing the carriage along its rods, or on it', 'default', 'A working figure of @rulecad/frames, so every part is sized and compared at one named load'),
|
|
43
|
+
switchLoad: rule(10, 'N', 'The design load on an endstop\'s mount: a knock on the switch', 'default', 'A working figure of @rulecad/frames'),
|
|
44
|
+
relief: rule(1, 'mm', 'The round relief cut into a saddle\'s inside corners, where the beam\'s corners sit: no square inside corner, and nothing rubs the beam\'s rounded corner', 'default', 'A working figure of @rulecad/frames'),
|
|
45
|
+
couple: rule(0.5, '× length', 'A linear bearing takes a moment about its middle as two equal and opposite forces this share of its length apart (its ball circuits\' ends)', 'estimate', 'A working figure of @rulecad/frames: the makers rate a single bush by its radial load only, so a moment on one is an estimate until measured'),
|
|
46
|
+
flag: rule({ thickness: 3, width: 4, engage: 4 }, 'mm', 'The flag on a carriage that trips an endstop: its thickness along the beam, its width, and how far it reaches down past the end of the switch\'s lever', 'default', 'A working figure of @rulecad/frames'),
|
|
47
|
+
lever: rule(12.4, 'mm', 'A miniature switch\'s lever face, from its base along its length: its body\'s length, 2 mm to the lever and the lever\'s 0.4 mm, as @rulecad/cad draws a switch', 'estimate', 'How @rulecad/cad draws a switch from its set (its lever 2 mm over the body); measure your switch\'s lever and its pretravel'),
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// ---------- the sets ----------
|
|
51
|
+
const known = (part) => Object.values(SETS).filter((s) => s.part === part).map((s) => s.name).sort();
|
|
52
|
+
const setOf = (what, key, part, name) => {
|
|
53
|
+
const s = SETS[String(name ?? '').toLowerCase()];
|
|
54
|
+
if (!s || s.part !== part) throw new Error(`${what}: ${key} is a ${part.replace('_', ' ')}'s rule set, one of ${known(part).join(', ') || 'none'} (got ${shown(name)})`);
|
|
55
|
+
return s;
|
|
56
|
+
};
|
|
57
|
+
// a motor's mounting figures from its set: the holes in its own frame (x across, y along its body's offset, z along the
|
|
58
|
+
// shaft), the thread its screws take, the boss and the shaft; read as @rulecad/motors reads them
|
|
59
|
+
function motorFigures(what, s) {
|
|
60
|
+
const pattern = fig(s, 'mount_pattern'), sp = fig(s, 'mount_hole_spacing'), off = fig(s, 'boss_offset') ?? 0;
|
|
61
|
+
if (!['pair', 'square'].includes(pattern) || !isNum(sp)) throw new Error(`${what}: ${s.name} has no mounting holes a plate can take (mount_pattern pair or square, and mount_hole_spacing): a plate for it needs them in its set`);
|
|
62
|
+
const holes = pattern === 'square' ? [[-1, -1], [1, -1], [1, 1], [-1, 1]].map(([a, b]) => [r3((a * sp) / 2), r3((b * sp) / 2)]) : [[r3(-sp / 2), -off], [r3(sp / 2), -off]];
|
|
63
|
+
let thread = fig(s, 'mount_hole_thread'), tapped = true;
|
|
64
|
+
if (typeof thread !== 'string') {
|
|
65
|
+
// plain holes (a geared motor's ears): the largest metric thread whose major fits the hole, through it to a nut
|
|
66
|
+
const d = fig(s, 'mount_hole_diameter');
|
|
67
|
+
thread = ['M5', 'M4', 'M3', 'M2.5', 'M2'].find((t) => fixingModel(t).major <= d - 0.15 + 1e-9);
|
|
68
|
+
if (!thread) throw new Error(`${what}: ${s.name}'s ${mm(d)} mm mounting holes take no metric screw from M2 up`);
|
|
69
|
+
tapped = false;
|
|
70
|
+
}
|
|
71
|
+
const shape = fig(s, 'body_shape'), body = shape === 'round' ? { round: true, size: fig(s, 'body_diameter'), centre: [0, -off] } : { round: false, size: fig(s, 'body_width'), centre: [0, -off] };
|
|
72
|
+
return { set: s.name, pattern, holes, thread, tapped, depth: fig(s, 'mount_hole_depth') ?? null, ear: fig(s, 'mount_ear_thickness') ?? null, boss: { d: fig(s, 'boss_diameter') ?? 0, h: fig(s, 'boss_height') ?? 0 }, shaft: { d: fig(s, 'shaft_diameter'), length: fig(s, 'shaft_length'), flat: fig(s, 'shaft_flat_length') ?? null }, body, offset: off, mass: fig(s, 'mass') ?? null };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// The face the rods run over, and its two sides: where the beam's middle is across the face (yc, from the face's first
|
|
76
|
+
// slot), how far it reaches either side (across) and down (deep), and each side face's nearest slot, in a part's frame
|
|
77
|
+
function faceOf(what, p, face) {
|
|
78
|
+
const name = String(face ?? 'top');
|
|
79
|
+
if (!['top', 'bottom', 'front', 'back'].includes(name)) throw new Error(`${what}: face is the face the rods run over: top, bottom, front or back (got ${shown(face)})`);
|
|
80
|
+
const place = p.faces[name]?.[0];
|
|
81
|
+
if (!place) throw new Error(`${what}: ${p.name} has no ${name} face`);
|
|
82
|
+
const n = place.normal, ydir = [n[1], -n[0]], half = (v) => Math.abs(v[0]) * (p.width / 2) + Math.abs(v[1]) * (p.height / 2);
|
|
83
|
+
const rel = (q) => [r3((q[0] - place.at[0]) * ydir[0] + (q[1] - place.at[1]) * ydir[1]), r3((q[0] - place.at[0]) * n[0] + (q[1] - place.at[1]) * n[1])];
|
|
84
|
+
const [yc] = rel([0, 0]), across = half(ydir), deep = 2 * half(n);
|
|
85
|
+
const sides = (name === 'top' || name === 'bottom' ? ['front', 'back'] : ['top', 'bottom']).map((sd) => {
|
|
86
|
+
const list = p.faces[sd] ?? [], q = [...list].sort((a, b) => (b.at[0] * n[0] + b.at[1] * n[1]) - (a.at[0] * n[0] + a.at[1] * n[1]))[0];
|
|
87
|
+
const out = q ? Math.sign(q.normal[0] * ydir[0] + q.normal[1] * ydir[1]) : 0, [y, z] = q ? rel(q.at) : [null, null];
|
|
88
|
+
return { side: sd, place: q ?? null, name: q ? `${sd}${list.length > 1 ? `.${q.index}` : ''}` : sd, slot: q?.slot ?? null, out, y, z };
|
|
89
|
+
});
|
|
90
|
+
return { name, place, yc, across, deep, sides, ydir, normal: n };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The layout of a rod guide on a face of a profile, with what its drive adds: the rods' spacing across the face and their
|
|
95
|
+
* height over it, the carriage's size, and the sets each part reads. The spacing leaves room for the lead nut's flange
|
|
96
|
+
* between the bearings (ROD_DEFAULTS.web); the height clears the carriage, the nut's flange, the screw's bearing in a
|
|
97
|
+
* holder, the coupler and the motor's body over the face. Refused by name: a set of the wrong part, a spacing or height
|
|
98
|
+
* that leaves no room. @param {string | object} profile
|
|
99
|
+
* @param {{ face?: string, rod?: string, bearing?: string, spacing?: number, height?: number, screw?: string, nut?: string, support?: string | null, coupler?: string, motor?: string, given?: object }} [o]
|
|
100
|
+
* @returns {object} the layout
|
|
101
|
+
*/
|
|
102
|
+
export function rodsLayout(profile, o = {}) {
|
|
103
|
+
const what = 'rodsLayout';
|
|
104
|
+
options(what, o ?? {}, ['face', 'rod', 'bearing', 'spacing', 'height', 'screw', 'nut', 'support', 'coupler', 'motor', 'printer', 'given']);
|
|
105
|
+
const p = profileOf(what, profile, o.given ?? {}), F = faceOf(what, p, o.face);
|
|
106
|
+
const rod = setOf(what, 'rod', 'rod', o.rod ?? 'rod-8'), bearing = setOf(what, 'bearing', 'linear_bearing', o.bearing ?? 'lm8uu');
|
|
107
|
+
const d = fig(rod, 'diameter'), D = fig(bearing, 'outer_diameter'), Lb = fig(bearing, 'length');
|
|
108
|
+
if (Math.abs(fig(bearing, 'bore') - d) > 1e-6) throw new Error(`${what}: ${bearing.name}'s ${mm(fig(bearing, 'bore'))} mm bore does not run on ${rod.name}'s ${mm(d)} mm rod`);
|
|
109
|
+
const screw = o.screw != null ? setOf(what, 'screw', 'leadscrew', o.screw) : null, nut = screw ? setOf(what, 'nut', 'nut', o.nut ?? 't8-nut') : null;
|
|
110
|
+
if (screw && Math.abs(fig(nut, 'diameter') - fig(screw, 'diameter')) > 1e-6) throw new Error(`${what}: ${nut.name} is for a ${mm(fig(nut, 'diameter'))} mm screw and ${screw.name} is ${mm(fig(screw, 'diameter'))} mm`);
|
|
111
|
+
const support = screw && o.support !== null ? setOf(what, 'support', 'bearing', o.support ?? 'bearing-608') : null;
|
|
112
|
+
if (support && fig(support, 'bore') < fig(screw, 'diameter') - 1e-6) throw new Error(`${what}: ${support.name}'s ${mm(fig(support, 'bore'))} mm bore is smaller than ${screw.name}`);
|
|
113
|
+
const coupler = o.motor != null ? setOf(what, 'coupler', 'coupler', o.coupler ?? 'coupler-5-8') : null, motor = o.motor != null ? motorFigures(what, setOf(what, 'motor', 'motor', o.motor)) : null;
|
|
114
|
+
if (motor && !screw) throw new Error(`${what}: a motor drives the carriage through a screw: give screw (t8-screw)`);
|
|
115
|
+
if (coupler && (Math.abs(fig(coupler, 'bore_a') - motor.shaft.d) > 1e-6 || Math.abs(fig(coupler, 'bore_b') - fig(screw, 'diameter')) > 1e-6)) throw new Error(`${what}: ${coupler.name} joins ${mm(fig(coupler, 'bore_a'))} mm to ${mm(fig(coupler, 'bore_b'))} mm, and the motor's shaft is ${mm(motor.shaft.d)} mm and the screw ${mm(fig(screw, 'diameter'))} mm`);
|
|
116
|
+
const wall = ROD_DEFAULTS.wall.value, gap = ROD_DEFAULTS.gap.value, Fd = nut ? fig(nut, 'flange_diameter') : 0;
|
|
117
|
+
const half = r3(up(Math.max(D / 2 + (nut ? Fd / 2 + ROD_DEFAULTS.web.value : wall), F.across), 0.5)), s = o.spacing ?? 2 * half;
|
|
118
|
+
const fewest = D + (nut ? Fd + 2 * ROD_DEFAULTS.web.value : wall);
|
|
119
|
+
if (!(isNum(s) && s >= fewest - 1e-9)) throw new Error(`${what}: spacing is the rods' distance apart, mm, at least ${mm(fewest)} (two ${bearing.name} pockets${nut ? ` and ${nut.name}'s flange` : ''} between) (got ${shown(o.spacing)})`);
|
|
120
|
+
// the rods' and the screw's height over the face: whatever needs most room under them
|
|
121
|
+
const needs = [['the carriage under its bearings', D / 2 + wall + gap], ...(nut ? [[`${nut.name}'s flange`, Fd / 2 + gap]] : []), ...(support ? [[`${support.name} in a holder`, fig(support, 'outer_diameter') / 2 + wall]] : []),
|
|
122
|
+
...(coupler ? [[`${coupler.name}`, fig(coupler, 'outer_diameter') / 2 + gap]] : []), ...(motor ? [[`${motor.set}'s body`, (motor.body.round ? motor.body.size / 2 : motor.body.size / 2) - motor.offset + gap]] : [])];
|
|
123
|
+
const least = Math.max(...needs.map((x) => x[1])), h = o.height ?? r3(up(least, 0.5));
|
|
124
|
+
if (!(isNum(h) && h >= least - 1e-9)) throw new Error(`${what}: height is the rods' and screw's height over the face, mm, at least ${mm(least)} for ${needs.reduce((a, x) => (x[1] > a[1] ? x : a))[0]} (got ${shown(o.height)})`);
|
|
125
|
+
const Lc = r3(up(Lb + ROD_DEFAULTS.floor.value, 1)), Wc = r3(s + D + 2 * wall), zb = r3(h - D / 2 - wall), zt = r3(h + D / 2 + wall);
|
|
126
|
+
return { kind: 'rods-layout', profile: p.name, face: F.name, frame: F, rod: { set: rod.name, d, straightness: rod.rules.straightness?.value ?? null }, bearing: { set: bearing.name, D, length: Lb, C0: fig(bearing, 'static_rating'), C: fig(bearing, 'dynamic_rating'), mass: fig(bearing, 'mass') ?? null },
|
|
127
|
+
spacing: s, height: h, needs, carriage: { length: Lc, width: Wc, bottom: zb, top: zt },
|
|
128
|
+
screw: screw ? { set: screw.name, d: fig(screw, 'diameter'), lead: fig(screw, 'lead'), friction: fig(screw, 'friction_coefficient') ?? null, frictionKind: screw.rules.friction_coefficient?.kind ?? null } : null,
|
|
129
|
+
nut: nut ? { set: nut.name, flange: Fd, flangeWidth: fig(nut, 'flange_width'), body: fig(nut, 'body_diameter'), length: fig(nut, 'length'), circle: fig(nut, 'hole_circle'), holes: fig(nut, 'hole_count'), hole: fig(nut, 'mount_hole_diameter') } : null,
|
|
130
|
+
support: support ? { set: support.name, D: fig(support, 'outer_diameter'), width: fig(support, 'width'), bore: fig(support, 'bore'), mass: fig(support, 'mass') ?? null } : null,
|
|
131
|
+
coupler: coupler ? { set: coupler.name, length: fig(coupler, 'length'), D: fig(coupler, 'outer_diameter') } : null, motor };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// ---------- drawing ----------
|
|
135
|
+
// A part drawn as it prints, P = R part + t, turned back into its fitted frame
|
|
136
|
+
const toFit = (g, R, t) => {
|
|
137
|
+
// part = Rᵀ (P - t): a column-major 4x4 of Rᵀ and -Rᵀ t
|
|
138
|
+
const RT = [0, 1, 2].map((i) => [0, 1, 2].map((j) => R[j][i])), o = RT.map((row) => -(row[0] * t[0] + row[1] * t[1] + row[2] * t[2]));
|
|
139
|
+
return transform([RT[0][0], RT[1][0], RT[2][0], 0, RT[0][1], RT[1][1], RT[2][1], 0, RT[0][2], RT[1][2], RT[2][2], 0, o[0], o[1], o[2], 1], g);
|
|
140
|
+
};
|
|
141
|
+
const prismZ = (loop, z0, z1) => translate([0, 0, z0], extrudeLinear({ height: z1 - z0 }, polygon({ points: ccw(loop) })));
|
|
142
|
+
const discZ = (x, y, d, z0, z1) => translate([x, y, (z0 + z1) / 2], cylinder({ radius: d / 2, height: z1 - z0, segments: 48 }));
|
|
143
|
+
// a print frame's (X, Y) from a part's (y, z): sy is +1 (X = y) or -1 (X = -y)
|
|
144
|
+
const flat2 = (sy) => ([y, z]) => [sy * y, z];
|
|
145
|
+
|
|
146
|
+
// A saddle's outline in the part's (y, z): a plate over the face from y0 to y1 and up to top, legs down the sides of
|
|
147
|
+
// the beam to zLeg, a relief at each of the beam's corners; its concave corners elsewhere rounded
|
|
148
|
+
function saddleLoop(F, fit, legT, zLeg, y0, y1, top) {
|
|
149
|
+
const L1 = F.yc - F.across - fit, R1 = F.yc + F.across + fit, L0 = Math.min(y0, L1 - legT), R0 = Math.max(y1, R1 + legT);
|
|
150
|
+
const loop = [[L1 - legT, zLeg], [L1, zLeg], [L1, 0], [R1, 0], [R1, zLeg], [R1 + legT, zLeg], ...(R0 > R1 + legT + 1e-9 ? [[R1 + legT, 0], [R0, 0]] : []), [R0, top], [L0, top], ...(L0 < L1 - legT - 1e-9 ? [[L0, 0], [L1 - legT, 0]] : [])];
|
|
151
|
+
const pts = ccw(loop), corner = (q) => Math.abs(q[1]) < 1e-9 && (Math.abs(q[0] - L1) < 1e-9 || Math.abs(q[0] - R1) < 1e-9);
|
|
152
|
+
return { loop: roundConcave(pts, Math.min(2, legT / 2), (i) => !corner(pts[i])), L1, R1, L0, R0 };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// The screws through a saddle's legs into the side faces' slots: their thread from the slots' nuts, sized so a length
|
|
156
|
+
// sold engages the nut and stops short of its floor (the leg's thickness across is the grip)
|
|
157
|
+
function legScrews(what, p, F, o, k) {
|
|
158
|
+
const head = o.head ?? 'cap', sds = F.sides.map((x) => { if (!x.slot) throw new Error(`${what}: ${p.name}'s ${x.side} face beside the ${F.name} face is closed: a saddle's legs screw into slots either side`); return slotSide(what, p, x.name, o.thread, o.nut, k.fit, o.given ?? {}); });
|
|
159
|
+
const thread = sds[0].thread;
|
|
160
|
+
if (sds[1].thread !== thread) throw new Error(`${what}: the slots either side of the ${F.name} face take different threads (${sds[0].thread}, ${sds[1].thread}): give thread`);
|
|
161
|
+
const sc = screwOf(what, thread, head, k.pr), least = up(FITTING_DEFAULTS.least.value * sc.major, k.layer), fits = sold(least, k.layer, sds, thread);
|
|
162
|
+
const legT = fits ? fits.t : least, along = r3(up(Math.max(sc.dk + 2 * FITTING_DEFAULTS.reach.value, 2 * sc.hd), 0.5)), endBy = r3(up(Math.max(sc.dk / 2 + FITTING_DEFAULTS.reach.value, sc.hd), 0.5));
|
|
163
|
+
const deepest = Math.min(...F.sides.map((x) => x.z)), zLeg = r3(deepest - endBy);
|
|
164
|
+
return { sds, thread, head, sc, legT, fits, along, zLeg };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
// ---------- the holders ----------
|
|
169
|
+
/**
|
|
170
|
+
* A printed holder for two rods at one end of a rod guide: a saddle standing across the beam, its legs screwed into the
|
|
171
|
+
* slots of the faces either side, the rods pressed through it along the beam (their holes the rod's diameter with the
|
|
172
|
+
* printer's hole compensation: a light press), and, where a screw drives the carriage, the screw's bearing pressed in a
|
|
173
|
+
* pocket from its inner face (a bearing block at each end). Sized from a load along the beam at the rods' height to about
|
|
174
|
+
* twice the margin, by beam formulas. It prints on its outer face, the rods' holes upright.
|
|
175
|
+
* @param {string | object} profile
|
|
176
|
+
* @param {{ face?: string, end?: 'a' | 'b', rod?: string, bearing?: string, spacing?: number, height?: number, screw?: string, leadNut?: string, support?: string | null, load?: number, thread?: string, head?: 'cap' | 'button', nut?: string, printer?: object, material?: string | object, given?: object }} [o]
|
|
177
|
+
* end: a (its outer face toward end a, the default) or b (turned to face b); leadNut: the lead screw's nut's set; nut: the slot nuts' kind
|
|
178
|
+
* @returns {object} its model
|
|
179
|
+
*/
|
|
180
|
+
export function rodHolderModel(profile, o = {}) {
|
|
181
|
+
const what = 'rodHolderModel';
|
|
182
|
+
options(what, o ?? {}, ['face', 'end', 'rod', 'bearing', 'spacing', 'height', 'screw', 'leadNut', 'support', 'load', 'thread', 'head', 'nut', 'printer', 'material', 'given']);
|
|
183
|
+
const end = o.end ?? 'a';
|
|
184
|
+
if (!['a', 'b'].includes(end)) throw new Error(`${what}: end is a or b, the end of the stretch it holds: at b it is turned to face a (got ${shown(o.end)})`);
|
|
185
|
+
const L = rodsLayout(profile, { face: o.face, rod: o.rod, bearing: o.bearing, spacing: o.spacing, height: o.height, screw: o.screw, nut: o.leadNut, support: o.support, given: o.given });
|
|
186
|
+
const p = profileOf(what, profile, o.given ?? {}), F = L.frame, k = partSetup(what, o), wall = ROD_DEFAULTS.wall.value, s = L.spacing, h = L.height, d = L.rod.d;
|
|
187
|
+
const S = loadOf(what, o.load, ROD_DEFAULTS.load.value), ls = legScrews(what, p, F, o, k), sup = L.support;
|
|
188
|
+
const comp = k.pr.rules?.hole_comp?.value ?? 0.1, rodHole = r3(d + comp), Rtop = Math.max(d / 2 + wall, sup ? sup.D / 2 + wall : 0), top = r3(up(h + Rtop, 0.5)), y0 = r3(F.yc - s / 2 - d / 2 - wall), y1 = r3(F.yc + s / 2 + d / 2 + wall);
|
|
189
|
+
// its thickness along the beam: the rods' grip (a diameter), the screw's bearing and a floor, the load's bend
|
|
190
|
+
const b = y1 - y0, M = S * h, t0 = Math.max(d, sup ? sup.width + wall : 0, up(FITTING_DEFAULTS.least.value * ls.sc.major, k.layer), bendT(M, b, k.S, want()));
|
|
191
|
+
const t = r3(up(t0, k.layer)), legs = r3(Math.max(t, ls.along)), margin = r3(bendMargin(M, b, t, k.S)), stress = r3((6 * M) / (b * t * t));
|
|
192
|
+
const shape = saddleLoop(F, k.fit, ls.legT, ls.zLeg, y0, y1, top);
|
|
193
|
+
const screwHole = L.screw ? r3(L.screw.d + 2 * k.fit + 1) : 0, pocket = sup ? r3(sup.D - ROD_DEFAULTS.press.value + comp) : 0;
|
|
194
|
+
const screws = F.sides.map((x, i) => ({ thread: ls.thread, head: ls.head, grip: ls.legT, side: x.name, at: [r3(legs / 2), r3(x.out > 0 ? shape.R1 + ls.legT : shape.L1 - ls.legT), x.z], axis: [0, -x.out, 0], nut: ls.sds[i].nut.name, nutKind: ls.sds[i].nut.nutKind, length: ls.fits?.lengths[i] ?? null }));
|
|
195
|
+
// at end b, the same part turned half round about the beam's middle line over the face: its outer face looks toward b
|
|
196
|
+
const turn = end === 'b' ? (q) => [r3(-q[0]), r3(2 * F.yc - q[1]), q[2]] : (q) => q, axisOf = end === 'b' ? (v) => [v[0] ? -v[0] : 0, v[1] ? -v[1] : 0, v[2]] : (v) => v;
|
|
197
|
+
for (const q of screws) { q.at = turn(q.at); q.axis = axisOf(q.axis); const i = F.sides.findIndex((sd) => sd.out === Math.sign(q.at[1] - F.yc)); Object.assign(q, { side: F.sides[i].name, nut: ls.sds[i].nut.name, nutKind: ls.sds[i].nut.nutKind, length: ls.fits?.lengths[i] ?? null }); } // (turned, each leg is on the other side)
|
|
198
|
+
if (end === 'b') screws.reverse();
|
|
199
|
+
const anchors = { r1: { at: [0, r3(F.yc - s / 2), h], axis: [1, 0, 0], ref: [0, 0, 1] }, r2: { at: [0, r3(F.yc + s / 2), h], axis: [1, 0, 0], ref: [0, 0, 1] }, screw: { at: [0, F.yc, h], axis: [1, 0, 0], ref: [0, 0, 1] }, ...(sup ? { s1: { at: [r3(t - sup.width), F.yc, h], axis: [1, 0, 0], ref: [0, 0, 1] } } : {}) };
|
|
200
|
+
for (const a of Object.values(anchors)) { a.at = turn(a.at); a.axis = axisOf(a.axis); }
|
|
201
|
+
const m = { kind: 'fitting', fitting: 'rod-holder', guide: 'rods', end, name: `rod-holder-${L.rod.set}-${short(p.name)}-${F.name}${sup ? `-${sup.set.replace(/^bearing-/, '')}` : ''}`, title: `printed holder for two ${L.rod.set} rods${sup ? ` and a ${sup.set}` : ''} on ${p.name}'s ${F.name} face`,
|
|
202
|
+
profile: p.name, face: F.name, frame: F, rod: L.rod.set, spacing: s, height: h, thickness: t, legs, top, legT: ls.legT, zLeg: ls.zLeg, y0, y1, outline: shape.loop, rodHole, screwHole, support: sup ? { set: sup.set, pocket, depth: sup.width, D: sup.D } : null,
|
|
203
|
+
thread: ls.thread, head: ls.head, screws, hardware: [], load: { force: S, what: `${mm(S)} N along the beam at the rods' ${mm(h)} mm height` }, stress, margin,
|
|
204
|
+
anchors, size: { along: t, legs, across: r3(shape.R0 - shape.L0), height: r3(top - ls.zLeg) }, volume: 0, grams: 0, material: k.mat.name, printer: k.pr.name, findings: [],
|
|
205
|
+
rests: [{ name: `${k.mat.name}.strength`, value: k.S }, ...['load', 'wall', 'press'].map((x) => ({ name: `ROD_DEFAULTS.${x}`, value: ROD_DEFAULTS[x].value, kind: ROD_DEFAULTS[x].kind }))] };
|
|
206
|
+
keep(m, k); weigh(m, rodHolder(m), k.density);
|
|
207
|
+
m.findings.push(screwFinding(ls, 'leg'));
|
|
208
|
+
if (sup) m.findings.push(finding('info', `${sup.set} pressed ${mm(sup.width)} mm into a pocket from its inner face (${mm(pocket)} mm across: ${mm(ROD_DEFAULTS.press.value)} mm under its ${mm(sup.D)} mm, an estimate of a light press): the screw's bearing at this end`, 'guide.support', { values: { pocket, depth: sup.width } }));
|
|
209
|
+
closingFindings(m, { S: k.S, sizeText: `${mm(b)} mm across, ${mm(top)} mm over the face, ${mm(t)} mm along the beam, legs ${mm(legs)} mm along it down to ${mm(-ls.zLeg)} mm under the face; ${ls.thread} into the slots either side`, marginText: `under ${m.load.what}, it bends at the face to ${mm(stress)} MPa`, pose: 'on its outer face, the rods\' holes upright' });
|
|
210
|
+
return m;
|
|
211
|
+
}
|
|
212
|
+
/** A rod holder's solid: as it prints (on its outer face) or in its fitted frame. @param {object} m rodHolderModel's @param {{ pose?: 'print' | 'fit', ops?: object }} [o] @returns {object} */
|
|
213
|
+
export function rodHolder(m, o = {}) {
|
|
214
|
+
if (m?.fitting !== 'rod-holder') throw new Error(`rodHolder: give a rod holder's model (rodHolderModel), not ${shown(m)}`);
|
|
215
|
+
// print frame: X = y, Y = z, Z = x (its outer face on the bed)
|
|
216
|
+
const pr = printerOf('rodHolder', m.pr ?? null), F = m.frame, P = flat2(1), parts = [prismZ(m.outline.map(P), 0, m.thickness)];
|
|
217
|
+
for (const sd of [-1, 1]) if (m.legs > m.thickness) { const yIn = sd < 0 ? F.yc - F.across - m.fit : F.yc + F.across + m.fit, yOut = yIn + sd * m.legT; parts.push(prismZ([[yIn, m.zLeg], [yOut, m.zLeg], [yOut, 0], [yIn, 0]].map(P), 0, m.legs)); }
|
|
218
|
+
const back = m.end === 'b' ? (q) => [-q[0], 2 * F.yc - q[1], q[2]] : (q) => q, ax = m.end === 'b' ? (v) => [-v[0], -v[1], v[2]] : (v) => v; // (drawn as at end a)
|
|
219
|
+
const cuts = [m.anchors.r1.at, m.anchors.r2.at].map(back).map(([, y, z]) => discZ(y, z, m.rodHole, -1, m.legs + 1));
|
|
220
|
+
if (m.screwHole) cuts.push(discZ(F.yc, m.height, m.screwHole, -1, m.thickness + 1));
|
|
221
|
+
if (m.support) cuts.push(discZ(F.yc, m.height, m.support.pocket, m.thickness - m.support.depth, m.thickness + 1));
|
|
222
|
+
for (const sd of [-1, 1]) cuts.push(discZ(sd < 0 ? F.yc - F.across - m.fit : F.yc + F.across + m.fit, 0, 2 * ROD_DEFAULTS.relief.value, -1, m.legs + 1));
|
|
223
|
+
for (const q0 of m.screws) { const q = { at: back(q0.at), axis: ax(q0.axis) }; cuts.push(hole(q0.thread, { kind: 'clearance', into: q.axis[1] > 0 ? '+x' : '-x', at: [q.at[1] - q.axis[1], q.at[2], q.at[0]], depth: m.legT + 2, printer: pr })); }
|
|
224
|
+
const g = combine(parts, cuts, o.ops ?? null);
|
|
225
|
+
if (o.pose !== 'fit') return Object.assign(g, { model: m });
|
|
226
|
+
const fit = toFit(g, [[0, 1, 0], [0, 0, 1], [1, 0, 0]], [0, 0, 0]);
|
|
227
|
+
return Object.assign(m.end === 'b' ? transform([-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 2 * F.yc, 0, 1], fit) : fit, { model: m });
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// ---------- the motor plate ----------
|
|
231
|
+
/**
|
|
232
|
+
* A printed plate that holds a motor of the catalogue on a beam, its shaft along the beam over a face: a saddle standing
|
|
233
|
+
* across the beam, its legs screwed into the side faces' slots, two screws a leg so the motor's torque is held by shear,
|
|
234
|
+
* and the motor's mount cut from its own rules (its mounting holes, the boss's pocket and the shaft's hole, as
|
|
235
|
+
* @rulecad/motors' mount() cuts them; the screws' clearance holes are @rulecad/fixings'). The motor's mounting face lies on
|
|
236
|
+
* the plate's outer face, its body outside, a geared motor's body offset away from the face. The plate is at least half
|
|
237
|
+
* as thick again as the motor's screws (as @rulecad/motors asks) and sized from a load at the shaft to about twice the
|
|
238
|
+
* margin; where its shaft would reach too little into a coupler past it, a recess in its inner face takes the coupler in.
|
|
239
|
+
* It prints on its outer face: the boss's pocket ends in a 45° cone, the recess opens up.
|
|
240
|
+
* @param {string | object} profile
|
|
241
|
+
* @param {{ motor: string, face?: string, height?: number, coupler?: { length: number, D: number }, load?: number, thread?: string, head?: 'cap' | 'button', nut?: string, printer?: object, material?: string | object, given?: object }} o
|
|
242
|
+
* motor: its rule set (28byj48, nema14, nema17); height: the shaft's over the face (default the least the body clears);
|
|
243
|
+
* coupler: its length and diameter, where one goes on the shaft (default coupler-5-8's figures for a 5 mm shaft)
|
|
244
|
+
* @returns {object} its model, with anchors motor (where the motor's own frame goes) and coupler (where its face is)
|
|
245
|
+
*/
|
|
246
|
+
export function motorPlateModel(profile, o = {}) {
|
|
247
|
+
const what = 'motorPlateModel';
|
|
248
|
+
options(what, o ?? {}, ['motor', 'face', 'height', 'coupler', 'load', 'thread', 'head', 'nut', 'printer', 'material', 'given']);
|
|
249
|
+
if (o.motor == null) throw new Error(`${what}: motor is the motor's rule set, one of ${known('motor').join(', ')}`);
|
|
250
|
+
const p = profileOf(what, profile, o.given ?? {}), F = faceOf(what, p, o.face), k = partSetup(what, o), mo = motorFigures(what, setOf(what, 'motor', 'motor', o.motor)), gap = ROD_DEFAULTS.gap.value, wall = ROD_DEFAULTS.wall.value;
|
|
251
|
+
const least = r3(mo.body.size / 2 - mo.offset + gap), h = o.height ?? r3(up(least, 0.5));
|
|
252
|
+
if (!(isNum(h) && h >= least - 1e-9)) throw new Error(`${what}: height is the shaft's height over the face, mm, at least ${mm(least)} so ${mo.set}'s body clears it (got ${shown(o.height)})`);
|
|
253
|
+
const cs = o.coupler ?? (SETS['coupler-5-8'] && Math.abs(fig(SETS['coupler-5-8'], 'bore_a') - mo.shaft.d) < 1e-6 ? { length: fig(SETS['coupler-5-8'], 'length'), D: fig(SETS['coupler-5-8'], 'outer_diameter') } : null);
|
|
254
|
+
if (cs != null && !(isNum(cs.length) && cs.length > 0 && isNum(cs.D) && cs.D > 0)) throw new Error(`${what}: coupler is { length, D } in mm (got ${shown(o.coupler)})`);
|
|
255
|
+
const S = loadOf(what, o.load, ROD_DEFAULTS.load.value), ls = legScrews(what, p, F, o, k), comp = k.pr.rules?.hole_comp?.value ?? 0.1;
|
|
256
|
+
// the motor's holes in the part's (y, z): its x across the beam the other way, its y down toward the face
|
|
257
|
+
const at = ([mx, my]) => [r3(F.yc - mx), r3(h - my)], holes = mo.holes.map(at), major = fixingModel(mo.thread).major, clear = holeModel(mo.thread, { kind: 'clearance', printer: k.pr }).diameter;
|
|
258
|
+
const ys = holes.map((q) => q[0]), zs = holes.map((q) => q[1]), rim = clear / 2 + wall + 1;
|
|
259
|
+
const y0 = r3(Math.min(...ys) - rim), y1 = r3(Math.max(...ys) + rim), top = r3(up(Math.max(...zs) + rim, 0.5));
|
|
260
|
+
const pocket = mo.boss.d ? r3(mo.boss.d + 2 * k.fit + comp) : 0, pocketDepth = mo.boss.h ? r3(mo.boss.h + 2 * k.layer) : 0, shaftHole = r3(mo.shaft.d + 2 * k.fit + comp + 0.4);
|
|
261
|
+
const b = y1 - y0, M = S * h, t0 = Math.max(up(1.5 * major, k.layer), pocketDepth + 3 * k.layer, bendT(M, b, k.S, want()));
|
|
262
|
+
const t = r3(up(t0, k.layer)), margin = r3(bendMargin(M, b, t, k.S)), stress = r3((6 * M) / (b * t * t));
|
|
263
|
+
// the coupler: its face where the shaft goes its own diameter into it, or the shaft's flat's length, whichever is more;
|
|
264
|
+
// a recess in the inner face takes it in where that is inside the plate; a longer shaft (a NEMA 17's 24 mm) stops
|
|
265
|
+
// there too, the coupler clear of the plate, so the shaft does not reach past the coupler's middle into the screw
|
|
266
|
+
const want_ = Math.min(cs ? cs.length / 2 : Infinity, Math.max(mo.shaft.d, mo.shaft.flat ?? 0)), face = r3(Math.max(0, mo.shaft.length - want_));
|
|
267
|
+
const recess = cs && face < t + gap / 2 - 1e-9 ? { d: r3(cs.D + 2 * gap), depth: r3(t - (face - gap / 2)) } : null, couplerAt = recess ? face : r3(Math.max(t + gap / 2, face));
|
|
268
|
+
if (recess && t - recess.depth < pocketDepth + pocket / 2 - shaftHole / 2 - 1e-9 + 2 * k.layer && t - recess.depth < 2 * k.layer) throw new Error(`${what}: ${mo.set}'s ${mm(mo.shaft.length)} mm shaft is too short to reach a coupler through a ${mm(t)} mm plate`);
|
|
269
|
+
// the screws into the slots: two a leg along the beam, the legs reaching in from its outer face
|
|
270
|
+
const legs = r3(Math.max(t, 2 * ls.along)), xs = [r3(ls.along / 2), r3(legs - ls.along / 2)];
|
|
271
|
+
const screws = F.sides.flatMap((x, i) => xs.map((xm) => ({ thread: ls.thread, head: ls.head, grip: ls.legT, side: x.name, at: [xm, r3(x.out > 0 ? F.yc + F.across + k.fit + ls.legT : F.yc - F.across - k.fit - ls.legT), x.z], axis: [0, -x.out, 0], nut: ls.sds[i].nut.name, nutKind: ls.sds[i].nut.nutKind, length: ls.fits?.lengths[i] ?? null })));
|
|
272
|
+
const shape = saddleLoop(F, k.fit, ls.legT, ls.zLeg, y0, y1, top), engaged = r3(mo.shaft.length - couplerAt);
|
|
273
|
+
const m = { kind: 'fitting', fitting: 'motor-plate', name: `motor-plate-${mo.set}-${short(p.name)}-${F.name}`, title: `printed plate for the motor ${mo.set} on ${p.name}'s ${F.name} face`, profile: p.name, face: F.name, frame: F, motor: mo.set, mount: mo,
|
|
274
|
+
height: h, thickness: t, legs, top, legT: ls.legT, zLeg: ls.zLeg, y0, y1, outline: shape.loop, holes: holes.map((q) => ({ at: q, diameter: r3(clear) })), thread: ls.thread, head: ls.head, screws, engaged, recess,
|
|
275
|
+
pocket: { d: pocket, depth: pocketDepth }, shaftHole, hardware: [], load: { force: S, what: `${mm(S)} N along the beam at the shaft's ${mm(h)} mm height` }, stress, margin,
|
|
276
|
+
anchors: { motor: { at: [0, F.yc, h], axis: [1, 0, 0], ref: [0, -1, 0] }, coupler: { at: [couplerAt, F.yc, h], axis: [1, 0, 0], ref: [0, 0, 1] } },
|
|
277
|
+
size: { along: t, legs, across: r3(shape.R0 - shape.L0), height: r3(top - ls.zLeg) }, volume: 0, grams: 0, material: k.mat.name, printer: k.pr.name, findings: [],
|
|
278
|
+
rests: [{ name: `${k.mat.name}.strength`, value: k.S }, ...['load', 'wall', 'gap'].map((x) => ({ name: `ROD_DEFAULTS.${x}`, value: ROD_DEFAULTS[x].value, kind: ROD_DEFAULTS[x].kind }))] };
|
|
279
|
+
keep(m, k); weigh(m, motorPlate(m), k.density);
|
|
280
|
+
m.findings.push(screwFinding(ls, 'leg, two a leg,'));
|
|
281
|
+
m.findings.push(finding('info', `${mo.set} on its mounting face at the plate's outer face, from its own rules: ${mo.holes.length} ${mo.thread} clearance holes (${mm(clear)} mm${mo.tapped ? ', into the motor\'s own thread' : ', through its ears to a nut'}) through ${mm(t)} mm, its ${mm(mo.boss.d)} mm boss in a ${mm(pocketDepth)} mm pocket, its shaft through a ${mm(shaftHole)} mm hole${cs ? ` and ${mm(engaged)} mm into the coupler${recess ? `, which sits ${mm(recess.depth)} mm into a ${mm(recess.d)} mm recess in the inner face` : ''}` : ''}`, 'fitting.motor', { values: { holes: mo.holes.length, thread: mo.thread, clearance: r3(clear), pocket, pocketDepth, engaged, recess } }));
|
|
282
|
+
closingFindings(m, { S: k.S, sizeText: `${mm(b)} mm across, ${mm(top)} mm over the face, ${mm(t)} mm along the beam, legs ${mm(legs)} mm along it; four ${ls.thread} into the slots either side`, marginText: `under ${m.load.what}, it bends at the face to ${mm(stress)} MPa`, pose: 'on its outer face, the boss\'s pocket ending in a 45° cone' });
|
|
283
|
+
return m;
|
|
284
|
+
}
|
|
285
|
+
/** A motor plate's solid: as it prints (on its outer face) or in its fitted frame. @param {object} m motorPlateModel's @param {{ pose?: 'print' | 'fit', ops?: object }} [o] @returns {object} */
|
|
286
|
+
export function motorPlate(m, o = {}) {
|
|
287
|
+
if (m?.fitting !== 'motor-plate') throw new Error(`motorPlate: give a motor plate's model (motorPlateModel), not ${shown(m)}`);
|
|
288
|
+
// print frame: X = y, Y = z, Z = x (its outer face on the bed, the legs reaching up)
|
|
289
|
+
const pr = printerOf('motorPlate', m.pr ?? null), F = m.frame, P = flat2(1), t = m.thickness, parts = [prismZ(m.outline.map(P), 0, t)];
|
|
290
|
+
for (const sd of [-1, 1]) { const yIn = sd < 0 ? F.yc - F.across - m.fit : F.yc + F.across + m.fit, yOut = yIn + sd * m.legT; parts.push(prismZ([[yIn, m.zLeg], [yOut, m.zLeg], [yOut, 0], [yIn, 0]].map(P), 0, m.legs)); }
|
|
291
|
+
const cuts = m.holes.map((q) => discZ(q.at[0], q.at[1], q.diameter, -1, t + 1));
|
|
292
|
+
cuts.push(discZ(F.yc, m.height, m.shaftHole, -1, m.legs + 1));
|
|
293
|
+
// the boss's pocket from the bed, its roof a 45° cone down to the shaft's hole: nothing to bridge
|
|
294
|
+
if (m.pocket.d && m.pocket.depth) {
|
|
295
|
+
const R = m.pocket.d / 2, r = m.shaftHole / 2, z1 = m.pocket.depth;
|
|
296
|
+
cuts.push(translate([F.yc, m.height, 0], jscad.extrusions.extrudeRotate({ segments: 48 }, polygon({ points: [[0, -1], [R, -1], [R, z1], [r, z1 + R - r], [0, z1 + R - r]] }))));
|
|
297
|
+
}
|
|
298
|
+
if (m.recess) cuts.push(discZ(F.yc, m.height, m.recess.d, t - m.recess.depth, m.legs + 1));
|
|
299
|
+
for (const sd of [-1, 1]) cuts.push(discZ(sd < 0 ? F.yc - F.across - m.fit : F.yc + F.across + m.fit, 0, 2 * ROD_DEFAULTS.relief.value, -1, m.legs + 1));
|
|
300
|
+
for (const q of m.screws) cuts.push(hole(q.thread, { kind: 'clearance', into: q.axis[1] > 0 ? '+x' : '-x', at: [q.at[1] - q.axis[1], q.at[2], q.at[0]], depth: m.legT + 2, printer: pr }));
|
|
301
|
+
const g = combine(parts, cuts, o.ops ?? null);
|
|
302
|
+
return Object.assign(o.pose === 'fit' ? toFit(g, [[0, 1, 0], [0, 0, 1], [1, 0, 0]], [0, 0, 0]) : g, { model: m });
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// ---------- the carriage ----------
|
|
306
|
+
/**
|
|
307
|
+
* A printed carriage for a rod guide: a block over the face, two linear bearings pressed into pockets along the beam
|
|
308
|
+
* (from its inner end, a floor at the far end), and where a screw drives it the lead nut's body in a bore through its
|
|
309
|
+
* middle with the flange screwed to its far end, into pilots. With an endstop, a flag hangs from its far end beside the
|
|
310
|
+
* beam down past the switch's lever. Sized from a load on its middle, between the bearings, by beam formulas. It prints on
|
|
311
|
+
* its far end, the pockets opening up and the flag on the bed.
|
|
312
|
+
* @param {string | object} profile
|
|
313
|
+
* @param {{ face?: string, rod?: string, bearing?: string, spacing?: number, height?: number, screw?: string, leadNut?: string, flag?: { y: number, z: number }, load?: number, printer?: object, material?: string | object, given?: object }} [o]
|
|
314
|
+
* flag: where its tip reaches, in its frame (y across, z over the face: below 0 is beside the beam)
|
|
315
|
+
* @returns {object} its model, with anchors slide (its joint), lm1 and lm2 (the bearings), nut and top
|
|
316
|
+
*/
|
|
317
|
+
export function rodCarriageModel(profile, o = {}) {
|
|
318
|
+
const what = 'rodCarriageModel';
|
|
319
|
+
options(what, o ?? {}, ['face', 'rod', 'bearing', 'spacing', 'height', 'screw', 'leadNut', 'flag', 'load', 'printer', 'material', 'given']);
|
|
320
|
+
const L = rodsLayout(profile, { face: o.face, rod: o.rod, bearing: o.bearing, spacing: o.spacing, height: o.height, screw: o.screw, nut: o.leadNut, given: o.given });
|
|
321
|
+
const p = profileOf(what, profile, o.given ?? {}), F = L.frame, k = partSetup(what, o), comp = k.pr.rules?.hole_comp?.value ?? 0.1, wall = ROD_DEFAULTS.wall.value, s = L.spacing, h = L.height, { length: Lc, width: Wc, bottom: zb, top: zt } = L.carriage, B = L.bearing, nut = L.nut;
|
|
322
|
+
const S = loadOf(what, o.load, ROD_DEFAULTS.load.value), pocket = r3(B.D - ROD_DEFAULTS.press.value + comp), bore = r3(L.rod.d + 2 * k.fit + 1);
|
|
323
|
+
const nutBore = nut ? r3(nut.body + 2 * k.fit + comp) : 0;
|
|
324
|
+
// the flange's screws: through the flange into pilots in the carriage's far end, a length sold that engages the plastic
|
|
325
|
+
let pilots = null, hardware = [];
|
|
326
|
+
if (nut) {
|
|
327
|
+
const th = ['M2', 'M2.5', 'M3', 'M4', 'M5'].filter((x) => fixingModel(x).major <= nut.hole - 0.3 + 1e-9).at(-1), need = engagement(th, { depth: 1, material: k.mat.name }).need, lens = [...(fixingModel(th).figures.lengths?.value ?? [])].sort((a, b) => a - b);
|
|
328
|
+
const Ls = lens.find((x) => x - nut.flangeWidth >= need - 1e-9) ?? null, depth = Ls ? r3(up(Ls - nut.flangeWidth + FIX.tip_room.value + k.layer, k.layer)) : null;
|
|
329
|
+
pilots = { thread: th, length: Ls, depth, need, at: Array.from({ length: nut.holes }, (_, i) => { const a = (Math.PI / 4) + (2 * Math.PI * i) / nut.holes; return [r3(F.yc + (nut.circle / 2) * Math.cos(a)), r3(h + (nut.circle / 2) * Math.sin(a))]; }) };
|
|
330
|
+
hardware = [{ name: Ls ? `${th}x${Ls} button` : `${th} button`, kind: 'screw', thread: th, length: Ls, head: 'button', count: nut.holes, why: `${nut.set}'s flange to the carriage, ${mm(need)} mm into ${k.mat.name}` }];
|
|
331
|
+
if (Ls == null || depth > Lc - wall) throw new Error(`${what}: no ${th} screw sold holds ${nut.set}'s flange with ${mm(need)} mm in the carriage's ${mm(Lc)} mm`);
|
|
332
|
+
for (const [y, z] of pilots.at) if (Math.abs(y - F.yc) > s / 2 - B.D / 2 - holeModel(th, { kind: 'pilot', printer: k.pr }).diameter / 2 - 0.5 && Math.abs(z - h) < B.D / 2 + 2) throw new Error(`${what}: ${nut.set}'s flange screws reach the bearings' pockets: a wider spacing`);
|
|
333
|
+
}
|
|
334
|
+
// the flag: from the carriage's underside at its far end down beside the beam to the switch's lever
|
|
335
|
+
let flag = null;
|
|
336
|
+
if (o.flag != null) {
|
|
337
|
+
const fl = o.flag, fd = ROD_DEFAULTS.flag.value;
|
|
338
|
+
if (!fl || !isNum(fl.y) || !isNum(fl.z)) throw new Error(`${what}: flag is where its tip reaches, { y, z } in the carriage's frame (got ${shown(o.flag)})`);
|
|
339
|
+
if (Math.abs(fl.y - F.yc) + fd.width / 2 > Wc / 2 - 1e-9) throw new Error(`${what}: the flag would hang ${mm(Math.abs(fl.y - F.yc))} mm from the middle, past the carriage's ${mm(Wc / 2)} mm: give a wider spacing, or mount the switch closer`);
|
|
340
|
+
if (fl.z > zb - 1e-9) throw new Error(`${what}: the flag's tip at ${mm(fl.z)} mm is not under the carriage's underside (${mm(zb)} mm)`);
|
|
341
|
+
flag = { y: r3(fl.y), z: r3(fl.z), width: fd.width, thickness: fd.thickness };
|
|
342
|
+
}
|
|
343
|
+
// its loop in (y, z): a block, and the flag under it where there is one
|
|
344
|
+
const yl = r3(F.yc - Wc / 2), yr = r3(F.yc + Wc / 2);
|
|
345
|
+
const loop = [[yl, zb], [yr, zb], [yr, zt], [yl, zt]];
|
|
346
|
+
// sized: the load on its middle across the bearings, the block bent over the nut's bore (or the screw's room)
|
|
347
|
+
const M = (S * s) / 4, web = r3(zt - h - Math.max(nutBore, 0) / 2), b = Lc, margin = r3(bendMargin(M, b, Math.max(web, 0.1), k.S)), stress = r3((6 * M) / (b * Math.max(web, 0.1) ** 2));
|
|
348
|
+
const m = { kind: 'fitting', fitting: 'rod-carriage', guide: 'rods', name: `rod-carriage-${B.set}-${short(p.name)}-${F.name}${nut ? `-${nut.set}` : ''}`, title: `printed carriage on two ${B.set} over ${p.name}'s ${F.name} face`,
|
|
349
|
+
profile: p.name, face: F.name, frame: F, bearing: B.set, spacing: s, height: h, length: Lc, width: Wc, bottom: zb, top: zt, loop, pocket, bore, depth: B.length, nut: nut ? { set: nut.set, bore: nutBore, flange: nut.flange, flangeWidth: nut.flangeWidth } : null, pilots, flag,
|
|
350
|
+
hardware, screws: [], load: { force: S, what: `${mm(S)} N on its middle, between its bearings ${mm(s)} mm apart` }, stress, margin, own: r3(Lc + (nut ? nut.flangeWidth : 0)),
|
|
351
|
+
anchors: { slide: { at: [0, F.yc, h], axis: [1, 0, 0], ref: [0, 0, 1] }, lm1: { at: [r3(-Lc / 2), r3(F.yc - s / 2), h], axis: [1, 0, 0], ref: [0, 0, 1] }, lm2: { at: [r3(-Lc / 2), r3(F.yc + s / 2), h], axis: [1, 0, 0], ref: [0, 0, 1] },
|
|
352
|
+
...(nut ? { nut: { at: [r3(Lc / 2), F.yc, h], axis: [1, 0, 0], ref: [0, 0, 1] } } : {}), top: { at: [0, F.yc, zt], axis: [0, 0, 1], ref: [1, 0, 0] }, ...(flag ? { flag: { at: [r3(Lc / 2 - flag.thickness), flag.y, flag.z], axis: [-1, 0, 0], ref: [0, 0, 1] } } : {}) },
|
|
353
|
+
size: { length: Lc, width: Wc, height: r3(zt - zb) }, volume: 0, grams: 0, material: k.mat.name, printer: k.pr.name, findings: [],
|
|
354
|
+
rests: [{ name: `${k.mat.name}.strength`, value: k.S }, ...['load', 'press', 'web', 'floor'].map((x) => ({ name: `ROD_DEFAULTS.${x}`, value: ROD_DEFAULTS[x].value, kind: ROD_DEFAULTS[x].kind }))] };
|
|
355
|
+
keep(m, k); weigh(m, rodCarriage(m), k.density);
|
|
356
|
+
m.findings.push(finding('info', `two ${B.set} pressed ${mm(B.length)} mm into pockets from its inner end (${mm(pocket)} mm across: ${mm(ROD_DEFAULTS.press.value)} mm under their ${mm(B.D)} mm, an estimate of a light press), on a ${mm(Lc - B.length)} mm floor, ${mm(s)} mm apart`, 'guide.bearings', { values: { pocket, spacing: s, floor: r3(Lc - B.length) } }));
|
|
357
|
+
if (nut) m.findings.push(finding('info', `${nut.set}'s body in a ${mm(nutBore)} mm bore, its flange on the far end held by ${hardware[0].count} ${hardware[0].name} into ${mm(pilots.depth)} mm pilots (${mm(pilots.need)} mm of ${k.mat.name} asked)`, 'guide.nut', { values: { bore: nutBore, screws: hardware[0].count, length: pilots.length, depth: pilots.depth } }));
|
|
358
|
+
if (flag) m.findings.push(finding('info', `a ${mm(flag.thickness)} x ${mm(flag.width)} mm flag at its far end hangs to ${mm(flag.z)} mm, ${mm(Math.abs(flag.y - F.yc))} mm from the middle: it trips the endstop's lever`, 'guide.flag', { values: { ...flag } }));
|
|
359
|
+
closingFindings(m, { S: k.S, sizeText: `${mm(Wc)} mm across, ${mm(Lc)} mm along the beam, from ${mm(zb)} to ${mm(zt)} mm over the face`, marginText: `under ${m.load.what}, the ${mm(web)} mm over ${nut ? 'the nut\'s bore' : 'the middle'} bends to ${mm(stress)} MPa`, pose: 'on its far end, the bearings\' pockets opening up' });
|
|
360
|
+
return m;
|
|
361
|
+
}
|
|
362
|
+
/** A rod carriage's solid: as it prints (on its far end) or in its fitted frame. @param {object} m rodCarriageModel's @param {{ pose?: 'print' | 'fit', ops?: object }} [o] @returns {object} */
|
|
363
|
+
export function rodCarriage(m, o = {}) {
|
|
364
|
+
if (m?.fitting !== 'rod-carriage') throw new Error(`rodCarriage: give a rod carriage's model (rodCarriageModel), not ${shown(m)}`);
|
|
365
|
+
// print frame: X = -y, Y = z, Z = length / 2 - x (its far end on the bed)
|
|
366
|
+
const P = flat2(-1), Lc = m.length, F = m.frame, parts = [prismZ(m.loop.map(P), 0, Lc)], pr = printerOf('rodCarriage', m.pr ?? null);
|
|
367
|
+
if (m.flag) {
|
|
368
|
+
const f = m.flag, y0 = f.y - f.width / 2, y1 = f.y + f.width / 2, r = Math.min(2, f.width / 2);
|
|
369
|
+
// the flag and a fillet where it meets the underside (no square inside corner)
|
|
370
|
+
const drop = ccw([[y0, f.z], [y1, f.z], [y1, m.bottom + 0.01], [y0, m.bottom + 0.01]].map(P));
|
|
371
|
+
const root = (x0, s) => ccw([[x0, m.bottom - r], [x0, m.bottom + 0.01], [x0 + s * r, m.bottom + 0.01]].map(P));
|
|
372
|
+
parts.push(prismZ(drop, 0, f.thickness), prismZ(root(y0, -1), 0, f.thickness), prismZ(root(y1, 1), 0, f.thickness));
|
|
373
|
+
}
|
|
374
|
+
const ys = [m.anchors.lm1.at[1], m.anchors.lm2.at[1]], cuts = [];
|
|
375
|
+
for (const y of ys) cuts.push(discZ(-y, m.height, m.pocket, Lc - m.depth, Lc + 1), discZ(-y, m.height, m.bore, -1, Lc + 1));
|
|
376
|
+
if (m.nut) {
|
|
377
|
+
cuts.push(discZ(-F.yc, m.height, m.nut.bore, -1, Lc + 1));
|
|
378
|
+
for (const [y, z] of m.pilots.at) cuts.push(hole(m.pilots.thread, { kind: 'pilot', into: '+z', at: [-y, z, 0], depth: m.pilots.depth, printer: pr }));
|
|
379
|
+
} else cuts.push(discZ(-F.yc, m.height, 2 * ROD_DEFAULTS.wall.value, -1, Lc + 1));
|
|
380
|
+
const g = combine(parts, cuts, o.ops ?? null);
|
|
381
|
+
return Object.assign(o.pose === 'fit' ? toFit(g, [[0, -1, 0], [0, 0, 1], [-1, 0, 0]], [0, 0, Lc / 2]) : g, { model: m });
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// ---------- the endstop's mount ----------
|
|
385
|
+
/**
|
|
386
|
+
* A printed mount for a miniature switch (the catalogue's endstop-10t85) on a beam's slotted side face, where a carriage
|
|
387
|
+
* passes: a block on the face, the switch screwed to it through its own holes into pilots, its lever facing along the
|
|
388
|
+
* beam toward b and reaching across the face in the direction toward (+1 or -1 along the mount's y), and the block's screw
|
|
389
|
+
* into the slot ahead of the lever, its head sunk in a counterbore so the carriage's flag passes over it. It prints on the
|
|
390
|
+
* face side. @param {string | object} profile
|
|
391
|
+
* @param {{ switch?: string, face: string, toward?: 1 | -1, load?: number, thread?: string, nut?: string, printer?: object, material?: string | object, given?: object }} o
|
|
392
|
+
* @returns {object} its model: anchors.switch (the switch's own frame), lever (where its lever's face is, in the mount's frame)
|
|
393
|
+
*/
|
|
394
|
+
export function endstopMountModel(profile, o = {}) {
|
|
395
|
+
const what = 'endstopMountModel';
|
|
396
|
+
options(what, o ?? {}, ['switch', 'face', 'toward', 'load', 'thread', 'nut', 'printer', 'material', 'given']);
|
|
397
|
+
const p = profileOf(what, profile, o.given ?? {}), sw = setOf(what, 'switch', 'switch', o.switch ?? 'endstop-10t85'), k = partSetup(what, o), toward = o.toward ?? 1;
|
|
398
|
+
if (![1, -1].includes(toward)) throw new Error(`${what}: toward is 1 or -1, which way across the face the switch's lever reaches (got ${shown(o.toward)})`);
|
|
399
|
+
const w = fig(sw, 'body_width'), dep = fig(sw, 'body_depth'), len = fig(sw, 'body_length'), sp = fig(sw, 'mount_hole_spacing'), hd = fig(sw, 'mount_hole_diameter');
|
|
400
|
+
if (![w, dep, len, sp, hd].every(isNum)) throw new Error(`${what}: ${sw.name} needs body_width, body_depth, body_length, mount_hole_spacing and mount_hole_diameter to be mounted`);
|
|
401
|
+
const sd = slotSide(what, p, o.face, o.thread, o.nut, k.fit, o.given ?? {}), sc = screwOf(what, sd.thread, 'cap', k.pr), S = loadOf(what, o.load, ROD_DEFAULTS.switchLoad.value);
|
|
402
|
+
// the switch's screws: the largest metric thread through its holes, through its body into pilots in the block
|
|
403
|
+
const th = ['M3', 'M2.5', 'M2'].find((x) => fixingModel(x).major <= hd - 0.3 + 1e-9);
|
|
404
|
+
if (!th) throw new Error(`${what}: ${sw.name}'s ${mm(hd)} mm holes take no screw from M2 up`);
|
|
405
|
+
const need = engagement(th, { depth: 1, material: k.mat.name }).need, lens = [...(fixingModel(th).figures.lengths?.value ?? [])].sort((a, b) => a - b), Ls = lens.find((x) => x - dep >= need - 1e-9);
|
|
406
|
+
if (Ls == null) throw new Error(`${what}: no ${th} screw sold passes ${sw.name}'s ${mm(dep)} mm and ${mm(need)} mm into ${k.mat.name}`);
|
|
407
|
+
const pilot = r3(up(Ls - dep + FIX.tip_room.value + k.layer, k.layer)), cb = counterboreModelOf(sd.thread, k), least = up(FITTING_DEFAULTS.least.value * sc.major, k.layer);
|
|
408
|
+
// the screw's grip under its counterbore a thickness a length sold takes; the counterbore as deep as the rest
|
|
409
|
+
const fits = sold(least, k.layer, [sd], sd.thread), grip = fits ? fits.t : least, tb = r3(up(Math.max(grip + cb.depth, pilot + 2 * k.layer), k.layer));
|
|
410
|
+
cb.depth = r3(tb - grip);
|
|
411
|
+
const lever = ROD_DEFAULTS.lever.value, gap = ROD_DEFAULTS.gap.value, xs = r3(lever + gap + cb.diameter / 2 + FITTING_DEFAULTS.reach.value), x0 = r3(-ROD_DEFAULTS.wall.value), x1 = r3(xs + cb.diameter / 2 + ROD_DEFAULTS.wall.value);
|
|
412
|
+
const W = r3(w), M = S * (tb + dep), stress = r3((6 * M) / (W * tb * tb)), margin = r3(bendMargin(M, W, tb, k.S));
|
|
413
|
+
const holes = [-1, 1].map((q) => [r3(len / 2), r3(q * (sp / 2))]); // (the switch's holes along its width, at its body's mid-length)
|
|
414
|
+
const m = { kind: 'fitting', fitting: 'endstop-mount', name: `endstop-mount-${sw.name}-${short(p.name)}-${sd.face.replace('.', '-')}`, title: `printed mount for the switch ${sw.name} on ${p.name}'s ${sd.face} face`, profile: p.name, face: sd.face, switch: sw.name, toward,
|
|
415
|
+
thickness: tb, outline: [[x0, -W / 2], [x1, -W / 2], [x1, W / 2], [x0, W / 2]], counterbore: cb, holes, pilot, switchScrew: { thread: th, length: Ls },
|
|
416
|
+
thread: sd.thread, head: 'cap', screws: [{ thread: sd.thread, head: 'cap', grip, at: [xs, 0, grip], axis: [0, 0, -1], nut: sd.nut.name, nutKind: sd.nut.nutKind, length: fits?.lengths[0] ?? null }],
|
|
417
|
+
lever: { x: lever, out: r3(tb + dep / 2), reach: r3(0.6 * w), width: Math.min(4, dep) },
|
|
418
|
+
hardware: [{ name: `${th}x${Ls} cap`, kind: 'screw', thread: th, length: Ls, head: 'cap', count: 2, why: `${sw.name} to its mount, ${mm(need)} mm into ${k.mat.name}` }],
|
|
419
|
+
load: { force: S, what: `${mm(S)} N on the switch, across the face` }, stress, margin,
|
|
420
|
+
anchors: { switch: { at: [0, 0, r3(tb + dep / 2)], axis: [1, 0, 0], ref: [0, toward, 0] } },
|
|
421
|
+
size: { along: r3(x1 - x0), across: W, thickness: tb }, volume: 0, grams: 0, material: k.mat.name, printer: k.pr.name, findings: [],
|
|
422
|
+
rests: [{ name: `${k.mat.name}.strength`, value: k.S }, { name: 'ROD_DEFAULTS.lever', value: lever, kind: ROD_DEFAULTS.lever.kind }, { name: `${sw.name}.mount_hole_spacing`, value: sp, kind: sw.rules.mount_hole_spacing.kind }] };
|
|
423
|
+
keep(m, k); weigh(m, endstopMount(m), k.density);
|
|
424
|
+
m.findings.push(fits ? finding('pass', `${sd.thread}x${fits.lengths[0]} cap into its slot nut through ${mm(tb - cb.depth)} mm under a ${mm(cb.depth)} mm counterbore, so the flag passes over its head`, 'fitting.screw', { values: { lengths: fits.lengths, windows: fits.windows } })
|
|
425
|
+
: finding('warn', `no ${sd.thread} cap screw sold engages its slot nut fully here: the screw's length is the fasten check's to choose`, 'fitting.screw', {}));
|
|
426
|
+
m.findings.push(finding('info', `${sw.name} by 2 × ${th}x${Ls} cap through its ${mm(hd)} mm holes into ${mm(pilot)} mm pilots, ${mm(sp)} mm apart (${sw.rules.mount_hole_spacing.kind}: measure your switch)`, 'fitting.device', { values: { thread: th, length: Ls, pilot } }));
|
|
427
|
+
closingFindings(m, { S: k.S, sizeText: `${mm(x1 - x0)} mm along the beam, ${mm(W)} mm across, ${mm(tb)} mm thick`, marginText: `under ${m.load.what}, it bends to ${mm(stress)} MPa`, pose: 'on the face side, its counterbore and pilots opening up' });
|
|
428
|
+
return m;
|
|
429
|
+
}
|
|
430
|
+
const counterboreModelOf = (thread, k) => { const c = counterbore(thread, { head: 'cap', printer: k.pr, into: '-z', at: [0, 0, 0] }).model; return { diameter: c.diameter, depth: c.depth }; };
|
|
431
|
+
/** An endstop mount's solid, in its fitted frame (which is how it prints). @param {object} m endstopMountModel's @param {{ pose?: 'print' | 'fit', ops?: object }} [o] @returns {object} */
|
|
432
|
+
export function endstopMount(m, o = {}) {
|
|
433
|
+
if (m?.fitting !== 'endstop-mount') throw new Error(`endstopMount: give an endstop mount's model (endstopMountModel), not ${shown(m)}`);
|
|
434
|
+
const t = m.thickness, pr = printerOf('endstopMount', m.pr ?? null), body = prismZ(m.outline, 0, t), q = m.screws[0];
|
|
435
|
+
const cuts = [counterbore(q.thread, { head: 'cap', printer: pr, into: '-z', at: [q.at[0], q.at[1], t], depth: m.counterbore.depth, length: t + 1 })];
|
|
436
|
+
for (const [x, y] of m.holes) cuts.push(hole(m.switchScrew.thread, { kind: 'pilot', into: '-z', at: [x, y * m.toward, t], depth: m.pilot, printer: pr }));
|
|
437
|
+
const g = combine([body], cuts, o.ops ?? null);
|
|
438
|
+
return Object.assign(g, { model: m });
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// the printer a part was drawn for, kept with its model (not a figure of it), and its fit
|
|
442
|
+
const keep = (m, k) => { Object.defineProperty(m, 'pr', { value: k.pr, enumerable: false }); m.fit = k.fit; };
|
|
443
|
+
// a load in N, the default where none is given; refused by name
|
|
444
|
+
function loadOf(what, F, dflt) {
|
|
445
|
+
if (F == null) return dflt;
|
|
446
|
+
if (!(isNum(F) && F > 0)) throw new Error(`${what}: load is the part's design load, in N, above 0 (got ${shown(F)})`);
|
|
447
|
+
return F;
|
|
448
|
+
}
|
|
449
|
+
const screwFinding = (ls, where) => (ls.fits
|
|
450
|
+
? finding('pass', `${ls.thread}x${ls.fits.lengths[0]} ${ls.head} through each ${where} (${mm(ls.legT)} mm) into its slot nut, its tip between ${mm(ls.fits.windows[0].lo)} (the nut's thread engaged) and ${mm(ls.fits.windows[0].hi)} mm in`, 'fitting.screw', { values: { lengths: ls.fits.lengths, windows: ls.fits.windows } })
|
|
451
|
+
: finding('warn', `no ${ls.thread} ${ls.head} screw sold engages its slot nut fully and stops short of the slot's floor through ${mm(ls.legT)} mm: the screw's length is the fasten check's to choose`, 'fitting.screw', {}));
|
|
452
|
+
|
|
453
|
+
// ---------- the bearings' loads ----------
|
|
454
|
+
/**
|
|
455
|
+
* A rod carriage's loads against its linear bearings' static rating: the force and moment on the carriage, in its frame
|
|
456
|
+
* about its slide (on the rods' line between them), shared between its two bearings: the forces across the rods half
|
|
457
|
+
* each, a roll about the rods' line as a couple across their spacing, pitch and yaw as a couple along each bearing
|
|
458
|
+
* (ROD_DEFAULTS.couple: an estimate). Each bearing's radial load over its static rating; the margin is the least.
|
|
459
|
+
* The force along the beam is the drive's. @param {object} m rodCarriageModel's (its bearing named)
|
|
460
|
+
* @param {{ force: number[], moment: number[] }} load N and N m, in the carriage's frame
|
|
461
|
+
* @returns {{ bearings: { name: string, radial: number, ratio: number }[], worst: string, margin: number, level: 'pass' | 'warn' | 'fail', rating: number }}
|
|
462
|
+
*/
|
|
463
|
+
export function rodMargin(m, load) {
|
|
464
|
+
const B = SETS[m.bearing], C0 = fig(B, 'static_rating'), Lb = fig(B, 'length'), s = m.spacing / 1000, arm = (ROD_DEFAULTS.couple.value * Lb) / 1000;
|
|
465
|
+
const [, Fy, Fz] = load.force, [Mx, My, Mz] = load.moment;
|
|
466
|
+
const bearings = [-1, 1].map((sg, i) => {
|
|
467
|
+
const y = Fy / 2, z = Fz / 2 + (sg * Mx) / s; // (a roll about x pushes one bearing up and the other down)
|
|
468
|
+
const py = Mz / 2 / arm, pz = My / 2 / arm; // (pitch and yaw as forces at each bearing's two ends)
|
|
469
|
+
const radial = Math.hypot(Math.abs(y) + Math.abs(py), Math.abs(z) + Math.abs(pz));
|
|
470
|
+
return { name: `lm${i + 1}`, radial: r3(radial), ratio: r3(radial / C0) };
|
|
471
|
+
});
|
|
472
|
+
const worst = bearings.reduce((a, b) => (b.ratio > a.ratio ? b : a)), margin = worst.ratio > 0 ? r3(1 / worst.ratio) : Infinity;
|
|
473
|
+
return { bearings, worst: worst.name, margin, level: margin < 1 ? 'fail' : margin < want() ? 'warn' : 'pass', rating: C0 };
|
|
474
|
+
}
|
|
475
|
+
|
package/section.d.mts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** Twice-signed area's half: positive for a counter-clockwise loop. @param {number[][]} loop @returns {number} */
|
|
2
|
+
export function signedArea(loop: number[][]): number;
|
|
3
|
+
/**
|
|
4
|
+
* Area, centroid and second moments of area of a section, by the polygon (Green's theorem) formulas, summed over its
|
|
5
|
+
* loops so that a clockwise hole takes away. The second moments are about axes through the centroid, parallel to x and y.
|
|
6
|
+
* @param {number[][][]} loops
|
|
7
|
+
* @returns {{ area: number, centroid: [number, number], inertiaX: number, inertiaY: number, inertiaXY: number }} mm², mm, mm⁴
|
|
8
|
+
*/
|
|
9
|
+
export function polygonSection(loops: number[][][]): {
|
|
10
|
+
area: number;
|
|
11
|
+
centroid: [number, number];
|
|
12
|
+
inertiaX: number;
|
|
13
|
+
inertiaY: number;
|
|
14
|
+
inertiaXY: number;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The torsion constant of a section (St Venant's J, written It on a maker's sheet): torque = G J × twist per length.
|
|
18
|
+
* Prandtl's stress function φ is solved on a raster of square cells: ∇²φ = −2 in the material, φ = 0 on the outside,
|
|
19
|
+
* and φ one unknown constant over each hole, fixed by the hole's own balance (the flow of φ into a hole is twice its
|
|
20
|
+
* area). Then J = 2 ∫φ dA over material and holes. That is why a closed tube is stiff and a slotted one is not: an
|
|
21
|
+
* open slot is outside (φ = 0 along it), a closed hole carries φ across itself.
|
|
22
|
+
* @param {number[][][]} loops the outside counter-clockwise, holes clockwise
|
|
23
|
+
* @param {{ cells?: number, tolerance?: number }} [o] cells: about how many raster cells cover the section's bounding
|
|
24
|
+
* box (40 000: a 20 mm section in 0.1 mm cells); tolerance: where the solver stops, as a share of the load
|
|
25
|
+
* @returns {{ torsion: number, cell: number, cells: number, iterations: number }} mm⁴, the cell's side in mm
|
|
26
|
+
*/
|
|
27
|
+
export function torsionConstant(loops: number[][][], o?: {
|
|
28
|
+
cells?: number;
|
|
29
|
+
tolerance?: number;
|
|
30
|
+
}): {
|
|
31
|
+
torsion: number;
|
|
32
|
+
cell: number;
|
|
33
|
+
cells: number;
|
|
34
|
+
iterations: number;
|
|
35
|
+
};
|
|
36
|
+
/** Whether a point is inside a loop (even-odd). @param {number[]} p @param {number[][]} loop @returns {boolean} */
|
|
37
|
+
export function inside([x, y]: number[], loop: number[][]): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* The gap between two closed outlines: the least distance between them, or a negative number when they overlap (one
|
|
40
|
+
* crossing or inside the other), whose size is not a depth.
|
|
41
|
+
* @param {number[][]} p @param {number[][]} q @returns {number}
|
|
42
|
+
*/
|
|
43
|
+
export function gap(p: number[][], q: number[][]): number;
|