My friend Gary Hinze introduced me to Paul Snyder who is into CNC and so forth.
I know Gary from the Squirrel Model Airplane project. He lives in California.
Paul sent me this picture of his cnc machine with a pen mounted in it. He’s been working on Postscript codes and converting them to g-code.
Here an explanation:
I’ve had some limited success in translating PostScript arcto function calls into G codes. The picture shows outline of an oak leaf from a logo. The original file was in PostScript. The outline was generated by a series of arcto calls. This function takes as arguments two points and a radius (p1, p2, r) along with the current position (p0) It then draws a straight segment along line p0p1 up to a point of tangency, then draws an arc of radius r tangent to both lines p0p1 & p1p2. The function returns coordinates of both points of tangency. I pulled the parameters for the arcto calls from the original PostScript file & plopped them into a spreadsheet which then calculated the appropriate corresponding parameters needed to generate the same curve using G codes. Then I copied the G code parameters from the spreadsheed into a text editor. The G code syntax was added around the numbers using macros written in the text editor, so the actual typing wasn’t bad, but making sure the macros and the spreadsheet were bug free was time consuming.
The stylus is a modified ballpoint pen. In order to get a nice dark line for the photograph the point is slightly spring-loaded against the drawing surface. The arcs have a sort of skewed Gumby-head shape from the horizontal slop in the pen. I have another more rigid Rapidograph-like pen that draws much more circular arcs, but whose tracings don’t photograph well because the Z coordinate is so critical. Anyway, I’m hoping that when I go to the next step, which is cutting, I’ll get a nice fair shape on the curves.
I’ve attached the following files in a zip file.
leaf.ngc — the g-code file to draw the outline
phillet_c.xls — the spreadsheet containing all the calculations
phillet_c2.csv — extract of the spreadsheet with only columns for tangent points & arc center offsets
basicProblemDiag.gif — showing the geometric meanings of the columns in the spreadsheet
Referring to the .gif the process only involves equations for straight line and distance between two points.
Given: points P1, P2, P3 and a radius r.
Find: — points of tangency of an arc of radius r to lines P1P2 & P2P3.
— center of the circle of radius r tangent to both lines
The order of calculation is:
–find L1 thru P1 & P2
–find d1, the x-intercept of L1
–find LP1, the line parallel to L1 and distance r from L1
–find L2 thru P2 & P3
–find d2, the x-intercept of L2
–find LP2, the line parallel to L2 and distance r from L2
–find center point C at intersection of L1 & L2
–find line Lt1 thru C and perpendicular to L1
–find line Lt2 thru C and perpendicular to L2
–find entry tangent point t1 at intersection of LT1 & L1
–find entry tangent point t2 at intersection of LT2 & L2
Once the spreadsheet phillet_c.xls was built to do all the calculation I exported only the 6 columns I needed — xt1,yt1,xt2,y2t,I,J — into a .csv text file.
The text editor I used is called Programmer’s File Editor. It has been around for several years. The macros I used are specific to this editor, I think.
The gist of what the macro does is:
1. insert “G1 X”
2. replace next comma with ” Y”
3. replace next comma with ” G2 X”
4. replace next comma with ” Y”
5. replace next comma with ” I”
6. replace next comma with ” J”
7. go to start of next line
8. insert “G1 X”
9. replace next comma with ” Y”
A. replace next comma with ” G3 X”
B. replace next comma with ” Y”
C. replace next comma with ” I”
D. replace next comma with ” J”
E. go to start of next line
I have to 2 lines in one macro execution because the outline is drawn by alternately arcing clockwise (G2) & counterclockwise (G3).
I suppose this could be done with the macros in Word, or in Visual Basic, or AutoHotKey, or sed, or perl or any of dozens of ways in Unix.
Because I am trying to get something done for my sister I have been fighting the temptation to tackle the more juicy problem of coming up with logic to automically determine when to insert a G2 vs a G3.