You are on page 1of 5

Python based 3-Axis CNC Plotter

Tekumatla Shivakumar Manne Sai Sravan, K Selvajyothi


Mechanical (Design & Manufacturing) Engineering Electronics (Design & Manufacturing) Engineering
IIITDM Kancheepuram IIITDM Kancheepuram
Chennai, India Chennai, India
mdm13b032@iiitdm.ac.in edm13b018@iiitdm.ac.in, ksjyothi@iiitdm.ac.in

Abstract—This paper discusses on an open source python signal generators, driver circuitry and the machine setup. The
based three-axis CNC system. Python being one of the easiest availability of certain components is restricted to only a few
languages to understand exempts the user from requiring countries, thus making it difficult to import. Also, abundant
extreme programming skills to amend the code for personal use. software is designed only for specific machine dimensions
This paper features a novel way of directly importing the CAD making it difficult to adopt them for personal usage.
file into the system without the use of any G-code parser. This
system is economical as it utilizes Arduino UNO board as a signal After a thorough study on the above-mentioned limitations,
generator without compromising on the performance of the we propose the following:
system.
1. A more standard method to directly obtain coordinate
Keywords—Arduino; motion controller; CNC learning data from computer-aided design (CAD) models by eliminating
equipment; open source CNC learning tool; open source CNC the usage of G-code parser.
software; Python; rapid prototyping. 2. To develop a system, capable of governing at least
three-axis.
I. INTRODUCTION
3. A hardware which is less expensive and a setup which is
At present there is a rising demand for computer numerical less complex.
control (CNC) applications in small-scale industries,
educational institutions and among the hobbyists. There are 4. A development language which is open source, easy to
several commercial CNC machine manufacturers like M/s understand, requiring basic programming knowledge, thereby
Fanuc Ltd and M/s SINUMERIK which however meet this making it easily amendable for the user.
need, but are not affordable by the above-mentioned user 5. A much more economical way of using the hardware
community. The high cost of the machine can be associated to which is easily available in most countries.
the usage of custom designed embedded controllers and
machine components. In the past one decade, there have been a In today’s times, the above requirements can be well met
few kinds of literature concerning the implementation of low- by developing the CNC system using Python [7] and Arduino
cost CNC system. In [1] the authors use grbl (open-source G- electronics platform for signal generation.
code interpreter for Arduino) to reduce the cost and an open As suggested by the stack overflow survey [8], Python is
source computer-aided manufacturing (CAM) software which emerging as a widely used programming language for
is machine specific. In [2] a real-time operating system reduces beginners and it is developed under an open source initiative
the development period and the cost, and thereby greatly (OSI)-approved open source license. Python, a dynamic object-
decreasing the program complexity in the design. In [3] the oriented programming language can be used for developing
authors discuss about realizing STEP-NC controller using a many kinds of software. As it offers strong support for
low cost microcontroller to control a CNC machine with two integrating with other languages and tools, Python comes with
degrees of freedom. In [4] the authors discusses on reducing extensive standard libraries and can be learned in a very short
the cost by realizing the controller using Arduino based time. Hence choosing Python in order to develop the CNC
embedded system and an offline G-code parser to convert the system is well justified.
code into National Institute of Standards and Technology
(NIST-SAI) canonical code. The various stages of the system design are shown in Fig.
1. The complete paper is organized as follows: section II
There exists a few open source CNC software online [5][6], discusses proposed a methodology and elaborates the
but however, most of these are not easily customizable. The individual system components and its functionality. Section III
source code of this software is very challenging to understand discusses the results in each stage of the plotter. Then in
as they are mainly developed in Java or Visual Basic. The section IV, conclusion and future scope of the work has been
major disadvantage of the current existing open-source discussed.
software is their integration with hardware, which includes

978-1-5090-2547-3/16/$31.00 ©2016 IEEE 823


Fig. 1. Block diagram representation of the proposed plotter.

means resolution of the tool. ¨x and ¨y are the displacements


