// // NopSCADlib Copyright Chris Palmer 2018 // nop.head@gmail.com // hydraraptor.blogspot.com // // This file is part of NopSCADlib. // // NopSCADlib is free software: you can redistribute it and/or modify it under the terms of the // GNU General Public License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. // // NopSCADlib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. // See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with NopSCADlib. // If not, see . // // //! NEMA stepper motor model. // include <../core.scad> include use <../utils/tube.scad> use <../utils/thread.scad> use use function NEMA_width(type) = type[1]; //! Width of the square face function NEMA_length(type) = type[2]; //! Body length function NEMA_radius(type) = type[3]; //! End cap radius function NEMA_body_radius(type) = type[4]; //! Body radius function NEMA_boss_radius(type) = type[5]; //! Boss around the spindle radius function NEMA_boss_height(type) = type[6]; //! Boss height function NEMA_shaft_dia(type) = type[7]; //! Shaft diameter function NEMA_shaft_length(type)= type[8]; //! Shaft length above the face, if a list then a leadscrew: length, lead, starts function NEMA_hole_pitch(type) = type[9]; //! Screw hole pitch function NEMA_holes(type) = [-NEMA_hole_pitch(type) / 2, NEMA_hole_pitch(type) / 2]; //! Screw positions for for loop function NEMA_big_hole(type) = NEMA_boss_radius(type) + 0.2; //! Clearance hole for the big boss stepper_body_colour = "black"; stepper_cap_colour = grey(50); stepper_machined_colour = grey(90); module NEMA_outline(type) //! 2D outline intersection() { side = NEMA_width(type); square([side, side], center = true); circle(NEMA_radius(type)); } module NEMA(type, shaft_angle = 0) { //! Draw specified NEMA stepper motor side = NEMA_width(type); length = NEMA_length(type); body_rad = NEMA_body_radius(type); boss_rad = NEMA_boss_radius(type); boss_height =NEMA_boss_height(type); shaft_rad = NEMA_shaft_dia(type) / 2; cap = 8; vitamin(str("NEMA(", type[0], "): Stepper motor NEMA", round(NEMA_width(type) / 2.54), " x ", length, "mm")); thread_d = 3; // Is this always the case? module cap_shape(end) difference() { intersection() { square([side, side], center = true); circle(NEMA_radius(type), $fn = 360); } if(end > 0) for(x = NEMA_holes(type), y = NEMA_holes(type)) translate([x, y]) circle(d = thread_d); } color(stepper_body_colour) // black laminations translate_z(-length / 2) linear_extrude(length - cap * 2, center = true) intersection() { square([side, side], center = true); circle(body_rad); } color(stepper_machined_colour) { tube(or = boss_rad, ir = shaft_rad + 2, h = boss_height * 2); // raised boss linear_extrude(eps) cap_shape(1); } color(stepper_cap_colour) // aluminium end caps for(end = [-1, 1]) translate_z(-length / 2 + end * (length - cap) / 2) linear_extrude(cap, center = true) cap_shape(end); if(show_threads) for(x = NEMA_holes(type), y = NEMA_holes(type)) translate([x, y, -cap / 2]) female_metric_thread(thread_d, metric_coarse_pitch(thread_d), cap, colour = stepper_cap_colour); shaft = NEMA_shaft_length(type); translate_z(-5) rotate(shaft_angle) if(!is_list(shaft)) color(stepper_machined_colour) cylinder(r = shaft_rad, h = shaft + 5); // shaft else not_on_bom() leadscrew(shaft_rad * 2, shaft.x + 5, shaft.y, shaft.z, center = false) translate([0, side / 2, -length + cap / 2]) rotate([90, 0, 0]) for(i = [0 : 3]) rotate(225 + i * 90) color(["red", "blue","green","black"][i]) translate([1, 0, 0]) cylinder(r = 1.5 / 2, h = 12, center = true); } module NEMA_screw_positions(type, n = 4) { //! Positions children at the screw holes pitch = NEMA_hole_pitch(type); for($i = [0 : 1 : min(n - 1, 4)]) rotate($i * 90) translate([pitch / 2, pitch / 2]) rotate($i * -90) children(); } module NEMA_screws(type, screw, n = 4, screw_length = 8, earth = undef) //! Place screws and optional earth tag NEMA_screw_positions(type, n) if($i != earth) screw_and_washer(screw, screw_length, true); else rotate($i > 1 ? 180 : 0) ring_terminal(M3_ringterm) star_washer(screw_washer(screw)) screw(screw, screw_length);