@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/frames.mjs
CHANGED
|
@@ -1,10 +1,43 @@
|
|
|
1
|
-
// @rulecad/frames: structures from beams, of any profile
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
// @rulecad/frames: structures from beams, of any profile. This release reads a profile (a beam's constant section, as
|
|
2
|
+
// a model from its rule set, its outline, and what that outline is worth beside the maker's sheet) and makes beams of
|
|
3
|
+
// it: a length with its mass, its anchors, the operations on it (cut, mitre, tap, holes, pockets, notches) and its solid;
|
|
4
|
+
// and a frame's cut list (the bars to buy and the cuts on each) and a cut-and-drill sheet for each kind of beam; and joins
|
|
5
|
+
// between beams by kind (the operations on both, the screws, a stiffness for the solver); and printed fittings for those
|
|
6
|
+
// joins (a corner bracket, gusset and splice plates), sized from a named load by finite elements; panels cut to a bay
|
|
7
|
+
// and the printed parts that hold them, a door's hinges, handle, latch and catch, and the parts for a beam's end (caps,
|
|
8
|
+
// feet, levelling feet, castor plates, stacking feet); and the parts that carry a machine's services (cable clips and
|
|
9
|
+
// tie anchors, mounts for boards, supplies, fans and drag chains read from their rule sets, a DIN rail adapter and a
|
|
10
|
+
// spool holder); and bought fittings as rule sets (a cast corner bracket, joining plates, inner and anchor
|
|
11
|
+
// connectors, hinges, end caps, levelling feet), which a join or a mount chooses by name in place of a printed one,
|
|
12
|
+
// with their price and their stiffness, an estimate until the joint rig measures it; and guides: a miniature rail on a
|
|
13
|
+
// slotted face (its holes at its pitch, its screws into slot nuts, each carriage's travel, its carriages' loads against
|
|
14
|
+
// their ratings, its terms in an error budget) and a printed jig that centres it; a carriage on V-wheels in a V-slot's
|
|
15
|
+
// tracks (a printed plate, the wheels' seats from the track, their eccentrics' preload, each wheel's load against its
|
|
16
|
+
// rating) and a printed slider in or over a slot; and two smooth rods in printed holders with a printed carriage on
|
|
17
|
+
// linear bearings, driven by a lead screw from a printed motor plate for the catalogue's motors, with an endstop's
|
|
18
|
+
// printed mount and a flag on the carriage; and jigs for hand tools from a beam's operations (a drill guide, a tap
|
|
19
|
+
// guide, a cut-length stop and a squaring corner); and a bay squared by its diagonals (their length and the difference
|
|
20
|
+
// to accept, from the cut tolerance). Belts follow: the plan is https://github.com/JoniBach/rulecad/issues/240.
|
|
21
|
+
//
|
|
22
|
+
// Every profile, slot family, slot nut, bought fitting and rail is a rule set in @rulecad/rules, so the numbers are open data and live
|
|
23
|
+
// there. A section is drawn in x (across, its width) and y (up, its height), with the middle of its envelope at the
|
|
24
|
+
// origin; a beam runs along z from end a at z = 0. Its faces are top (+y), bottom (-y), front (-x) and back (+x).
|
|
25
|
+
// Units: mm, grams, degrees.
|
|
26
|
+
export * from './profile.mjs';
|
|
27
|
+
export { beamModel, beam, beamAnchor, printable } from './beam.mjs';
|
|
28
|
+
export { OPS, OP_DEFAULTS } from './ops.mjs';
|
|
29
|
+
export { JOINS, JOIN_STIFFNESS, JOIN_SCALE, JOIN_TAP, JOIN_SET, joinRuleSet, joinStiffness, joinModel, boughtStiffness } from './join.mjs';
|
|
30
|
+
export { BOUGHT_KINDS, boughtFittings, boughtFittingModel, boughtFitting, printedCost } from './bought.mjs';
|
|
31
|
+
export { CUT_DEFAULTS, beamMarks, packBars, cutList, cutListText } from './cutlist.mjs';
|
|
32
|
+
export { beamSheet } from './cutsheet.mjs';
|
|
33
|
+
export { slotNutModel, nutFit, slotNut, nutFor, carrierModel, carrier, CARRIER_DEFAULTS, NUT_KINDS } from './slotnut.mjs';
|
|
34
|
+
export { FITTINGS, FITTING_DEFAULTS, bracketModel, bracket, plateModel, plate, fittingFE } from './fitting.mjs';
|
|
35
|
+
export { SHEETS, PANEL_DEFAULTS, panelModel, panel, panelClipModel, panelClip, panelCornerModel, panelCorner, slotCoverModel, slotCover, panelEdgeModel, panelEdge, gasketStripModel, gasketStrip } from './panel.mjs';
|
|
36
|
+
export { DOOR_DEFAULTS, hingeModel, hinge, handleModel, handle, latchModel, latch, magnetCatchModel, magnetCatch } from './door.mjs';
|
|
37
|
+
export { SERVICE_DEFAULTS, FANS, DIN_RAIL, deviceMountModel, deviceMount, fanMountModel, fanMount, dragChainEndModel, dragChainEnd, dinRailAdapterModel, dinRailAdapter, cableClipModel, cableClip, runClips, tieAnchorModel, tieAnchor, spoolHolderModel, spoolHolder } from './services.mjs';
|
|
38
|
+
export { GUIDE_KINDS, GUIDE_DEFAULTS, rails, railModel, rail, carriage, carriageMargin, guideFit, railTerms, railJigModel, railJig } from './guide.mjs';
|
|
39
|
+
export { WHEEL_DEFAULTS, wheels, trackFit, wheelsModel, wheelPlate, vWheel, wheelMargin, sliderModel, slider } from './wheels.mjs';
|
|
40
|
+
export { ROD_DEFAULTS, rodsLayout, rodHolderModel, rodHolder, motorPlateModel, motorPlate, rodCarriageModel, rodCarriage, endstopMountModel, endstopMount, rodMargin } from './rods.mjs';
|
|
41
|
+
export { END_DEFAULTS, endCapModel, endCap, footModel, foot, levellingFootModel, levellingFoot, castorPlateModel, castorPlate, stackingFootModel, stackingFoot } from './ends.mjs';
|
|
42
|
+
export { JIG_KINDS, JIG_DEFAULTS, drillGuideModel, drillGuide, tapGuideModel, tapGuide, lengthStopModel, lengthStop, squareCornerModel, squareCorner } from './jig.mjs';
|
|
43
|
+
export { squareness } from './square.mjs';
|
package/guide.d.mts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A rail cut to a length and its carriages: where its holes fall, the screws, the share of the rail each carriage
|
|
3
|
+
* rides and its travel, its mass and what it adds to the error budget. Refused by name: a set that is no rail, a
|
|
4
|
+
* carriage it does not have, a length past what its maker sells or too short for one hole or for its carriages.
|
|
5
|
+
* @param {string | object} set a rail's rule set or its name (rail-mgn12)
|
|
6
|
+
* @param {{ variant?: string, length: number, carriages?: number, given?: object }} o
|
|
7
|
+
* variant: the carriage (MGN12C, standard; MGN12H, long); carriages: how many ride it, each its own share
|
|
8
|
+
* @returns {object} its model: rail, carriage, holes, screws, lanes, travel, terms, findings
|
|
9
|
+
*/
|
|
10
|
+
export function railModel(set: string | object, o?: {
|
|
11
|
+
variant?: string;
|
|
12
|
+
length: number;
|
|
13
|
+
carriages?: number;
|
|
14
|
+
given?: object;
|
|
15
|
+
}): object;
|
|
16
|
+
/**
|
|
17
|
+
* A rail's solid in its frame, its counterbored holes cut. @param {object} m railModel's @returns {object} a JSCAD geom3
|
|
18
|
+
*/
|
|
19
|
+
export function rail(m: object): object;
|
|
20
|
+
/**
|
|
21
|
+
* A carriage's solid in its frame (its middle at the origin, on the rail's face): its block over the rail with a
|
|
22
|
+
* channel the rail runs in, and its four tapped holes drawn at the tap drill. @param {object} m railModel's @returns {object}
|
|
23
|
+
*/
|
|
24
|
+
export function carriage(m: object): object;
|
|
25
|
+
/**
|
|
26
|
+
* A carriage's loads against its ratings: the force square to the rail's face and across it over C0, each moment over
|
|
27
|
+
* its own rating, summed (GUIDE_DEFAULTS.combine). The force along the rail is the drive's, not the carriage's.
|
|
28
|
+
* @param {object} m railModel's
|
|
29
|
+
* @param {{ force: number[], moment: number[] }} load in the carriage's frame: force [along, across, out of the face] in N; moment [roll about x, pitch about y, yaw about z] in N m
|
|
30
|
+
* @returns {{ ratios: { normal: number, roll: number, pitch: number, yaw: number }, sum: number, margin: number, level: 'pass' | 'warn' | 'fail', worst: string }}
|
|
31
|
+
*/
|
|
32
|
+
export function carriageMargin(m: object, load: {
|
|
33
|
+
force: number[];
|
|
34
|
+
moment: number[];
|
|
35
|
+
}): {
|
|
36
|
+
ratios: {
|
|
37
|
+
normal: number;
|
|
38
|
+
roll: number;
|
|
39
|
+
pitch: number;
|
|
40
|
+
yaw: number;
|
|
41
|
+
};
|
|
42
|
+
sum: number;
|
|
43
|
+
margin: number;
|
|
44
|
+
level: "pass" | "warn" | "fail";
|
|
45
|
+
worst: string;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Whether a rail fits a beam's face, as findings (code guide.fit): its holes over the slot's centre line and its width
|
|
49
|
+
* over the face, its screws' thread suiting a slot nut made for that slot (named, with the kinds there are), and its
|
|
50
|
+
* ends clear of what crosses the face. Fails are said by name with what would fit.
|
|
51
|
+
* @param {object} m railModel's
|
|
52
|
+
* @param {string | object} profile the beam's profile
|
|
53
|
+
* @param {{ face?: string, from?: number, beam?: number, nut?: string, keep?: { from: number, to: number, what: string }[], given?: object }} [o]
|
|
54
|
+
* from: where the rail starts along the beam, mm from end a; beam: the beam's length; keep: stretches of the face something else holds
|
|
55
|
+
* @returns {{ findings: object[], nut: object | null, face: string, slot: string | null }}
|
|
56
|
+
*/
|
|
57
|
+
export function guideFit(m: object, profile: string | object, o?: {
|
|
58
|
+
face?: string;
|
|
59
|
+
from?: number;
|
|
60
|
+
beam?: number;
|
|
61
|
+
nut?: string;
|
|
62
|
+
keep?: {
|
|
63
|
+
from: number;
|
|
64
|
+
to: number;
|
|
65
|
+
what: string;
|
|
66
|
+
}[];
|
|
67
|
+
given?: object;
|
|
68
|
+
}): {
|
|
69
|
+
findings: object[];
|
|
70
|
+
nut: object | null;
|
|
71
|
+
face: string;
|
|
72
|
+
slot: string | null;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* The error a rail adds to a machine's budget along its travel, in mm: its parallelism and its carriage's play from
|
|
76
|
+
* its rule set, the beam's own straightness over the rail from the profile's, and the beam's sag under its own weight
|
|
77
|
+
* and what it carries (GUIDE_DEFAULTS.sag, an estimate). @param {object} m railModel's @param {string | object} profile
|
|
78
|
+
* @param {{ beam: number, carried?: number, given?: object }} o beam: the beam's length; carried: kg on its carriages
|
|
79
|
+
* @returns {{ term: string, value: number, kind: string, note: string }[]}
|
|
80
|
+
*/
|
|
81
|
+
export function railTerms(m: object, profile: string | object, o?: {
|
|
82
|
+
beam: number;
|
|
83
|
+
carried?: number;
|
|
84
|
+
given?: object;
|
|
85
|
+
}): {
|
|
86
|
+
term: string;
|
|
87
|
+
value: number;
|
|
88
|
+
kind: string;
|
|
89
|
+
note: string;
|
|
90
|
+
}[];
|
|
91
|
+
/**
|
|
92
|
+
* A printed jig that snaps over a beam and the rail laid on it: a key into the slot of each side face holds it on the
|
|
93
|
+
* beam's centre, and a channel over the rail holds the rail there while its screws are tightened. Slide it along as
|
|
94
|
+
* each screw goes in. It prints on its side, its section the first layer, with no supports.
|
|
95
|
+
* @param {string | object} profile the beam's profile
|
|
96
|
+
* @param {{ rail: string | object, face?: string, length?: number, load?: number, printer?: object, material?: string | object, given?: object }} o
|
|
97
|
+
* @returns {object} its model
|
|
98
|
+
*/
|
|
99
|
+
export function railJigModel(profile: string | object, o?: {
|
|
100
|
+
rail: string | object;
|
|
101
|
+
face?: string;
|
|
102
|
+
length?: number;
|
|
103
|
+
load?: number;
|
|
104
|
+
printer?: object;
|
|
105
|
+
material?: string | object;
|
|
106
|
+
given?: object;
|
|
107
|
+
}): object;
|
|
108
|
+
/** A rail jig's solid: on its side to print, or fitted. @param {object} m railJigModel's @param {{ pose?: 'print' | 'fit', tongues?: boolean, ops?: object }} [o] @returns {object} */
|
|
109
|
+
export function railJig(m: object, o?: {
|
|
110
|
+
pose?: "print" | "fit";
|
|
111
|
+
tongues?: boolean;
|
|
112
|
+
ops?: object;
|
|
113
|
+
}): object;
|
|
114
|
+
export namespace GUIDE_KINDS {
|
|
115
|
+
namespace rail {
|
|
116
|
+
let what: string;
|
|
117
|
+
let sets: string;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
export namespace GUIDE_DEFAULTS {
|
|
121
|
+
namespace endLeast {
|
|
122
|
+
export { text as rule };
|
|
123
|
+
export { kind };
|
|
124
|
+
export { source };
|
|
125
|
+
export { CHECKED as checked };
|
|
126
|
+
export { unit };
|
|
127
|
+
export { value };
|
|
128
|
+
}
|
|
129
|
+
namespace clear { }
|
|
130
|
+
namespace combine { }
|
|
131
|
+
namespace across { }
|
|
132
|
+
namespace sag { }
|
|
133
|
+
namespace jigLength { }
|
|
134
|
+
namespace jigLoad { }
|
|
135
|
+
namespace jigKey { }
|
|
136
|
+
namespace jigRound { }
|
|
137
|
+
}
|
|
138
|
+
export function rails(): string[];
|
|
139
|
+
declare const CHECKED: "2026-11-17";
|
|
140
|
+
export {};
|
package/guide.mjs
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
// Guides: linear motion on a beam. A miniature rail (MGN7, 9, 12 or 15, from its rule set: rail-mgn12) screwed down
|
|
2
|
+
// on a beam's slotted face into slot nuts at its hole pitch, and its carriages, each riding its own share of the rail.
|
|
3
|
+
// The model says where the holes fall in the length it is cut to, the screws and the slot nut each takes, how far each
|
|
4
|
+
// carriage can travel, what the rail adds to a machine's error budget, and whether it fits the face (guideFit). A
|
|
5
|
+
// carriage's loads are held to its ratings (carriageMargin). A printed jig centres the rail on the beam while its
|
|
6
|
+
// screws are tightened (railJigModel).
|
|
7
|
+
//
|
|
8
|
+
// A rail's frame: x along it from its end a (0 to its length), y across, z out of the face it is screwed to (0 on the
|
|
9
|
+
// face). A carriage's frame: its middle over the rail's centre line, on that face, x along the rail, z up; its top is
|
|
10
|
+
// at z = H (carriage_height). A jig's fitted frame is a mount's (x along the beam, y across, z out of the face, 0 on
|
|
11
|
+
// it); it prints on its side, its section the first layer. Units: mm, N, N m, kg, grams.
|
|
12
|
+
import jscad from '@jscad/modeling';
|
|
13
|
+
import { SETS } from './catalogue.mjs';
|
|
14
|
+
import { profileOf, options, roundConcave, ccw } from './fitting.mjs';
|
|
15
|
+
import { nutFor, NUT_KINDS } from './slotnut.mjs';
|
|
16
|
+
import { partSetup, weigh, closingFindings, sideToFit } from './panel.mjs';
|
|
17
|
+
|
|
18
|
+
const { cuboid, cylinder, polygon } = jscad.primitives, { extrudeLinear } = jscad.extrusions, { subtract } = jscad.booleans;
|
|
19
|
+
const { translate, transform } = jscad.transforms;
|
|
20
|
+
const CHECKED = '2026-11-17';
|
|
21
|
+
const isNum = (x) => typeof x === 'number' && Number.isFinite(x);
|
|
22
|
+
const shown = (v) => { const s = v === undefined ? 'nothing' : JSON.stringify(v) ?? String(v); return s.length > 80 ? `${s.slice(0, 77)}...` : s; };
|
|
23
|
+
const mm = (x) => String(+Number(x).toFixed(2));
|
|
24
|
+
const r3 = (x) => +x.toFixed(3);
|
|
25
|
+
const finding = (level, text, code, extra = {}) => ({ level, text, code, ...extra });
|
|
26
|
+
const rule = (value, unit, text, kind, source) => ({ value, ...(unit ? { unit } : {}), rule: text, kind, source, checked: CHECKED });
|
|
27
|
+
const box = (lo, hi) => cuboid({ size: hi.map((h, k) => h - lo[k]), center: hi.map((h, k) => (h + lo[k]) / 2) });
|
|
28
|
+
const prism = (loop, h) => extrudeLinear({ height: h }, polygon({ points: ccw(loop) }));
|
|
29
|
+
|
|
30
|
+
/** The kinds of guide, each with what it is. Only rails are built yet; wheels, rods, sliders, screws and belts follow. */
|
|
31
|
+
export const GUIDE_KINDS = {
|
|
32
|
+
rail: { what: 'a miniature linear rail screwed down on a slotted face, its carriages riding on it', sets: 'rail-mgn7, rail-mgn9, rail-mgn12, rail-mgn15' },
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/** The working figures of the guides, each with what it rests on. */
|
|
36
|
+
export const GUIDE_DEFAULTS = {
|
|
37
|
+
endLeast: rule(1, 'mm', 'A rail\'s last hole is at least this far plus its counterbore\'s radius from the rail\'s cut end, so the steel round the hole does not break out', 'estimate', 'A working figure of @rulecad/frames: HIWIN asks for no less than an E-min its catalogue\'s text does not print; check your maker\'s drawing'),
|
|
38
|
+
clear: rule(1, 'mm', 'A rail\'s end stands at least this clear of a beam or fitting that crosses its face', 'default', 'A working figure of @rulecad/frames'),
|
|
39
|
+
combine: rule(1, '', 'A carriage\'s loads are held to its ratings together: its force across the rail over C0, and each moment over its own rating (MR, MP, MY), summed. The sum\'s inverse is its margin: under 1 it fails, under 2 it warns', 'estimate', 'A working rule of @rulecad/frames: HIWIN\'s catalogue rates each load alone; summing them is the cautious way to combine them'),
|
|
40
|
+
across: rule(1, '× C0', 'A carriage takes a force sideways across its rail as it takes one square to the rail\'s face: one C0 for both', 'estimate', 'HIWIN\'s MG catalogue says its gothic arch contact takes load from all directions (2-4-1), and gives one C0; equal ratings each way are an estimate'),
|
|
41
|
+
sag: rule(1, '', 'A beam carrying a guide sags under its own weight and the carriages\' as a beam on two pinned supports at its ends: the worse of pinned and fixed', 'estimate', 'Simply supported beam formulas, 5wL⁴/384EI and PL³/48EI (Roark\'s Formulas for Stress and Strain, table 8.1, cases 1a and 2e); the joins at the ends hold it more than this'),
|
|
42
|
+
jigLength: rule(20, 'mm', 'A rail jig\'s least length along the beam: longer where the push on the rail needs it', 'default', 'A working figure of @rulecad/frames'),
|
|
43
|
+
jigLoad: rule(20, 'N', 'The design load on a rail jig: a hand pushing the rail sideways against it while the screws go in', 'default', 'A working figure of @rulecad/frames'),
|
|
44
|
+
jigKey: rule(1, 'mm', 'The most a rail jig\'s keys reach into the slots of the beam\'s side faces; less where snapping the jig on over them would bend its legs past half the plastic\'s strength', 'estimate', 'A working figure of @rulecad/frames, to be checked by a test print'),
|
|
45
|
+
jigRound: rule(0.6, 'mm', 'The rounding of a rail jig\'s inside corners', 'default', 'A working figure of @rulecad/frames: no square inside corners, and under the beam\'s own corner radius'),
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const RAILS = () => Object.values(SETS).filter((s) => s.part === 'rail').map((s) => s.name).sort();
|
|
49
|
+
/** The rail sets frames knows, by name. @returns {string[]} */
|
|
50
|
+
export const rails = () => RAILS();
|
|
51
|
+
|
|
52
|
+
// a rail's set by name or as given, its variant's values and whole rules laid over its own
|
|
53
|
+
function railSet(what, set, variant, given = {}) {
|
|
54
|
+
const s = typeof set === 'string' ? given.sets?.[set] ?? SETS[set] : set;
|
|
55
|
+
if (!s?.rules || s.part !== 'rail') throw new Error(`${what}: rail is a rail's rule set or its name: ${RAILS().join(', ')} (got ${shown(set)})`);
|
|
56
|
+
if (variant == null) return { set: s, rules: s.rules, variant: Object.keys(s.variants ?? {})[0] ?? null };
|
|
57
|
+
const v = s.variants?.[variant];
|
|
58
|
+
if (!v) throw new Error(`${what}: ${s.name} has no carriage ${shown(variant)}: it has ${Object.keys(s.variants ?? {}).join(', ') || 'none'}`);
|
|
59
|
+
return { set: s, variant, rules: { ...s.rules, ...Object.fromEntries(Object.entries(v.values ?? {}).map(([k, value]) => [k, { ...s.rules[k], value, kind: v.kind ?? s.rules[k]?.kind, source: v.source ?? s.rules[k]?.source }])), ...(v.rules ?? {}) } };
|
|
60
|
+
}
|
|
61
|
+
const fig = (R, k) => R[k]?.value;
|
|
62
|
+
const threadRules = (t) => SETS[String(t).toLowerCase().replace('.', '_')]?.rules;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A rail cut to a length and its carriages: where its holes fall, the screws, the share of the rail each carriage
|
|
66
|
+
* rides and its travel, its mass and what it adds to the error budget. Refused by name: a set that is no rail, a
|
|
67
|
+
* carriage it does not have, a length past what its maker sells or too short for one hole or for its carriages.
|
|
68
|
+
* @param {string | object} set a rail's rule set or its name (rail-mgn12)
|
|
69
|
+
* @param {{ variant?: string, length: number, carriages?: number, given?: object }} o
|
|
70
|
+
* variant: the carriage (MGN12C, standard; MGN12H, long); carriages: how many ride it, each its own share
|
|
71
|
+
* @returns {object} its model: rail, carriage, holes, screws, lanes, travel, terms, findings
|
|
72
|
+
*/
|
|
73
|
+
export function railModel(set, o = {}) {
|
|
74
|
+
const what = 'railModel';
|
|
75
|
+
options(what, o ?? {}, ['variant', 'length', 'carriages', 'given']);
|
|
76
|
+
const { set: s, rules: R, variant } = railSet(what, set, o.variant, o.given), L = o.length, n = o.carriages ?? 1;
|
|
77
|
+
if (!(isNum(L) && L > 0)) throw new Error(`${what}: length is the rail cut to, in mm, above 0 (got ${shown(o.length)})`);
|
|
78
|
+
if (!(Number.isInteger(n) && n >= 1 && n <= 8)) throw new Error(`${what}: carriages is how many carriages ride the rail, a whole number from 1 to 8 (got ${shown(o.carriages)})`);
|
|
79
|
+
const max = fig(R, 'rail_length_max'); if (isNum(max) && L > max + 1e-9) throw new Error(`${what}: ${s.name} is sold up to ${mm(max)} mm in one piece (got ${mm(L)}): two rails butted end to end are two guides`);
|
|
80
|
+
const P = fig(R, 'rail_hole_pitch'), Es = fig(R, 'rail_hole_end'), D = fig(R, 'rail_counterbore_diameter'), least = r3(D / 2 + GUIDE_DEFAULTS.endLeast.value);
|
|
81
|
+
// the holes: as many as leave each end at least `least`, the rest shared between the two ends
|
|
82
|
+
const count = Math.floor((L - 2 * least) / P + 1e-9) + 1;
|
|
83
|
+
if (count < 1 || L < 2 * least) throw new Error(`${what}: a ${mm(L)} mm rail of ${s.name} has room for no hole ${mm(least)} mm from each end: cut it to at least ${mm(2 * least)} mm`);
|
|
84
|
+
const E = r3((L - (count - 1) * P) / 2), holes = Array.from({ length: count }, (_, i) => r3(E + i * P));
|
|
85
|
+
const Lm = fig(R, 'carriage_length_max'), lane = L / n, travel = r3(lane - Lm);
|
|
86
|
+
if (travel <= 0) throw new Error(`${what}: ${n} ${variant ?? s.name} carriage${n > 1 ? 's' : ''} ${mm(Lm)} mm long ${n > 1 ? 'each need' : 'needs'} more than ${n > 1 ? `a ${mm(lane)} mm share of ` : ''}a ${mm(L)} mm rail to move at all: cut it longer than ${mm(n * Lm)} mm`);
|
|
87
|
+
const HR = fig(R, 'rail_height'), h = fig(R, 'rail_counterbore_depth'), thread = fig(R, 'rail_thread');
|
|
88
|
+
const screws = holes.map((x, i) => ({ name: `h${i + 1}`, at: [x, 0, r3(HR - h)], axis: [0, 0, -1], thread, head: 'cap', listed: fig(R, 'rail_screw_length') }));
|
|
89
|
+
const lanes = Array.from({ length: n }, (_, i) => ({ from: r3(i * lane), to: r3((i + 1) * lane), rest: r3(i * lane + Lm / 2), travel }));
|
|
90
|
+
const par = fig(R, 'rail_parallelism'), steps = Array.from({ length: (par?.length ?? 0) / 2 }, (_, i) => [par[2 * i], par[2 * i + 1]]), parallel = steps.length ? (steps.find(([upTo]) => L <= upTo + 1e-9) ?? steps.at(-1))[1] : null;
|
|
91
|
+
const ct = fig(R, 'carriage_thread'), tr = threadRules(ct);
|
|
92
|
+
const carriage = { variant, length: fig(R, 'carriage_length'), lengthMax: Lm, body: fig(R, 'carriage_body_length'), width: fig(R, 'carriage_width'), height: fig(R, 'carriage_height'), clearance: fig(R, 'carriage_clearance'),
|
|
93
|
+
holes: [[-1, -1], [1, -1], [1, 1], [-1, 1]].map(([a, b]) => [r3((a * fig(R, 'carriage_hole_x')) / 2), r3((b * fig(R, 'carriage_hole_y')) / 2)]), thread: ct, depth: fig(R, 'carriage_thread_depth'), tap: tr?.tap_drill?.value ?? null,
|
|
94
|
+
mass: fig(R, 'carriage_mass'), play: fig(R, 'carriage_play'), stiffness: fig(R, 'carriage_stiffness'),
|
|
95
|
+
ratings: { C: fig(R, 'dynamic_rating'), C0: fig(R, 'static_rating'), MR: fig(R, 'moment_roll'), MP: fig(R, 'moment_pitch'), MY: fig(R, 'moment_yaw') } };
|
|
96
|
+
const rail = { width: fig(R, 'rail_width'), height: HR, pitch: P, end: E, standardEnd: Es, least, hole: fig(R, 'rail_hole_diameter'), counterbore: { diameter: D, depth: h }, thread, screwLength: fig(R, 'rail_screw_length'), mass: r3((fig(R, 'rail_mass') * L) / 1000), parallelism: parallel };
|
|
97
|
+
const terms = [
|
|
98
|
+
...(parallel != null ? [{ term: 'rail parallelism', value: parallel, kind: R.rail_parallelism.kind, note: `${s.name} over ${mm(L)} mm, normal class`, rule: `${s.name}.rail_parallelism` }] : []),
|
|
99
|
+
...(carriage.play != null ? [{ term: 'carriage play', value: carriage.play, kind: R.carriage_play.kind, note: `${variant ?? s.name}, light clearance (ZF)`, rule: `${s.name}.carriage_play` }] : []),
|
|
100
|
+
];
|
|
101
|
+
const m = { kind: 'guide', guide: 'rail', name: `${s.name}-${mm(L)}`, title: `${s.name} rail, ${mm(L)} mm, ${n} × ${variant ?? 'carriage'}`, set: s.name, variant, length: L, rail, carriage, holes, screws, lanes, travel, terms, mass: r3(rail.mass + n * (carriage.mass ?? 0)), findings: [],
|
|
102
|
+
rests: ['rail_hole_pitch', 'rail_hole_end', 'carriage_length_max', 'static_rating', 'moment_roll', 'moment_pitch', 'moment_yaw'].map((k) => ({ name: `${s.name}.${k}`, value: R[k].value, kind: R[k].kind })) };
|
|
103
|
+
m.findings.push(finding('info', `${s.name} cut to ${mm(L)} mm: ${count} holes ${mm(P)} mm apart, the first and last ${mm(E)} mm from its ends (its maker's standard end is ${mm(Es)} mm), each an ${thread} cap screw in a ${mm(D)} mm counterbore`, 'guide.holes', { values: { holes: count, pitch: P, end: E } }));
|
|
104
|
+
if (E > P / 2 + 1e-9) m.findings.push(finding('warn', `its end holes are ${mm(E)} mm from its ends, more than half the ${mm(P)} mm pitch: HIWIN advises no more, so its ends stay steady. Cut it to ${mm((count - 1) * P + 2 * Es)} or ${mm(count * P + 2 * Es)} mm for its standard ${mm(Es)} mm ends`, 'guide.end', { values: { end: E, pitch: P, standard: Es } }));
|
|
105
|
+
m.findings.push(finding('info', `${n} ${variant ?? 'carriage'}${n > 1 ? 's' : ''}, ${mm(Lm)} mm long with ${n > 1 ? 'their' : 'its'} seals, ${n > 1 ? `each in its own ${mm(lane)} mm of the rail, ` : ''}travel ${mm(travel)} mm`, 'guide.travel', { values: { carriages: n, lane: r3(lane), travel, length: Lm } }));
|
|
106
|
+
return m;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* A rail's solid in its frame, its counterbored holes cut. @param {object} m railModel's @returns {object} a JSCAD geom3
|
|
111
|
+
*/
|
|
112
|
+
export function rail(m) {
|
|
113
|
+
if (m?.guide !== 'rail') throw new Error(`rail: give a rail's model (railModel), not ${shown(m)}`);
|
|
114
|
+
const { width: W, height: H, hole, counterbore: c } = m.rail, cuts = m.holes.flatMap((x) => [
|
|
115
|
+
translate([x, 0, H / 2], cylinder({ radius: hole / 2, height: H + 2, segments: 24 })),
|
|
116
|
+
translate([x, 0, H - c.depth / 2 + 0.5], cylinder({ radius: c.diameter / 2, height: c.depth + 1, segments: 32 }))]);
|
|
117
|
+
return Object.assign(subtract(box([0, -W / 2, 0], [m.length, W / 2, H]), ...cuts), { model: m });
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* A carriage's solid in its frame (its middle at the origin, on the rail's face): its block over the rail with a
|
|
122
|
+
* channel the rail runs in, and its four tapped holes drawn at the tap drill. @param {object} m railModel's @returns {object}
|
|
123
|
+
*/
|
|
124
|
+
export function carriage(m) {
|
|
125
|
+
if (m?.guide !== 'rail') throw new Error(`carriage: give a rail's model (railModel), not ${shown(m)}`);
|
|
126
|
+
const c = m.carriage, Lc = c.length, W = c.width, run = 0.2; // (the channel stands this clear of the rail, so the overlap check reads no contact)
|
|
127
|
+
const block = box([-Lc / 2, -W / 2, c.clearance], [Lc / 2, W / 2, c.height]), channel = box([-Lc / 2 - 1, -m.rail.width / 2 - run, -1], [Lc / 2 + 1, m.rail.width / 2 + run, m.rail.height + run]);
|
|
128
|
+
const taps = c.holes.map(([x, y]) => translate([x, y, c.height - c.depth / 2 + 0.25], cylinder({ radius: (c.tap ?? 2.5) / 2, height: c.depth + 0.5, segments: 24 })));
|
|
129
|
+
return Object.assign(subtract(block, channel, ...taps), { model: m });
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* A carriage's loads against its ratings: the force square to the rail's face and across it over C0, each moment over
|
|
134
|
+
* its own rating, summed (GUIDE_DEFAULTS.combine). The force along the rail is the drive's, not the carriage's.
|
|
135
|
+
* @param {object} m railModel's
|
|
136
|
+
* @param {{ force: number[], moment: number[] }} load in the carriage's frame: force [along, across, out of the face] in N; moment [roll about x, pitch about y, yaw about z] in N m
|
|
137
|
+
* @returns {{ ratios: { normal: number, roll: number, pitch: number, yaw: number }, sum: number, margin: number, level: 'pass' | 'warn' | 'fail', worst: string }}
|
|
138
|
+
*/
|
|
139
|
+
export function carriageMargin(m, load) {
|
|
140
|
+
const what = 'carriageMargin';
|
|
141
|
+
if (m?.guide !== 'rail') throw new Error(`${what}: give a rail's model (railModel), not ${shown(m)}`);
|
|
142
|
+
const ok = (v) => Array.isArray(v) && v.length === 3 && v.every(isNum);
|
|
143
|
+
if (!load || !ok(load.force) || !ok(load.moment)) throw new Error(`${what}: load is { force: [along, across, out], moment: [roll, pitch, yaw] }, in N and N m in the carriage's frame (got ${shown(load)})`);
|
|
144
|
+
const r = m.carriage.ratings, [, Fy, Fz] = load.force, [Mx, My, Mz] = load.moment;
|
|
145
|
+
const ratios = { normal: (Math.abs(Fz) + GUIDE_DEFAULTS.across.value * Math.abs(Fy)) / r.C0, roll: Math.abs(Mx) / r.MR, pitch: Math.abs(My) / r.MP, yaw: Math.abs(Mz) / r.MY };
|
|
146
|
+
const sum = ratios.normal + ratios.roll + ratios.pitch + ratios.yaw, margin = sum > 0 ? 1 / sum : Infinity, worst = Object.entries(ratios).sort((a, b) => b[1] - a[1])[0][0];
|
|
147
|
+
return { ratios: Object.fromEntries(Object.entries(ratios).map(([k, v]) => [k, r3(v * 1000) / 1000])), sum, margin, level: margin < 1 ? 'fail' : margin < 2 ? 'warn' : 'pass', worst };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Whether a rail fits a beam's face, as findings (code guide.fit): its holes over the slot's centre line and its width
|
|
152
|
+
* over the face, its screws' thread suiting a slot nut made for that slot (named, with the kinds there are), and its
|
|
153
|
+
* ends clear of what crosses the face. Fails are said by name with what would fit.
|
|
154
|
+
* @param {object} m railModel's
|
|
155
|
+
* @param {string | object} profile the beam's profile
|
|
156
|
+
* @param {{ face?: string, from?: number, beam?: number, nut?: string, keep?: { from: number, to: number, what: string }[], given?: object }} [o]
|
|
157
|
+
* from: where the rail starts along the beam, mm from end a; beam: the beam's length; keep: stretches of the face something else holds
|
|
158
|
+
* @returns {{ findings: object[], nut: object | null, face: string, slot: string | null }}
|
|
159
|
+
*/
|
|
160
|
+
export function guideFit(m, profile, o = {}) {
|
|
161
|
+
const what = 'guideFit';
|
|
162
|
+
if (m?.guide !== 'rail') throw new Error(`${what}: give a rail's model (railModel), not ${shown(m)}`);
|
|
163
|
+
options(what, o ?? {}, ['face', 'from', 'beam', 'nut', 'keep', 'given']);
|
|
164
|
+
const given = o.given ?? {}, p = profileOf(what, profile, given), face = o.face ?? 'top', [fname, idx] = String(face).split('.'), place = p.faces[fname]?.[(idx ? +idx : 1) - 1], out = [], f = (level, text, values = {}, refs = {}) => out.push(finding(level, text, 'guide.fit', { values, refs }));
|
|
165
|
+
if (!place) throw new Error(`${what}: ${p.name} has no face ${shown(face)}: a rail goes on top, bottom, front or back, with .2 for a second slot`);
|
|
166
|
+
if (o.nut != null && !NUT_KINDS.includes(o.nut)) throw new Error(`${what}: nut is a kind of slot nut, ${NUT_KINDS.join(', ')} (got ${shown(o.nut)})`);
|
|
167
|
+
const slot = place.slot ? p.slots[place.slot] : null, cell = Math.abs(place.along[0]) > 0.5 ? p.pitch[0] : p.pitch[1], W = m.rail.width;
|
|
168
|
+
if (!slot) { f('fail', `${p.name}'s ${face} face is closed: a rail's screws go into slot nuts, so it goes on a slotted face`, {}, { profile: p.name }); return { findings: out, nut: null, face, slot: null }; }
|
|
169
|
+
// its holes on the slot's centre line by construction; its width bridging the opening and within the face's cell
|
|
170
|
+
if (W <= slot.opening + 1e-9) f('fail', `${m.set}'s ${mm(W)} mm rail is no wider than ${slot.name}'s ${mm(slot.opening)} mm opening: it would sink into the slot. A rail wider than the opening bridges it`, { width: W, opening: slot.opening });
|
|
171
|
+
else if (W > cell + 1e-9) f('fail', `${m.set}'s ${mm(W)} mm rail is wider than the ${mm(cell)} mm face it sits on: it overhangs the beam`, { width: W, face: cell });
|
|
172
|
+
else f('pass', `${m.set}'s ${mm(W)} mm rail bridges ${slot.name}'s ${mm(slot.opening)} mm opening on the ${mm(cell)} mm face, its holes on the slot's centre line`, { width: W, opening: slot.opening, face: cell });
|
|
173
|
+
// its screws into slot nuts made for this slot
|
|
174
|
+
let nut = null;
|
|
175
|
+
try { nut = nutFor(p, face, m.rail.thread, { ...(o.nut ? { kind: o.nut } : {}), given }); }
|
|
176
|
+
catch (e) {
|
|
177
|
+
const there = ['M3', 'M4', 'M5', 'M6', 'M8'].filter((t) => { try { nutFor(p, face, t, { given }); return true; } catch { return false; } });
|
|
178
|
+
f('fail', `no ${m.rail.thread}${o.nut ? ` ${o.nut}` : ''} slot nut is made for ${slot.name}: ${m.set}'s holes take ${m.rail.thread}, and the nuts there take ${there.join(', ') || 'nothing in the catalogue'}. ${String(e.message).replace(/^nutFor: /, '')}`, { thread: m.rail.thread }, { slot: slot.name });
|
|
179
|
+
}
|
|
180
|
+
if (nut) f('pass', `its ${m.holes.length} ${m.rail.thread} screws go into ${nut.name} (${nut.nutKind}), one at each hole ${mm(m.rail.pitch)} mm apart`, { screws: m.holes.length, pitch: m.rail.pitch }, { nut: nut.name, slot: slot.name });
|
|
181
|
+
// its ends on the beam, and clear of what crosses the face
|
|
182
|
+
if (o.from != null) {
|
|
183
|
+
const a = o.from, b = o.from + m.length, cl = GUIDE_DEFAULTS.clear.value;
|
|
184
|
+
if (a < -1e-9 || (o.beam != null && b > o.beam + 1e-9)) f('fail', `the rail runs from ${mm(a)} to ${mm(b)} mm along a beam ${o.beam != null ? `${mm(o.beam)} mm long` : 'from its end a'}: past its end`, { from: a, to: b, beam: o.beam ?? null });
|
|
185
|
+
for (const k of o.keep ?? []) if (k.from - cl < b && k.to + cl > a) f('fail', `the rail, ${mm(a)} to ${mm(b)} mm along the beam, runs into ${k.what} at ${mm(k.from)} to ${mm(k.to)} mm (with ${mm(cl)} mm clear): move it or cut it shorter`, { from: a, to: b, at: [k.from, k.to] }, { what: k.what });
|
|
186
|
+
if (!out.some((x) => x.level === 'fail' && x.values.from != null)) f('pass', `its ends, ${mm(a)} and ${mm(b)} mm along the beam, are on it and clear of ${o.keep?.length ? (o.keep.map((k) => k.what).join(', ')) : 'anything crossing its face'}`, { from: a, to: b });
|
|
187
|
+
}
|
|
188
|
+
return { findings: out, nut, face, slot: slot.name };
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* The error a rail adds to a machine's budget along its travel, in mm: its parallelism and its carriage's play from
|
|
193
|
+
* its rule set, the beam's own straightness over the rail from the profile's, and the beam's sag under its own weight
|
|
194
|
+
* and what it carries (GUIDE_DEFAULTS.sag, an estimate). @param {object} m railModel's @param {string | object} profile
|
|
195
|
+
* @param {{ beam: number, carried?: number, given?: object }} o beam: the beam's length; carried: kg on its carriages
|
|
196
|
+
* @returns {{ term: string, value: number, kind: string, note: string }[]}
|
|
197
|
+
*/
|
|
198
|
+
export function railTerms(m, profile, o = {}) {
|
|
199
|
+
const what = 'railTerms';
|
|
200
|
+
if (m?.guide !== 'rail') throw new Error(`${what}: give a rail's model (railModel), not ${shown(m)}`);
|
|
201
|
+
options(what, o ?? {}, ['beam', 'carried', 'face', 'given']);
|
|
202
|
+
const p = profileOf(what, profile, o.given ?? {}), L = o.beam;
|
|
203
|
+
if (!(isNum(L) && L > 0)) throw new Error(`${what}: beam is the length of the beam the rail is on, in mm (got ${shown(o.beam)})`);
|
|
204
|
+
const out = [...m.terms], st = p.figures.straightness_per_metre;
|
|
205
|
+
if (isNum(st?.value)) out.push({ term: 'beam straightness', value: r3((st.value * m.length) / 1000), kind: st.kind, note: `${p.name}, ${mm(st.value)} mm a metre over the rail's ${mm(m.length)} mm` });
|
|
206
|
+
const across = ['top', 'bottom'].includes(String(o.face ?? 'top').split('.')[0]), I = (across ? p.figures.inertia_x : p.figures.inertia_y)?.value, mod = p.material?.modulus, E = isNum(mod) ? mod : mod?.value;
|
|
207
|
+
const kgm = p.figures.mass_per_metre?.value, carried = (o.carried ?? 0) + m.mass;
|
|
208
|
+
if (isNum(I) && isNum(E) && isNum(kgm)) {
|
|
209
|
+
const w = (kgm * 9.81) / 1000, P = carried * 9.81, sag = (5 * w * L ** 4) / (384 * E * I) + (P * L ** 3) / (48 * E * I);
|
|
210
|
+
out.push({ term: 'beam sag', value: r3(sag), kind: 'estimate', note: `${mm(L)} mm of ${p.name} pinned at its ends, under its own ${mm(kgm)} kg/m and ${mm(carried)} kg at its middle` });
|
|
211
|
+
}
|
|
212
|
+
return out;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// ---------- a printed jig that centres a rail on its beam ----------
|
|
216
|
+
/**
|
|
217
|
+
* A printed jig that snaps over a beam and the rail laid on it: a key into the slot of each side face holds it on the
|
|
218
|
+
* beam's centre, and a channel over the rail holds the rail there while its screws are tightened. Slide it along as
|
|
219
|
+
* each screw goes in. It prints on its side, its section the first layer, with no supports.
|
|
220
|
+
* @param {string | object} profile the beam's profile
|
|
221
|
+
* @param {{ rail: string | object, face?: string, length?: number, load?: number, printer?: object, material?: string | object, given?: object }} o
|
|
222
|
+
* @returns {object} its model
|
|
223
|
+
*/
|
|
224
|
+
export function railJigModel(profile, o = {}) {
|
|
225
|
+
const what = 'railJigModel';
|
|
226
|
+
options(what, o ?? {}, ['rail', 'face', 'length', 'load', 'printer', 'material', 'given']);
|
|
227
|
+
const given = o.given ?? {}, p = profileOf(what, profile, given), k = partSetup(what, o), { set: s, rules: R } = railSet(what, o.rail, null, given);
|
|
228
|
+
const face = o.face ?? 'top', fname = String(face).split('.')[0], sides = fname === 'top' || fname === 'bottom' ? ['front', 'back'] : ['top', 'bottom'];
|
|
229
|
+
if (!p.faces[fname]?.length) throw new Error(`${what}: ${p.name} has no face ${shown(face)}`);
|
|
230
|
+
if (p.faces[fname].length > 1) throw new Error(`${what}: ${p.name}'s ${fname} face has ${p.faces[fname].length} slots: a jig centres a rail on a face of one slot`);
|
|
231
|
+
const keys = sides.map((sd) => { const q = p.faces[sd]?.[0]; if (!q?.slot) throw new Error(`${what}: ${p.name}'s ${sd} face has no slot for the jig to key into`); return { side: sd, slot: p.slots[q.slot], at: q.at }; });
|
|
232
|
+
const F = o.load ?? GUIDE_DEFAULTS.jigLoad.value;
|
|
233
|
+
if (o.length != null && !(isNum(o.length) && o.length >= 8)) throw new Error(`${what}: length is the jig along the beam in mm, at least 8 (got ${shown(o.length)})`);
|
|
234
|
+
if (!(isNum(F) && F > 0)) throw new Error(`${what}: load is the push on the rail it holds, in N, above 0 (got ${shown(o.load)})`);
|
|
235
|
+
// the section across the beam: y across, z out of the face, the face at z = 0, the beam's middle at z = -depth/2
|
|
236
|
+
const across = fname === 'top' || fname === 'bottom' ? p.width : p.height, deep = fname === 'top' || fname === 'bottom' ? p.height : p.width;
|
|
237
|
+
const fit = k.fit, WR = R.rail_width.value, HR = R.rail_height.value, rr = GUIDE_DEFAULTS.jigRound.value, kd = GUIDE_DEFAULTS.jigKey.value;
|
|
238
|
+
const keyW = r3(Math.min(...keys.map((x) => x.slot.opening)) - 2 * fit), lipMin = Math.min(...keys.map((x) => x.slot.lip));
|
|
239
|
+
if (keyW < 2 * k.line) throw new Error(`${what}: ${p.name}'s side slots leave a key ${mm(keyW)} mm wide: too thin to print`);
|
|
240
|
+
// walls three lines; the keys as deep as snapping on allows at twice the margin (a leg l long bent by the key: 3 E t δ / (2 l²)),
|
|
241
|
+
// and the jig as long as the push on the rail allows at twice the margin (6 F l / (w t²) at the leg's root)
|
|
242
|
+
const t = r3(Math.max(Math.ceil((3 * k.line) / 0.1 - 1e-9) * 0.1, 1.2)), l = r3(deep / 2), E = k.mat.rules.modulus.value, half = k.S / 2;
|
|
243
|
+
const key = r3(Math.min(kd, lipMin, Math.floor(((2 * half * l * l) / (3 * E * t)) * 100) / 100));
|
|
244
|
+
if (key < 0.2) throw new Error(`${what}: snapping the jig over ${p.name}'s ${mm(deep)} mm leaves its keys ${mm(key)} mm deep: too little to hold it (a beam this shallow takes a jig slid on from its end)`);
|
|
245
|
+
const len = Math.max(o.length ?? GUIDE_DEFAULTS.jigLength.value, Math.ceil((6 * F * l) / (t * t * half)));
|
|
246
|
+
const yi = r3(across / 2 + fit), yo = r3(yi + t), zc = r3(-deep / 2), zb = r3(zc - keyW / 2 - t), ch = r3(HR + fit + rr), top = r3(ch + t), wc = r3(WR / 2 + fit);
|
|
247
|
+
// legs: from the bridge down past the side slots' middle; a key on each, its tip in the slot
|
|
248
|
+
const loop = [[-yo, zb], [-yi, zb], [-yi, r3(zc - keyW / 2)], [r3(-yi + key), r3(zc - keyW / 2 + key)], [r3(-yi + key), r3(zc + keyW / 2 - key)], [-yi, r3(zc + keyW / 2)], [-yi, 0], [-wc, 0], [-wc, ch], [wc, ch], [wc, 0], [yi, 0],
|
|
249
|
+
[yi, r3(zc + keyW / 2)], [r3(yi - key), r3(zc + keyW / 2 - key)], [r3(yi - key), r3(zc - keyW / 2 + key)], [yi, r3(zc - keyW / 2)], [yi, zb], [yo, zb], [yo, top], [-yo, top]];
|
|
250
|
+
const section = roundConcave(ccw(loop), rr).map(([y, z]) => [r3(y), r3(z)]);
|
|
251
|
+
// what it takes: the push on the rail bends a leg at the bridge (6 F l / (w t²)); snapping on bends it by the key (3 E t δ / (2 l²))
|
|
252
|
+
const bend = r3((6 * F * l) / (len * t * t)), snap = r3((3 * E * t * key) / (2 * l * l)), stress = Math.max(bend, snap), margin = r3(k.S / stress);
|
|
253
|
+
const m = { kind: 'fitting', fitting: 'rail-jig', name: `rail-jig-${s.name.replace(/^rail-/, '')}-${p.name.replace(/^profile-/, '')}`, title: `printed jig centring ${s.name} on ${p.name}`, profile: p.name, face, rail: s.name, length: len,
|
|
254
|
+
section, bridge: [[-yo, 0], [-wc, 0], [-wc, ch], [wc, ch], [wc, 0], [yo, 0], [yo, top], [-yo, top]], wall: t, key: { width: keyW, depth: key, slots: keys.map((x) => x.slot.name) }, channel: { width: r3(2 * wc), height: ch }, screws: [], anchors: {},
|
|
255
|
+
load: { force: F, what: `${F} N pushing the rail against it, and snapping it on over its ${mm(key)} mm keys` }, stress, margin, size: { length: len, width: r3(2 * yo), height: r3(top - zb), channel: r3(2 * wc) },
|
|
256
|
+
volume: 0, grams: 0, material: k.mat.name, printer: k.pr.name, findings: [], rests: ['jigKey', 'jigLoad', 'jigRound'].map((x) => ({ name: `GUIDE_DEFAULTS.${x}`, value: GUIDE_DEFAULTS[x].value, kind: GUIDE_DEFAULTS[x].kind })) };
|
|
257
|
+
weigh(m, railJig(m), k.density);
|
|
258
|
+
closingFindings(m, { S: k.S, sizeText: `a ${mm(2 * wc)} mm channel over the ${mm(WR)} mm rail (its fit ${mm(fit)} mm each side), keys ${mm(keyW)} mm wide and ${mm(key)} mm into ${keys.map((x) => x.slot.name).join(' and ')}, walls ${mm(t)} mm, ${mm(len)} mm along the beam`, marginText: `under ${m.load.what}, its legs bend to ${mm(stress)} MPa`, pose: 'on its side, its section the first layer' });
|
|
259
|
+
m.findings.push(finding('info', `it centres the rail to within ${mm(2 * fit)} mm (the printer's fit each side, twice): slide it along to each screw as it is tightened`, 'guide.jig', { values: { within: r3(2 * fit) } }));
|
|
260
|
+
return m;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** A rail jig's solid: on its side to print, or fitted. @param {object} m railJigModel's @param {{ pose?: 'print' | 'fit', tongues?: boolean, ops?: object }} [o] @returns {object} */
|
|
264
|
+
export function railJig(m, o = {}) {
|
|
265
|
+
if (m?.fitting !== 'rail-jig') throw new Error(`railJig: give a rail jig's model (railJigModel), not ${shown(m)}`);
|
|
266
|
+
// (tongues: false leaves out the legs and keys beside the beam, for an overlap check against the beam's envelope)
|
|
267
|
+
const g = prism(o.tongues === false ? m.bridge : m.section, m.length);
|
|
268
|
+
return Object.assign(o.pose === 'fit' ? transform(sideToFit(m.length), g) : g, { model: m });
|
|
269
|
+
}
|
package/jig.d.mts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A drill guide for a hole across a beam (an access hole, a drilled hole or a counterbore's hole), as its model. It
|
|
3
|
+
* stops on the end nearer the hole (or the one asked), keys into the drilled face's slot, and holds a bush for the
|
|
4
|
+
* drill at the sheet's dimension, on the slot's centre line. Its plate is as thick as the bush is long (JIG_DEFAULTS.bush
|
|
5
|
+
* times the drill), its stop as thick as keeps it from bending more than JIG_DEFAULTS.within under the load. It prints
|
|
6
|
+
* on its outer face, the stop and the tongue standing up. Refused by name: not a hole across, a closed face, a hole
|
|
7
|
+
* too far from both ends for one print.
|
|
8
|
+
* @param {object} b the beam's model (beamModel)
|
|
9
|
+
* @param {number | object} op the hole's index in b.ops (the sheet's number less one), or the op itself
|
|
10
|
+
* @param {{ from?: 'a' | 'b', load?: number, printer?: object, material?: string | object }} [o] from: the end the stop is on (the nearer where not given)
|
|
11
|
+
* @returns {object} its model: name, title, profile, beam, op, from, distance, bush, plate, stop, tongue, size, fit (the 4x4 turn from the print frame to the beam's), findings
|
|
12
|
+
*/
|
|
13
|
+
export function drillGuideModel(b: object, op: number | object, o?: {
|
|
14
|
+
from?: "a" | "b";
|
|
15
|
+
load?: number;
|
|
16
|
+
printer?: object;
|
|
17
|
+
material?: string | object;
|
|
18
|
+
}): object;
|
|
19
|
+
/**
|
|
20
|
+
* A drill guide's solid: in its print pose, or fitted on the beam (in the beam's frame). A mark is cut into its contact
|
|
21
|
+
* face beside the tongue where one is given (a geom2 in the label's frame: x along, y across, about its middle).
|
|
22
|
+
* @param {object} m drillGuideModel's @param {{ pose?: 'print' | 'fit', mark?: object, ops?: object }} [o] @returns {object} a JSCAD geom3
|
|
23
|
+
*/
|
|
24
|
+
export function drillGuide(m: object, o?: {
|
|
25
|
+
pose?: "print" | "fit";
|
|
26
|
+
mark?: object;
|
|
27
|
+
ops?: object;
|
|
28
|
+
}): object;
|
|
29
|
+
/**
|
|
30
|
+
* A tap guide for a tapped end, as its model: a cap over the end, a sleeve round the section that centres it, and a
|
|
31
|
+
* bore over each bore the op taps, as long as JIG_DEFAULTS.bush times the thread, so the tap starts square to the end.
|
|
32
|
+
* It prints on its outer face, the sleeve standing up, the bores upright.
|
|
33
|
+
* @param {object} b the beam's model @param {number | object} op the tap's index in b.ops, or the op
|
|
34
|
+
* @param {{ shank?: number, load?: number, printer?: object, material?: string | object }} [o] shank: the tap's shank in mm, where it is wider than its thread
|
|
35
|
+
* @returns {object} its model: name, title, profile, beam, op, end, thread, bores (print X, Y), plate, sleeve, size, fit, findings
|
|
36
|
+
*/
|
|
37
|
+
export function tapGuideModel(b: object, op: number | object, o?: {
|
|
38
|
+
shank?: number;
|
|
39
|
+
load?: number;
|
|
40
|
+
printer?: object;
|
|
41
|
+
material?: string | object;
|
|
42
|
+
}): object;
|
|
43
|
+
/** A tap guide's solid: in its print pose, or fitted on the beam's end. @param {object} m tapGuideModel's @param {{ pose?: 'print' | 'fit', mark?: object, ops?: object }} [o] @returns {object} */
|
|
44
|
+
export function tapGuide(m: object, o?: {
|
|
45
|
+
pose?: "print" | "fit";
|
|
46
|
+
mark?: object;
|
|
47
|
+
ops?: object;
|
|
48
|
+
}): object;
|
|
49
|
+
/**
|
|
50
|
+
* A cut-length stop for one length of a profile, as its model: a block that a spring clamp holds against a saw's fence
|
|
51
|
+
* (or a mitre box's back), its face square to the fence, and a printed gauge as long as the cut, in pieces no longer
|
|
52
|
+
* than the bed takes, that sets the block from the blade's near side. Every edge on the table is chamfered by the
|
|
53
|
+
* printer's chamfer so the first layer's spread does not lengthen the gauge or hold the beam off the stop.
|
|
54
|
+
* @param {string | object} profile @param {number} length the cut, mm (a mitred beam's long side)
|
|
55
|
+
* @param {{ load?: number, printer?: object, material?: string | object, given?: object }} [o]
|
|
56
|
+
* @returns {object} its model: name, title, profile, length, block, gauge { pieces, length, section }, within, size, findings
|
|
57
|
+
*/
|
|
58
|
+
export function lengthStopModel(profile: string | object, length: number, o?: {
|
|
59
|
+
load?: number;
|
|
60
|
+
printer?: object;
|
|
61
|
+
material?: string | object;
|
|
62
|
+
given?: object;
|
|
63
|
+
}): object;
|
|
64
|
+
/** A length stop's block, or one piece of its gauge, in its print pose. @param {object} m lengthStopModel's @param {{ part?: 'block' | 'gauge', mark?: object, ops?: object }} [o] @returns {object} */
|
|
65
|
+
export function lengthStop(m: object, o?: {
|
|
66
|
+
part?: "block" | "gauge";
|
|
67
|
+
mark?: object;
|
|
68
|
+
ops?: object;
|
|
69
|
+
}): object;
|
|
70
|
+
/**
|
|
71
|
+
* A squaring corner for two beams that meet square, as its model: an L that lies on a face of each in one plane, a
|
|
72
|
+
* tongue along each arm in that face's slot, so it holds a's end square to b while the join is tightened. Its arms
|
|
73
|
+
* run JIG_DEFAULTS.arm times the face's width past the corner. It prints on its outer face, the tongues on top.
|
|
74
|
+
* An L has a hand: arm a runs along a away from b, and arm b runs along b one way only. Right-handed, arm b runs
|
|
75
|
+
* along n x u, where n is a's face's outward normal and u runs along a away from b (+X of the print frame);
|
|
76
|
+
* left-handed, the other way (-X), the mirror image. Choose the hand whose arm b lies on b, not past its end.
|
|
77
|
+
* @param {{ profile: string | object, face?: string, end?: 'a' | 'b', length?: number }} a the beam whose end meets b, its face in the plane, the end that meets b (a where not given), and its length (for the fitted pose on end b)
|
|
78
|
+
* @param {{ profile: string | object, face?: string, edge?: 'lo' | 'hi' }} b the beam a meets, its face in the plane, and which edge of that face (along the place's across direction) a stands on
|
|
79
|
+
* @param {{ hand?: 'right' | 'left', load?: number, printer?: object, material?: string | object, given?: object }} [o] hand: which way arm b runs (right where not given)
|
|
80
|
+
* @returns {object} its model: name, title, profiles, hand, outline, arms, tongues, square, size, fit (the 4x4 turn from the print frame to a's, or null on end b with no length), findings
|
|
81
|
+
*/
|
|
82
|
+
export function squareCornerModel(a: {
|
|
83
|
+
profile: string | object;
|
|
84
|
+
face?: string;
|
|
85
|
+
end?: "a" | "b";
|
|
86
|
+
length?: number;
|
|
87
|
+
}, b: {
|
|
88
|
+
profile: string | object;
|
|
89
|
+
face?: string;
|
|
90
|
+
edge?: "lo" | "hi";
|
|
91
|
+
}, o?: {
|
|
92
|
+
hand?: "right" | "left";
|
|
93
|
+
load?: number;
|
|
94
|
+
printer?: object;
|
|
95
|
+
material?: string | object;
|
|
96
|
+
given?: object;
|
|
97
|
+
}): object;
|
|
98
|
+
/** A squaring corner's solid: in its print pose, or fitted on beam a (in a's frame). @param {object} m squareCornerModel's @param {{ pose?: 'print' | 'fit', mark?: object, ops?: object }} [o] @returns {object} */
|
|
99
|
+
export function squareCorner(m: object, o?: {
|
|
100
|
+
pose?: "print" | "fit";
|
|
101
|
+
mark?: object;
|
|
102
|
+
ops?: object;
|
|
103
|
+
}): object;
|
|
104
|
+
/** The kinds of jig, each with what it is for. */
|
|
105
|
+
export const JIG_KINDS: {
|
|
106
|
+
'drill-guide': {
|
|
107
|
+
what: string;
|
|
108
|
+
ops: string[];
|
|
109
|
+
};
|
|
110
|
+
'tap-guide': {
|
|
111
|
+
what: string;
|
|
112
|
+
ops: string[];
|
|
113
|
+
};
|
|
114
|
+
'length-stop': {
|
|
115
|
+
what: string;
|
|
116
|
+
ops: string[];
|
|
117
|
+
};
|
|
118
|
+
'square-corner': {
|
|
119
|
+
what: string;
|
|
120
|
+
ops: any[];
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
export namespace JIG_DEFAULTS {
|
|
124
|
+
namespace load {
|
|
125
|
+
export { text as rule };
|
|
126
|
+
export { kind };
|
|
127
|
+
export { source };
|
|
128
|
+
export { CHECKED as checked };
|
|
129
|
+
export { unit };
|
|
130
|
+
export { value };
|
|
131
|
+
}
|
|
132
|
+
namespace bush { }
|
|
133
|
+
namespace stop { }
|
|
134
|
+
namespace within { }
|
|
135
|
+
namespace shank { }
|
|
136
|
+
namespace sleeve { }
|
|
137
|
+
namespace arm { }
|
|
138
|
+
namespace plate { }
|
|
139
|
+
namespace square { }
|
|
140
|
+
namespace block { }
|
|
141
|
+
namespace gauge { }
|
|
142
|
+
namespace gaugeError { }
|
|
143
|
+
namespace edge { }
|
|
144
|
+
}
|
|
145
|
+
declare const CHECKED: "2026-11-17";
|
|
146
|
+
export {};
|