Sunday, July 10, 2011

Translating toolpaths with scriptop

I have committed a change to my git repo that lets me snap new coordinates anywhere on the drawing and then have my toolpaths generated relative to it. This becomes useful if I import a dxf file and the geometry isn't anywhere near where it needs to be for sensible fixture offsets. Here's an example:



Notice how the origin/datum is to the far left of the rectangular sketch. To make things a little easier, create a new coordinate system with 'Set Origin' (I like to use the 'Pick 1 Point' option).



Snap the new coordinate datum to the upper left corner of the sketch:



Create a 'ScriptOp' operation and copy/paste the new coordinate object into it. Then you can position the ScriptOp operation just before a regular machining operation,such as Profiling. When you post process, the gcode will be shifted by the distance that the new coordinate object is away from the original origin:



This is useful if you want to place your fixture offset in a familiar place. In the case of this sketch, the fixture offset (G54-G59) is placed in the upper left corner. I like to place a fixture offset on that corner because I touch off to the fixed back jaw of my vise and the left side of the part. There are always other ways of doing things, but that is a common one.

Note for my fellow git brothers: I changed nc.py, iso.py, and ScriptOp.cpp to make this happen :)

Saturday, July 9, 2011

Manual Tool Changer Carousel

My Bridgeport CNC mill uses 'Quick Switch 30' tooling. I like it for prototype work- it's easy to change out a tool by hand. All that's required is a spanner wrench at the spindle nose to loosen and tighten the knurled ring. It only takes a quarter turn to secure the tool in the taper. When I bought the mill, it came with a small aluminum plate that had 5 holes in it for holding tools, that could be clamped down to the table. This made it convenient to have 5 tools within reach while running programs. This is not enough for the programs that I am running nowadays. Right now, I have 29 Quick Switch 30 toolholders and I like to use the hell out of them during a program. Sometimes I have 8 different tools in a program.
I have been thinking about using an old Heathkit turntable platter that I have had in my stock pile (junk pile) for many years- to make a tool carousel. It's a substantial aluminum casting that's .20" thick in it's cross section and about 11" diameter. It looked like I could put 10 holes in it that would comfortably hold 10 QC 30 tools.
I ended up writing a program in HeeksCNC, using scriptop to bore holes with an end mill. It ended up being pretty slick- it descends in a helical motion and then spirals out with an even chip load on the tool. It was kind of fun to write and use.







Here's a link to my 'array_of_holes.heeks' file that was used for this project:
https://github.com/danielfalck/heekscnc/blob/master/contrib/scriptop/array_of_holes.heeks

Friday, July 1, 2011

Creating a rectangle with radiused corners (fillets)

I am just copy pasting this in from a reply to a question on the heekscad user's list on google groups. This might be helpful to some.


Q: How do I create a rectangular cut-out, but with rounded
corners?

A: Doing a rectangle with fillets in heekscad is pretty easy- use the sketch toolbar and look for the icon that is square- the tooltip for this is 'Start drawing rectangles'. After you select this, a box with appear in the left hand column of HeeksCAD that is titled 'input'. There is an entry for 'radius'. It might not work for you on the first try, so fill it in with a radius value and attempt to draw your rectangle on the screen. If your rectangle doesn't have fillets, right click with the mouse 'stop drawing' and then try making the rectangle all over again- then your fillet/radius values should stick this time.

Sunday, May 22, 2011

Cutter Radius Compensation

I do a lot of milling in my home shop with my CNC Bridgeport mill. This machine has a Centroid M40 control on it that works pretty well. It has a feature called 'cutter radius compensation' in it that is standard on most modern controls. This allows for variations in cutter size or cutting conditions such that the machine operator (me) can make the toolpath run closer or further from the part profile. Cutter radius compensation is a subject that is covered pretty well in cnc programming textbooks, so I won't get into it much here, except to mention a few things about programming to 'part profile' or programming to 'cutter centerline'. Over 20 years ago, I was taught to program a part to 'part profile' like this, when using cutter radius comp:




Using this method, it's easy to look at a blueprint and just write the program by hand. You can just enter the end points and center points of lines and radius' and add a G41 (or G42) to your code. Once the program is done,it's pretty intuitive to change the diameter value in the control to the actual diameter of the cutter and get a reasonable part milled. If your end mill is .499 inches in diameter, just enter that as the D value in your control. If you want to make the part a bit bigger all around, enter the value as .501 and 'trick' the control into moving the path away from the part profile. With just a little simple math, done in your head, it's easy to manipulate the size of the part.

After moving across the country, to the west coast, I was taught a different way of using cutter radius compensation. A part programmer can use a CAM system to make the cutter path the radius value of the cutter away from the part profile and then use very small values in the D value of the control to manipulate the size of the part.


The cutter value can be .000" to be 'on the line' and you can change it by .001" or -.001" to manipulate the part profile.
I guess you could call this the 'West Coast' method. Nowadays, I am using this method with my home shop mill. I've just gotten used to it. I'm using my Centroid post processor with HeeksCNC and things work well for this. In the post, there is a bit of code that adds a lead in line to the roll on radius. This is needed to give the control a bit of distance to move the cutter before it reaches an arc, while doing the cutter compensation. If I don't have a straight line on the first line of a crc move, the control gives an error. It works the same way on the lead out line just after the roll off radius. I don't think EMC2 works this way- I think you can start with a roll on radius with a crc command, without getting an error. This seems to be an exception in the cnc control world though. Most commercial controls expect a straight line.

Friday, November 5, 2010

Creating Cross Sections of Parts in HeeksPython

Ok, I worked out a scheme for creating a cross sectional view of a simple assembly in HeeksPython. I altered my dxf_to_heekspython script slightly to let the sketches have unique IDs. Then it's possible to create objects out of them and do CSG operations to the unique objects.
Here is a sample script:

import HeeksPython as cad
import sys
sys.path.insert(0,'/home/dan/heeks/heekspython2/examples')
import dxf_to_heekspython
from math import pi

a1 = 90*(pi/180)


units = 25.4 #inch units
cad.setcolor(255,255,255)
r1='/home/dan/Documents/drawings/revolve1.dxf'
part1 = "cad.setcolor(0,0,0)\n"
part1 = dxf_to_heekspython.gen_heekspython_entities(r1,1)
part1 = part1 +"cad.scale(sketch1,0,0,0,units)\n"
part1 = part1 +"cad.setcolor(255,255,255)\n"
part1 = part1 +"cad.revolve(sketch1,360)\n"
part1 = part1 +"cup = cad.getlastobj()\n"
exec(part1)
cad.setcolor(0,255,0)
r2='/home/dan/Documents/drawings/revolve2.dxf'
part2 = "cad.setcolor(0,0,0)\n"
part2 = dxf_to_heekspython.gen_heekspython_entities(r2,2)
part2 = part2 +"cad.scale(sketch2,0,0,0,units)\n"
part2 = part2 +"cad.setcolor(0,255,0)\n"
part2 = part2 +"cad.revolve(sketch2,360)\n"
part2 = part2 +"sleeve = cad.getlastobj()\n"
exec(part2)

cad.view_extents()

c1= '/home/dan/Documents/drawings/cutaway.dxf'
cut = dxf_to_heekspython.gen_heekspython_entities(c1,3)
cut = cut + "cad.scale(sketch3,0,0,0,units)\n"
cut = cut + "cad.revolve(sketch3,90)\n"
cut = cut + "cutter = cad.getlastobj()\n"
cut = cut + "cad.rotate(cutter,0,0,0,1,0,0,a1)"
exec(cut)

cad.cut(cup,cutter)
cad.cut(sleeve,cutter)

Here is the assembly:


Just prior to importing these dxf files into HeeksPython I had also added fillets to all the corners in Caduntu (yes, this works well now Ries!). So now I can work in my favorite 2D CAD program and my favorite 3D CADCAM program to create assemblies with python.


It's easy to alter the design of the parts in this assembly by simply changing them in the dxf files:



Then re run the python script in HeeksPython:



