omdl  v0.9.6
OpenSCAD Mechanical Design Library
mounts.scad
Go to the documentation of this file.
1 //! Screw mounts tabs, mount slots, mount posts, etc.
2 /***************************************************************************//**
3  \file
4  \author Roy Allen Sutton
5  \date 2025
6 
7  \copyright
8 
9  This file is part of [omdl] (https://github.com/royasutton/omdl),
10  an OpenSCAD mechanical design library.
11 
12  The \em omdl is free software; you can redistribute it and/or modify
13  it under the terms of the [GNU Lesser General Public License]
14  (http://www.gnu.org/licenses/lgpl.html) as published by the Free
15  Software Foundation; either version 2.1 of the License, or (at
16  your option) any later version.
17 
18  The \em omdl is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  Lesser General Public License for more details.
22 
23  You should have received a copy of the GNU Lesser General Public
24  License along with the \em omdl; if not, write to the Free Software
25  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26  02110-1301, USA; or see <http://www.gnu.org/licenses/>.
27 
28  \details
29 
30  \amu_define group_name (Mounts)
31  \amu_define group_brief (Screw mounts tabs, mount slots, mount posts, etc.)
32 
33  \amu_include (include/amu/pgid_path_pstem_pg.amu)
34 *******************************************************************************/
35 
36 //----------------------------------------------------------------------------//
37 // group and macros.
38 //----------------------------------------------------------------------------//
39 
40 /***************************************************************************//**
41  \amu_include (include/amu/group_in_parent_start.amu)
42  \amu_define includes_required_add
43  (
44  models/3d/fastener/screws.scad
45  )
46  \amu_include (include/amu/includes_required.amu)
47 *******************************************************************************/
48 
49 //----------------------------------------------------------------------------//
50 
51 //! A mount tab with screw hole and support brace.
52 /***************************************************************************//**
53  \param wth <decimal> wall thickness.
54 
55  \param screw <datastruct | decimal> screw bore; structured data or
56  a single decimal to set the bore diameter.
57 
58  \param brace <decimal-list-2 | decimal> brace percentage; a list
59  [by, bz] or a single decimal to set (by=bz).
60 
61  \param size <decimal-list-2 | decimal> tab size; a list [sx, sy].
62 
63  \param vr <decimal-list-4 | decimal> rounding radius; a list
64  [v1r, v2r, v3r, v4r] or a single decimal for
65  (v1r=v2r=v3r=v4r).
66 
67  \param vrm <integer> rounding mode {0|1|2|3|4}.
68 
69  \details
70 
71  Construct a mount tab with a screw hole. The parameters \p wth and
72  \p screw are required (the others are optional). When \p brace is
73  specified, braces are constructed to support and reinforce the
74  connection to the adjacent structure. The brace-to-tab and
75  brace-to-wall lengths can be specified independently. When the \p
76  size if not supplied, a default size will be used based on the
77  specified mount tab features.
78 
79  ## Multi-value and structured parameters
80 
81  ### screw
82 
83  #### Data structure fields: screw
84 
85  e | data type | default value | parameter description
86  ---:|:-----------------:|:-----------------:|:------------------------------------
87  0 | <decimal> | required | \p d : bore diameter
88  1 | (see below) | \b undef | \p h : screw head
89  2 | (see below) | \b undef | \p t : tolerance
90 
91  See screw_bore() for documentation of the data types for the screw
92  bore parameters \p h and \p t.
93 
94  \amu_define scope_id (example_mount_tab)
95  \amu_define title (Screw mount tab example)
96  \amu_define image_views (top right diag)
97  \amu_define image_size (sxga)
98 
99  \amu_include (include/amu/scope_diagrams_3d.amu)
100 *******************************************************************************/
101 module screw_mount_tab
102 (
103  wth,
104  screw,
105  brace,
106  size,
107  vr,
108  vrm
109 )
110 {
111  // screw: diameter, head, and tolerance
112  d = defined_e_or(screw, 0, screw);
113  h = defined_e_or(screw, 1, undef);
114  t = defined_e_or(screw, 2, undef);
115 
116  // default size: x and y (adjusted for tolerance and brace thickness)
117  dx = d*3 + defined_e_or(t, 0, 0) + (is_undef(brace) ? 0 : wth*2);
118  dy = d*3 + defined_e_or(t, 1, 0);
119 
120  x = defined_e_or(size, 0, dx);
121  y = defined_e_or(size, 1, dy);
122 
123  // rounding defaults
124  r = defined_or(vr, d/2);
125 
126  rm = vrm == 1 ? [[5,5,0,0], [10,0,9]]
127  : vrm == 2 ? [[5,5,10,9], [10,0,9]]
128  : vrm == 3 ? [[1,1,0,0], [4,0,3]]
129  : vrm == 4 ? [[1,1,4,3], [4,0,3]]
130  : [0, 0];
131 
132  translate([0, y/2, wth/2])
133  union()
134  {
135  // mount tab
136  difference()
137  {
138  extrude_linear_uss(wth, center=true)
139  pg_rectangle([x, y], vr=r, vrm=first(rm), center=true);
140 
141  screw_bore(d=d, l=wth+eps*8, h=h, t=t, a=0);
142  }
143 
144  // mount tab reinforcement triangular brace
145  if ( is_defined(brace) )
146  {
147  by = defined_e_or(brace, 0, brace);
148  bz = defined_e_or(brace, 1, by);
149 
150  sy = y * by /100;
151  sz = y * bz /100;
152 
153  for ( i=[-1, 1] )
154  rotate([0, 90, 0])
155  translate([-wth/2 -sz - eps*2, -y/2, (x/2 - wth/2)*i])
156  extrude_linear_uss(wth, center=true)
157  pg_triangle_sas([sy, 90, sz], vr=r, vrm=second(rm));
158  }
159  }
160 }
161 
162 //! @}
163 //! @}
164 
165 
166 //----------------------------------------------------------------------------//
167 // openscad-amu auxiliary scripts
168 //----------------------------------------------------------------------------//
169 
170 /*
171 BEGIN_SCOPE example_mount_tab;
172  BEGIN_OPENSCAD;
173  include <omdl-base.scad>;
174  include <models/3d/fastener/screws.scad>;
175  include <parts/3d/enclosure/mounts.scad>;
176 
177  $fn = 36;
178 
179  d = 4;
180  h = [7, 1, 1/2];
181  t = [0, 10];
182 
183  mirror([0,1,0])
184  screw_mount_tab(wth=3, screw=[d, h, t], brace=[50, 25], vrm=4);
185 
186  // end_include
187  END_OPENSCAD;
188 
189  BEGIN_MFSCRIPT;
190  include --path "${INCLUDE_PATH}" {var_init,var_gen_png2eps}.mfs;
191  table_unset_all sizes;
192 
193  images name "sizes" types "sxga";
194  views name "views" views "top right diag";
195 
196  variables set_opts_combine "sizes views";
197  variables add_opts "--viewall --autocenter --view=axes";
198 
199  include --path "${INCLUDE_PATH}" scr_make_mf.mfs;
200  END_MFSCRIPT;
201 END_SCOPE;
202 */
203 
204 //----------------------------------------------------------------------------//
205 // end of file
206 //----------------------------------------------------------------------------//
207 
eps
<decimal> Epsilon, small distance to deal with overlapping shapes.
Definition: constants.scad:195
function defined_e_or(v, i, d)
Return an element of an iterable when it exists or a default value otherwise.
function second(v)
Return the second element of an iterable value.
function first(v)
Return the first element of an iterable value.
function defined_or(v, d)
Return given value, if defined, or a secondary value, if primary is not defined.
function is_defined(v)
Test if a value is defined.
module screw_bore(d=1, l=1, h, n, t, s, f=1, a=0)
Flat and beveled-head screw bore with nut, nut slot, and bore tolerance.
Definition: screws.scad:359
module screw_mount_tab(wth, screw, brace, size, vr, vrm)
A mount tab with screw hole and support brace.
Definition: mounts.scad:362
module pg_triangle_sas(v, a=x_axis_ci, o, vr, vrm=1, vfn, cm=0)
A polygon triangle specified by size-angle-size with vertex rounding.
Definition: polygon.scad:1104
module pg_rectangle(size=1, o, vr, vrm=1, vfn, center=false)
A polygon rectangle with vertex rounding.
Definition: polygon.scad:765
module extrude_linear_uss(h, center=false, c=true, ha=0)
Linearly extrude a 2d shape with uniformly-spaced profile scaling.
Definition: extrude.scad:666