Development of a Computer Numerically Controlled Router Machine With 4 Degrees of Freedom Using an Open Architecture

Leonardo Romero Munoz˜ Moises Garc´ıa Villanueva Mario Santana Gomez´ Facultad de Ingenier´ıa Electrica´ Facultad de Ingenier´ıa Electrica´ Facultad de Ingenier´ıa Electrica´ UMSNH UMSNH UMSNH Morelia, Mich., Mexico Morelia, Mich., Mexico Morelia, Mich., Mexico Email: [email protected] Email: moises@correo.fie.umich.mx Email: msantana@correo.fie.umich.mx

TABLE I Abstract—A CNC router machine, of low cost, medium preci- ESTIMATEDANNUALSHIPMENTSOFINDUSTRIALROBOTSINSELECTED sion, using an open architecture, with four degrees of freedom, is COUNTRIES [9]. presented. It is described its hardware and software components. Also some applications to do simple tasks are presented. yrtnuoC 0102 1102 *2102 *5102 aciremA 001,53006,03722,62411,71 I.INTRODUCTION North America ( Canada, Mexico, USA) 16,356 24,341 28,000 31,000 aciremA htuoS dna lartneC dna htuoS aciremA 857 688,1 006,2 001,4 ailartsuA/aisA 007,611009,89896,88338,96 Industrial robots have been used with success to do multi- anihC 879,41 775,22 000,62 000,53 ple tasks including: automotive industry, electrical/electronic aidnI 677 745,1 000,2 005,3 napaJ 309,12 498,72 000,13 000,53 industry, metal products and many others (see Figure 1). cilbupeR fo aeroK 805,32 635,52 008,62 000,52 nawiaT 092,3 886,3 004,4 005,5 dnaliahT 054,2 354,3 001,4 000,7 htO re ailartsuA/aisA 829,2 384,02 006,4 007,5 Estimated worldwide annual supply of industrial robots at year-end eporuE 002,74001,44628,34384,02 by industries 2009 - 2011 hcezC .peR 204 816,1 000,2 000,3 ecnarF 940,2 850,3 003,3 005,3 Electrical/electronics* ynamreG 160,41 335,91 000,91 000,02 Motor vehicles ylatI 715,4 190,5 006,4 009,4 Automotive parts niapS 798,1 190,3 005,2 000,3

Chemical, rubber and plastics detinU modgniK 878 415,1 000,2 002,2 eporuE rehto eporuE 739,6 129,9 001,11 006,01 Metal products acirfA 952 323 053 005 Food 2011 **latoT 005,702059,081820,661585,021 Industrial machinery 2010 Sources: IFR, national robot associations. Communication 2009 *forecast

Consumer, domestic appliances **including sales which are not specified by countries

Glass, ceramics

Medical, precision & optical instruments

Others Unspecified are interested in helping the small guitars factories in Paracho, 0 5,000 10,000 15,000 20,000 25,000 30,000 35,000 units *incl. computers Michoacan, Mexico, to improve their competitiveness against Source: IFR Statistical Department factories in other countries that already use robots. We are taking into account developing a machine with Fig. 1. Estimated worldwide annual supply of industrial robots at year-end low cost, open and easy to use (hardware and software). An by industries 20092011 [9]. Open Architecture should have the capacity to integrate pieces of equipment from several different manufacturers and to Table I shows how the shipments of industrial robots are obtain control solutions with several programmable application distributed over countries. Most of them are used in Asia interfaces, maintaining the same performance at lower costs. (in particular China, Japan and Korea) and Europe. These While there are some efforts to define a Open Architecture, for countries are taking advantage of the benefits of using robots this project we follows the OSEC (Open System Environment in their industries. for Controller) Architecture which is based on a standard Unfortunately, industrial robots are expensive and many personal microcomputer IBM-PC to control manufacturing small and medium size companies in Mexico can not afford equipment [2]. The cost of the machine developed is less to buy and use industrial robots. than half the cost of a commercial CNC machine with similar In the Michoacana University we are developing a CNC characteristics. router table with medium precision, suitable to do tasks over This paper shows the hardware and software components of soft materials like wood, plastic or aluminum. In particular, we the CNC router developed as well as some applications. The

