On Sunday, October 1, 2023 at 11:40:38 PM EDT, Sanjeev Prabhakar sprabhakar2006@gmail.com wrote:
Can you make a video to explain beginners how to get started with your library with some simple use cases.
It's difficult for me to understand how is it working.
I am not cool enough for videos.
Probably this is a bit too obscure for general usage --- it is my reaction to OpenSCAD not having CAM functionality, and there not being a CAD/CAM program for CNC routers which I can both wrap my mind around and which works with the control I want.
Basically one uses this library setup to make an OpenSCAD file which will make a 3D file and a matching G-code file which will cut it out --- the first test file is quite prosaic, a block w/ a single angled cut in it (and one which is not particularly good practice since it cuts a slot deeper than the endmill diameter in a single pass --- working on improving that next).
I'll try to write it up and document the source at:
https://willadams.gitbook.io/design-into-3d/programming
(there's a bit of that there, and it should at least provide the background)
It's not interested unless one wants to work in subtractive G-code directly (for additive see: http://fullcontrolgcode.com/ ) and has a CNC router/mill to run the G-code on --- I suppose one could use CAMotics to get a 3D model, but that would be a lot more awkward than just exporting an STL from OpenSCAD.
Step-by-step instructions --- download and place the library files:
https://github.com/WillAdams/gcodepreview/blob/main/pygcodepreview.scad
https://github.com/WillAdams/gcodepreview/blob/main/gcodepreview.py
https://github.com/WillAdams/gcodepreview/blob/main/gcodepreview.scad
in the OpenSCAD library folder, e.g.,:
"C:\Users\willa\OneDrive\Documents\OpenSCAD\libraries\gcodepreview.py""C:\Users\willa\OneDrive\Documents\OpenSCAD\libraries\gcodepreview.scad""C:\Users\willa\OneDrive\Documents\OpenSCAD\libraries\pygcodepreview.scad"
Then install:
http://www.guenther-sohler.net/openscad/
then create a file which:
loads the files in question:
use <gcodepreview.py>;use <pygcodepreview.scad>;include <gcodepreview.scad>;
has the appropriate variables:
/* [G-code] /Gcode_filename = "gcode.nc"; / [G-code] /generategcode = true;
/ [CAM] /feedrate = 850;/ [CAM] /plungerate = 425;/ [CAM] /toolradius = 1.5875;/ [CAM] /squaretoolno = 102;
/ [Feeds and Speeds] /plunge = 100;/ [Feeds and Speeds] /feed = 400;/ [Feeds and Speeds] /speed = 16000;/ [Feeds and Speeds] /square_ratio = 1.0; // [0.25:2]/ [Feeds and Speeds] /small_V_ratio = 0.75; // [0.25:2]/ [Feeds and Speeds] /large_V_ratio = 0.875; // [0.25:2]
/ [Stock] /stocklength = 219;/ [Stock] /stockwidth = 150;/ [Stock] /stockthickness = 8.35;/ [Stock] /zeroheight = "Top"; // [Top, Bottom]/ [Stock] /stockorigin = "Center"; // [Lower-Left, Center-Left, Top-Left, Center]/ [Stock] */retractheight = 9;
and has appropriate commands --- hopefully the command names are sensible enough:
opengcodefile(Gcode_filename);
The one tricky part is one has to declare the difference command and make the stock:
difference() {setupstock(stocklength, stockwidth, stockthickness, zeroheight, stockorigin);
and then all the other things are subtracted from it:
movetosafez();
toolchange(squaretoolno,speed * square_ratio);
movetoorigin();
movetosafeheight();
cutoneaxis_setfeed("Z",-1,plunge*square_ratio);
the file actually only makes one "real" cut --- the rest of it is to make a G-code file which cuts the same as the OpenSCAD files shows.
cutwithfeed(stocklength/2,stockwidth/2,-stockthickness,feed);
closecut();}
closegcodefile();
Here's the matching G-code file:
(gcode.nc)(stockMin: -109.5, -75mm, -8.35mm)(stockMax:109.5mm, 75mm, 0.00mm)(STOCK/BLOCK, 219, 150, 8.35, 109.5, 75, 8.35)G90G21(Move to safe Z to avoid workholding)G53G0Z-5.000(Toolpath)M05(TOOL/MILL,3.17, 0.00, 0.00, 0.00)M6T102M03S16000(PREPOSITION FOR RAPID PLUNGE)G0X-0.000Y0.000Z9G1Z-1F100G1 X109.5 Y75 Z-8.35F400G53G0Z-5.000M05M02
which, as noted, if you load it into a G-code previewer will show a preview to match.
William