]> www.fi.muni.cz Git - openparking.git/blob - things/hc-sr04.scad
a9d1a1cb39af146314f9771dda76fb0c728b9bc2
[openparking.git] / things / hc-sr04.scad
1 eps = 0.01;
2 infty = 100;
3
4 wall = 1.5;
5
6 cyl_r = 8 + 0.5;
7 cyl_x = 26.6 / 2;
8 cyl_h = 8; // above pcb, max 13.8;
9
10 pcb_x = 45.6 + 1.0;
11 pcb_y = 20.2 + 0.7;
12 xtal_h = 5;
13 pcb_supp = 3; // side support thickness
14 pcb_h = 8; // 1.2 + space for connector etc
15 pcb_thick = 2.5;
16
17 cyl_base = pcb_x/2 + wall - cyl_x;
18
19 conn_x = 10 + 0.5;
20 conn_y = 15;
21
22 cable_w = 7;
23 cable_h = 4;
24
25 screw_head = 7.5;
26 screw_d = 4;
27 screw_base = 2*wall;
28
29 clip_r = 1;
30 clip_h = 8;
31
32 module sensor() {
33         hull() {
34                 // space above pcb
35                 translate([-pcb_x/2, -pcb_y/2, -eps])
36                         cube([pcb_x, pcb_y, pcb_h-pcb_thick+eps]);
37                 // connector
38                 translate([-conn_x/2, pcb_y/2-eps, -eps])
39                         cube([conn_x, conn_y+eps, pcb_h-pcb_thick+eps]);
40         }
41         // cable protrusion
42         translate([-cable_w/2, pcb_y/2+conn_y-eps, -eps])
43                 cube([cable_w, 2*wall + eps, cable_h]);
44
45         // cylinders
46         for (x = [-1, 1]) translate([cyl_x*x, 0, pcb_h - eps])
47                 cylinder(r = cyl_r, h = cyl_h + 2+wall + eps);
48         // pcb
49         translate([-pcb_x/2, -pcb_y/2, pcb_h-pcb_thick-eps])
50                 cube([pcb_x, pcb_y, pcb_thick+eps]);
51         // space below the pcb (xtal, etc)
52         translate([-pcb_x/2+pcb_supp, -pcb_y/2, pcb_h-pcb_thick - eps])
53                 cube([pcb_x - 2*pcb_supp, pcb_y, xtal_h+pcb_thick+eps]);
54 };
55 module case_body() {
56         hull() {
57                 // pcb
58                 translate([-pcb_x/2-wall, -pcb_y/2-wall, 0])
59                         cube([pcb_x+2*wall, pcb_y+2*wall, pcb_h+wall]);
60
61                 // cylinders
62                 for (x = [-1, 1]) translate([cyl_x*x, 0, pcb_h + cyl_h])
63                         cylinder(r = cyl_base, h = wall);
64
65                 translate([0, 8, pcb_h + cyl_h])
66                         cylinder(r = cyl_base, h = wall);
67
68                 // connector
69                 translate([-conn_x/2-wall, pcb_y/2-wall, 0])
70                         cube([conn_x+2*wall, conn_y+2*wall, pcb_h-pcb_thick+wall]);
71                 // screw mounts
72                 for (x = [1, -1]) scale([x, 1, 1])
73                         translate([pcb_x/2+wall, -screw_head/2-wall, 0])
74                                 cube([screw_head, screw_head+2*wall, screw_base]);
75         }
76 }
77
78 module case() {
79         difference() {
80                 case_body();
81                 difference() {
82                         sensor();
83                         // pcb clip
84                         translate([-clip_h/2, -pcb_y/2, pcb_h-pcb_thick-clip_r/2])
85                         rotate([0, 90, 0])
86                         cylinder(r=clip_r, h = clip_h, $fn = 4);
87                 }
88                 // mount holes
89                 for (x = [-1, 1]) scale([x, 1, 1]) {
90                         translate([pcb_x/2+wall, -screw_head/2, screw_base])
91                                 cube([screw_head+eps, screw_head, infty]);
92                         // screw hole
93                         translate([pcb_x/2+wall+screw_head/2-screw_d/2, -screw_head/2, -eps])
94                                 cube([screw_d, screw_head, infty]);
95                 }
96                 // text
97                 translate([0, 3.5, pcb_h + cyl_h + eps])
98                         rotate([0, 0, 90])
99                         linear_extrude(height=wall)
100                         text("CVT FI", font="DejaVu Sans:style=Bold", size=5,
101                                 halign="center", valign="center");
102         }
103 }
104
105 rotate([180, 0, 0]) // rotate it for easier print
106         case();