]> www.fi.muni.cz Git - bike-lights.git/blobdiff - parts/rearlight.scad
mudflap for dual rearlights
[bike-lights.git] / parts / rearlight.scad
index 00a3cf625caeac0028454c830f0f29212b0dc6ca..05a79cb31cca19163c5507e42e9ebbcc8b97b229 100644 (file)
@@ -5,226 +5,303 @@ epsilon = 0.01;
 infty = 100;
 debug = 0;
 
-heatsink_thickness = 2.5;
-heatsink_width = 18-3.4;
-heatsink_length = 58;
-
-module fraen_lens_pin() {
-       cylinder(r1=2, r2=6.15/2, h=23);
-       translate([epsilon, 0, -5])
-               cylinder(r=3.4/2, h=5+epsilon);
-};
+wall_thickness = 1.5;
+fraen_diam = 30.90;
+fraen_h = 29.3;
+pin_diam = 4;
+pin_offset = 10.35*1.4142;
+pin_len = 9.2;
+front_add = 4;
 
-module fraen_lens() {
-       cylinder(r1=6, r2=30.51/2, h=23);
-       translate([9, 9, 0])   fraen_lens_pin();
-       translate([9, -9, 0])  fraen_lens_pin();
-       translate([-9, 9, 0])  fraen_lens_pin();
-       translate([-9, -9, 0]) fraen_lens_pin();
-};
+rear_pin_dist = 9.1;
+rear_pin_diam = 3.25;
 
-module heatsink() {
-       translate([-heatsink_length+ 5 +heatsink_width/2, -heatsink_width/2, 0])
-               cube([heatsink_length, heatsink_width, heatsink_thickness]);
-}
+side_barrier_x_offset = 13;
+side_barrier_pin_z_offset = 4.2;
+side_barrier_thickness = 2;
 
-module seat_holder() {
-       translate([-41, 8, 29])
-               cube([3, 30, 60], center=true);
-};
+heatsink_thickness = 2;
+
+clip_h1 = 27; // front height (on the heatsink side)
+clip_h2 = 20; // rear height (on the lens side)
+clip_l  = 28;
+clip_wall = wall_thickness;
+clip_space = 3.5;
+clip_bolt1_z = 6;
+clip_bolt1_x = 19.5;
+clip_bolt2_z = 22;
+clip_bolt2_x = 21;
+clip_angle = 18;
+clip_top_xoff = clip_l*tan(clip_angle);
 
-module stem_ellipse(h, w, x, y) {
-       translate([x, y, 0])
+clip_y_off = 34;
+clip_x_off = 2;
+clip_x_rot = -3;
+
+// z-axis is up
+module bolt_mount(d, h, w1, w2, fn) {
        difference() {
-               translate([0, 0, 6])
-                       scale([1, w/2, h-6])
-                               rotate([0, 90, 0])
-                                       cylinder(r=1, h=epsilon);
-               translate([0, 0, -100]) cube([200, 200, 200], center=true);
+               translate([0, 0, -epsilon])
+                       cylinder(r1=w2/2, r2=w1/2, h=h+epsilon);
+               translate([0, 0, -2*epsilon])
+               cylinder(r=d/2, h=h+3*epsilon, $fn=fn);
        };
-}
+};
 
