962d04046c0cc6f7569ca2472f4cf20f84d2e2ed
Stefan Schuermans CAD drawing of first example

Stefan Schuermans authored 11 years ago

1) <?xml version="1.0" encoding="utf-8"?>
Stefan Schuermans first few lines of document...

Stefan Schuermans authored 11 years ago

2) 
Stefan Schuermans CAD drawing of first example

Stefan Schuermans authored 11 years ago

3) <article xmlns="http://docbook.org/ns/docbook" version="5.0" xml:lang="en">
Stefan Schuermans first few lines of document...

Stefan Schuermans authored 11 years ago

4) 
5)   <title>DXF to NGC Converter: dxfncg</title>
6) 
7) 
Stefan Schuermans CAD drawing of first example

Stefan Schuermans authored 11 years ago

8)   <sect1 xml:id="introduction">
Stefan Schuermans first few lines of document...

Stefan Schuermans authored 11 years ago

9) 
10)     <title>Introduction</title>
11) 
12)     <para>
13) 
Stefan Schuermans CAD drawing of first example

Stefan Schuermans authored 11 years ago

14)       The DXF to NGC converter <emphasis>dxfngc</emphasis> provides a
15)       means to convert 2D technical drawings in DXF file format to G-code
16)       in NGC format used by CNC mills or routers (e.g. LinuxCNC).
Stefan Schuermans first few lines of document...

Stefan Schuermans authored 11 years ago

17) 
18)     </para>
19) 
20)     <para>
21) 
22)       Usually, the 2D drawings in DXF format do not contain enough information
23)       for G-code creation, e.g. about which lines describe the border of a part
Stefan Schuermans CAD drawing of first example

Stefan Schuermans authored 11 years ago

24)       and which lines describe holes.  The diameter of the cutting tool and the
25)       depth of the cut are other examples.  Therefore, dxfngc relies on a
26)       script file to control the G-code generation.  This script is the input
27)       to the tool.  It sets all required parameters, reads the drawing,
28)       controls generation of the G-code and finally writes the output file.
Stefan Schuermans first few lines of document...

Stefan Schuermans authored 11 years ago

29) 
30)     </para>
31) 
32)   </sect1>
33) 
Stefan Schuermans CAD drawing of first example

Stefan Schuermans authored 11 years ago

34)   <sect1 xml:id="first_example">
Stefan Schuermans first few lines of document...

Stefan Schuermans authored 11 years ago

35) 
36)     <title>A first example</title>
37) 
38)     <para>
39) 
Stefan Schuermans running the script, image o...

Stefan Schuermans authored 11 years ago

40)       To illustrate the usage of dxfngc, suppose a stencil for the
41)       <emphasis>BlinkenArea</emphasis> logo shall be cut with a CNC mill.  The
42)       basic shape of the stencil is a circle.  The logo is formed by two holes
43)       with a specific shape (see <xref linkend="logo_stencil"/>).
Stefan Schuermans first few lines of document...

Stefan Schuermans authored 11 years ago

44) 
45)     </para>
46) 
Stefan Schuermans CAD drawing of first example

Stefan Schuermans authored 11 years ago

47)     <figure xml:id="logo_stencil">
48)       <title>Logo Stencil</title>
49)       <mediaobject>
50)         <imageobject>
51)           <imagedata fileref="logo_stencil.svg" format="SVG" width="30%"/>
52)         </imageobject>
53)       </mediaobject>
54)       <caption>The logo stencil to be cut on the CNC mill.</caption>
55)     </figure>
56) 
Stefan Schuermans running the script, image o...

Stefan Schuermans authored 11 years ago

57)     <sect2>
58) 
59)       <title>Creating the Drawing</title>
60) 
61)       <para>
62) 
63)         First, the 2D drawing is created with a CAD program in DXF format.  The
64)         circular border is drawn on layer <parameter>border</parameter> and the
65)         two holes are drawn on layer <parameter>holes</parameter> (see <xref
66)         linkend="logo_drawing"/>).
67) 
68)       </para>
69) 
70)       <figure xml:id="logo_drawing">
71)         <title>Logo Drawing</title>
72)         <mediaobject>
73)           <imageobject>
74)             <imagedata fileref="logo_drawing.svg" format="SVG" width="42%"/>
75)           </imageobject>
76)         </mediaobject>
77)         <caption>The CAD drawing of the logo stencil on 10mm grid.
78)                  Border and holes are on separate layers.</caption>
79)       </figure>
Stefan Schuermans first few lines of document...

Stefan Schuermans authored 11 years ago

80) 
Stefan Schuermans running the script, image o...

Stefan Schuermans authored 11 years ago

81)     </sect2>
Stefan Schuermans first few lines of document...

Stefan Schuermans authored 11 years ago

82) 
Stefan Schuermans running the script, image o...

Stefan Schuermans authored 11 years ago

83)     <sect2>
Stefan Schuermans first few lines of document...

Stefan Schuermans authored 11 years ago

84) 
Stefan Schuermans running the script, image o...

Stefan Schuermans authored 11 years ago

