PDA

View Full Version : The simplest 4th Axis Wrapper and FREE


PEU
Wed 24 November 2010, 19:37
I just posted this at CNCzone, I'm sure it will be enjoyed here too :)

Here you go, the simplest 4th axis wrapper that does the conversion in just one line of piped code, it uses GNU commands, so any user with ANY operating system can use the wrapper.
Since I'm a windows user I used GNUwin version and made a batch file that does some validation on the input parameters, but the gist of the program is just ONE LINE!!!

How do you use it?

Simple: dump all the files in any folder, put the text file with the Gcode in the same folder and launch the wrapper.cmd file with these parameters:

wrapper <InputFile> <axis> <diameter> <OutputFile>

Do not expect fancy windows, this script runs from a DOS box (cmd)

Here is the code:

@REM WRAPPER.CMD v1.0 2010-11-23
@REM
@REM Heavylifting (parsing) by Daniel Sentinelli
@REM Idea, math and errorchecks by Pablo E. Untroib (PEU)
@REM
@REM USAGE: wrapper <InputFile> <axis> <diameter> <OutputFile>

@echo off
@SETLOCAL ENABLEEXTENSIONS

@REM Check if all required parameters are present
if [%1]==[] goto :MissingParameter
if [%2]==[] goto :MissingParameter
if [%3]==[] goto :MissingParameter
if [%4]==[] goto :MissingOutput

@REM Check for valid source file
if NOT EXIST %1 goto :MissingInput else
(
@REM Check for G2 or G3 movements (these are not allowed)
grep -iq G[23] %1
if errorlevel 1 goto :MoreChecks
goto :NoG2G3
)

:MoreChecks
@REM Check if axis is X or Y
if /i [%2]==[Y] (goto :OkProcess) else goto :CheckX

:CheckX
if /i [%2]==[X] (goto :OkProcess) else goto :WrongAxis


@REM Here we do the heavy lifting (parsing) to replace X or Y
:OkProcess

cat %1 | tr [:lower:] [:upper:] | sed "s/\([A-Z]\)/ \1/g ; s/ \+/ /g ; s/^ //g" | gawk "{ for (n=1 ; n<=NF ; n++) if (substr($n,1,1)==toupper(\"%2\")) {printf \"A%%f \",substr($n,2)*(114.59155902616464175359630962821/%3) } else {printf \"%%s \", $n}; print \"\" }" >%4
goto :success


@REM Error messages
:NoG2G3
echo.
echo ERROR: No G2 or G3 movements allowed
grep -i G[23] %1
goto :ProperSyntax

:WrongAxis
echo.
echo ERROR: Axis should be X or Y
goto :ProperSyntax

:MissingParameter
echo.
echo ERROR: Missing parameters
goto :ProperSyntax

:MissingInput
echo.
echo ERROR: Missing Input Filename
goto :ProperSyntax

:MissingOutput
echo.
echo ERROR: Missing Output Filename
goto :ProperSyntax

:ProperSyntax
echo Syntax: wrapper ^<InputFile^> ^<X or Y^> ^<Diameter^> ^<OutputFile^>
echo.
goto :EOF

:success
echo.
echo FILE: %4 successfully created!
echo.


I tried many files directly out of CAM and they wrapped perfectly, no ARC movements are allowed (g2 or g3) so if your gcode is only g0 and g1 it will work for sure.

If you want to backplot the file in mach3 remember to set the A axis as angular in the general config section and in the settings screen (Alt-6) set the correct rotating radius (diameter/2)


Enjoy!

Download Link: http://dl.dropbox.com/u/3624504/WrapperByPEU.zip (it contains all the needed GNUwin files)


Pablo