II. PROPOSED PLOTTER along x and y-axes respectively in between the two consecutive
The detailed schematic for the proposed plotter is shown in points O and A as shown in Fig. 2.
Fig. 1. The geometric data of a CAD model is converted to In order to reduce the program complexity, the system is
coordinate points and fed to a motion control unit coded in the designed in such a way that at any instant only one axis will be
open source software. These signals are fed serially to the in motion. Hence, in the case of a vertical or horizontal
control circuit for the 3-axis control. Each subsystem used for movement, the number of steps required is proportional to the
this plotter are elaborated in the succeeding subsections. displacement in that particular direction. But, for an inclined
line, the motion of X and Y-axes needs to be altered
A. DXF reader individually as shown in Fig. 2.
A Python library called dxfgrabber [9] is being used to
To draw an inclined line, the movement in the x and y axes
obtain the geometric data from the .dxf file [10]. The .dxf file
is going to be in a serial manner. So the inclined line cannot be
of the CAD model is given as an input to DXF reader and the
obtained exactly but can be approximated to the accuracy of
output is given as an input to coordinate point generator.
the machine tool. For example, let OA be the line of required
pattern which is shown in Fig. 2. But the machine is going to
B. Coordinate point generator follow the green and red colored path where the movements of
The output from the DXF reader is geometrical data, which X and Y-axes are represented with green and red respectively.
is not suitable for the motion control of the machine. Thus it is For the line OA inclined at an angle ș, the step x and the step y
required to convert that geometrical data into useful are calculated as follows: for ¨x > ¨y, the serial data
coordinates. transmitted will be in the sequential order of one step along y
Parametric forms of geometrical shapes is used to convert axis and ¨x/¨y steps along X-axis. This process is repeated for
the geometrical data into coordinates. For example let (x1, y1) ¨y iterations and vice versa.
be the center of a circle with radius r. Any point on this circle
can be represented in coordinate form as (x1 + r cosș, y1 + r
sinș), where ș is varied between 0° and 360°. The number of
data points obtained depends on the discrete levels of ș. Thus
the geometrical data of the circle can be converted into its
coordinates.

C. Motion Control Unit


Once the discrete coordinate points are obtained from the
Fig. 2. Representation of interpolation between two points in the curve and
point generator, the steps required for the motion of individual the illustration of the same by the plotter.
axis motors can be calculated. Here linear interpolation is used
to approximate the curve. Fig. 2 shows the interpolation of two In a similar way, any curve can be converted into a set of
points in the curve and illustrates the same using the plotter. lines and the data required to follow the given path information
Let step x and step y be the number of steps rotated by the regarding the motion of each axis can be calculated in python
X and Y-axes stepper motors respectively where one step and stored in an array. Every element in the array has the axis
name and a direction of rotation associated with it. Once the

824
data is stored in the array, it is sent to machine’s electronics coils. Full stepping scheme is used for plotting vertical and
system to drive the motors. The following encoding scheme horizontal lines whereas, for inclined lines or curved designs
shown in Table I is adopted to attribute this information along 1/8 micro-stepping scheme is used. Use of both the schemes
with the number of steps. Arduino can handle a maximum data together results in a significant decrease in the total plotting
size of 32-bits. i.e. 0 – 4294967295 integer values. time. Depending on the current rating of the stepper motors and
the maximum switching frequency of the PWM input signal,
TABLE I. ENCODING SCHEME
the MOSFET’S or BJT’s used in building the circuits have to
be chosen accordingly. Each stepper motor will be connected
Actual Data Encoded Data to two H-Bridge circuits i.e. one H-Bridge circuit per coil and
X axis: clockwise direction + step count 1******** is built using power MOSFET-55NF06. Fig. 3 shows the
X axis: anti-clockwise direction + step count 2********
hardware circuit for the motor control. The Z-axis servomotor
Y axis: clockwise direction + step count 3********
Y axis: anti-clockwise direction + step count 4********
is controlled directly from the Arduino using PWM.
Z axis: clockwise direction + step count 5********
Z axis: anti-clockwise direction + step count 6********
where *’s indicate the step count. e.g. 200000036 means X- axis should move 36 steps in the
negative direction.