978-1-4799-2370-0/13/$31.00 ©2013 IEEE rest of the paper is organized as follows: Section II describes the general characteristics of the machine developed. Section III presents the control software and some applications in 2D. motor Z Section IV describes how to post-process Gcode files in order motor Y to optimize execution time. Finally, Section V presents the conclusions and future work. Z Y X II.THE CNC ROUTERMACHINE A motor A Figure 2 shows the machine developed, an XYZA CNC router table, using a Dewalt DWP611 router. Additionally it includes a commercial vacuum cleaner to absorb the materials arising from the workpiece when the router is operating. The vacuum cleaner is under the router table and its hose is located motor X next to the Dewalt router. (a) The four degrees of freedom

(b) Rotation around the X axis

Fig. 3. The CNC router table.

precision nuts (5 turns per inch). Each axis uses a Nema 23 stepper motor, model 23HS9430 from Longs Motor [8], 425 oz-in, 3 A, 30 V and 1.8 deg/step. Fig. 2. The CNC router developed. Figure 4 shows the box with four stepper motor driver DM542A, 1850 VDC, peak 4.2A; the Power supply S-350- The router can move in the X, Y and Z directions, and the 24 of 350Watts (24VDC/14.6A); and the Breakout board (all workpiece can be rotated around the X axis, using the motor from Longs Motor). The DM542A applies a PWM (Pulse A, as shown in Figure 3 (a) and (b). The characteristics of the Width Modulation) current control scheme to move the stepper machine are shown in Table II. motor. The stepper motor is controlled by two signals, a P ulse signal (or Step signal) to move the motor a single step, and a TABLE II Direction signal to indicate the direction of the movement. MACHINE SPECIFICATIONS The from the breakout board is used to connect Travel distance Resolution Speed to a Personal Computer (PC). The parallel port outputs are X-axis 16” 0.0005” 1”/s used to control the four stepper motors and the parallel port Y-axis 8” 0.0005” 1”/s inputs receive the status of limit switches for axis X, Y and Z-axis 2.5” 0.0005” 1”/s Z A-axis − 0.45o 1800o/s , and the status of an emergency button (a red button used to stop the machine in an emergency situation). The 5 V supply required by the breakout board is supplied by a USB cable from the PC. Figure 5 shows the connexions between the A. Hardware components different components of the CNC router machine. The CNC router machine has a solid frame of steel and All these components make up a robust CNC router machine aluminum. The axis X, Y , and Z use lead screws and controlled by the parallel port of a PC. NIST first became interested in writing a motion control package as a test platform for concepts and standards. Early sponsorship from General Motors resulted in an adaptation of the fledgling version of EMC using PMAC intelligent control boards running under a ”real time” version of Windows NT and controlling a large machine. Early considerations focused on replacing the expensive and temperamental ”real time” Windows NT system. It was proposed that a relatively new (at the time) real time extension of the operating system be tried. This idea was pursued with success. NIST set up a mailing list for people interested in EMC. As time went on, others outside NIST became interested in improving (a) Driver box (b) DM542A EMC. Many people requested or coded small improvements to the code. As this community became larger, the EMC mailing list and code archives were moved to the SourceForge and the LinuxCNC web site was established. LinuxCNC has many features and brings a lot of function- ality (a flexible and powerful Hardware Abstraction Layer that allows you to adapt it to many kinds of machinery, a software PLC controller, easier installation, a new trajectory planner, and more). LinuxCNC also has a Simulator version, without (c) Breakout board using realtime, that works on standard Linux systems [6]. LinuxCNC is precompiled with LTS (long term Fig. 4. The motor driver box. support) versions for ease of installation and longevity. We use the version of Ubuntu 10.04 LTS in a Personal Computer. Figures 6 and 7 show the parallel port setup and the X axis configuration, respectively. Configurations for axis Y , Z and A are similar.

Fig. 5. Connexions between different components.

III.SOFTWARE COMPONENTS We select a realtime version of Linux operating system on the Personal Computer to control the CNC router machine. This environment is called LinuxCNC [7].

A. LinuxCNC

LinuxCNC is a software system for computer control of Fig. 6. LinuxCNC Parallel Port Setup machines such as milling machines, , plasma cutters, cutting machines, robots, hexapods, etc. LinuxCNC is Free The linuxcnc program executes CNC machine programs in software released under the terms of the GNU GPLv2. the G Code format. The LinuxCNC G Code language is based LinuxCNC is a descendent of the Enhanced Machine Con- on the NIST RS274/NGC language. troller (EMC) created by the National Institute of Standards and Technology (NIST), which is an agency of the Commerce B. Making simple drawings Department of the United States government (see [1] for a Here we review four programs for Linux related to the task survey in 1995 of the NIST realtime control system). of making simple drawings: xfig, potrace, pstoedit and image– Fig. 9. LinuxCNC interface.