85)       <title>Writing the Script</title>
86) 
87)       <para>
88) 
89)         The next step is to write the dxfngc script.  Such a script is shown in
90)         <xref linkend="logo_script"/>.  All lines starting with a hash
91)         character (<code>#</code>) are comments.  They will be ignored by
92)         dxfngc.  During processing of the script, dxfngc manages three three
93)         data objects in memory: the current settings, the current drawing and
94)         the list of G-code commands.  Initially, the settings are set to some
95)         reasonable defaults.  The drawing and the G-code are empty.
96) 
97)       </para>
98) 
99)       <para>
100) 
101)         The first section of the example script fills the G-code list with
102)         some setup commands to configure the CNC mill.  This is done using
103)         the <code>cmd</code> command.  All the text folloing <code>cmd</code>
104)         is treated as a G-code command and is appended as a new command to
105)         the G-code list in memory.  Afterwards, the settings for processing the
106)         drawing to G-code are configured.  This includes the Z coordinates
107)         and the feed rates for moving and cutting as well as the diameter of
108)         the cutting tool.  Please see !!!TODO!!! for a description of all
109)         settings.
Stefan Schuermans CAD drawing of first example

Stefan Schuermans authored 11 years ago

110) 
Stefan Schuermans running the script, image o...

Stefan Schuermans authored 11 years ago

111)       </para>
112) 
113)       <para>
114) 
115)         The <code>read_dxf</code> reads a CAD drawing in DXF format.  In this
116)         example, the logo drawing shown in <xref linkend="logo_drawing"/> is
117)         read.  This loads all layers of the DXF file to memory.  The layers can
118)         then be processed with the cutting commands (see !!!TODO!!!) to produce
119)         G-code.  The <code>cut_inside</code> command is used here to cut the
120)         holes.  It will calculate the path of the cutting tool to be half its
121)         diameter further to the inside of the holes.  This makes sure the hole
122)         has the desired size and shape after cutting - or more precise as close
123)         to it as possible with the selected cutting tool.  The
124)         <code>cut_outside</code> command is used for cutting the border of the
125)         stencil.  It basically works the same way, but moves the path of the
126)         cutting tool further to the outside.
127) 
128)       </para>
129) 
130)       <para>
131) 
132)         After all G-code for cutting has been created, the G-code commands
133)         for finishing (e.g. turning off the CNC-mill) are appended using
134)         <code>cmd</code> like for the setup.  Finally, the G-code accumulated
135)         in memory is written to an output file useg <code>write_ngc</code>.
136) 
137)       </para>
138) 
139)       <figure xml:id="logo_script">
140)         <title>Logo Script</title>
141)         <programlisting><![CDATA[# add setup G-code commands
142) cmd G21
143) cmd G90
144) cmd G64 P0.01
145) cmd G17
146) cmd G40
147) cmd G49
148) 
149) # configure settings
150) set_precision 0.01
151) set_tool_diameter 3
152) set_move_z 5
153) set_base_z 0
154) set_cut_z -3.2
155) set_cut_z_step 1.1
156) set_feed_drill 100
157) set_feed_mill 200
158) set_layer_mode path_by_path
159) 
160) # read drawing
161) read_dxf logo.dxf
162) 
163) # generate G-code for actual cutting
164) cut_inside holes
165) cut_outside border
166) 
167) # add finishing G-code commands
168) cmd M2
169) 
170) # write G-code to output file
171) write_ngc logo.ngc]]></programlisting>
172)       </figure>
173) 
174)     </sect2>
175) 
176)     <sect2>
177) 
178)       <title>Running the Script</title>
179) 
180)       <para>
181) 
182)         Once drawing and script are ready, the script can be run using the
183)         <code>dxfngc</code> tool.  (It is assumed here it has already been
184)         compiled. See !!!TODO!!! for instruction for compiling.)  As the script
185)         contains the filenames of input and output files, it is sufficient to
186)         provide the filename of the script file to dxfngc:
187) 
188)       </para>
189) 
190)       <programlisting><![CDATA[./dxfngc logo.txt]]></programlisting>
191) 
192)       <para>
193) 
194)         If everything goes well, this will produce a G-code file.  Otherwise an
195)         error message will be printed that informs about what went wrong.
196)         (There might also be some output like <code>dimeModel::largestHandle:
197)         65535</code>, which is coming from inside the DXF library used
198)         internally.  This output can be ignored.)
199)         <xref linkend="logo_g-code"/> shows the produced G-code rendered by
200)         LinuxCNC.
201) 
202)       </para>
203) 
204)       <figure xml:id="logo_g-code">
205)         <title>G-code for Logo Stencil</title>
206)         <mediaobject>
207)           <imageobject>
208)             <imagedata fileref="logo_g-code.png" format="PNG" width="100%"/>
209)           </imageobject>
210)         </mediaobject>
211)         <caption>G-code for the logo stencil, rendered by LinuxCNC.</caption>
212)       </figure>
213)     </sect2>
Stefan Schuermans CAD drawing of first example

Stefan Schuermans authored 11 years ago

214)