This file is part of QCAD/CAM of the postprocessor sub-directory. Do not edit this file; changes will be lost after an update. rev date by description - 07-04-2019 HJS Birth date A 15-04-2019 HJS For comments and spell check ===What is a Post Processor?================================================== A CAD-drawing is a database of lines, arcs and other CAD drawing entities. A very common used CAD interchange format is .DXF. G-code RS274/NGC (LinuxCNC developed by the National Institute of Standards and Technology; NIST) is the non official overall interchange language for CNC- machines. However, not every CNC-machine uses the same 'tongue'; the several different G-code languages are called 'dialects'. Grbl, Mach3, TinyG are such well known dialects. What dialect a CNC-machine uses is defined by its manufacturer and purpose, as drafting a sheet of paper, cutting vinyl or metal plate, milling materials or cutting on a lathe. The processing sequence on a penplotter is non critical or might even be random, a carving sequence on a router becomes more critical, where as in milling or turning the processing sequence is very decisive and critical. Some G-codes are only available on a router, others only on a mill, and some other only on a lathe. Making it worse; the meaning and purpose of some G-codes might be something totally different on different CNC-machines. Old school CNC-machines are like the old type Windows-printers; with these machines an external G-code reader (or computer) is used for direct controlling the machine's hardware. Today, like many printers, CNC-machines are computerised. Many modern machines uses a build-in computer and application (a GUI) for 'parametric'-CNC-programming. However, at the end, almost every CNC-machines are G-code controlled. If coded correctly, almost every CNC-machine can read external generated G-code files. QCAD uses a built in sub-program (the toolpath-generator) to transform selected CAD-entities into 'toolpath-entities' also known als CL-data (Cutter Location Data). This toolpath defining proces is called 'CAM'-ing. Some CAD- applications stores the CL-data in a different file, where as in QCAD the CL-Data becomes part of the drawing (database), defining the subsequent machining processing steps and actions. QCAD stores the CL-data (and the CNC-machine specifications) in some specific 'CAM'-layers and blocks. The stored CL-data can be observed in QCAD's 3D CAD-simulation. Keep in mind; you are watching CL-data-simulation; not real machine G-code actions. 'Post processing' is converting the CL-data into machining instructions (LinuxCNC, grbl, mach3,...), by pointing out how the CL-data has to be written out as G-code, and stored into a machine ready G-code-file. The machine dependable 'How-to write G-code instructions' is located in a separate file; called a 'post processor'. Therefore, by design, post processors are always CNC-machine specific linked. Even more; there might be several post processors available for the same CNC-machine; for example a first one as 2-axis, another one as a 3-axis. QCAD's CAM uses the selected 'post processor' directions (instructions) to generate a G-code-file whenever an CAM Export command is executed. ===Programming a post processor=============================================== First of all; a succesfull 3D CAD simulation is not a garanty of a correct G-code file. Second; one does not 'program' a post processor, but one 'codes' a post processor. Third; QCAD uses Open Source post processors, so everyone can make or adjust their own, free of charge! Manufacturer independable! Support the QCAD/CAM community by returning your post processor to Ribbonsoft. (Re)coding a post processor, is like defining instructions on how the G-code must be written. A bonus for knowing how to code a post processor, is more flexibility in G-code representation, automatic set up of the CNC-machine, adding information, probing the workpiece, moving the table or spindle to an load/unload position, moving the lathe's turret to a save tool change position, and so on. Last but not least it is very helpful in quick locating and sorting out errors, called 'debugging'. Concluding: a post processor file is a list of instructions on how to write the G-code ('syntaxing') for a particular CNC-machine. Keep in mind; all toolpath data and variables are already been CAD/CAM generated; a CAM Export only collects the required data, where the post processor points out the correct data order. Since the correct data order is CNC-machine dependable; one has to check the CNC-machine's documentation. Another solution is with trial and error, and using the other post processors in this directory as examples. ===G-code Block defaults====================================================== A CNC-machine ready G-code file is a list (text lines) of machine instructions. Every line has a maximum length of 70 characters, and makes up a separate instruction called a 'block' and starts with a blocknumber 'Nxx'. The files 'Gcode.js' and 'GcodeBase.js' defines many 'defaulted' block- construction-syntax-routines and associated functions (conform RS274/NGC). If the used post processor does not redefine a particular common block-syntax- construction, then the default G-code construction is used in coorporation with its functions. (This saves a lot of detailled coding.) Since a fixed laser has no z-movements at all, z-movement calculation and Z-G-code writings might be skipped. One can disable the undesired calculation and G-code block writing by emptying its associated functions variable with two brackets. linearMoveZ = []; Disables linearMoveZ; no linear z-move G-code is written. ===Single/Multi-pass========================================================== Every single processing action is a 'single pass', so one cut, drill or carv is a single pass. A single pass might require several G-coded blocks. As usual the exeption; some CAM-entities might exists of multiple passes, producing more as several G-coded Blocks. ===Note on previous values==================================================== G-code defines a movement always from the current (undocumented) position (current coordinate) to a new one. "G0 X10 Y20" is a movement to absolute coordinate x,y = 10,20 OR is a relative movement of 10 units to the right and 20 units up. Keep always in mind the current tool position is defined by its previous movement. An absolute movement from 100,100 to 10,20 is a complete different direction and endposition as the relative movement from 100,100 (to 110,120). A simple trick to remember the current position, is whenever a movement is completed, by writing it down as a 'Previous' value. QCAD uses the phrase 'first' for defining the last completed action. LinearMove = "G0 X100 Y100" ; example of setting up a variable FirstLinearMove = LinearMove ; after movement update previous var LinearMove = "G0 X10 Y20" ; update variable as movement => The CNC-machine interpretes the last action as from 'FirstLinearMove' to 'LinearMove'; in absolute mode it moves to coordinate x,y=10,20 OR in relative mode it moves 10 units right and 20 units up. ===Compiling post processor=================================================== The post processor files themselfes are 'normal' ASCII text files. Whenever QCAD starts, it will compile (translate) all post processor text files into binairy application files. If a CAM Export is executed, the current post processor is used. Only by (re)saving the drawing, the updated post processor becomes part of the drawings CL-data. Updating an existing drawing with an updated post processor is only effective whenever that drawing is opened from within a clean started QCAD with Menu, File, Open.. . If a drawing file is opened by association by a filemanager, an updated post processor is not compiled and will therefore not update the post processor in the CL-data. If the (updated) post processor does not turn up in QCAD's post processor list, check the post processor ASCII text file for typo-errors. ===Post Processor Reference=================================================== This 'codes' list is sorted more or less in the order of appearance in the post processor; just add/change the onces in the right order required by your CNC-machine. [PostProcessor].js A 'post processor' is an ASCII text file with instructions how to write G-code in a specified order for a specific CNC-machine. CamExporter() This is QCAD's CL-Data-to-coordinates-value compiler. This routine catches all required CL-data variables and values stored in the CAM-layers en blocks. CamExporterV2() Same as CamExporter() but a newer version. Gcode() The routine compiles and calculates CamExporter's data into G-code usable values. GCodeBase() A routine defining all available G-codes, variables, and default settings. // Double slash. Used for comments in the post processor file; Ignored by QCAD. unit = RS.Millimeter; Measurement units in millimeter. decimals = 3; Precision of calculations in decimals. Note; The older the machine is, the lower the precision might be. grbl requires 5 decimals; a lower value might generate CNC-errors. trailingZeros = false Use 'true' if decimal values needs a preceding zero. forceSign = false Use 'true' if all values need a preceeding + or - sign. useComma = false Use 'true' if the comma is used as decimal separator. splitFullCircles = false Use 'true' if circles has to be split in two arcs. Older CNC-machines do not know circles, but use two arc's to mimic a circle. stopAtTab = true Skip toolpath-tabs. When cutting, tabs are small pieces of non processed material to be used as 'placeholders' for keeping the workpiece fixed on the table. LinearMoveZ = []; Disable the [called movement] for calculation and G-code generation. lineNumber = 10 Variable containing the preset of the first G-code blocknumber. lineNumberIncrement = 10 Every next blocknumber is raised by this presetted value. A 'skipped blocknumbering' (like 10) allows manualy inserting blocks without renumbering the complete file. separator = " "; A 'space' is used to separate subsequent G-codes in a block. On some rare machines a double space might be required. lineEndding = "\n"; A variable containing the last character of a block. In this case a LineFeed-command (ASCII LF)is added. Older CNC-machines sometimes need a more specific EndOfBlock code like "\r\n". header = [...]; Section between brackets is pre-added as File header. Header is used for file or machine info, and more often used for pre-re-setting the CNC-machine. footer = [...]; Section between brackets is post-added as File footer. Footer is often used for homing tool, switch off sequences, and stopping the execution of the G-code file. [N] Blocknumber. Where [ ] = brackets defines a G-code field and variable [N] = current blocknumber as string: "N10" , "N20" [N#] = select only the field value: "10" , "20" [N!] = last used value, no matter the current one note: # and ! parameters are allowed for all field-variables ; G-code comment. Everything in a G-code block after this glyph is ignored by the CNC-machine. In G-code used for adding comments, or inserting blank lines. [FILENAME] A field with the cad filename. [FILEPATH] A field with the path setting. [DATETIME] A field terurning the current date and time. BUG; [DATETIME] has a mixed up output. More handy would be separate fields as [TODAYDATE] and [TODAYTIME]. [PROGRAM_NAME] hold. external call? [TOOLPATH_NAME] A field with the current ToolPathName: 'Profile 1' [TOOLPATH_ORDER] Order number of toolpath: '1' '2' '3' [TOOLPATH_INDEX] Order number of toolpath: '1' '2' '3' [TOOLPATH_HEAD] BUG: Missing. A field used for manualy adding G-code at the start of a toolpath in CAD/CAM, such as moving the tool to a particular toolpath start position. Might also be used for comments or Debug-marker. [TOOLPATH_FOOT] BUG: Missing. A field used for manualy adding G-code at the end of a toolpath, such as moving the tool to a particular desired toolpath end position. Note: as G-code does, QCAD's toolpath generator also starts at the last know position; the next toolpath-pass-sequences is thereby influenzed by the last position of the current toolpath. A work around for now is to make an extra between toolpath to the desired start position for the next toolpath. Might also be used for comments or Debug-marker. [TOOL_CALLS] Number of times a tool is called for a pass. G-codes As every other CNC-hardware/machine-interpreter, QCAD/CAM generates a very limited number of G-codes. Available are; G00 Rapid movement for moving the tool without processing any material. G01 Normal movement for material processing. G02 Clockwise (CW) circular processing movement. G03 CounterClockwise (CCW) circular processing movement. G04 BUG: Missing. Dwell time is not defined yet. Dwell time pauses the execution at the given time in seconds for cooling down tool or material. When drilling it stops plunging and holds the drill the given time on position for chip removal. A PWM laser uses dwell time as hold time in point burn-mode. When laser cutting the dwell time is also used as 'pre-burn-time'. G40 No radius compensation; Toolpath on cad entity. G41 Leftside radius compensation; Toolpath on leftside of the upwards moving vector of cad entity. G42 Rightside radius compensation. Coordinates [X] value as coordinate (absolute mode) OR as movement (relative mode). [Y] value, ditto. [Z] value, ditto [I] arc/circle center x-value [J] arc/circle center y-value Home [XH] X value Home position. Derived from CAM Configuration. [YH] Y value Home position [ZH] Z value Home position Startpoint [X1] X start position. Derived from CAM Configuration. [Y1] Y start position [Z1] Z start position Note: Startpoint indicates the startpoint of the first toolpath, and is NOT the same as Zero Workpoint. Size [X_MIN] Lowest X-value. HOLD; proces values? [Y_MIN] Lowest Y-value [Z_MIN] Lowest Z-value [X_MAX] Highest X-value [Y_MAX] Highest Y-value [Z_MAX] Highest Z-value Control Derived from Tool and ToolPath-settings. [F] Feed rate. [S] Spindle speed. [SD] BUG; Missing. Spindle direction: CW/CCW [T] Tool. Only the Tool indexnumber is valid. [TR] Tool radius. Used for Right-/Leftside toolpaths offset distance. [TD] Tool diameter. [FP] Feed rate Plunge. [DT] BUG; Missing. Dwell Time value in seconds not defined yet [CF] BUG; Missing. Coolant Fluid On [CM] BUG; Missing. Coolant Mist On [CO] BUG; Missing. Coolant Off Level [ZS] Z Safety distance. This is the highest tool Z position. [ZU] Z Up clearance. Z rapid/toolpath change height. [ZUP] Z Up clearance Pass. Rapid x-y-movement height. [Z_START] Z Start. Calculated z processing startpoint. [Z_END] Z End. Calculated z processing endpoint [ZD] Z cutting Depth. The absolute distance of cutting. Set in toolpath window. Finish [UX] BUG; Missing. X-offset clearance (finish/roughing mode not defined yet) [UY] BUG; Missing. Y-offset clearance [UZ] BUG; Missing. Z-offset clearance [UR] BUG; Missing. Radius offset clearance Machine Most machine codes are not regular field variables, but have to be 'text coded'. "M00" Program Stop (programmed paused) "M01" Optional stop (halted by operator) "M02" Program End (sub-program only) [M03] BUG; Missing. ClockWise CW-mode. Spindle / Chuck Clockwise On Tool Down / Laser On (mode) grbl 1.1 : Static laser-mode [M04] BUG; Missing. CounterClockWise CCW-mode. Spindle / Chuck CounterClockwise On Tool Down / Laser On (mode) grbl 1.1 : Dynamic laser-mode "M05" Spindle / Chuck Stop Tool Up / Laser Off (mode) [M06] Tool change. grbl does not support M06. [M07] BUG; Missing. Mist Coolant On; not defined yet [M08] BUG; Missing. Flood coolant On; not defined yet [M09] BUG; Missing. Coolant off not defined yet "M30" End program. Movements Rapid moves. Executed at 'rapid plane'-height. rapidMove = "[N] G00 [X] [Y]"; rapidMoveZ = "[N] G00 [Z]"; Linear X,Y moves. Executed as machining movements. firstLinearMove = "[N] G01 [X] [Y] [F]"; linearMove = "[N] [X] [Y] [F]"; Linear Z moves. Executed as machining movements. firstLinearMoveZ = "[N] G01 [Z] [F]"; linearMoveZ = "[N] [Z] [F]"; Circular moves. Executed as machining movements. firstArcCWMove = "[N] G02 [X] [Y] [I] [J] [F]"; arcCWMove = "[N] G02 [X] [Y] [I] [J] [F]"; firstArcCCWMove = "[N] G03 [X] [Y] [I] [J] [F]"; arcCCWMove = "[N] G03 [X] [Y] [I] [J] [F]"; Dwell time. BUG, Missing. Not defined yet. As a work around one can use a negative(!) drill cut depth distance. "dwellTime" = "G04 P[DT]"; Tool compensation linearMoveCompensationLeft = ["[N] [F!]" , "[N] G41 [X] [Y]" ]; linearMoveCompensationRight = ["[N] [F!]", "[N] G42 [X] [Y]" ]; linearMoveCompensationOff = "[N] G40 [X] [Y]"; Sections Whenever G-code has to be checked and debugged, some in file additional information is quite handy. 'Section' headers and footers can be used to make the G-code file more human readable. File header before / file footer after output: header = [" -add preset codes here - "]; footer = ["[N] M30"]; Tool change toolHeader = ["[N] [T] M6", ; grbl does not support M6 "[N] [S] M03" ]; toolFooter = ["[N] ;"]; ; add empty block as separator Toolpath (might contain multiple contours) toolpathHeader = ["[N] ; [TOOLPATH_NAME]", ; diplay toolpath name ]; toolpathFooter = ["[N] ;"]; ; add empty block as separator Contour (might be several contours within a toolpath contourHeader = []; contourFooter = []; Single Z Pass singleZPassHeader = []; singleZPassFooter = []; Multiple Z passes multiZPassHeader = []; multiZPassFooter = []; First of multiple pass zPassFirstHeader = []; zPassFirstFooter = []; Last of multiple pass zPassHeader = []; zPassFooter = []; Last pass of multiple Z passes zPassLastFooter = [];