BlinkenArea - GitList
Repositories
Blog
Wiki
dxfngc
Code
Commits
Branches
Tags
Search
Tree:
962d040
Branches
Tags
master
dxfngc
doc
dxfngc.xml
running the script, image of G-code output
Stefan Schuermans
commited
962d040
at 2013-05-20 13:06:47
dxfngc.xml
Blame
History
Raw
<?xml version="1.0" encoding="utf-8"?> <article xmlns="http://docbook.org/ns/docbook" version="5.0" xml:lang="en"> <title>DXF to NGC Converter: dxfncg</title> <sect1 xml:id="introduction"> <title>Introduction</title> <para> The DXF to NGC converter <emphasis>dxfngc</emphasis> provides a means to convert 2D technical drawings in DXF file format to G-code in NGC format used by CNC mills or routers (e.g. LinuxCNC). </para> <para> Usually, the 2D drawings in DXF format do not contain enough information for G-code creation, e.g. about which lines describe the border of a part and which lines describe holes. The diameter of the cutting tool and the depth of the cut are other examples. Therefore, dxfngc relies on a script file to control the G-code generation. This script is the input to the tool. It sets all required parameters, reads the drawing, controls generation of the G-code and finally writes the output file. </para> </sect1> <sect1 xml:id="first_example"> <title>A first example</title> <para> To illustrate the usage of dxfngc, suppose a stencil for the <emphasis>BlinkenArea</emphasis> logo shall be cut with a CNC mill. The basic shape of the stencil is a circle. The logo is formed by two holes with a specific shape (see <xref linkend="logo_stencil"/>). </para> <figure xml:id="logo_stencil"> <title>Logo Stencil</title> <mediaobject> <imageobject> <imagedata fileref="logo_stencil.svg" format="SVG" width="30%"/> </imageobject> </mediaobject> <caption>The logo stencil to be cut on the CNC mill.</caption> </figure> <sect2> <title>Creating the Drawing</title> <para> First, the 2D drawing is created with a CAD program in DXF format. The circular border is drawn on layer <parameter>border</parameter> and the two holes are drawn on layer <parameter>holes</parameter> (see <xref linkend="logo_drawing"/>). </para> <figure xml:id="logo_drawing"> <title>Logo Drawing</title> <mediaobject> <imageobject> <imagedata fileref="logo_drawing.svg" format="SVG" width="42%"/> </imageobject> </mediaobject> <caption>The CAD drawing of the logo stencil on 10mm grid. Border and holes are on separate layers.</caption> </figure> </sect2> <sect2> <title>Writing the Script</title> <para> The next step is to write the dxfngc script. Such a script is shown in <xref linkend="logo_script"/>. All lines starting with a hash character (<code>#</code>) are comments. They will be ignored by dxfngc. During processing of the script, dxfngc manages three three data objects in memory: the current settings, the current drawing and the list of G-code commands. Initially, the settings are set to some reasonable defaults. The drawing and the G-code are empty. </para> <para> The first section of the example script fills the G-code list with some setup commands to configure the CNC mill. This is done using the <code>cmd</code> command. All the text folloing <code>cmd</code> is treated as a G-code command and is appended as a new command to the G-code list in memory. Afterwards, the settings for processing the drawing to G-code are configured. This includes the Z coordinates and the feed rates for moving and cutting as well as the diameter of the cutting tool. Please see !!!TODO!!! for a description of all settings. </para> <para> The <code>read_dxf</code> reads a CAD drawing in DXF format. In this example, the logo drawing shown in <xref linkend="logo_drawing"/> is read. This loads all layers of the DXF file to memory. The layers can then be processed with the cutting commands (see !!!TODO!!!) to produce G-code. The <code>cut_inside</code> command is used here to cut the holes. It will calculate the path of the cutting tool to be half its diameter further to the inside of the holes. This makes sure the hole has the desired size and shape after cutting - or more precise as close to it as possible with the selected cutting tool. The <code>cut_outside</code> command is used for cutting the border of the stencil. It basically works the same way, but moves the path of the cutting tool further to the outside. </para> <para> After all G-code for cutting has been created, the G-code commands for finishing (e.g. turning off the CNC-mill) are appended using <code>cmd</code> like for the setup. Finally, the G-code accumulated in memory is written to an output file useg <code>write_ngc</code>. </para> <figure xml:id="logo_script"> <title>Logo Script</title> <programlisting><![CDATA[# add setup G-code commands cmd G21 cmd G90 cmd G64 P0.01 cmd G17 cmd G40 cmd G49 # configure settings set_precision 0.01 set_tool_diameter 3 set_move_z 5 set_base_z 0 set_cut_z -3.2 set_cut_z_step 1.1 set_feed_drill 100 set_feed_mill 200 set_layer_mode path_by_path # read drawing read_dxf logo.dxf # generate G-code for actual cutting cut_inside holes cut_outside border # add finishing G-code commands cmd M2 # write G-code to output file write_ngc logo.ngc]]></programlisting> </figure> </sect2> <sect2> <title>Running the Script</title> <para> Once drawing and script are ready, the script can be run using the <code>dxfngc</code> tool. (It is assumed here it has already been compiled. See !!!TODO!!! for instruction for compiling.) As the script contains the filenames of input and output files, it is sufficient to provide the filename of the script file to dxfngc: </para> <programlisting><![CDATA[./dxfngc logo.txt]]></programlisting> <para> If everything goes well, this will produce a G-code file. Otherwise an error message will be printed that informs about what went wrong. (There might also be some output like <code>dimeModel::largestHandle: 65535</code>, which is coming from inside the DXF library used internally. This output can be ignored.) <xref linkend="logo_g-code"/> shows the produced G-code rendered by LinuxCNC. </para> <figure xml:id="logo_g-code"> <title>G-code for Logo Stencil</title> <mediaobject> <imageobject> <imagedata fileref="logo_g-code.png" format="PNG" width="100%"/> </imageobject> </mediaobject> <caption>G-code for the logo stencil, rendered by LinuxCNC.</caption> </figure> </sect2> </sect1> </article>