chiark / gitweb /
bike-lipo-box: TestWall: replace ad-hoc with S1930_Positive (nfc)
[reprap-play.git] / bike-lipo-box.scad.m4
1 // -*- C -*-
2
3 include <commitid.scad>
4 include <utils.scad>
5
6 pxp6012_rad = 22.5 / 2 + 0.5;
7 pxp6012_rad_outer = 32.0 / 2 - 0.5;
8
9 s1930_y = 30.2 + 0.2;
10 s1930_x =   22 + 0.2;
11 s1930_y_outer = 36.4 + 0.2;
12 s1930_x_outer = 27.6 + 0.2;
13
14 s1930_recess = 3;
15 s1930_around = 3;
16 s1930_behind = 3;
17
18 wallthick = 2.5;
19
20 // origin is at centre on outer face wall
21 // outside is towards positive x
22 // mounting is vertical
23 module S1930_Positive(){
24   d = s1930_recess + s1930_behind;
25   translate([-d/2, 0,0])
26     cube([d,
27           s1930_x_outer + s1930_around,
28           s1930_y_outer + s1930_around], center=true);
29 }
30
31 module TestWall(){ ////toplevel
32   sw_ctr = [25, 0, 25];
33   sw_ctr_new = [25,
34                 wallthick + 0.5, // xxx compatibility bug
35                 25];
36
37   rotate([0,0,-90]){
38     difference(){
39       union(){
40         cube([50, wallthick, 42]);
41       }
42
43       translate([30, -1, 20])
44         rotate([-90,0,0])
45         cylinder(r = pxp6012_rad, h=10, $fn=60);
46
47       rotate([90,0,0])
48         Commitid_BestCount([15,40]);
49     }
50   }
51
52   difference(){
53     union(){
54       cube([50, wallthick, 50]);
55       translate(sw_ctr_new)
56         rotate([0,0,90])
57         S1930_Positive();
58     }
59
60     translate(sw_ctr) {
61       rotate([90,0,0]) {
62         cube([s1930_x, s1930_y, 10], center=true);
63         translate([0,0, -5])
64           cube([s1930_x_outer, s1930_y_outer, 10], center=true);
65       }
66     }
67   }    
68 }
69
70 floorth = 2.5;
71 ceilth = 2.5;
72 innertube = 1.0 + 0.2;
73 lidoverlap = 1.5;
74 lidoverhang = 6;
75 tubesealrad = 2.0;
76
77 ts_xbox = 30;
78 ts_ybox = 25;
79 ts_cnrrad = 10;
80 ts_zbox = 8;
81
82 ts_cidoff = (ts_cnrrad * (1-.7) + wallthick * .8) * [1,1];
83
84 m4_dnl Box_Part($1=transl_x,$2=transl_y, $3=rot_z,$4=mirror_xy)
85 m4_dnl          $5=kind, $6=kindargs, $7=profile(profileargsargs))
86 m4_define(`Box_Part',`
87   translate([($1),($2)])
88     rotate([0,0,($3)])
89     mirror([($4),0,0])
90     BoxPart_Extrude_$5($6, $7)') m4_dnl
91
92 boxpart_d = 0.01;
93
94 m4_dnl BoxPart_Extrude_Linear(dist, `profile(...);');
95 m4_define(`BoxPart_Extrude_Linear',`
96   rotate([90,0,0])
97     translate([0,0, -($1)])
98     linear_extrude(height= boxpart_d + ($1)) {
99       $2
100     }
101 ')
102
103 m4_dnl BoxPart_Extrude_Arc(x0_radius, swept_angle, `profile(...);')
104 m4_dnl  arc starting at transl_x, transl_y, moving towards positive
105 m4_dnl  y at first and then bending towards negative x, until
106 m4_dnl  use negative x0_radius to inciate bending towards positive x
107 m4_dnl  swept_angle is reached
108 m4_dnl  x0_radius is the radius of the extruded part at x=0, not of the box
109 m4_define(`BoxPart_Extrude_Arc',`
110   translate([-($1),0,0])
111     intersection(){
112       translate([0,0,-500])
113         linear_extrude(height=1000)
114         scale(500)
115         mirror([($1)<0, 0,0])
116         FArcSegment_mask($2);
117       rotate_extrude(convexity=10, $fs=1, $fn=36)
118         mirror([($1)<0, 0,0])
119         translate([+($1),0,0]){
120           $3
121         }
122     }
123 ')
124
125 ts_xbox_lin = ts_xbox - ts_cnrrad*2;
126 ts_ybox_lin = ts_ybox - ts_cnrrad*2;
127
128 m4_dnl TestSealDoBoxShape(`profile(profileargs)');
129 m4_define(`TestSealDoBoxShape',`
130   Box_Part(0,               ts_cnrrad,    0,0, Linear,`ts_ybox_lin', `$1' )
131   Box_Part(0, ts_ybox-ts_cnrrad,          0,0, Arc,`-ts_cnrrad,90' , `$1' )
132   Box_Part(ts_cnrrad,       ts_ybox,    -90,0, Linear,`ts_xbox_lin', `$1' )
133   Box_Part(ts_xbox-ts_cnrrad, ts_ybox,  -90,0, Arc,`-ts_cnrrad,90' , `$1' )
134   Box_Part(ts_xbox, ts_ybox-ts_cnrrad, -180,0, Linear,`ts_ybox_lin', `$1' )
135   Box_Part(ts_xbox,         ts_cnrrad, -180,0, Arc,`-ts_cnrrad,90' , `$1' )
136   Box_Part(ts_xbox-ts_cnrrad, 0,       -270,0, Linear,`ts_xbox_lin', `$1' )
137   Box_Part(ts_cnrrad,         0,       -270,0, Arc,`-ts_cnrrad,90' , `$1' )
138 ')
139
140 m4_dnl '
141
142 module WallProfile(){
143   z = ts_zbox - innertube - tubesealrad;
144   translate([0, -0.1]) square([wallthick, z]);
145   translate([tubesealrad, z]) circle(r=tubesealrad, $fn=20);
146 }
147
148 module FloorProfile(){
149   mirror([0,1]) square([wallthick, floorth]);
150 }
151
152 module LidProfile(){
153   rad = tubesealrad + innertube;
154   morex = wallthick;
155   difference(){
156     translate([-lidoverlap - innertube,
157                ts_zbox - lidoverhang - innertube])
158       square([lidoverlap + innertube + wallthick,
159               lidoverhang + innertube + ceilth]);
160     hull(){
161       translate([tubesealrad,
162                  ts_zbox - innertube - tubesealrad])
163         for (t=[ [0,0],
164                  [morex*2, 0],
165                  [0, -ts_zbox]
166                  ]) {
167           translate(t)
168             circle(r= tubesealrad + innertube, $fn=20);
169         }
170     }
171   }
172 }
173
174 module CeilProfile(){
175   translate([0, ts_zbox])
176     square([wallthick*2, ceilth]);
177 }
178
179 module TestSealBox(){ ////toplevel
180   TestSealDoBoxShape(WallProfile(););
181   hull(){ TestSealDoBoxShape(FloorProfile();); }
182   translate(ts_cidoff)
183     Commitid_BestCount([ts_xbox,ts_ybox] - 2*ts_cidoff);
184 }
185
186 module TestSealLid(){ ////toplevel
187   difference(){
188     union(){
189       TestSealDoBoxShape(LidProfile(););
190       hull(){ TestSealDoBoxShape(CeilProfile();); }
191     }
192     translate([ts_xbox * .75, ts_ybox/2, 0])
193       cylinder(h=100, r=5);
194     
195     translate([-wallthick + ts_cnrrad*.5,
196                ts_cnrrad*.5 - wallthick,
197                ts_zbox + ceilth])
198       Commitid_BestCount([ts_xbox * .75 - 2.5 - (ts_cnrrad*.5),
199                           ts_ybox - (ts_cnrrad*.5 - wallthick)*2]);
200   }
201 }
202
203 module TestSealLidPrint(){ ////toplevel
204   rotate([180,0,0]) TestSealLid();
205 }
206
207 module ProfileDemos(){
208   WallProfile();
209   color("blue") FloorProfile();
210   LidProfile();
211   color("blue") CeilProfile();
212 }
213                           
214 //TestWall();
215 //ProfileDemos();
216 //TestSealBox();
217 //TestSealLid();
218 //FArcSegment_mask(350);