chiark / gitweb /
digispark-with-cable: wip progress some todos
[reprap-play.git] / topeak-mtx-tortec-expeditionrack-adapter.scad
1 // -*- C -*-
2
3 // brk_*: "bracket", the Topeak MTX bracket
4 // rack_*: the Tortec rack
5 // adapt_*: the adapter, ie this file
6
7 include <utils.scad>
8
9 // strength factor, set to 1 for real prints
10 //$strf = 0.33;
11 $strf = 1;
12
13 brk_recess_actual = 5.20;
14
15 rack_rail_dia = 10.40 + 0.30;
16 rack_width_inner = 115.86 - 1.0; // between insides of rails
17
18 rear_elevation_nominal = 10.04;
19 // ^ top of rack to bottom of bracket, at rack cross rail (fam)
20 rear_to_front_distance = 230; // rack cross rail (fam) to very front end
21 rear_to_cross_rail = 43.05; // bolt centre to rail centre, rail to rear
22 rear_bolt_to_front_bolt = 155.4;
23 front_elevation_nominal = 0; // this parameter adjusts rear too somehow?
24
25 cross_rail_distance = 232.09;
26
27 general_gap_y = 1.0;
28 support_bridge_gap_z = 1.0;
29
30 strap_w = 8.0 + 1.0;
31 strap_th = 2.5;
32 strap_barrel_dia = 14;
33 strap_guide_sz = 1;
34
35 brk_block_xw = 68.5;
36 brk_block_z = 14.55 - 0.00;
37
38 brk_bolt_dia = 5.0 + 0.5;
39 brk_nearbolt_recess_dia = 8.86 + 1.5;
40 brk_nearbolt_recess_depth = 1.09 + 0.25;
41
42 bolt_nut_around = 5;
43 bolt_nut_around_y_extra = 3;
44
45 brk_bolt_eff_len = 11.78; // inside of recess, to end of bolt
46 brk_bolt_len_slop = 0.5;
47 brk_bolt_nut_th = 3.89;
48 brk_bolt_nut_across_flats = 7.86 + 0.50;
49
50 brk_overall_w = 90.07;
51
52 fit_slope_len = 5;
53
54 // "foreaftmaint" aka "fam" is the hook-like part that stops
55 // the adapter sliding forwards/backwards along the rails
56 foreaftmaint_r_slop = 0.0;
57 foreaftmaint_y_slop = -0.25;
58 foreaftmaint_top_block_zs = [34.0, 39.0]; // rearwards from bolt hole
59
60 main_sz_y = $strf * 12;
61 grasp_sz = $strf * 6;
62 grasp_thin_sz = $strf * 0.5;
63 beside_strap_sz = $strf * 8;
64 main_sz_core_z = $strf * 12;
65
66 // "length" in for-aft direction of interaction with rack rail
67 min_on_rail_sz_z = $strf * 18;
68
69 // when printer produces support
70 support_around = 1.7; // how far does the support extend around (in XY)
71 support_remnant = 0.75; // how much frass remains attached (Z height)
72
73 $fa=10;
74 $fs=1;
75
76 // calculated
77
78 bolt_z = -brk_block_z/2;
79
80 front_to_rear_elevation_change =
81   rear_elevation_nominal - front_elevation_nominal;
82
83 main_sz_rhs_z = max(min_on_rail_sz_z, beside_strap_sz*2 + strap_w);
84 main_sz_lhs_z = min_on_rail_sz_z;
85
86 main_sz_x_fam = main_sz_y;
87
88 brk_bottom_y = -brk_recess_actual;
89 adapt_main_top_y = brk_bottom_y - general_gap_y;
90
91 // on LHS, so -ve
92 rack_rail_x = -(rack_width_inner/2 + rack_rail_dia/2);
93 rack_rail_outer_x = -(rack_width_inner/2 + rack_rail_dia);
94
95 grasp_large_r = (rack_rail_dia + grasp_sz)/2;
96 grasp_small_r = (rack_rail_dia + grasp_thin_sz)/2;
97 grasp_large_x = rack_rail_outer_x + grasp_large_r;
98 grasp_small_x = rack_rail_outer_x + grasp_small_r;
99
100 block_x = grasp_large_x + grasp_large_r;
101 block_y_min = adapt_main_top_y - main_sz_y;
102
103 strap_barrel_x = rack_width_inner/2 + strap_barrel_dia/2;
104
105 rack_shear_ratio = - front_to_rear_elevation_change / rear_to_front_distance;
106
107 front_to_cross_rail =
108   cross_rail_distance * sqrt(1 - rack_shear_ratio * rack_shear_ratio)
109   - rear_bolt_to_front_bolt
110   - rear_to_cross_rail
111   - sqrt( pow( cross_rail_distance * rack_shear_ratio, 2 )
112           - pow(  front_to_rear_elevation_change, 2 ) )
113   ;
114
115 brk_bolt_nut_top_y = -brk_nearbolt_recess_depth
116   - brk_bolt_eff_len + brk_bolt_nut_th + brk_bolt_len_slop;
117                        
118 brk_bolt_nut_r = brk_bolt_nut_across_flats/2 / cos(360/12);
119
120 function elevation_of_bolt_for(z) = rear_elevation_nominal
121   + front_elevation_nominal
122   + (z - brk_block_z/2) * rack_shear_ratio;
123
124 function rack_rail_y_of_elevation(elevation_nominal) =
125   brk_bottom_y - elevation_nominal - general_gap_y  - rack_rail_dia/2;
126
127 echo(rack_shear_ratio);
128
129 module GraspElevation(){
130   hull(){
131     translate([ grasp_large_x, adapt_main_top_y - grasp_large_r ])
132       circle(grasp_large_r);
133
134     translate([ grasp_small_x, $rack_rail_y - rack_rail_dia/2 ])
135       circle(grasp_small_r);
136
137     translate([ rack_rail_x + grasp_large_r/2,
138                 $rack_rail_y - rack_rail_dia/2 ])
139       circle(grasp_small_r);
140
141     translate([ grasp_large_x, $rack_rail_y + rack_rail_dia/2 ])
142       circle(grasp_large_r);
143
144     translate([ grasp_large_x + grasp_large_r/2,
145                 $rack_rail_y + rack_rail_dia/2 ])
146       circle(grasp_large_r);
147   }
148 }
149
150 module BlockElevation(){
151   hull(){
152     rectfromto([ +block_x, adapt_main_top_y ],
153                [ -block_x, block_y_min ]);
154     rectfromto([ -grasp_large_x, adapt_main_top_y ],
155                [ +grasp_large_x, adapt_main_top_y - 0.1 ]);
156   }
157   hull(){
158     rectfromto([ +block_x, adapt_main_top_y ],
159                [ -block_x, block_y_min ]);
160     rectfromto([ grasp_large_x, block_y_min ],
161                [ 0, block_y_min + 0.1 ]);
162   }
163 }
164
165 module MainExtrude(z){
166   linextr(0, z)
167     children();
168 }
169 module RackShear(){
170   s = rack_shear_ratio * $reverse_sign;
171   multmatrix([ [ 1, 0,  0, 0 ],
172                [ 0, 1, s , 0 ],
173                [ 0, 0,  1, 0 ],
174                [ 0, 0,  0, 1 ] ])
175     children();
176 }
177
178 module GraspFixingElevation(){
179   intersection(){
180     union(){
181       hull(){
182         mirror([1,0]) {
183           GraspElevation();
184         }
185         translate([ -block_x, block_y_min ] + [0,0.1]*1 )
186           circle(0.1);
187       }
188       translate([ strap_barrel_x, $strap_barrel_y ])
189         circle(strap_barrel_dia/2 + strap_guide_sz);
190     }
191     union(){
192       rectfromto([0, $rack_rail_y],
193                  [rack_width_inner, 50]);
194       intersection(){
195         translate([ rack_rail_x, $rack_rail_y ])
196           circle(r = rack_width_inner/2 - rack_rail_x);
197         polygon([ [ -block_x-0.1, 0 ],
198                   [ rack_width_inner/2, 0 ],
199                   $rail_fixing_fit_corner,
200                   $rail_fixing_fit_corner + [-1,-1] * fit_slope_len,
201                   [ -grasp_large_x - grasp_large_r*2, block_y_min ],
202                   [ -block_x-0.1 -2, block_y_min +2 ]]);
203       }
204     }
205   }
206 }
207
208 module StrapBarrelElevation(){
209   translate([ strap_barrel_x, $strap_barrel_y ])
210     circle(strap_barrel_dia/2);
211 }
212
213 // Bracket support block, goes up inside bracket
214 // Z origin is bolt hole
215 module BrkBlock(){
216   difference(){
217     linextr( -brk_block_z/2,
218              +brk_block_z/2 ) {
219       rectfromto([ -brk_block_xw/2, adapt_main_top_y - 0.1 ],
220                  [ +brk_block_xw/2, 0 ]);
221     }
222     linextr_y_xz( -50, 10 ) {
223       translate([ 0, brk_block_z + bolt_z ])
224         square(center=true,
225                [ main_sz_x_fam + support_around*2,
226                  support_remnant *2 ]);
227     }
228   }
229 }
230
231 // Z origin is bolt hole
232 module BoltHole(){
233   linextr_y_xz( -100, 10 )
234     circle(brk_bolt_dia/2);
235
236   linextr_y_xz( -brk_nearbolt_recess_depth, 10)
237     circle(brk_nearbolt_recess_dia/2);
238
239   linextr_y_xz( -100, brk_bolt_nut_top_y ) {
240     hull()
241       for (dz = [0, support_bridge_gap_z])
242         translate([0, dz])
243           circle( r= brk_bolt_nut_r, $fn = 6 );
244   }
245 }
246
247 module IfFam(){
248   if ($foreaftmaint_dz) {
249     children();
250   }
251 }
252
253 module FamLinextr(){
254   IfFam()
255     linextr_x_yz(-main_sz_x_fam/2, +main_sz_x_fam/2)
256     rotate(-90)
257     children();
258 }
259
260 module FamGraspElevation(){
261   difference(){
262     hull(){
263       ybot = $rack_rail_y - rack_rail_dia/2 + grasp_large_r
264         - fit_slope_len * 0.5;
265       for (y = [
266                 ybot,
267                 adapt_main_top_y - grasp_large_r
268                 ])
269         for (dx= [/*-1,*/ +1] * rack_rail_dia/2)
270           translate([ -$foreaftmaint_rail_z + dx, y ])
271             circle(r= grasp_large_r);
272     }
273     if ($foreaftmaint_cutoff) {
274       translate([ -$foreaftmaint_rail_z, 0 ])
275         rectfromto([-100, -100],
276                    [0, 100]);
277     }
278   }
279 }
280
281 module FamStemElevation(){
282   hull(){
283     rectfromto([ -$foreaftmaint_rail_z
284                  , adapt_main_top_y ],
285                [ 0, block_y_min]);
286     translate([
287                -$foreaftmaint_rail_z,
288                $rack_rail_y +
289                rack_shear_ratio * $foreaftmaint_rail_z * $reverse_sign,
290                ])
291       square([0.1, rack_rail_dia * 0.5], center=true);
292   }
293 }
294
295 module Principal(){
296   // calculated
297   $rack_rail_y = rack_rail_y_of_elevation($elevation_nominal);
298
299   $strap_barrel_y = $rack_rail_y + rack_rail_dia/2 + strap_barrel_dia/2;
300
301   $rail_fixing_fit_corner = [
302     rack_width_inner/2,
303     $rack_rail_y - rack_rail_dia/2
304   ];
305
306   $foreaftmaint_rail_z = brk_block_z/2 + $foreaftmaint_dz - foreaftmaint_y_slop;
307
308   translate([0,0,brk_block_z/2])
309   mirror([0,0, $reverse_sign > 0 ? 0 : 1])
310   translate([0,0,-brk_block_z/2])
311   difference(){
312     union(){
313       MainExtrude(main_sz_lhs_z){
314         GraspElevation();
315       }
316       RackShear() MainExtrude(main_sz_rhs_z){
317         StrapBarrelElevation();
318       }
319       translate([ 0,0, brk_block_z/2]) {
320         BrkBlock();
321       }
322
323       difference(){
324         union(){
325           MainExtrude(main_sz_core_z){
326             BlockElevation();
327           }
328           if ($strf<1) {
329             MainExtrude(max(brk_block_z, main_sz_rhs_z)){
330               rectfromto([-8, adapt_main_top_y + 0.1],
331                          [+8, block_y_min]);
332               rectfromto([-block_x -5,  adapt_main_top_y],
333                          [-grasp_large_x, block_y_min]);
334             }
335           }
336           RackShear() MainExtrude(main_sz_rhs_z){
337             GraspFixingElevation();
338           }
339         }
340
341         translate([0,0, main_sz_rhs_z/2]) linextr(-strap_w/2, +strap_w/2) {
342           translate([ rack_width_inner/2 - strap_th, 0 ])
343             rectfromto([ 0, -50 ], [ 50, 50 ]);
344         }
345       }
346
347       FamLinextr(){
348         if ($foreaftmaint_top_block) {
349           rectfromto([ -foreaftmaint_top_block_zs[0] + bolt_z, 0 ],
350                      [ -foreaftmaint_top_block_zs[1] + bolt_z, block_y_min] );
351         }
352         FamGraspElevation();
353       }
354       intersection(){
355         union(){
356           RackShear()
357             FamLinextr()
358             FamGraspElevation();
359           FamLinextr()
360             FamStemElevation();
361         }
362         translate([ 0,
363                     adapt_main_top_y - 50,
364                     $foreaftmaint_rail_z ])
365           cube(center=true, 100);
366       }
367
368       linextr_y_xz( block_y_min - bolt_nut_around_y_extra , adapt_main_top_y )
369         intersection(){
370           translate([ 0, brk_block_z/2 ])
371             circle(r = bolt_nut_around + brk_bolt_nut_r );
372           rectfromto([-100, 0], [+100,+100]);
373       }
374     }
375
376     RackShear() linextr(-10, main_sz_lhs_z+main_sz_rhs_z) {
377       for (mx=[0,1]) {
378         mirror([mx,0]) {
379           translate([ rack_rail_x, $rack_rail_y ]){
380             hull(){
381               for (dx = [-rack_rail_dia, 0])
382                 translate([dx, 0])
383                   circle(r= rack_rail_dia/2);
384             }
385           }
386         }
387       }
388     }
389
390     RackShear() IfFam(){
391       // Distance from bolt hole, in backwards direction
392       cr = rack_rail_dia/2 + foreaftmaint_r_slop;
393       translate([ 0, $rack_rail_y, $foreaftmaint_rail_z ])
394         linextr_x_yz(+rack_rail_x,
395                      -rack_rail_x) {
396         hull(){
397           for (dy=[0,50]) {
398             translate([-dy,0])
399               circle(r= cr);
400           }
401         }
402         hull(){
403           for (dd=[[0,0], [-1,-1], [-1,+1]]) {
404             translate(
405                       [-1, 0] * (rack_rail_dia - fit_slope_len)
406                       + 20 * dd
407                       )
408               circle(r= cr);
409           }
410         }
411       }
412     }
413
414     translate([ 0,0, brk_block_z/2]) BoltHole();
415   }
416 }
417
418 module ForRackForDemo(){
419   elevation = elevation_of_bolt_for(rear_to_cross_rail);
420   rack_rail_y = rack_rail_y_of_elevation(elevation);
421
422   rotate([atan(
423                front_to_rear_elevation_change /
424                cross_rail_distance
425                ), 0,0])
426     translate([0, rack_rail_y, brk_block_z/2 + rack_rail_y*rack_shear_ratio])
427     children();
428 }
429
430 module RackForDemoRails(){
431   ForRackForDemo() {
432     for (m=[0]) mirror([m,0,0]) {
433       linextr(-(50 + cross_rail_distance), 50 + rear_to_cross_rail)
434         translate([rack_rail_x, 0])
435         circle(r= rack_rail_dia/2);
436     }
437   }
438 }
439
440 module RackForDemoCrosses(){
441   ForRackForDemo() {
442     for (z = [
443               rear_to_cross_rail,
444               rear_to_cross_rail - cross_rail_distance,
445               ]) {
446       translate([0,0,z])
447         linextr_x_yz(rack_rail_x, -rack_rail_x)
448         circle(r= rack_rail_dia/2, $fn=8);
449     }
450   }
451 }
452
453 module Front(){ ////toplevel
454   rotate([180,0,0])
455   Principal($reverse_sign = -1,
456             $foreaftmaint_top_block = false,
457             $foreaftmaint_cutoff = true,
458             $elevation_nominal=
459       elevation_of_bolt_for(rear_to_cross_rail + rear_bolt_to_front_bolt),
460             $foreaftmaint_dz= front_to_cross_rail);
461 }
462
463 module Rear(){ ////toplevel
464   Principal($reverse_sign = +1,
465             $foreaftmaint_top_block = true,
466             $foreaftmaint_cutoff = false,
467             $elevation_nominal=
468       elevation_of_bolt_for(rear_to_cross_rail),
469             $foreaftmaint_dz= rear_to_cross_rail);
470 }
471
472 module SomeDemo(){
473   rotate([90, 0, 0]){
474     children();
475
476     color("blue")
477       translate([ 0, -2, -4 ])
478       square(center=true, [ brk_overall_w, 1 ]);
479
480     color("red")
481       translate([ 0, -brk_nearbolt_recess_depth, -4 ])
482       linextr_y_xz(-brk_bolt_eff_len, 0)
483       circle(r = brk_bolt_dia/2);
484
485   }
486 }
487
488 module FrontDemo(){ ////toplevel
489   SomeDemo() rotate([180,0,0]) Front();
490 }
491 module RearDemo(){ ////toplevel
492   SomeDemo() Rear();
493 }
494 module RearRackDemo(){ ////toplevel
495   rotate([atan(rack_shear_ratio),0,0]) SomeDemo() {
496     Rear();
497     translate([0, 0, -rear_bolt_to_front_bolt])
498       rotate([180,0,0]) Front();
499     %RackForDemoRails();
500     color("blue") RackForDemoCrosses();
501   }
502 }