1
0
mirror of https://github.com/nophead/NopSCADlib.git synced 2025-08-06 23:46:30 +02:00

Added comments and make holes a linear_extrude result

This commit is contained in:
Dirkjan Krijnders
2023-03-11 15:00:10 +01:00
parent c5fab08a45
commit ebfb330ac6
2 changed files with 44 additions and 47 deletions

View File

@@ -1,78 +1,75 @@
include <../utils/core/core.scad> include <../utils/core/core.scad>
include <../utils/rounded_polygon.scad>
function pi_name(type) = type[0]; function pi_base_width(type) = type[1]; //! Width of the base
function pi_base_height(type) = type[3]; function pi_base_length(type) = type[2]; //! Length of the base
function pi_base_length(type) = type[2]; function pi_base_height(type) = type[3]; //! Height of the base
function pi_base_width(type) = type[1]; function pi_gap_height(type) = type[4]; //! Heigth of the gap where the light can be interrupted
function pi_gap_height(type) = type[4]; function pi_gap_width(type) = type[6]; //! Width of the gap
function pi_gap_width(type) = type[6]; function pi_stem_width(type) = type[5]; //! Width of the stems
function pi_stem_width(type) = type[5]; function pi_hole_diameter(type) = type[7]; //! Diameter of the mounting holes
function pi_hole_diameter(type) = type[7]; function pi_color(type) = type[8]; //! Color of photo interrupter
function pi_color(type) = type[8]; function pi_pcb(type) = type[9]; //! Parameter for the support PCB, created with pi_pcb
function pi_pcb(type) = type[9];
module pi_hole_locations(type) { module pi_hole_locations(type) { //! Locations of photo interrupter mounting holes
translate([0, -(pi_base_length(type) - pi_base_width(type)) / 2, 0]) translate([0, -(pi_base_length(type) - pi_base_width(type)) / 2, 0])
children(); children();
translate([0, (pi_base_length(type) - pi_base_width(type)) / 2, 0]) translate([0, (pi_base_length(type) - pi_base_width(type)) / 2, 0])
children(); children();
} }
module pi_pcb_hole_locations(pcb) { module pi_pcb_hole_locations(pcb) { //! Locations of the PCB holes
for (xy = pcb[7]) { for (xy = pcb[7]) {
translate([xy[0], xy[1], 0]) translate([xy[0], xy[1], 0])
children(); children();
} }
} }
module pi_pcb(type) { module pi_pcb(type) { //! Draw the support PCB
pcb = pi_pcb(type); pcb = pi_pcb(type);
color(pcb[6]) { color(pcb[6]) {
difference() { translate([0, 0, -pcb[2]]) {
union() { linear_extrude(pcb[2]) {
translate([0, 0, -pcb[2]]){ difference() {
if (pcb[4]) { rounded_polygon([[0, -(pi_base_length(type) - pi_base_width(type)) / 2, -pi_base_width(type) / 2],
hull() { [pi_base_width(type) / 2, -pcb[1]/2, eps],
pi_hole_locations(type) [pcb[0]+1, -pcb[1]/2, eps],
cylinder(h=pcb[2], d=pi_base_width(type)); [pcb[0]+1, pcb[1]/2, eps],
} [pi_base_width(type) / 2, pcb[1]/2, eps],
} [0, (pi_base_length(type) - pi_base_width(type)) / 2, -pi_base_width(type) / 2]
} ]);
translate([pcb[4], 0, -pcb[2]/2]) { pi_pcb_hole_locations(pcb)
cube([pcb[0], pcb[1], pcb[2]], center = true); circle(d = pcb[8]);
} pi_hole_locations(type)
} circle(d=pi_hole_diameter(type));
translate([0, 0, -pcb[2]]) { }
pi_pcb_hole_locations(pcb)
cylinder(h=pcb[2]+0.1, d = pcb[8]);
pi_hole_locations(type)
cylinder(h=pcb[2]+0.1, d=pi_hole_diameter(type));
} }
} }
} }
} }
module photo_interrupter(type) { module photo_interrupter(type) { //! Draw the photo interrupter, with PCB
vitamin(pi_name(type)); vitamin(type[0]);
color(pi_color(type)) color(pi_color(type)) {
difference() { linear_extrude(pi_base_height(type)) {
union() { difference() {
hull() { hull() {
pi_hole_locations(type)
circle(d = pi_base_width(type));
}
pi_hole_locations(type) pi_hole_locations(type)
cylinder(h = pi_base_height(type), d = pi_base_width(type)); circle(d = pi_hole_diameter(type));
} }
translate([-pi_base_width(type)/2, -(pi_gap_width(type)/2 + pi_stem_width(type)), 0])
cube([pi_base_width(type), pi_stem_width(type), pi_gap_height(type) + pi_base_height(type)]);
translate([-pi_base_width(type)/2, pi_gap_width(type)/2, 0])
cube([pi_base_width(type), pi_stem_width(type), pi_gap_height(type) + pi_base_height(type)]);
} }
pi_hole_locations(type) translate([-pi_base_width(type)/2, -(pi_gap_width(type)/2 + pi_stem_width(type)), 0])
cylinder(h = pi_base_height(type), d = pi_hole_diameter(type)); cube([pi_base_width(type), pi_stem_width(type), pi_gap_height(type) + pi_base_height(type)]);
translate([-pi_base_width(type)/2, pi_gap_width(type)/2, 0])
cube([pi_base_width(type), pi_stem_width(type), pi_gap_height(type) + pi_base_height(type)]);
} }
pi_pcb(type); pi_pcb(type);
} }
module pi_cutout(type) { module pi_cutout(type) { //! Shape to substract for fitting a photo interrupter
hull() { hull() {
pi_hole_locations(type) pi_hole_locations(type)
cylinder(h = pi_base_height(type), d = pi_base_width(type)); cylinder(h = pi_base_height(type), d = pi_base_width(type));

View File

@@ -1,4 +1,4 @@
PH1 = ["PH1: Photo interrupter", 6.4, 25.9 , 3.5, 8.6, 4.1, 5.9, 3, "black", [22, 20, 1.6, true, 11-3.2, 0, "blue",[[8.3, -7.5], [8.3, 7.5]], 3]]; PH1 = ["PH1: Photo interrupter", 6.4, 25.9 , 3.5, 8.6, 4.1, 5.9, 3, "grey", [22, 20, 1.6, true, 11-3.2, 0, "blue",[[8.3, -7.5], [8.3, 7.5]], 3]];
photo_interrupters = [PH1]; photo_interrupters = [PH1];