Fig. 7. LinuxCNC X Axis Configuration. to–gcode. 1) xfig program: Xfig is a freeware interactive vectorial drawing tool which runs under X Window System on most UNIX-compatible platforms. There is a version of xfig to export drawings to the G Code format [4]. For instance, Figure 8 shows the xfig interface, Figure 9 shows the Linuxcnc Fig. 10. Final workpiece interface associated with the file generated by xfig (hello.ngc), and Figure 10 shows the final result executing hello.ngc. Gimppath, and Xfig. We only found this free program, others similars are comercial programs. 3) pstoedit program: pstoedit translates PostScript and PDF graphics into other vector formats, including the G Code format [12]. 4) image–to–gcode: The program image–to–gcode [13] is integrated to the LinuxCNC program and it transforms a greyscale image into a milling depth map (a G Code file). A depth map is a greyscale image where the brightness of each pixel corresponds to the depth (or height) of the object at each point.

C. Making more complex drawings Fig. 8. Xfig interface. As we can see, Figure 8 shows the letters filled with a black 2) potrace program: Potrace transforms bitmaps into vector color, but the G Code program follows only the contours, as graphics [11]. Potrace is a free software tool for tracing a shown in Figure 10. The same result is obtained using the bitmap, which means, transforming a bitmap into a smooth, pstoedit program. scalable image. The input is a bitmap (PBM, PGM, PPM, We write a program called fill image, to generate paths to or BMP format), and the default output is an encapsulated the router inside the black filled areas, in order to get the same PostScript file (EPS). A typical use is to create EPS files depth in the border and in the interior of the black areas. The from scanned data, such as company or university logos, input to fill image is an image like the one shown in Figure handwritten notes, etc. The resulting image is softer than the 11. original bitmap and it can then be rendered at any resolution. The program fill image uses the OpenCV Software Library Potrace can currently produce the following output formats: (see [5] for a good introduction to Computer Vision using EPS, PostScript, PDF, SVG (scalable vector graphics), DXF, the OpenCV library) and it follows Algorithm 1. It computes GeoJSON, PGM (for easy antialiasing of pixel-based images), the image contours using the Canny operator, where contours Fig. 11. A black & white butterfly Fig. 12. The output of program fill image are represented by non-zero pixels (white pixels over a black background). To Dilate an image, a morphological filter is used.

Algorithm 1 Finding contours INPUT: I, a binary image OUTPUT: R, a binary image with contours R ← BlackImage() // All pixels equal to zero while hasBlackP ixels(I) do C ← CannyOperator(I) // Compute contours of I R ← Add(R,C) D ← Dilate(C) I ← Add(D,I) end while return R

