separate dimensions from form
[challenge-bot] / 3d-printables / sonar-table-top-holder.scad
index ef9e0f51af448fc803269f75936b216015d32ca4..23279e40736dbab68368ba2076d4f6a0c7e70093 100644 (file)
 // https://gitorious.org/ozzloy/challenge-bot
 // https://github.com/waynegramlich/challenge-bot
 
+/*
+  this holds an hc-sr04 sonar sensor to a 3/16 inch deck.
+  http://fritzing.org/projects/hc-sr04-project
+  it can hold the sonar sensor either facing down, or forwards.
+  when facing down, it can detect if it passes over the edge of a table.
+  when facing forwards, it can detect and follow something in front of it.
+ */
+
 $fn = 60;
 
-// 3/16 inch in mm deck_depth = 4.7625;
-// 1/4 inch in mm = 6.35
-// subtract a little to be a squeeze fit
-deck_depth = 4.7625 - 0.4;
-sonar_plate_width = 20;
-// sonar sensor measurements taken with calipers:
-//  10.82 in between, 42.33 outside, 15.82 diameter
-// measured diameter of 15.82 with calipers,
-//  but when printed ends up being too small
-sonar_sensor_radius = 15.82 / 2 + 0.3;
-sonar_sensor_height = 13.8;
-between_sensor_centers = 15.82 + 10.82;
-sonar_plate_length = 3 + between_sensor_centers + sonar_sensor_radius + 3;
-sonar_holder_length = sonar_plate_length + 10;
-sonar_holder_width = sonar_plate_width + 3;
-sonar_holder_depth = 4;
-
-deck_holder_length = 30;
-
-module sensors(){
-  translate([between_sensor_centers / 2, 0, 0]){
-    cylinder(r = sonar_sensor_radius, h = sonar_sensor_height);}
-  translate([-between_sensor_centers / 2, 0, 0]){
-    cylinder(r = sonar_sensor_radius, h = sonar_sensor_height);}}
-
-module sensor_holder(){
+include <sonar-table-top-holder-dimensions.scad>
+use <oshw.scad>
+oshw_dy = 120.366;
+oshw_dx = 133.888;
+
+module sonar_holder_2d() {
+  difference() {
+    square([sonar_holder_length, sonar_holder_width]); } }
+
+module sonars(){
+  translate([between_sonar_centers / 2, 0, 0]){
+    cylinder(r = sonar_radius, h = sonar_height);}
+  // for the variance with which the physical sonar cylinders are placed
+  translate([between_sonar_centers / 2 - between_sonar_centers_variance, 0, 0]){
+    cylinder(r = sonar_radius, h = sonar_height);
+    translate([0, -sonar_radius, 0]){
+      cube([between_sonar_centers_variance, sonar_diameter, sonar_height]);}}
+  translate([-between_sonar_centers / 2, 0, 0]){
+    cylinder(r = sonar_radius, h = sonar_height);}}
+
+module sonar_holder(){
+  elbow_length = deck_depth - 0.5;
+  rounded_corner_radius = buffer;
   difference(){
     cube([sonar_holder_length, sonar_holder_width, sonar_holder_depth]);
     translate([sonar_holder_length / 2, sonar_holder_width / 2, -0.05]){
-      sensors();}}
+      sonars();}
+    translate([sonar_holder_length,
+               sonar_holder_width,
+               0]){
+      corner_rounder(rounded_corner_radius,
+                     sonar_holder_depth,
+                     "bottom-right");}}
   translate([sonar_holder_length, 0, 0]){
-    cube([sonar_holder_depth + 0.7, deck_depth, deck_depth - 0.7]);
-    translate([sonar_holder_depth + 0.7, 0, 0]){
-      // subtract a little bit (0.3) to make it fit
-      cube([deck_depth - 0.7, sonar_holder_width, deck_depth - 0.7]);}}}
+    cube([elbow_length, deck_depth, sonar_holder_depth]);
+    translate([elbow_length, 0, 0]){
+      linear_extrude(height = sonar_holder_depth){
+        polygon([[                 0, 0],
+                 [sonar_holder_depth, 0],
+                 [sonar_holder_depth, sonar_holder_width / 2],
+                 [                 0,
+                  sonar_holder_width / 2 + sonar_holder_depth]]);}
+      translate([0, (sonar_holder_width + sonar_holder_depth) / 2, 0]){
+        cube([sonar_holder_depth / 2,
+              (sonar_holder_width - sonar_holder_depth) / 2 + 0.8,
+              sonar_holder_depth]);}
+      translate([-1.7, sonar_holder_width + 0.8, 0]){
+        linear_extrude(height = sonar_holder_depth){
+          polygon([[                           0, 0],
+                   [sonar_holder_depth / 2 + 1.7, 4],
+                   [sonar_holder_depth / 2 + 1.7, 0]]);}}}}}
 
 module deck_holder(){
   deck_holder_width = sonar_holder_width - deck_depth;
-  cube([deck_holder_length, sonar_holder_depth, deck_holder_width]);
-  cube([sonar_holder_depth,
-        sonar_holder_depth * 2 + deck_depth,
-        deck_holder_width]);
-  translate([0, sonar_holder_depth + deck_depth, 0]){
-    cube([deck_holder_length, sonar_holder_depth, deck_holder_width]);}
-  translate([sonar_holder_depth + deck_depth, 0, 0]){
-    cube([sonar_holder_depth,
-          sonar_holder_depth * 2 + deck_depth,
-          deck_holder_width]);}}
-
-translate([0, sonar_holder_depth * 2 + deck_depth + 2, 0]){
-  sensor_holder();}
-deck_holder();
+  deck_holder_height = sonar_holder_depth * 2 + deck_depth;
+  linear_extrude(height = deck_holder_width){
+    difference(){
+      square([deck_holder_length, deck_holder_height]);
+      translate([sonar_holder_depth, sonar_holder_depth]){
+        square(deck_depth);}
+      translate([deck_holder_height, sonar_holder_depth]){
+        square([deck_holder_length - (deck_holder_height), deck_depth]);}}}
+  translate([deck_holder_length - oshw_dy * 0.05, 0, deck_holder_width / 2])
+    scale([0.1, 1, 0.1])
+      rotate(v = [1, 0, 0], a = 90)
+        rotate(90)
+          linear_extrude(height = 0.5)
+            oshw();
+  translate([deck_holder_length - oshw_dy * 0.05,
+             deck_holder_height + 0.5,
+             deck_holder_width / 2])
+    rotate(v = [1, 0, 0], a = 90)
+      rotate(90)
+        scale([0.1, 0.1, 1])
+          linear_extrude(height = 0.5)
+            oshw();}
+
+module corner_rounder_2d(radius, corner_name="top-left"){
+  rotate_for_corner = (corner_name == "top-left") ? 0 :
+    ((corner_name == "top-right") ? -90 :
+     ((corner_name == "bottom-left") ? 90 :
+      ((corner_name == "bottom-right") ? 180 :
+       1 / 0)));
+  rotate(rotate_for_corner){
+    difference (){
+      square(radius);
+      translate([radius, radius]){
+        circle(radius);}}}}
+
+module corner_rounder(radius, height, corner_name="top-left"){
+  linear_extrude(height = height){
+    corner_rounder_2d(radius, corner_name);}}
+
+sonar_holder();