D. Serial Communication
The data (step count) corresponding to the motion of
individual axis X, Y and Z is encoded and stored in an array.
PySerial library is utilized to establish the serial
communication. The time of execution of a drawing is greatly
dependent on the data transfer rate and also on the decoding
and encoding scheme complexity.
The clock frequency of a computer is around 2.2 to 3.6
GHz, whereas the Arduino UNO maximum clock frequency is
16 MHz. This variation in the clock frequencies can lead to
significant data loss or data misinterpretation thereby distorting
the workpiece. Therefore a proper synchronization needs to be
maintained in order to prevent any data loss. This can be
achieved by using a widely known technique called Fig. 3. Experimental electronic controller for the motors.
Handshaking protocol. By implementing this protocol the
entire unit will be functioning at a maximum clock frequency G. Mechanical system
of 16 MHz.
The three-axis CNC pen plotter draws the objects in the
E. Decoding Scheme: CAD file. The rotary motions of the motors have to be
converted to linear motion, which can be done in many ways.
Once the data is available in the serial register of Arduino it Ball screw mechanism and Rack and pinion mechanism are
reads in and compares the first digit to determine the encoding two methods among them. Rack and pinion mechanism, in
type and then executes the corresponding functionality. The which the table rails are glued with a belt drive as racks and the
next data will be available in Arduino serial register but will small plastic gears as pinions is built as shown in Fig. 4. The
not be read until the current function is executed completely. In pitch of the pinion is equal to the belt pitch. With this setup, an
order to establish a proper serial connection the designer must accuracy of 0.08mm is obtained.
make sure that the serial port parameters are set with the same
values in both the Python terminal and Arduino. These include
Port number, Baud rate, Data bits, Stop bits, Parity type and
Flow control.

F. Signal generation
The three stepper motors being used are having a resolution
of (1.8°) 200 steps per revolution. In order to reduce the cost of
the equipment and to keep it simple, rack and pinion
mechanism is used. Therefore the tool resolution is completely
dependent on the resolution of the stepper motors and pitch of
the gear. In order to increase the number of steps 1/8 micro-
stepping scheme is used. The cost of the equipment is reduced
by designing and building a micro stepping driver circuit based
on the rating of the motors. For this study, micro stepping
driver IC A3967 is used to generate the PWM signals and H- Fig. 4. Rack with belt arrangement.
Bridge circuit to switch the 5 V power supply to the motor

825
One servo motor and three stepper motors are being used to drawn by the pen plotter is shown in Fig. 10. The total time
provide the motion along the X, Y and Z-axes. The servo taken by the plotter to plot this CAD model specified as per
motor attached to a slider crank mechanism shown in Fig. 5 Fig. 7 is about 16.2 s by the proposed scheme. Consider
gives the motion along Z-axis which allows the pen to move another CAD model of alphabet “D” as input to the plotter as
upside down. Two stepper motors on the near end of Fig. 6 shown in Fig. 11. The output of point generator and the plotter
which are connected to rack and pinion give the motion along output are shown in Fig. 12 and Fig. 13 respectively. Here the
the Y-axis and one stepper motor with rack and pinion placed time taken by the plotter is about 69.4 s with the proposed
on the farther end gives the motion along X-axis. Here servo methodology. This is to demonstrate the smooth plotting of
motor is used along with slider crank mechanism to decrease curves.
the load on both X-axis and Y-axis.
A study has been made on the errors in plotting a line,
inclined line and a curve. The error in final plotting is due to
approximation of curves and nonlinearities present in the
mechanical equipment. But these errors are not the same in
every case. Table III represents the approximate errors in the
plotter for various plots.

TABLE II. SPECIFICATION OF THE PLOTTER


Component Specification
Max. material size and layout 500mm×600mm×170mm(19.685”
area ×23.622”×5.905”)
Resolution 80ȝm
Repeatability ± 0.080 mm
Travel speed Varies
X-drive 1-Bipolar stepper motor
Y-drive 2-Bipolar stepper motors
Fig. 5. Slider crank arrangement for Z-axis movement of the pen. Z-drive 1 servo motor
Machine baseplate Plywood
Power Supply 5V 4A Power Adaptor

Fig. 6. Proposed CNC pen plotter having two stepper motors for Y-axis
control, one stepper motor for X-axis control and a servomotor for Z-axis
control.
Fig. 7. CAD model of alphabet T fed as input to the plotter.