The output of the program fill image with the image of Figure 11 as input, is shown in Figure 12. It can be noted that black areas in the input image are replaced by interior contours that follow the same shape like the exterior contours. We can use the pstoedit program to convert this new image Fig. 13. Eagle Board Editor Interface. (or its inverted one) to a G Code program and finally we get the desired result on the CNC machine. Another alternative to get a similar result is using the image- 2) PCB-Gcode ULP: Pcb-Gcode allows use milling ma- to–gcode program, but in that case the CNC router follows chine, router, engraver, etc. to make printed circuit boards paths from left to right, and from top to bottom, similar to the without using toxic chemicals. Machine cuts around the traces operation of an ink printer (and hence it takes a lot more time for the circuits. PCB-Gcode also creates drill files to drill to finish the task). The result using the fill image program is holes, mill files to cut the board out, or make cutouts in the similar to the operation of a plotter. board [10]. As a test, we create a simple design with Eagle, then use D. Creating Printed Circuit Boards (PCB) PCB-Gcode to create the associated G-code file. Figure 14 For this task we use the program Eagle and the User shows the final result. Language Program (ULP) PCB-Gcode. 1) Eagle program: Eagle is a powerful and flexible PCB design software offering high level functionality [3]. It has algorithms of autorouter the vias and tools that supports in manual routing. Allows feature enhancement through User Language Programs (ULP) which are partly integrated. Eagle can generate data for mounting machines, test equipments, milling machines or any other data format. Figure 13 shows an example of the Board Editor interface of Eagle. Fig. 14. A PCB made with the CNC router machine. IV. POST-PROCESSING THE GCODE FILE Algorithm 2 Optimize the sequence of strokes INPUT: T , sequence of strokes The file generated by pstoedit does not start with strokes OUTPUT: Tn, a new sequence of strokes from the CNC machine origin, instead it starts on the image x ← 0 origin (near to the top left corner of the image) continuing s y ← 0 with the next point located to the right and then it repeats the s while T 6= NULL do left–right search from top to bottom. In this way the strokes t ← SearchClosestStroke(T, < x , y >) sequence makes unnecessary movements. i s s // t starts in point < x , y > and ends in < x , y > We write a program called fast gcode to improve the time i s s e e T ← add(t ) required to do the sequence of movements on the CNC n i < x , y >←< x , y > machine. The input to this program is a g–code file, and its o o e e Delete t from T output is a g–code file where the strokes has been ordered i end while to minimize the movement (and hence the time) of the CNC return T machine between successive strokes. The first stroke selected n has its start point closest to the origin position of CNC machine. We implement the Algorithm 2 to obtain the sequence of Also we plan to review programs that convert 3D models strokes that improve the time to develop the task of CNC from Autocad (or similar programs like blender) to Gcode and machine. add two cameras to the CNC router machine to form a stereo vision system. The idea is to get a 3D model from several Some results of this program are shown in Table III (strokes views of an object and to reproduce the object using the CNC are done using a constant feed rate of 10in/min). router machine. TABLE III ACKNOWLEDGMENT TIMEIMPROVEDWHENSTROKESAREOPTIMIZEDTOMAKETHE CNC MACHINE TASK. The authors would like to thank to the Michoacana Univer- sity to finance a research project to develop the CNC router Strokes pstoedit (min) Our Algorithm (min) Images machine presented in this paper.

REFERENCES 49 9:58 9:00 [1] James S Albus et al. The nist real-time control system (rcs): An application survey. In Proceedings of the AAAI 1995 Spring symposium Series, pages 27–29, 1995. [2] O. L. Asato, E. R. R. Kato, R. Y Inamasu, and A. J. V. Porto. Analysis 272 23:30 21:50 of open cnc architecture for machine tools. J. Braz. Soc. Mech. Sci., 24(3):208–212, 2002. [3] CadSoft. Eagle PCB design software, October 2013. http://www. 280 27:42 26:30 cadsoftusa.com/. [4] Till Harbaum. EMC - machining under linux, October 2013. http: //www.harbaum.org/till/cnc/index.shtml. [5] Robert Laganiere. OpenCV 2 Computer Vision Application Program- ming Cookbook. Packt Publishing, 2011. 316 45:20 40:07 [6] LinuxCNC.org. Linuxcnc: Pure simulator, October 2013. http://wiki. linuxcnc.org/cgi-bin/wiki.pl?LinuxCNC Pure Simulator. [7] LinuxCNC.org. Linuxcnc: Software for realtime control, October 2013. http://www.linuxcnc.org/. 32 1:30 1:25 [8] Longs Motor. 23HS stepper motor, October 2013. http://www. longs-motor.com/productinfo/detail 12 25 114.aspx. [9] International Federation of Robotics. statistics, June 2001. http://www.ifr.org/industrial-robots/statistics/. [10] PCB-Gcode. Use your milling machine, router, engraver, etc. to make V. CONCLUSIONAND FUTURE WORK pcb, June 2013. http://www.pcbgcode.org/. [11] Potrace. Transforming bitmaps into vector graphics, October 2013. http: We have presented a low cost and open CNC router machine //potrace.sourceforge.net/. with 4 degrees of freedom, using stepper motors and the [12] Pstoedit.net. Translates postscript and pdf graphics into other vector parallel port interface of a PC. The PC runs LinuxCNC, a formats, October 2013. http://www.pstoedit.net/. [13] Image to gcode. Milling “depth maps”, October 2013. http://www. real–time version of the Linux operating system. Also we have linuxcnc.org/docs/2.4/html/gui image-to-gcode.html. describe some programs in the Linux environment to make simple tasks. In the near future we planned to apply this CNC router machine as a test bed to do some tasks in the guitars factories in Paracho, Michoacan, Mexico, looking to improve their processes. We also plan to develop open software easy to use to do special tasks over wood in those factories.