You are on page 1of 6

Low-Cost Production CNC System

Ankit Khanna, Ankit Kumar, Anupam Bhatnagar,


Rajiv Tyagi and Smriti Srivastava

Abstract-The paper discusses the development of a low


cost CNC system capable of 6 axis simultaneous interpolated
operation. The lower cost is achieved by incorporating all
the features of a standard PC or micro-controller based
CNC system in an Arduino based embedded system. The
system also features an offline G-Code parser wherein the
G-code is first converted to the NIST-SAl canonical code
(NCC) {8]{6] and then interpreted on the micro-controller
from a USB stick. Novel procedures are employed in the
system to reduce the computational overheads in controlling a
6-axis CNC machine, while avoiding any loss in overall
system performance. The whole project is launched as an open
source project under GNU GPL v3.0. The source code and
hardware reference design will be available on Google Code.
Keywords: Low Cost CNC System,
RS274NGC, G-code, V-drive, MicroVGA.

Maple,

NIST

I. INTRODUCTION

2
CNC stands for Computer Numerical Control[ ], and refers
to a computer "controller" that drives a machine tool to
create objects by selective removal of material. This
computer based controller reads G-code instructions,
interprets them and performs numerically directed
interpolation[I] of a cutting tool in the work envelope of a
machine to fabricate components.
The designer generally uses a Computer Aided Design/
Computer Aided Manufacturing (CAD/CAM) program on a
computer to generate the "G-code" file. The output G-code
from the CAM system is transferred to the Machine Controller
for interpretation and consequent tool motion control.
The machine controller interprets the part program to control
the tool motion in multiple axes[3 ], to realize the target
object after removal of excess material. The axes of the
machine are moved by screws which are powered by servo
motors or stepper motors. The signals from the machine
controller are amplified by the drives so that they are
powerful enough and suitably timed to operate the motors.
The traditional machine controllers (like Fanuc[5], siemens)
employ PC based or embedded CNC systems which,
because of the overheads imposed by a very large G-code
parser (>200 kB of binary code, in case of the NIST parser),
increase the hardware cost of the system, making it
unaffordable for use by small-scale industries and bottom
of-the-pyramid CNC users. The earlier developed micro978-1-4673-4603-0/12/$31.00 2012 IEEE

controller based CNC systems had many drawbacks. The


GRBL G-code interpreter[13 ] for example, implemented only
some of the many g-codes. Many projects like the "RTOS
based Embedded CNC System,,[12] and "An Open
Architecture Numerical Control System Based on Windows
CE,,[9] have implemented OS on the embedded system
which decreases the processing and memory capacity of the
system. Thus, these systems require high end and expensive
microprocessors. The project titled "Design and Realization
of a STEP-NC compliant CNC embedded controller,,[IO] and
"Design of a 3 Dimensional CNC System,,[ll] had the
disadvantage of workability with only a 2-Axes machine.
In this paper, development of a comprehensive, 6-axis,
simultaneous interpolation, low-cost production CNC
system, minus the hardware required in traditional CNC
systems is discussed. A 6-axis CNC system is stripped of the
need for a G-code parser and converted to an embedded 6axis CNC system using an Arduino based Leaf Maple
micro-controller[14]. Since the G-code parser, which is an
integral part of the system, is offline, a huge reduction in the
cost price is achieved, thus making the system affordable by
the bottom-of-the-pyramid CNC users as well. It is, of
course, usable all the way up the value chain. This
controller, however, will not lend itself to the development of
G-code on-line - that will have to be done on a traditional
CNC control system, which has an on-board G-code parser.
The Embedded CNC Controller (ECC) has the capability to
provide a precision of up to 1 micron. The ECC implements S
Curve acceleration profile in comparison to the trapezoidal
acceleration profile as provided by most of the other CNC
systems thus, smoothening motion of the axes, thereby
prolonging the life of critical precision motion components
of a CNC machine.
II. ARCHITECTURE

The complete system is divided into 2 parts: the GUI parser


which converts the input G-code file into a simpler file
7
containing the canonical functions[ ] called NCC and the
micro-controller system which acts as the machine control unit.
A. GUI Parser

