omdl  v0.9.5
OpenSCAD Mechanical Design Library
bearing_linear_rod.scad
Go to the documentation of this file.
1 //! Linear rod ball and sled bearing.
2 /***************************************************************************//**
3  \file
4  \author Roy Allen Sutton
5  \date 2023-2024
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 (Linear rod bearing)
31  \amu_define group_brief (Linear rod ball and sled bearing.)
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  tools/operation_cs.scad
45  )
46  \amu_include (include/amu/includes_required.amu)
47 *******************************************************************************/
48 
49 //----------------------------------------------------------------------------//
50 
51 //! Transform 2d or 3d shape into a linear rod ball or sled bearing.
52 /***************************************************************************//**
53  \param pipe <decimal-list-2> pipe or rod diameter [outer, inner].
54 
55  \param ball <decimal> ball bearing diameter.
56 
57  \param count <integer> ball bearing tunnel count.
58 
59  \param angle <decimal> ball bearing tunnel angle.
60 
61  \param h <data-list-3> bearing block height.
62 
63  \param tunnel <decimal-list-2> ball bearing tunnel size.
64 
65  \param feed <decimal-list-4> ball bearing feed specification.
66 
67  \param load <integer> ball bearing feed load position
68  (0=none, 1=inner, 2=outer, 3=top, 4=bottom).
69 
70  \param offset <integer> pipe-to-bearing alignment offset mode
71  (0=ball-tunnel, 1=ball, 2=ball-tunnel + 50% of gap).
72 
73  \param delta <decimal> pipe-to-bearing alignment absolute adjustment.
74 
75  \param gap <decimal> ball bearing gap percentage.
76 
77  \param reveal <decimal> ball bearing reveal percentage.
78 
79  \param dilate <decimal> ball bearing circulation tunnel-return
80  enlargement percentage.
81 
82  \param type <integer> bearing type (0=ball, 1=slide).
83 
84  \param align <integer> bearing block zero alignment location.
85  (0=+block_h/2, 1=+tunnel_h/2, 2=center, 3=-tunnel_h/2, 4=-block_h/2)
86 
87  \param verb <integer> verbosity (0=quiet).
88 
89  \param view <integer-list-3> bearing block internal view
90  (0=block, 1=pipe-tunnel, 2=ball-tunnel). Use, for example,
91  [1, 2] to view multiple.
92  \details
93 
94  This module transforms a child object into a linear bearing. By
95  default, a 2d profile is extruded into a linear bearing, but the
96  parameter \p h can be configured to operated on a 3d child object.
97 
98  The parameters \p pipe, \p ball, \p count, \p angle, and \p h are
99  required but the remaining are optional. Default values are used
100  for all unspecified parameters. Default values are also used for
101  unspecified elements positions for parameter that accepts a list of
102  values. For example, the following table are all valid
103  specifications for \p h:
104 
105  parameter h | value description
106  :-----------------------|:--------------------------------------------------------
107  10.5 | bearing block height, defaults for remaining
108  [10.5] | same as above
109  [10.5, 5] | block height and end cap thickness
110  [10.5, undef, false] | block height and extrusion options only
111  [10.5, 5, false] | block height, end cap thickness and extrusion
112 
113  A single scalar value can be used to specify the first value of a
114  multi-value parameter as shown in the above table.
115 
116  Multi-value parameters
117  ----------------------
118 
119  \b h
120 
121  e | data type | default value | parameter description
122  ---:|:-----------------:|:-----------------:|:------------------------------------
123  0 | decimal | required | total bearing height
124  1 | decimal | ball/4 | bearing end-cap height
125  2 | boolean | \b true | extrude child object
126 
127  \b tunnel
128 
129  e | data type | default value | parameter description
130  ---:|:-----------------:|:-----------------:|:------------------------------------
131  0 | decimal | ball/4 | perpendicular tunnel dimension
132  1 | decimal | ball | tunnel corner turn radius
133 
134  \b feed
135 
136  e | data type | default value | parameter description
137  ---:|:-----------------:|:-----------------:|:------------------------------------
138  0 | decimal | 1 | ball bearing feeder size factor
139  1 | decimal | 0 | tunnel position factor [0:1]
140  2 | decimal | 0 | rotation angle
141  3 | decimal | tunnel-diameter | ball bearing feeder length
142 
143  When the first value position of \p feed is assigned 0, the feed
144  option is disabled. The bearing feed can also be disabled by
145  assigning \p load = 0.
146 
147  \amu_define title (Bearing example)
148  \amu_define image_views (top right diag)
149  \amu_define image_size (sxga)
150 
151  \amu_define notes_diagrams
152  ( This example uses the \p view options to see the bearing internals.
153  Click image above to expand. )
154 
155  \amu_include (include/amu/scope_diagrams_3d.amu)
156 *******************************************************************************/
158 (
159  pipe,
160  ball,
161  count,
162  angle,
163  h,
164  tunnel,
165  feed,
166  load = 1,
167  offset = 1,
168  delta = 0,
169  gap = 10,
170  reveal = 50,
171  dilate = 15,
172  type = 0,
173  align = 2,
174  verb = 0,
175  view
176 )
177 {
178  // diameters
179  pipe_od = defined_e_or(pipe, 0, pipe);
180  pipe_id = defined_e_or(pipe, 1, 0);
181 
182  ball_d = ball;
183 
184  // ball tunnel: count, folding-angle
185  ball_tunnel_c = count;
186  ball_tunnel_a = angle;
187 
188  // bearing block: height, end-cap height, and extrusion
189  bearing_block_h = defined_e_or(h, 0, h);
190  bearing_end_cap_h = defined_e_or(h, 1, ball_d/4);
191  extrude_profile = defined_e_or(h, 2, true);
192 
193  // ball tunnel: width, end-radius
194  ball_tunnel_w = defined_e_or(tunnel, 0, ball_d / 4);
195  ball_tunnel_r = defined_e_or(tunnel, 1, ball_d * 1);
196 
197  // ball tunnel diameter (gap adjustment: add for ball, subtract for slide)
198  ball_tunnel_d = ball_d + (ball_d * gap/100) * ((type == 0) ? +1 : -1);
199 
200  // ball tunnel: length, height
201  ball_tunnel_l = bearing_block_h - (ball_tunnel_r*2 + ball_tunnel_d + bearing_end_cap_h*2);
202  ball_tunnel_h = bearing_block_h - bearing_end_cap_h*2;
203 
204  // ball bearing feed: ratio, position[0:1], angle, length
205  bearing_feed_r = is_defined(feed) ? defined_e_or(feed, 0, feed) : 1;
206  bearing_feed_p = defined_e_or(feed, 1, 0);
207  bearing_feed_a = defined_e_or(feed, 2, 0);
208  bearing_feed_l = defined_e_or(feed, 3, ball_tunnel_d);
209 
210  // ball bearing feed alignment: translate, rotate, translate
211  // 0: at pipe
212  // 1: outer return
213  // 2: top
214  // 3: bottom
215  ball_feed_alignment =
216  [
217  [ [-(ball_tunnel_r + ball_tunnel_w/2), -(bearing_feed_p * ball_tunnel_l - ball_tunnel_l/2), 0],
218  [0, 90 - ball_tunnel_a + bearing_feed_a, 0],
219  [0, 0, -(bearing_feed_l/2 + ball_tunnel_d/4)] ],
220  [ [+(ball_tunnel_r + ball_tunnel_w/2), +(bearing_feed_p * ball_tunnel_l - ball_tunnel_l/2), 0],
221  [0, 90 - ball_tunnel_a + bearing_feed_a, 0],
222  [0, 0, +(bearing_feed_l/2 + ball_tunnel_d/4)] ],
223  [ [+(bearing_feed_p * ball_tunnel_w - ball_tunnel_w/2), +(ball_tunnel_h/2 - ball_tunnel_d/2), 0],
224  [90 + bearing_feed_a, 0, 0],
225  [0, 0, -(bearing_feed_l/2 + ball_tunnel_d/4)] ],
226  [ [-(bearing_feed_p * ball_tunnel_w - ball_tunnel_w/2), -(ball_tunnel_h/2 - ball_tunnel_d/2), 0],
227  [90 + bearing_feed_a, 0, 0],
228  [0, 0, +(bearing_feed_l/2 + ball_tunnel_d/4)] ]
229  ];
230 
231  // pipe to ball offset (alignment & pipe tunnel diameter)
232  // 0: pipe to ball-tunnel
233  // 1: pipe to ball
234  // 2: pipe to ball minus 50% of gap (pipe to ball-tunnel + 50% of gap)
235 
236  // ball to pipe alignment: ball tunnel radial translate
237  ball_pipe_alignment = pipe_od/2 + delta +
238  [
239  ball_tunnel_d/2,
240  ball_d/2,
241  ball_d/2 - (ball_d * gap/100)/2
242  ][offset];
243 
244  // pipe tunnel diameter to expose ball bearing reveal
245  pipe_tunnel_d = pipe_od +
246  [
247  ball_d/2 * (reveal/100),
248  ball_d/2 * (reveal/100) - ball_d * gap/(100*2),
249  ball_d/2 * (reveal/100) - ball_d * gap/(100*4)
250  ][offset];
251 
252  // ball tunnel alignment
253  module align_ball_tunnel()
254  {
255  repeat_radial(n=ball_tunnel_c, r=pipe_od/2)
256  translate([ball_pipe_alignment, 0, 0])
257  rotate([0, 0, ball_tunnel_a])
258  translate([ball_tunnel_w/2 + ball_tunnel_r, 0, 0])
259  rotate([90, 0, 0])
260  children();
261  }
262 
263  // build ball bearing tunnel
264  module build_tunnel_path(r, l, s=1, m=255)
265  {
266  lx = l[0];
267  ly = l[1];
268 
269  // return path scale factor
270  sr = 1 + s/100;
271 
272  // corner rotation
273  for
274  (
275  i = [
276  [+lx/2, +ly/2, 0, 1, [sr, sr]],
277  [-lx/2, +ly/2, 90, 3, [sr, 1]],
278  [-lx/2, -ly/2, 180, 5, [ 1, sr]],
279  [+lx/2, -ly/2, 270, 7, [sr, sr]]
280  ]
281  )
282  if ( binary_bit_is(m, i[3], 1) )
283  {
284  translate([i[0], i[1], 0])
285  rotate([0, 0, i[2]])
286  extrude_rotate_trs(r=r, ra=90, s=i[4])
287  children();
288  }
289 
290  // linear extrusion
291  for
292  (
293  i = [
294  [ +r +lx/2, +ly/2, 0, ly, 0, sr],
295  [ -lx/2, +r +ly/2, 90, lx, 2, sr],
296  [ -r -lx/2, -ly/2, 180, ly, 4, 1],
297  [ lx/2, -r -ly/2, 270, lx, 6, sr]
298  ]
299  )
300  if ( binary_bit_is(m, i[4], 1) )
301  {
302  translate([i[0], i[1], 0])
303  rotate([90, 0, i[2]])
304  translate([0, 0, -eps])
305  linear_extrude(height=i[3] + eps*2)
306  scale(i[5])
307  rotate([0, 0, 0])
308  children();
309  }
310  }
311 
312  // bearing block zero alignment
313  translate
314  ( select_ci
315  ( [ [0, 0, +bearing_block_h/2],
316  [0, 0, +ball_tunnel_h/2],
317  [0, 0, 0],
318  [0, 0, -ball_tunnel_h/2],
319  [0, 0, -bearing_block_h/2]
320  ], align, false
321  )
322  )
323  union_cs()
324  {
325  // construct bearing
326  difference_cs( c=true, s=view )
327  {
328  // bearing block
329  extrude_linear_mss(bearing_block_h, center=true, c=extrude_profile)
330  children();
331 
332  // pipe tunnel
333  extrude_linear_mss(bearing_block_h + eps*2, center=true)
334  circle(d=pipe_tunnel_d);
335 
336  // ball tunnels
337  if ( type == 0 )
338  align_ball_tunnel()
339  union_cs()
340  { // tunnel
341  build_tunnel_path(r=ball_tunnel_r, l=[ball_tunnel_w, ball_tunnel_l], s=dilate)
342  circle(d=ball_tunnel_d);
343 
344  // feed
345  if ( is_between(load, 1, len(ball_feed_alignment)) )
346  translate( ball_feed_alignment[load-1][0] )
347  rotate( ball_feed_alignment[load-1][1] )
348  translate( ball_feed_alignment[load-1][2] )
349  extrude_linear_mss(bearing_feed_l + ball_tunnel_d/2, center=true)
350  circle(d=bearing_feed_r * ball_d);
351 
352  // report ball bearing count
353  if ( verb > 0 )
354  {
355  ball_path = 2 * pi * ball_tunnel_r + (ball_tunnel_w+ball_tunnel_l)*2;
356  echo(ball_path=ball_path, ball_count=ball_path/ball_d);
357  }
358  }
359  }
360 
361  // add solid slide bearing
362  if ( type == 1 )
363  align_ball_tunnel()
364  build_tunnel_path(r=ball_tunnel_r, l=[ball_tunnel_w, ball_tunnel_l], m=(8+16+32))
365  circle(d=ball_tunnel_d + eps);
366 
367  // internal view assist
368  if ( is_defined(view) )
369  {
370  // bearing block
371  %extrude_linear_mss(bearing_block_h, center=true, c=extrude_profile)
372  children();
373 
374  // pipe
375  %color("black")
376  extrude_linear_mss(bearing_block_h + eps*2, center=true)
377  difference_cs(pipe_id>0){circle(d=pipe_od); circle(d=pipe_id);}
378  }
379  }
380 }
381 
382 //! @}
383 //! @}
384 
385 //----------------------------------------------------------------------------//
386 // openscad-amu auxiliary scripts
387 //----------------------------------------------------------------------------//
388 
389 /*
390 BEGIN_SCOPE example;
391  BEGIN_OPENSCAD;
392  include <omdl-base.scad>;
393  include <tools/operation_cs.scad>;
394  include <parts/3d/bearing/bearing_linear_rod.scad>;
395 
396  emt = [length(0.706, "in"), length(0.622, "in")];
397  ball = length(6, "mm");
398 
399  r = 21.5; h = ball*8; c = 6; a = 85;
400 
401  make_bearing_linear_rod
402  (
403  pipe = emt,
404  ball = ball,
405  count = c,
406  angle = a,
407  h = [h, undef, false],
408  view = 2,
409  $fn = 36
410  )
411  minkowski()
412  {
413  linear_extrude(h-ball, center=true)
414  rotate(a) ngon(n=c, r=r);
415  sphere(r=ball/2);
416  }
417 
418  // end_include
419  END_OPENSCAD;
420 
421  BEGIN_MFSCRIPT;
422  include --path "${INCLUDE_PATH}" {var_init,var_gen_png2eps}.mfs;
423  table_unset_all sizes;
424 
425  images name "sizes" types "sxga";
426  views name "views" views "top right diag";
427 
428  variables set_opts_combine "sizes views";
429  variables add_opts "--viewall --autocenter --view=axes";
430 
431  include --path "${INCLUDE_PATH}" scr_make_mf.mfs;
432  END_MFSCRIPT;
433 END_SCOPE;
434 */
435 
436 //----------------------------------------------------------------------------//
437 // end of file
438 //----------------------------------------------------------------------------//
pi
<decimal> The ratio of a circle's circumference to its diameter.
Definition: constants.scad:198
eps
<decimal> Epsilon, small distance to deal with overlapping shapes.
Definition: constants.scad:195
function binary_bit_is(v, b, t=1)
Test if a binary bit position of an integer value equals a test bit.
function defined_e_or(v, i, d)
Return an element of an iterable when it exists or a default value otherwise.
function count(mv, v, s=true, i)
Count all occurrences of a match value in an iterable value.
function select_ci(v, i, l=true)
Select specified element from list or return a default.
function is_between(v, l, u)
Test if a numerical value is between an upper and lower bounds.
function is_defined(v)
Test if a value is defined.
module make_bearing_linear_rod(pipe, ball, count, angle, h, tunnel, feed, load=1, offset=1, delta=0, gap=10, reveal=50, dilate=15, type=0, align=2, verb=0, view)
Transform 2d or 3d shape into a linear rod ball or sled bearing.
module extrude_rotate_trs(r, pa=0, ra=360, s, m=0)
Translate, rotate, scale, and revolve a 2d shape about the z-axis.
Definition: extrude.scad:494
module extrude_linear_mss(h, center=false, c=true)
Linearly extrude a 2d shape with multi-segment uniformly-spaced profile scaling.
Definition: extrude.scad:748
module difference_cs(c=true, s)
Conditionally apply the difference boolean operation.
module union_cs(c=true, s)
Conditionally apply the union boolean operation.
module repeat_radial(n, r=1, o=0, angle=true, move=false)
Distribute copies of a 2d or 3d shape equally about a z-axis radius.
Definition: repeat.scad:459
function angle(a, from=angle_unit_default, to=angle_unit_base)
Convert an angle from some units to another.