Tuesday 5 January 2021

Is CAM the Answer ? It Depends on the Question.

My first encounters with g-code were in a shop with no CAM software.  This may sound strange to those who only know a time with easy access to CAM software but I pre-date the internet and powerful personal computers.  In fact the huge files that CAM software can post would have been a nuisance given the limited storage available on old equipment.  Also some machines stored programs on magnetic or paper tape but that's a war story for another day.  Cutter compensation (G41/G42), Macros and sub-programs  have fallen out of common use but we needed these daily.  These days cutter compensation is more likely to be used as wear offsets rather than used to compensate full radius or diameter.

What brought this to mind was a small job involving cutting a repeating chevron pattern around the circumference of a pipe.  FreeCAD has an axis-wrap Path dress-up which will be the topic of the next post.  In this case FreeCAD came close but just wouldn't bend to my will entirely.

The tool path itself is very simple, it's just a matter of repeating it at regular intervals of rotation.  A Macro or sub-program can do this and although linuxcnc doesn't have exactly those things it has the o-word which is a substitute:   http://www.linuxcnc.org/docs/html/gcode/o-code.html

O-word programs have the downside of being miserable to start anywhere but the top of the program.  Also any edit inside a loop affects all iterations of that loop.  There is a way to get CAM-like output that is fully customizable using a real programming language like Python.  I'm not a programmer so my code is clumsy but all that's needed is a loop and variables. I didn't bother figuring out how to get blogger to do fancy syntax highlighting so here it is raw:

*************************************************************                                      

#!/usr/bin/env python3
import math
## this script is run from terminal by typing
## python3 <name of this py script>  >  <name of output file>
## i is the rotated approach position
## n is counting the number of loops
## end ="" prevents printing new line in python3
## round function to limit oupput to 4 decimals
i = 0
n = 1
print("(0.25 EM)")
print("(# 3.5 inch tire)")
print("G54")
while (i < 347):
    print("G00 X-0.3 Y0 A", end ="")
    print(round(i, 4))
    print("G01 Z-0.1 F50")
    print("X0 F30")
    print("G01 X0.72 A", end ="")
    print(round(i + 13.61, 4))
    print("G01 X1.44 A", end ="")
    print(round(i, 4))
    print("G01 X 1.64")
    print("G00 Z 0.2")
    print("(", end ="")
    print(n, end ="")
    print(")")
    i = i + 15.7154
    n = n + 1
print("M02")
exit()

******************************************

and the first few lines of the output:

 (0.25 EM)
(# 3.5 inch tire)
G54
G00 X-0.3 Y0 A0
G01 Z-0.1 F50
X0 F30
G01 X0.72 A13.61
G01 X1.44 A0
G01 X 1.64
G00 Z 0.2
(1)
G00 X-0.3 Y0 A15.7154
G01 Z-0.1 F50
X0 F30
G01 X0.72 A29.3254
G01 X1.44 A15.7154
G01 X 1.64
G00 Z 0.2
(2)

It includes a handy loop counter.  I'm not about to become a proficient python coder but simple routines like this are easy and useful.  Another thing added to the toolbox.


  

No comments:

Post a Comment

Note: only a member of this blog may post a comment.