The GUI parser is developed using the QT Framework


compatible with both Linux and Windows. The GUI
executes the binary of the RS274NGC interpreter by passing 3

Proceedings of7'h International Conference on Intelligent Systems and Control (ISCO 2013)

524

input files - the input G-code file, the tool file and the
parameter file to it. The output generated is a text file
containing the canonical code (NCC). The GUI provides the
capability to upload the output file to a USB stick which
acts as an input to the actual CNC controller.

""" I

The USB Stick containing the NCC is read by interfacing a


VDRIVE2 module from FTDI with the Maple micro
controller[l41. The micro-controller reads the file specified
by the user via the HMI, line by line. It performs the
function specified by that line and then moves on to the next
line for parsing it.
This ECC system has the capability to control and drive up
to 6 motors of a machine with feedback being handled at the
servo drive, if required. The unit has a dedicated pulsing
engine unit which provides continuous pulses to the
STEP/DIR servo drives. The drives take the feedback from
the rotary encoders for precise positioning giving the system
a precision of up to I micron. The I micron limitation is not
that of the machine or encoders but of the arithmetic scheme
used within the micro-controller firmware.
G-Code Input from
CAM Software

G-Code to Canonical Function Converter using


PC based GUI Parser

Canonical Function Input DeVICe (USB Stick storing


the Canonical Functions)

FIG. I: STAGE 1 CANONlCAL CODE CONVERTER (C3)

The HMI consists of a keyboard and a VGA monitor


interfaced with the help of MicroVGA module. The HMI
provides the start, stop and status related information. The
MicroVGA is interfaced via Arduino RBBB (Really Bare
Bones Board) microcontrollerl151. The Arduino communicates
with Maple[141 using serial UART communication for
transfer of system parameters and status values like current
coordinates, feed rate etc. from one micro-controller to the
other.

V.dnve for USB Stick to Maple Interface

l=

B. Machine Control Unit

The machine control unit performs the functions of (i)


parsing of NCC by taking the input from a USB stick, (ii)
precise pulsing of the servo drive to drive the motors and (iii)
handling of the Human Machine Interface (HMI), the visual
aspect of which has been implemented by a stand-alone
VGA sub-system available as a stand-alone product called
MicroVGA. The micro-controller used is an Arduino based
Maple RET 6 edition micro-controller board[141 from Maple
Leaflabs with STM32 F103RB processor. The processor has
a clock speed of 72MHz, 39 digital 110 pins and a flash
memory of 128KB.

USB Stick Conummg unOlllcal


Funcoons

5l
:::k llfeevedbaCky

FIG. 2: STAGE 2 MICROCONTROLLER DRIVEN SYSTEM

III. IMPLEMENTATION MODULES

The process of reading and interpreting the G-code file to


drive the machine tool requires the execution of a number of
implementation modules. The process starts by taking up a
G-code file and interpreting this file by PC-based GUI
parser to produce a simpler canonical code (NCC) file. NCC
file is then transferred to the Machine Control Unit through
a USB stick. The Maple micro-controllerll41 then reads this file,
interprets it and provides precise pulses to the STEP/DIR
servo drives for driving the axes motors.
A. Interpreter and Canonical Code Converter
3
(CCC or C )

This Low-Cost, CNC system implements RS274NGC


programming language for G-code input. RS274 is a
programming language for numerically controlled (NC)
machine tools, which has been used for many years. It has a
predefined syntax of a tool path control language called G
Code. The RS274INGC interpreter takes this G-code as the
input and provides the canonical functions after interpreting
it. The G-code parser for Windows and Linux has been
derived from the US National Institute of Standards and
Technology (NIST) RS274NGC G-code parserl81[61, an open
source product from NIST.
The Interpreter, before accepting any input, sets up a world
model that includes data about itself, parameter data, and
data about the machining centre being controlled (including
data about the tools in the tool carousel of the machine). All
this data is contained in two files viz. the parameter file and
the tool file. Once initialized, the Interpreter runs in a two
step process:
1. It gets a line of RS274INGC code and reads it into
memory, building an internal representation of the
meaning of the entire line. We will call this stage
"reading."

Low-Cost Production CNC System

525

2. It then changes the internal state and/or calls one or


more canonical machining functions in order to do
what the line says to do. We call this "execution of the
line". These functions are printed in a text file for
execution on the micro-controller.
The Canonical Code Converter (CCC or C3) is PC based
parser providing a GUI compatible with Linux as well as
Windows. The basic idea of C3 is to generate a simplified
version of the canonical output for fast execution on the
computational and memory constrained environment of a
low-cost micro-controller. It provides the user with an easy
to use GUI environment.
3
The algorithm and flow of C is as follows:

The GUI once opened, loads the default input files if


present in the current directory.

If the user wants to change any of the files, he can change


it using the file menu.

The "Parse" button then parses the G-code input file,


and gives the output log. The output log shows an error
if present and displays "Successfully Parsed" if the G
code is parsed completely and error-free. The fust error
found is highlighted in the G-Code input field as shown
below.

C. 6- Axis Bresenham Algorithm

For producing a job with smoother finish, all the axes of the
machine should ideally move simultaneously. To achieve
this, a 6-axes Bresenham Algorithm is employed. The
inputs to the Bresenham module are the initial and the fmal
points. The outputs are the interpolated points between the
two endpoints. The whole data generated in addition to the
feed rate for each of the axis is stored in a FIFO buffer.
Many hardware interpolation circuits have been traditionally
employed like the project titled - "Interpolator for a Computer
Numerical Control System" [41. But for the micro-controller
based CNC system, Bresenham algorithm provides quick and
easy to process coordinates.

tep

6 stapting points: 1 ? 3 9 ? 8
ntep 6 end points: 2 ? 4 082
fDsplaYing the inteppolated points

?
I ?
?
?
I .. ?
?
2?
i? ?
12 ?
?

3 9 ?8
3 8 ? ?
3 ? ? ?
3 6 ? 6
35 ?5
4 485
43 8 4
4283
4 183
4 082

FIG. 4: BRESENHAM ALGORITHM SAMPLE OUTPUT

D. FIFO Buffer

11)15
g1 .. 5>5
$1 .. 3 t1
g1o5 z10
.. hlJ

OK

I'

FIG. 3: ERROR DETECTION MESSAGE Box

The output canonical file can then be uploaded to a


USB Stick from the file menu.

The interpolated coordinates as generated by the Bresenham


algorithm are stored in a Circular First in First out Buffer.
The processing of machining functions takes time so the
FIFO buffer keeps on storing coordinate values d-uring the
execution of functions. This provides smooth and
continuous motion of the axes as any motion discontinuity
will cause tool marks to be left on a job.
In addition to the coordinates, the instantaneous feed rate at
each point which is calculated from the S-curve speed
profile is also stored in the FIFO buffer. Thus, each node in this
FIFO buffer is a structure of 6 interpolated points as retwned
by Bresenham along with an instantaneous feed rate. In order
to minimize the time taken in inserting and fetching data from
the FIFO, it has been programmed to execute all these
operation in 0(1) order time complexity.

B. V-Drive Interfacing with the Machine Control Unit

The NCC file is transferred to the machine control unit via a


USB stick interfaced through the FTDI Vinculwn VDrive2
module. Libraries for V-Drive have been developed for this
project, to enable quick and modular reading of the contents
of the NCC file.
The NCC File specified on the HMI by the user is read line
by line and each line is parsed by a rudimentary text parser
developed on Maple[I41. The parser then calls the functions
as specified on that line.

Tail

(insert)

FIG. 5: FIFO BUFFER STRUCTURE

Proceedings of7'h International Conference on Intelligent Systems and Control (ISCO 2013)

526

E. S-Curve Speed Profile

The rate at which the machine's axes accelerate in about


90% of the traditional CNC systems is determined by a
trapezoidal speed profIle curve against time. Although being
used widely, this profile curve leads to abrupt changes in the
speed of the motors. The implementation used in the controller
being discussed is an S-curve speed profile. The advantage
of using S-curve in preference to trapezoidal curve is that it
leads to smooth velocity profile for all the axes motors.
The function used for S-curve profile is given by,

one can achieve a precise pulse width by triggering the


counter, sending a low signal on a specific pin and calculating
the counter value to obtain that pulse width. A high signal is
sent on that pin once the counter value matches with the
calculated value of the counter.
Each axis in a machine has a predefmed value of its micron
per pulse movement. This also gives the least count of the
motors in the machine. The feed rate obtained from the
FIFO buffer is used to decide the pulse period. The pulse
width is of a predefmed value, for instance 1-5 microseconds.
Each pulse would either move the motor in positive
direction or negative direction depending on the level of the
DIR pin on the drive.

Where,
S is the speed at the time instant t
F is the feed rate
a is a constant defined as
td is

a constant defmed as

Predefin ed
Pulse Widt h

e4A IF

log(F -1)

Feed Rate from

log(a)

S - Curve

The profile of the S-Curve is chosen such that the minimum


speed is the resolution of the motors in their respective axes.
For example, if the resolution is 1 micron per pulse then the
minimum value on the s-curve will be 1 micron. The
following figure shows a comparison between the
trapezoidal and S-curve profile speed. It shows the three
regions of the curve, viz. accelerating, constant velocity and
decelerating regions.

'-

>

I I
(

TEP

PIN PULSING

Pulse Per i od corres p onding


to Feed Rate
IOIR PINI PULSING

Ne' xt Coordinate> Previous

N '" C"d; ",' , < P","ou,

FIG. 7: SERVO DRIVE PULSING

_ S-Curve
Trapezoidal

IV. STEP BY STEP IMPLEMENTATION OF


VARIOUS ALGORITHMIC MODULES

10

40

lO

Time Axis

FIG. 6: TRAPEZOIDAL & S-CURVE SPEED PROFILE COMPARISON

F. Servo Drive Pulsing

The motion of the various axes is controlled by the motors


of the machine tool which are driven by the STEPIDIR
servo drives. The Maple micro-controllerfl41 provides pulses to
the TCTECH PMDC servo drives to drive the DC motors
which are controlled by positional feedback through a rotary
encoder.
The pulsing is accomplished by using "Timers" in the
Maple RET6 edition[141. Timers provide the capability to
generate periodic or delayed events through Maple[141. Each
channel of a timer has an associated 16-bit counter which
increments its value at a maximum rate of 72 MHz. Thus,

The G-code file is interpreted by C3 and a canonical output


functions file (NCC) is generated which is transferred to the
machine controller through a USB stick.
The USB flash disc interface provided by Vinculum
Vdrive2 module allows the NCC file in the USB stick to be
read line by line and corresponding machining functions are
called, for example STRAIGHT]EED, ARC]EED etc.
STRAIGHT_FEED is executed when machining is required
to be achieved in a coordinated linear motion from a current
machine coordinate to a specified point given by x, y, z, a, b
and c coordinates. The execution of STRAIGHT FEED
takes place in the following manner:
(a) The simultaneous interpolation of each of the axis is
achieved by the Bresenham algorithm.
(b) Each of the points which are returned by the 6-Axes
Bresenham algorithm and the instantaneous feed rate
calculated from the S-curve speed profile is stored in a

Low-Cost Production CNC System

527

FIFO buffer. The buffer keeps on storing these values


even during the execution of machining functions.
(c) Each axis of the machine has a predefmed value of its
micron per pulse movement which gives the least
count of the motion that can be carried out by the
motors of the machine. The rate at which each node is
removed from the FIFO buffer is directly proportional
to the instantaneous feed rate at each of the points
removed. This rate of removal is nothing but the
period of the pulses which will drive the motors by
pulsing the TCTECH PMDC servo drives. The motor
will move either in positive or negative direction
depending on the level of the DIR pin on the drive as
shown in the Figure 7.
The ARC_FEED function moves the machining axes in a
helical arc from the current position at the specified feed
rate.
This CNC System supports all the g-codes specified by the
RS274 Language i.e. gO-g4, glO, gI 7-g21, g2S, g30, g3S.2,
g40-g43, g49, g53-g59.3, g61, g61.l, g64, gSO-g94, g9S, g99.

B. Canonical Output File

The canonical output file was generated by the GUI parser.


Following are the output canonical functions generated by
the parser for the G-code mentioned above. Each line starts
with an alphabet or some special symbols which are predefmed
and are mapped to the corresponding canonical functions.
This is done keeping in mind the space constraints in the
micro-controller and the time machine will take in reading
the complete canonical function names, which have now been
reduced to just a single letter or in some cases, a symbol.
B 2#USE

LENGTH- UNITS

A 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000#SET-ORIGIN-OFFSETS


F2#SET_FEED_REFERENCE
E 9.0000#SETJEED_RA TE
L -S.OOOO 0.0000 S.OOOO 0.0000 0.0000 0.0000#STRA IGHTJEED
L -3.0000 0.0000 7.0000 0.0000 0.0000 0.0000#STRA IGHT FEED
L -S.OOOO 0.0000 10.0000 0.0000 0.0000 0.0000#STRA IGHT FEED
L -3.0000 0.0000 12.0000 0.0000 0.0000 0.0000#STRA IGHT FEED
L -9.S000 0.0000 2S.0000 0.0000 0.0000 0.0000#STRA IGHTJEED
L -6.0000 0.0000 SO.OOOO 0.0000 0.0000 0.0000#STRA IGHTJEED
L -10.0000 0.0000 60.0000 0.0000 0.0000 0.0000#STRA IGHTJEED

V. EXPERIMENTAL RESULTS

This CNC system was used to machine a rectangular piece


of wood into a chess piece (Bishop) on a lathe machine. The
top view profile of the job desired is shown in Fig. S .
The axes and the spindle speed of the lathe machine were
controlled by the machine control unit. The following
procedure shows the machining of this wooden piece to get
the desired chess piece

C -11.0000 0.0000 60.0000 0.0000 0.0000 0.0000#STRA IGHT TRA VERSE


C -11.0000 0.0000 0.0000 0.0000 0.0000 0.0000#STRA IGHT TRA VERSE
C 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000#STRA IGHT IRA VERSE

C. Machining the Wooden Piece

A. G-code Input File

A G-code input file containing the machining code was


passed to the G-code parser and an output canonical file is
generated by it. Following is the G-code written for the
machining of the wood piece.
F9.00
gl x-5 z5
gl x-3 z7
gl x-5 z10
gl x-3 z12
gl x-9.5 z25
gl x-6 z50
gl x-l0 z60
gO x- I I
gO zO
gO xO
%.

FIG. 9: CUBICAL WOODEN PIECE LATHED INTO A CYLINDER

Job Top View Profile


Z(mm)

FIG. 10: JOB IN PROGRESS

FIG. 8: DESIRED JOB PROFILE

The two axes motors each had a rating of 5 micron per


pulse. The following graph shows the profile desired on the
work piece and the error in the job done. It must be borne in
mind that the job was executed on soft wood, which will
show much higher error as compared to industrial plastics or
metals such as brass or die steel. The results shown below,
for wood, are considered excellent.

Proceedings of7'h International Conference on Intelligent Systems and Control (ISCO 2013)

528

TABLE 1: DESJRED AND OBTAINED DIAMETER COMPARISON

Diameter
S. No.

Desired
Diameter (mm)

Obtained
Diameter (mm)

Error
(microns)

5.02

20

3.02

20

5.03

30

3.05

50

9.5

9.55

50

6.05

50

10

10.05

50

Max Error

20 microns
Z(mm)

5.02 mm

X(mm)

PC now enables vendors of every kind to create their own


canonical functions, maybe better or more efficient than ours.
REFERENCES
[I]

G. G. Ertell, Numerical
Interscience, 1969.

[2]

Y. Koren, A. Shani, and 1. Ben Uri, "Numerical control of a


lathe," IEEE Trans. Ind. Gen. Appl., vol. IGA-6, pp. 175- 179,
Mar. 1970.

[3]

Y. Koren and 1. Ben Uri, "Digital control of multiaxial-motion


system," in 5th Int. Fed. Automat. Contr. World Congr.,
Paper 375, Paris, June 12-17,1972.

[4]

Yoram Koren, "Interpolator for a Computer Numerical Control


System", IEEE Transactions on Computers, Volume 25 Issue
1, Page 32-37, January 1976

[5]

Fanuc Ltd; Fanuc System 9-Model A Operators Manual; Pub


B-52364E/03; Fanuc Ltd; 1981

[6]

Martin Marietta; Controls Standardized Application (CSA);


Draft Volume V of Next Generation Workstation/Machine
Controller (NGC) Specification for an Open System
Architecture Standard (SOSAS); Martin Marietta Document
No. NGC-0001-14-000-CSA; March 1992

[7]

Proctor, Frederick M.; Kramer, Thomas R.; Michaloski, John


L.; Canonical Machining Commands; NISTIR 5970; National
Institute of Standards and Technology, Gaithersburg, MD;
January 1997

[8]

T.R. Kramer,F.M. Proctor,E. Messina; The NIST RS274INGC


Interpreter - Version 3;NISTIR 6556;National Institute of
Standards and Technology,Gaithersburg, MD; August 17,2000

[9]

FIG. 11: DESIRED AND OBTAINED DIAMETER COMPARISON

VI. CONCLUSIONS

We have already reached the stage of a working device,


very much usable in a commercial environment, albeit in a
limited way. The entire code-base is available for anyone to
program easily on to an Arduino based board and check for
themselves. The code-base is available on the following
Google code project titled 6-axis-cnc-system: http://code.
google.com/p/6-axis-cnc-system/downloads/list
This CNC system is capable enough to give a precision of
up to 1 micron. The implementation of S-curve speed
profile has enabled smooth motion of the machine axes in
comparison to the trapezoidal speed profile curve which is
implemented in traditional CNC controllers.
In this paper, it is thus shown that the development and
realization of a low-cost, production CNC system is
possible. The whole paper is about the fact that we have
worked out a method to reduce cost of a CNC system, using
an innovative method. The method we have used should be
portable across micro-controller architectures thus allowing
a unified interface and system for low-cost systems.
As a GPL v3.0 release, we are hoping that other people will
join this exercise and contribute to the code significantly.
What we have removed from the controller and placed on to a

Control.

New

York:

Wiley

An Open Architecture Numerical Control System Based on


Windows CE", iEEE international Conference on Control

and Automation.
[10] Giovanni Elentano, Francesco Calabrese,"Design and realization
of a STEP-NC compliant CNC embedded controller." Suhua
Xiao, Di Li, Yizong Lai, Jiafu Wan, and Shouting Feng, "
[II] Venkata Krishna Pabolu and Prof. Sri K.N.H.Srinivas, "Design
and Implementation of a Three Dimensional CNC Machine",

International Journal on Computer Science and Engineering.


[12] Aeronaut. Autom. Coil., Civil Aviation Univ. of China, Tianjin,
China, "An RTOS-based embedded CNC system", Computer,
Mechatronics, Control and Electronic Engineering (CMCE),
20I0 International Conference
[13] Coil. of Comput. Sci., Shaoguan Univ., Shaoguan, China, "The
research of embedded CNC system component", Computer
Application and System Modeling
(lCCASM), 2010
International Conference
[14] LeafLabs Maple Hardware Design Files - https:llgithub.com/
leaflabs/maple
[15] Paul Badger, Andrew Urbanski, Sebastian Corwin, Arduino
RBBB http://shop.moderndevice.com/products/rbbb-kit

Devices
[I]

Maple micro-controller board - http://ieaflabs.com/devices/maple

[2]

http://www.ftdichip.com/Products/Modules/
VDRIVE2
ApplicationModules.htm

[3]

MicroVGA - http://microvga.com/

[4]

RBBB Kit - http://shop.moderndevice.com/products/rbbb-kit