III. RESULTS AND DISCUSSION


Table II represents the specification of the pen plotter
developed. The outputs of the various stages of the plotter are
detailed in this section. Consider the CAD model of alphabet
“T” as input to the system. First, the CAD model is converted
into DXF format and given as input to the dxf reader. CAD
model of input is shown in Fig. 7. The data shown in Fig. 8 is
the output from the dxf reader and this file is given as input to
coordinate point generator. From the above data, the Fig. 8. The output from the dxf reader goes as input to coordinate point
coordinates are generated and output of the coordinate generator.
generator is shown in Fig. 9. Based on the coordinate data the
axis motion is controlled by the motion control unit. The output

826
TABLE III. THEORETICAL VS EXPERIMENTAL ERROR FOR THE PLOTTER
Geometry Theoretical error Experimental error
1.Vertical line 0mm ±0.5mm
2.Horizontal line 0mm ±0.5mm
3.Inclined line ±0.04mm ±0.54mm
4.Every other Curve ±0.08mm ±0.84mm

IV. CONCLUSION
The indigenous CNC plotter can be interfaced with any
mechanical setup by varying the resolution parameter in the
Python code depending on the resolution available with the
hardware. The accuracy in printing obtained using the
Fig. 9. Output T from the coordinate point generator plotted in Python. proposed plotter is 0.8mm. This accuracy can be increased
further by installing a proper mechanical system. As this
system is completely coded in Python, it is very easy to
understand the working of a machine and amend it for personal
use. The whole CNC system can be used as a learning tool for
university students which can be of a help in understanding the
automation involved in manufacturing. This system doesn’t
have any G-code parser. Hence, the understanding of CAD
methods in CAM is easy. The system is made using open
source hardware and software, thus making it available at low
Fig. 10. The output drawn by the pen plotter. cost, which can improve the profits of small scale industries.
This system can be directly implemented on Raspberry pi,
Beagle bone or other high-end embedded platforms. Thereby
completely eliminating the Arduino Board and PC from system
design and making it highly portable. This can significantly
reduce the system cost with a slight increase in setup
complexity.

REFERENCES
[1] S. Pandian and S. R. Pandian, "A low-cost build your-own three axis
CNC mill prototype", International Journal of Mechanical Engineering
Fig. 11. CAD model of alphabet D fed as input to the plotter. and Robotics, ISSN: 2321-5747 vol. 2, no. 1, 2014.
[2] Tao Wang, Qingjian Liu and Liwen Wang, "An RTOS-based embedded
CNC system," 2010 International Conference on Computer,
Mechatronics, Control and Electronic Engineering, pp. 33-36,
Changchun, 2010.
[3] F. Calabrese and G. Celentano, "Design and realization of a STEP-NC
compliant CNC embedded controller," IEEE Conference on Emerging
Technologies and Factory Automation, pp. 1010-1017, Patras, 2007.
[4] A. Khanna, A. Kumar, A. Bhatnagar, R. Tyagi and S. Srivastava, "Low-
cost production CNC system," 7th International Conference on
Intelligent Systems and Control (ISCO), 2013, Coimbatore, Tamil Nadu,
India, pp. 523-5282013.
[5] Free Mechanical Engineering CAD/CAM Software, availabe at
www.freebyte.com/, (accessed April 2016).
[6] Open source Arduino CNC controller softwares, available at
Fig. 12. Output coordinate points generated in Python for D. https://sourceforge.net, (accessed April 2016).
[7] Michael Dawson, Python Programming for the Absolute Beginner,
Course Technology, a part of Cengage Learning, 3rd edition, 2010.
[8] Stack overflow Developer Survey,
www.stackoverflow.com/research/developer-survey-2015, (accessed
April 2016).
[9] dxfgrabber-documentation and installation guide, available at
https://media.readthedocs.org/pdf/dxfgrabber/latest/dxfgrabber.pdf,
(accessed April 2016).
[10] DXFfiles-https://en.wikipedia.org/wiki/AutoCAD_DXF, (accessed
April 2016)
Fig. 13. The output drawn by the plotter.

827

You might also like