-module main() {
+module seat_clip() {
        difference() {
                union() {
+                       // right part
                        hull() {
-                               cylinder(r=34/2, h=33);
-                               stem_ellipse(h = 15, w = 10, x = -21, y=-5);
+                               translate([0, clip_space/2, 0])
+                                       cube([clip_h1, clip_wall, epsilon]);
+                               translate([clip_top_xoff, clip_space/2, clip_l])
+                                       cube([clip_h2, clip_wall, epsilon]);
                        };
+
+                       // left part
                        hull() {
-                               stem_ellipse(h = 15, w = 10, x = -21-epsilon, y=-5);
-                               stem_ellipse(h = 15, w = 10, x = -33, y=-5);
+                               translate([0, -clip_space/2-clip_wall, 0])
+                                       cube([clip_h1, clip_wall, epsilon]);
+                               translate([0+clip_top_xoff, -clip_space/2-clip_wall, clip_l])
+                                       cube([clip_h2, clip_wall, epsilon]);
                        };
+
+                       // top part
                        hull() {
-                               stem_ellipse(h = 15, w = 10, x = -33-epsilon, y=-5);
-                               stem_ellipse(h = 25, w = 15, x = -40+epsilon, y=-2.5);
+                               translate([-2*clip_wall, -clip_space/2-clip_wall, 0])
+                                       cube([2*clip_wall+epsilon, 2*clip_wall+clip_space, epsilon]);
+                               translate([-clip_wall+clip_top_xoff, -clip_space/2-clip_wall, clip_l])
+                                       cube([clip_wall+epsilon, 2*clip_wall+clip_space, epsilon]);
                        };
-                       translate([-41, 5, 52/2])
-                               cube([7, 30, 52], center=true);
-                       // bolt hole ring
-                       translate([-44+epsilon, 10, 40]) rotate([0, -90, 0]) difference() {
-                               cylinder(r1=9, r2=6, h=3);
-                               translate([0, 0, -epsilon])
-                                       cylinder(r=5, h=3+2*epsilon, $fn=6);
-                       }
-                       // screw hole ring
-                       translate([-38-epsilon, 10, 40]) rotate([0, 90, 0]) difference() {
-                               cylinder(r1=9, r2=6, h=3);
-                               translate([0, 0, -epsilon])
-                                       cylinder(r=5, h=3+2*epsilon);
-                       }
+
+                       // bolt mounts
+                       translate([clip_bolt1_x, clip_space/2 + clip_wall, clip_bolt1_z])
+                       rotate([-90, 0, 0])
+                       bolt_mount(6.5, 2, 7, 12, 6);
+
+                       translate([clip_bolt1_x, -clip_space/2 - clip_wall, clip_bolt1_z])
+                       rotate([90, 0, 0])
+                       bolt_mount(6.5, 2, 7, 12, 32);
+
+                       translate([clip_bolt2_x, clip_space/2 + clip_wall, clip_bolt2_z])
+                       rotate([-90, 0, 0])
+                       bolt_mount(6.5, 2, 7, 12, 6);
+
+                       translate([clip_bolt2_x, -clip_space/2 - clip_wall, clip_bolt2_z])
+                       rotate([90, 0, 0])
+                       bolt_mount(6.5, 2, 7, 12, 32);
                };
-               translate([-47, 10, 40]) rotate([0, 90, 0])
-                       cylinder(r=2.5, h=12);
-               translate([0, 0, 6-heatsink_thickness])
-                       cylinder(r=31/2, h=32);
-               translate([0, 0, 6])
-                       fraen_lens();
-               heatsink();
-               seat_holder();
-       }
-       if (debug == 1) {
-               translate([0, 0, 6]) color("gray") fraen_lens();
-               color("lightblue") heatsink();
-               color("lightgreen") seat_holder();
+               // bolt holes
+               translate([clip_bolt1_x, infty/2, clip_bolt1_z])
+                       rotate([90, 0, 0])
+                       cylinder(r=2, h=infty, $fn = 6);
+               translate([clip_bolt2_x, infty/2, clip_bolt2_z])
+                       rotate([90, 0, 0])
+                       cylinder(r=2, h=infty, $fn = 6);
        }
+
 }
 
-module bolt_mount(d, h, w1, w2, fn) {
+// upper part of the lens holder
+module round_part() {
        difference() {
-               translate([0, 0, -epsilon])
-                       cylinder(r1=w2/2, r2=w1/2, h=h+epsilon);
-               translate([0, 0, -2*epsilon])
-               cylinder(r=d/2, h=h+3*epsilon, $fn=fn);
-       };
-};
+               cylinder(r = fraen_diam/2 + pin_diam/2 + wall_thickness,
+                       h = front_add + pin_len);
 
-clip_h1 = 25; // inner height
-clip_h2 = 18; // inner height
-clip_l  = 35;
-clip_wall = 2;
-clip_space = 4;
-clip_bolt1_x = 10;
-clip_bolt2_x = 25;
+               hull() {
+                       translate([0, 0, -epsilon])
+                               cylinder(r = fraen_diam/2,
+                                       h = pin_len + front_add + 2*epsilon);
+                       for (angle = [0, 90, 180, 270]) {
+                               rotate([0, 0, angle+45])
+                                       translate([pin_offset, 0, -epsilon])
+                                               cylinder(r=pin_diam/2,
+                                                       h=epsilon);
+                       };
+               }
 
-module clip_top_circle() {
-       rotate([-90, 0, 0])
-       difference() {
-               translate([-clip_space/2, 0, 0])
-                       cylinder(r=clip_wall, h = epsilon, $fn=32);
-               translate([-infty/2, clip_wall/2-epsilon, -epsilon])
-                       cube(infty);
-               translate([clip_wall+epsilon, -infty/2, -epsilon])
-                       cube(infty);
+               // front cone
+               translate([0, 0, pin_len + 0.5*wall_thickness - epsilon])
+                       cylinder(r1 = fraen_diam/2,
+                               r2 = (fraen_diam+pin_diam + wall_thickness)/2,
+                               h = front_add - 0.5*wall_thickness+ 2*epsilon);
+               // pin holes
+               for (angle = [0, 90, 180, 270]) {
+                       rotate([0, 0, angle+45])
+                               translate([pin_offset, 0, epsilon])
+                                       cylinder(r=pin_diam/2,
+                                               h=pin_len+epsilon);
+               };
        };
-};
 
-module clip_top() {
-       hull() {
-               translate([0, 0, clip_h1/2+clip_wall])
-                       clip_top_circle();
-               translate([0, clip_l-epsilon, clip_h2/2+clip_wall])
-                       clip_top_circle();
-       };
+       // side barriers
+       for (angle = [0, 90, 180]) // omit the bottom one
+               rotate([0, 0, angle])
+                       intersection() {
+                               cylinder(r=fraen_diam/2+epsilon, h=infty);
+                               translate([-infty/2, side_barrier_x_offset,
+                                       pin_len - side_barrier_pin_z_offset - side_barrier_thickness ])
+                                       cube([infty, infty, side_barrier_thickness]);
+               };
 };
 
-module seat_clip() {
+module square_cone() {
        difference() {
-               polyhedron(points = [
-                       [-clip_wall-clip_space/2, 0, clip_h1/2+clip_wall],
-                       [-clip_wall-clip_space/2, clip_l, clip_h2/2+clip_wall],
-                       [-clip_wall-clip_space/2, clip_l, -clip_h2/2],
-                       [-clip_wall-clip_space/2, 0, -clip_h1/2],
-                       [ clip_wall+clip_space/2,  0, clip_h1/2+clip_wall],
-                       [ clip_wall+clip_space/2, clip_l, clip_h2/2+clip_wall],
-                       [ clip_wall+clip_space/2, clip_l, -clip_h2/2],
-                       [ clip_wall+clip_space/2, 0, -clip_h1/2],
-               ], triangles = [
-                       [0, 2, 1], [3, 2, 0], [4, 5, 6], [6, 7, 4],
-                       [0, 1, 5], [5, 4, 0], [2, 3, 7], [7, 6, 2],
-                       [1, 2, 6], [6, 5, 1], [0, 7, 3], [7, 0, 4],
-               ]);
-               polyhedron(points = [
-                       [-clip_space/2, -epsilon, clip_h1/2],
-                       [-clip_space/2, clip_l+epsilon, clip_h2/2],
-                       [-clip_space/2, clip_l+epsilon, -clip_h2/2-epsilon],
-                       [-clip_space/2, -epsilon, -clip_h1/2-epsilon],
-                       [ clip_space/2, -epsilon, clip_h1/2],
-                       [ clip_space/2, clip_l+epsilon, clip_h2/2],
-                       [ clip_space/2, clip_l+epsilon, -clip_h2/2-epsilon],
-                       [ clip_space/2, -epsilon, -clip_h1/2-epsilon],
-               ], triangles = [
-                       [0, 2, 1], [3, 2, 0], [4, 5, 6], [6, 7, 4],
-                       [0, 1, 5], [5, 4, 0], [2, 3, 7], [7, 6, 2],
-                       [1, 2, 6], [6, 5, 1], [0, 7, 3], [7, 0, 4],
-               ]);
-               // bolt holes
-               translate([0, clip_bolt1_x, 0])
-                       rotate([0, 90, 0])
-                       translate([0, 0, -clip_wall-clip_space/2-epsilon])
-                       cylinder(r=1.5, h=2*clip_wall+clip_space+2*epsilon);
-               translate([0, clip_bolt2_x, 0])
-                       rotate([0, 90, 0])
-                       translate([0, 0, -clip_wall-clip_space/2-epsilon])
-                       cylinder(r=1.5, h=2*clip_wall+clip_space+2*epsilon);
-       };
-
-       translate([-clip_space, clip_bolt1_x, 0])
-       rotate([0, -90, 0])
-       bolt_mount(6, 3, 7, 14, 6);
-
-       translate([-clip_space, clip_bolt2_x, 0])
-       rotate([0, -90, 0])
-       bolt_mount(6, 3, 7, 14, 6);
+               hull() {
+                       translate([0, 0, fraen_h - pin_len])
+                               cylinder(r = fraen_diam/2 + pin_diam/2 + wall_thickness,
+                                       h = epsilon);
+                       for (angle = [0, 90, 180, 270])
+                               rotate([0, 0, angle])
+                                       translate([rear_pin_dist, rear_pin_dist, 0])
+                                               cylinder(r=wall_thickness+3.75/2, h = epsilon);
+               }
+               hull() {
+                       translate([0, 0, fraen_h - pin_len + epsilon])
+                               cylinder(r = fraen_diam/2,
+                                       h = epsilon);
+                       for (angle = [0, 90, 180, 270]) {
+                               rotate([0, 0, angle]) 
+                                       translate([rear_pin_dist, rear_pin_dist, -epsilon])
+                                               cylinder(r=3.75/2, h = epsilon);
+                               rotate([0, 0, angle+45])
+                                       translate([pin_offset, 0, fraen_h - pin_len + epsilon])
+                                               cylinder(r=pin_diam/2,
+                                                       h=epsilon);
+                       }
+               }
+       }
+}
 
-       translate([clip_space, clip_bolt1_x, 0])
-       rotate([0, 90, 0])
-       bolt_mount(6, 3, 7, 14, 128);
+rear_spring_w = 2*rear_pin_dist-rear_pin_diam-2;
+rear_spring_h = 1.5;
+rear_spring_center_w = 4;
+led_zoff = 6;
 
-       translate([clip_space, clip_bolt2_x, 0])
-       rotate([0, 90, 0])
-       bolt_mount(6, 3, 7, 14, 128);
+module rear_spring() {
+       translate([0, 0, wall_thickness/2])
+               cube([rear_spring_center_w, rear_spring_w, wall_thickness],
+                       center=true);
+       translate([0, rear_spring_w/2-wall_thickness/2,
+               (led_zoff-heatsink_thickness)/2])
+               cube([rear_spring_center_w,
+                       wall_thickness, led_zoff-heatsink_thickness],
+                       center=true);
+       translate([0, -rear_spring_w/2+wall_thickness/2,
+               (led_zoff-heatsink_thickness)/2])
+               cube([rear_spring_center_w,
+                       wall_thickness, led_zoff-heatsink_thickness],
+                       center=true);
 
-       clip_top();
-};
+       for (angle=[0, 180]) {
+               rotate([0, 0, angle])
+               translate([5.5, 0, rear_spring_h/2])
+                       rotate([0, 0, 45]) {
+                               cube([wall_thickness, 14, rear_spring_h],
+                                       center=true);
+               }
+       }
+}
 
-seat_clip();
+module heatsink_holder() {
+       for (angle = [0, 180]) {
+               rotate([0, 0, angle])
+                       translate([rear_pin_dist+wall_thickness, 0, (led_zoff+wall_thickness)/2])
+                       cube([rear_pin_diam/2+wall_thickness, 2*rear_pin_dist-rear_pin_diam-2, led_zoff+wall_thickness], center=true);
+       }
+}
 
-difference() {
-       union() {
-               hull() {
-                       translate([40, epsilon, 2])
-                               clip_top();
-                       clip_top();
+module lens_holder() {
+       difference() {
+               union() {
+                       translate([0, 0, fraen_h - pin_len])
+                               round_part();
+                       square_cone();
                };
+               
+               // 0.5mm hole in the bottom
+               // translate([side_barrier_x_offset-epsilon, -0.25, -epsilon])
+               translate([0, -0.25, (fraen_h - pin_len)/2])
+                       cube([infty, 0.5, infty]);
 
-               translate([40, 0, 25])
-                       rotate([-90, 0, 0])
-                               cylinder(r=34/2, h=clip_l);
+               // cable hole, 2*3mm
+               translate([rear_pin_dist, 0, 6+3])
+                       rotate([0, 0, 60])
+                               cube([infty, 2, 3]);
+
+               // side LED hole, 3mm
+               translate([0, 0, fraen_h - pin_len])
+                       rotate([90, 0, 0])
+                               cylinder(r=rear_pin_diam/2, h=infty, $fn=6);
+       };
+               
+       rear_spring();
+       heatsink_holder();
+};
 
+module full_joint() {
+       difference() {
                hull() {
-                       translate([clip_space/2+epsilon, 0, 0])
-                               cube([clip_wall-epsilon, clip_wall, clip_h1/2+2*clip_wall-epsilon]);
-                       translate([40, 0, 14+epsilon])
-                               cube([clip_wall-epsilon, clip_wall, 34/2]);
+                               intersection() {
+                                       rotate([-90, 0, 0])
+                                       scale([0.25, 1, 1])
+                                               cylinder(r = fraen_h-pin_len, h = rear_pin_dist + wall_thickness+rear_pin_diam/2);
+                                       translate([-infty/2, rear_pin_dist + wall_thickness + rear_pin_diam/2 - epsilon, 0])
+                                               cube(infty);
+                               };
+                       translate([clip_x_off, clip_y_off, 0])
+                               intersection() {
+                                       seat_clip_rotated();
+                                       translate([(fraen_h-pin_len)*tan(clip_angle)-clip_wall, -clip_space/2-0.1*clip_wall+epsilon, 0])
+                                               rotate([90+clip_x_rot, 0, 0])
+                                               scale([0.45, 1, 1])
+                                                       cylinder(r = fraen_h-pin_len, h = epsilon);
+                               };
                };
-       };
-       translate([40, 6, 25])
-               rotate([-90, 0, 0]) {
-                       cylinder(r=31/2, h=clip_l);
-                       fraen_lens();
-                       heatsink();
+               hull() {
+                       translate([0, 0, fraen_h - pin_len + epsilon])
+                               cylinder(r = fraen_diam/2 + pin_diam/2 + wall_thickness/2,
+                                       h = epsilon);
+                       for (angle = [0, 90, 180, 270])
+                               rotate([0, 0, angle])
+                                       translate([rear_pin_dist, rear_pin_dist, -epsilon])
+                                               cylinder(r=wall_thickness/2+3.75/2, h = epsilon);
                };
+       }
 };
 
-/*
-if (debug == 1) {
+module seat_clip_rotated() {
        difference() {
-               main($fn=64);
-               //translate([0, -100, 0]) cube([200, 200, 200], center=true);
-               rotate([0, 0, 40])translate([0, -100, 0]) cube([200, 200, 200], center=true);
+               translate([clip_space/2+clip_wall, 0, 0])
+               rotate([clip_x_rot, 0, 0])
+               translate([-clip_space/2-clip_wall, 0, sin(clip_x_rot)*(clip_space/2+clip_wall+epsilon)])
+                       seat_clip();
+               translate([-infty/2, -infty/2, -infty])
+                       cube(infty);
        };
-} else {
-       main($fn=128);
-}
-*/
+};
+                       
+module main() {
+       lens_holder();
+       translate([clip_x_off, clip_y_off, 0])
+               seat_clip_rotated();
+       // xy_joint();
+       // yz_joint();
+       full_joint();
+};
+
+
+// scale([1, -1, 1]) main($fn=128);
+main($fn = 128);
+       // vnitrni prumer kruhu by mel byt 30.75mm
+       // vnejsi prumer aspon 35 mm
+       // pin od stredu 10.35mm na x a y
+       // prumer pinu 4 mm
+       // pin ma od cela do zabrany 4.2mm, celkove by mel mit 9.2mm
+
+       // piny by mely pokracovat jeste tak 4mm pod nulu,
+       // a pak uz muze jit konv.obal do ctverce
+       // vnitrni rozmery ctverce 21.5x21.5, zakulacene rohy prumer 3.5
+       // vrch chladice (s LEDkou) -18.5
+       // konec nozicek -24.5