Convert X-Axis to A-Axis using Linux AWK

07 Jan 2023 15:59 #261175 by Earlton2
To help CNC a walking stick I have finally added an A-Axis.  This allows me to simply rotate the stick while I use Y/Z to create the profile.  However I also use f-engrave to produce lettering files which spits out 600+ lines of:

G1 X-0.2642 Y0.0726 Z-0.0000
G1 X-0.2729 Y0.0833 Z-0.0149 etc

To convert the X parameter to A its necessary to divide it by πD where D is the Diameter of the job.  To do this I first used a text editor to add a space after the 'X' and then ran the following AWK program for a 0.62"D dowel:

#!/bin/awk -f
BEGIN {        # run once per input file
          # the A-axis angle is measured in 'revs'
          # so surface distance is Pi.D per rev
  dd = 0.620    # set job diameter in inches
  nn = -1 / ( 3.141592654 * dd )
{        # repeat for each line of input file
  aa = $3
  if ( $2 == "X" )
     aa = nn * $3
     print $1, "A", aa, $4, $5, $6, $7
     print $0
  print "; data conversion using awk -f ow.awk infile >> outfile"

i.e. if the second field is 'X', print "A",  value/πD, remaining fields; else print the original line.

Typical results were:
G1 A -0.2642 Y0.0726 Z-0.0000
G1 A -0.2729 Y0.0833 Z-0.0149

Notice "X" has been modified but the Y and Z parameters remain the same.

I've no doubt this is a two line Python program but not on my shift! 
The lettering worked however it was deeper than I expected and backwards, them's the breaks!

The following user(s) said Thank You: tommylight

Please Log in or Create an account to join the conversation.

08 Jan 2023 01:04 #261232 by andypugh
It might be worth pointing out that LinuxCNC can run an input filter at the point that a G-code file is opened, so you could arrange to run this transformation automatically.
You probably don't want it all the time, so you could check for a magic comment in the G-code. Or, even simpler, use a different file extension for files that need to be filtered.

Please Log in or Create an account to join the conversation.

Moderators: cncbasher
Time to create page: 0.183 seconds
Powered by Kunena Forum