One major improvement that I would like to do is to make the dxf_to_heekspython script deal with layers. Then I could do all the dxf editing in one file in Caduntu.
As I learn more about C++ programming, I might be able to utilize the functions in dxf.cpp from HeeksCAD itself. Importing would run much faster and I could take advantage of the things that already work well, like layers and importing polylines (which isn't currently implemented in the python script).

More DXF to HeeksPython Experiments

I created a python script to import a dxf file into HeeksPython, using parts of Doug Blanding's excellent python program 'Cadvas'. Doug and I have emailed back and forth over the years and he is happy to see his creation used for different things. He's not supporting it anymore, but in it's present state, it's a very good program to study. It's very simple and well laid out.
Included with Cadvas is the dxf.py module. I have copied some of it and altered it to suite my needs for dxf to heekspython conversion and uploaded the script into the /examples directory in the HeeksPython project. This script is called dxf_to_heekspython.py. Here are two profiles created in Qcad, that I want to manipulate in HeeksPython:





Here is a script to bring them into HeeksPython as separate revolved solid parts:

import HeeksPython as cad
import sys
sys.path.insert(0,'/home/dan/heeks/heekspython2/examples')
import dxf_to_heekspython


units = 25.4 #inch units
cad.setcolor(255,255,255)
r1='/home/dan/Documents/drawings/revolve1.dxf'
part1 = "cad.setcolor(0,0,0)\n"
part1 = dxf_to_heekspython.gen_heekspython_entities(r1)
part1 = part1 +"cad.scale(sketch,0,0,0,units)\n"
part1 = part1 +"cad.setcolor(255,255,255)\n"
part1 = part1 +"cad.revolve(sketch,360)"
exec(part1)
cad.setcolor(0,255,0)
r2='/home/dan/Documents/drawings/revolve2.dxf'
part2 = "cad.setcolor(0,0,0)\n"
part2 = dxf_to_heekspython.gen_heekspython_entities(r2)
part2 = part2 +"cad.scale(sketch,0,0,0,units)\n"
part2 = part2 +"cad.setcolor(0,255,0)\n"
part2 = part2 +"cad.revolve(sketch,360)\n"
part2 = part2 +"p1 = cad.getlastobj()\n"
exec(part2)

cad.view_extents()

Here is a screenshot of the resulting parts generated with this script:



The advantage of using this dxf_to_heekspython is that the dxf entities can be manipulated/transformed as they are brought in. I have some things that I would like to do with some dxf files - create solids by revolving them around the X axis. Eventually I will create cutaway views using this technique.

Friday, October 29, 2010

Well, it's been quite a long since I posted anything (obviously). I've been busy trying to learn a bit of C++ coding, in my quest to learn the ins and outs of HeeksCAD,HeeksCNC, and HeeksPython.
I am mostly doing the 'learn by example' route, plus a few good tutorials, books, and some very helpful advice from Dan Heeks himself. If I get into a bind, he usually can point to some example code that helps me understand things.
I have been able to add quite a few new functions to HeeksPython and a few things to HeeksCAD itself. HeeksPython is fun to add functions to, because there is a lot of 'low hanging fruit' so to speak. It's pretty easy to add a python binding to HeeksCAD, if there is already a C++ function in /interface/HeeksCADInterface.cpp . I started out by copying jonpry's existing functions ('NewArc', 'NewLine' etc). As I have gotten a little more experience, I have gotten more adventurous and added functions for deriving point data from the GraphicsCanvas itself. I also found a way of adding fillets to pairs of 2D lines. Over the last month, I have added ways of creating a new coordinate system,returning the parameters of coordinate systems,text,and a way of importing dxf files from python.
The HeeksPython function 'importdxf' is exiting for me because I have plans for creating solids quickly with the aid of other 2D cad programs like caduntu , qcad, or even true-type-tracer-dxf. Having HeeksPython loaded with functionality will help automate the design process somewhat.
Here is an example of a script that uses true-type-tracer-dxf to create some text on the HeeksCAD graphics screen:

import os
import HeeksPython as cad

path = '''/home/dan/Documents/drawings/ttt/'''
program = '''truetype-tracer-dxf'''
phrase = ''' \' this is a test \' '''
pipe = ''' > '''
file = '''aphrase.dxf'''

out = program + phrase + pipe + path + file
os.system(out)

f = path + file

cad.importdxf(f)
cad.view_extents()