Professional Documents
Culture Documents
Full Text 01
Full Text 01
Master’s Thesis
Authors
Changappa Kongiranda Ganapathi (chako332)
Vivek Mandanna Balapanda Erappa (vivbe598)
Abstract
The intent of the thesis is to automate the generation of computer numerical control (CNC) codes
from geometrical computer-aided design (CAD) models. The work is carried out using two
machines, MDX 40A milling machine and HAAS VM3 machine. The case study is to determine
the potential in automating the code generation process. The empirical findings from the research
studies reveal that the manual process for programming the codes for the models pose a challenge
of consuming more time using the procedures in computer-aided manufacturing and manual
operations performed by a programmer. One crucial factor to meet these requirements is the
productivity of the machining process. Design automation for machining is the potent tool to
increase the productivity in this process.
The main methods used in the study to fulfil the main objective of the thesis are addressed. The
programming of the code is automated for these two machines and the outcome is compared with
the manual approach. The need of automating the codes is to provide better accuracy and
efficiency. Further the automation is beneficial as it increases the capability to accommodate the
new changes in the design of the model. The conclusion drawn from the results of the study is that
the automation for code programming results in increasing the speed of the machining process by
reducing the time consumption. Though the approach of automating codes is carried out for two
machines, the potential of this approach is that the code generation process is not dependant on the
post processor of any specific machine.
II Linkoping University | Design automation for CNC machining
Acknowledgements
We would like to thank our supervisor Mehdi Tarkian who gave us an opportunity and handful
of support to work on this master thesis at Linköping University. We appreciate his advices,
dedication, approach and constructive comments and corrections made, which have helped us to a
great extent to accomplish our thesis project. The thesis report was written under the guidance of
our supervisor.
We would like to acknowledge our examiner Johan Olvander for giving us an opportunity to
complete our thesis successfully.
We are so grateful to have our research engineer at Linkping University Per Olof Karlsson who
helped us in providing all the resources at the machine lab. Thank you for being our teacher and
guide. His excellence of teaching helped our thesis work to be completed successfully.
Finally, we would like to express our deep sense of thanks and gratitude to our families. Their
continuous motivation and support made our journey so valuable.
Table of Contents
Abstract ............................................................................................................................................ I
Acknowledgements ......................................................................................................................... II
Table of Contents .......................................................................................................................... III
List of figures and tables ................................................................................................................ V
Nomenclature ................................................................................................................................ IX
1 Introduction ............................................................................................................................. 1
1.1 Aim ................................................................................................................................... 1
1.1. Problem statement ............................................................................................................ 1
1.2. Project goals ..................................................................................................................... 2
1.3. Deliverables ...................................................................................................................... 2
1.4. Limitations and challenges ............................................................................................... 2
1.5. Purpose and research questions ........................................................................................ 3
1.6. Thesis Background ........................................................................................................... 3
1.7. Ethical Aspects ................................................................................................................. 4
1.8. The structure of the report ................................................................................................ 4
2. Methodology ........................................................................................................................... 6
2.1. Research Approach .......................................................................................................... 6
2.2. Overall process and steps carried out in automated approach ......................................... 6
2.2.1. CAM system flowchart ............................................................................................. 8
2.3. Pre study ........................................................................................................................... 9
2.3.1. Introduction ............................................................................................................... 9
2.3.2. Computer- aided design (CAD) and Geometric Modelling .................................... 10
2.3.3. Computer-aided manufacturing (CAM) ................................................................. 11
2.3.4. Computer numerical control (CNC) ....................................................................... 12
2.4. Current process ............................................................................................................... 17
2.4.1. Current process in Roland MDX 40A machine (Manual approach) ...................... 17
2.4.2. Current process in HAAS VM3 machine (Manual approach) ................................ 18
2.5. Model validity and reliability ......................................................................................... 18
2.5.1. Validity ................................................................................................................... 19
2.5.2. Reliability................................................................................................................ 19
3. Theoretical framework .......................................................................................................... 20
IV Linkoping University | Design automation for CNC machining
Figure 41 Parameters created for point on the hole with formula. ............................................... 67
Figure 42 Image showing the two parameters of the point- pointl and pointhb. .......................... 67
Figure 43 Rule 1 assigned to Parameter X3.................................................................................. 68
Figure 44 Hole moved to the right from the centre by changing the parameter. .......................... 68
Figure 45 Parameters for workpiece and tool ............................................................................... 69
Figure 46 Machine and work piece origin shown as Point A and Point B ................................... 69
Figure 47 Tool movements according to the code ........................................................................ 72
Figure 48 CAD model of hollow cylinder with parameters ......................................................... 74
Figure 49 Design parameters of hollow cylinder .......................................................................... 75
Figure 50 Setting parameter for tool origin .................................................................................. 76
Figure 51 Setting parameters for machining ................................................................................. 76
Figure 52 Setting parameters for machining the cylinder ............................................................. 77
Figure 53 Hole drilling operation shown in Top View ................................................................. 78
Figure 54 View of the tool operation inside the cylinder. ............................................................ 80
Figure 55 Tool path for Outer part of cylinder ............................................................................. 81
Figure 56 Parameters used for 100mm cube having three fixed holes ......................................... 84
Figure 57 Parameters used to set the origin point ......................................................................... 84
Figure 58 The parameters for g-code of model 3 ......................................................................... 85
Figure 59 parameters created for making three different holes .................................................... 85
Figure 60 The parameters corresponding to three holes ............................................................... 85
Figure 61 Rule for X5 of model 3 ................................................................................................. 86
Figure 62 Rule for Y5 of model 3 ................................................................................................. 86
Figure 63 Parameters used for cube having three movable holes along with formulas used ....... 91
Figure 64 Cube having three different radius holes ...................................................................... 97
Figure 65 The pyramid having 10 steps. ....................................................................................... 97
Figure 66 Base parameters of the pyramid ................................................................................... 99
Figure 67 Parameters of top first box ........................................................................................... 99
Figure 68 Workpiece size for pyramid ....................................................................................... 100
Figure 69 Parameters used to remove excess material ............................................................... 100
Figure 70 Depth values Z ............................................................................................................ 103
Figure 71 The machining of first top box of the pyramid........................................................... 103
Tables
Table 1 Manufacturing processes ((Ching. C, 2008) ...................................................................... 9
Table 2 Common G codes ( HAAS automation book, 2011). ...................................................... 16
Table 3 Common M codes (HAAS automation book, 2011). ...................................................... 16
Table 4 Output Code for roughing process ................................................................................... 33
Table 5 Output Code for finishing process ................................................................................... 34
Table 6 Code for cuboid of Model A ............................................................................................ 35
Table 7 Code for pocket of Model A ............................................................................................ 35
Table 8 CNC code generated for Case 1 and Case 2 .................................................................... 38
Table 9 Automatic generation of codes for Model 4 (for different cases) .................................... 39
Table 10 G-Codes used in the work and their description ............................................................ 50
Table 11 M-codes used in the work and their description ............................................................ 51
Table 12 NC output from Catia for cuboid with a rectangular pocket. ........................................ 58
VII Linkoping University | Design automation for CNC machining
Table 13 Output Code for roughing process from SRP pro software for the Model A ................ 58
Table 14 Output Code for finishing process from SRP pro software for the Model A ................ 59
Table 15 NC code for cuboid ....................................................................................................... 60
Table 16 NC code for pocket ........................................................................................................ 60
Table 17 Manual method NC code generation for Model 1 ......................................................... 63
Table 18 Parameters called in VB script....................................................................................... 64
Table 19 Parameters called in for workpiece length and breadth of model 1 ............................... 69
Table 20 VBA script and its output from Line 1 to Line 10 ......................................................... 70
Table 21 VBA script and its output from Line 23 to Line 32 ....................................................... 71
Table 22 VBA script and its output from Line 11 to Line 17 ....................................................... 72
Table 23 VBA script and its output from Line 18 to Line 22 ....................................................... 73
Table 24 NC code for model 2 from CATIA V5 .......................................................................... 74
Table 25 Parameters called in for workpiece length and breadth of model 2 ............................... 76
Table 26 Parameters called in for workpiece of model 2 ............................................................. 77
Table 27 VBA script and its output from Line 4 to Line 6 for model 2 ....................................... 78
Table 28 VBA script and its output from Line 7 to Line 9 for model 2 ....................................... 78
Table 29 VBA script and its output from Line 10 to Line 11 for model 2 ................................... 78
Table 30 VBA script and its output from Line 12 to Line 14 for model 2 ................................... 79
Table 31 VBA script and its output from Line 15 to Line 19 for model 2 ................................... 79
Table 32 VBA script and its output from Line 33 to Line 41 for model 2 ................................... 79
Table 33 VBA script and its output from Line 23 to Line 28 for model 2 ................................... 80
Table 34 VBA script and its output from Line 42 to Line 50 for model 2 ................................... 81
Table 35 Comparison between model 3 and model 4 ................................................................... 82
Table 36 Design differences in model 3 ....................................................................................... 83
Table 37 For loop for model 3 ...................................................................................................... 87
Table 38 If loop for model 3 ......................................................................................................... 87
Table 39 VBA script and its output from Line 5 to Line 10 for model 3 ..................................... 88
Table 40 VBA script and its output from Line 33 to Line 41 for model 3 ................................... 88
Table 41 VBA script and its output from Line 14 to Line 20 for model 3 ................................... 89
Table 42 VBA script and its output from Line 23 to Line 28 for model 3 ................................... 89
Table 43 Design differences in model4 ........................................................................................ 90
Table 44 Difference in g-code between model 3 and model 4 ..................................................... 92
Table 45 Comparison of features between model 5 and model 6 ................................................. 93
Table 46 Design differences in model 5 ....................................................................................... 93
Table 47 VBA script and its output from Line 5 to Line 11 for model 5 ..................................... 94
Table 48 VBA script and its output from Line 14 to Line 15 for model 5 ................................... 95
Table 49 VBA script and its output from Line 21 to Line 25 for model 5 .................................. 95
Table 50 Design differences in model 6 ....................................................................................... 95
Table 51 NC code for model 7 using CATIA V5 ......................................................................... 98
Table 52 Length of 10 boxes of pyramid ...................................................................................... 99
Table 53 Using For loop in model 7 ........................................................................................... 101
Table 54 Using if loop in model 7 .............................................................................................. 101
Table 55 VBA script and its output from Line 5 to Line 8 for model 7 ..................................... 101
Table 56 First Sub-program in model 7 ...................................................................................... 102
Table 57 VBA script and its output from Line 40 to Line 53 for model 7 ................................. 102
Table 58 VBA script and its output from Line 11 to Line 13 for model 7 ................................. 102
VIII Linkoping University | Design automation for CNC machining
Nomenclature
Abbreviation Meaning
NC Numerical control
VB Visual basics
CL Cutting location
3D 3-Dimensional
DBF Design by feature
AFR Automated feature recognition
GA Genetic algorithm
ISOS Integrated setup planning and operation sequencing
PSO Particle swarm optimization
CIM Computer integrated manufacturing
IGES Initial graphic exchange specification
CSG Constructive solid geometry
FBM Feature-based machining
ISO International standard of organization
CAE Computer- aided engineering
X Linkoping University | Design automation for CNC machining
1 Linkoping University | Design automation for CNC machining
Chapter 1
1 Introduction
The introduction provides the background of design automation for CNC machining. It includes
the purpose, research questions, problem statement, aim, goals, deliverables and delimitations of
the thesis. This chapter concludes with the ethical aspects and outline of the thesis.
Automation is the innovation by which a procedure or method is practiced without human help. It
is actualized utilizing a program of guidelines joined with a control framework that executes the
directions. To automate a procedure, power is needed, both to drive the procedure itself and to
conduct the program and control framework. Even though, automation can be used in a wide range
of areas, it is most closely connected with the manufacturing industries. Automated manufacturing
systems operate on the physical product in the factory. Several Operations are performed such as
processing, inspection, assembly and material handling. In some cases, carry out more than one of
these operations in the same system. They are called automated on the grounds that they complete
operations with a decreased level of human support in comparison compared with the identical
manual procedure. In few cases of extremely automated systems, there is basically no human
participation (Shankar,R).
Examples of automated manufacturing systems include: (Shankar,R)
• Automated machine tools that form parts.
• Transfer lines that operate a sequence of machining processes
• Automated assembly systems in manufacturing
• Industrial robots are used in manufacturing systems to execute processing or assembly
operations.
• Storage systems and Automatic material handling to combine manufacturing
operations.
• Automatic assessment set up for quality control.
1.1 Aim
The Main aim of the thesis is to automate the CNC code generation process from a CAD model.
The code generated will be used in the CNC machine in the lab to examine how efficiently it
works.
To produce and calibrate CNC code is a very time-consuming procedure and more time is used for
CAD/CAM and manual CNC operations. This is noteworthy problem which slows down the
machining operation process. The automation of code generation process is the key to address this
issue.
feature recognition systems, the user determines parameters from the chosen form feature set and
using those guidelines executes automatic recognition of features from CAD files. By using
complex designs, it becomes more difficult to build parts with features. Hence, in most CAPP
systems, the design by features and interactive form feature recognition-based methods might not
be appropriate (Turley,S et al., 2014)
The literature is concerned about the featuring recognition which is basic in CAD and CAPP
systems. To build an effective system for automation of CAD and CAM, setup analysis and
operation sequences must also be focused. Setup analysis classifies features to be machined in
each setup and finds the datum for each setup. To solve integrated setup planning and operation
sequencing (ISOS) problem, a generative system and genetic algorithm (GA) were presented by
adding up a tolerance relative analysis in limits (Kafashi S, 2011).
To understand the automation of process planning, feature recognition, setup analysis, tool path
generation, and tool selection must be focused at the same time. The intent of this study is to
develop an approach to achieve orthogonal machining profiles. For this purpose, a feature
recognition model will be established where machining features are found using machined and
non-machined faces of part drawings that is to automate CNC code generation, the feature or the
outer profile of the work object should be identified by the program and select appropriate
operations and tools necessary. (Ji. Q and Marefat M. M., 1997)
Chapter 2
2. Methodology
This chapter consists of research approach, overall process including the methods used, the major
proposal of the study, the procedures used during the studies made on the literatures and the thesis
quality and reliability. Overall this chapter illustrates how the objective of the thesis was reached
using the methodology steps considering the current process.
2.1. Research Approach
When explaining about the research approach, differentiating between the quantitative and
qualitative research strategies is very useful. The quantitative research strategies focus highly on
quantification while the qualitative strategy focuses on basic meaning of the words (Bryman &
Bell, 2003). The qualitative data needs an inductive approach and quantitative data needs deductive
approach of analysis. The inductive and deductive type of approach are utilised when the data is
mixed up. The research should focus towards the research findings in order to make the research
reliable. The qualitative research has high intensity on the methods to generate data or collect data.
It has less intensity on the analytical approaches to analysis of data. The inductive approach mainly
utilises comprehensive study of secondary data to derive the models, and concepts. Thus, it is
primarily used for the analysis of qualitative data. The quantitative research makes the connection
between what is known and what can be learned by the research. Choosing any one approach over
the other firmly limits the scope of study. One approach cannot be used to answer all the questions
that might arise during the research on a topic. The researchers should have access to all the
research tools in order to have more detailed study. The researchers should be more skilled in both
type of approaches. The research aim and research problem should be considered (Chetty. P, 2016).
The purpose of this thesis is to achieve a methodology that reduces the human effort by automating
the NC code generation for machining. The process of automating the NC code generation starts
by a literature study to understand the process of automation and then using simple models that
are easy to automate and then increase the complexity to the desired level. This is achieved by first
acquiring a model to be manufactured and then apply a set of rules in the CAD modelling software
which can also generate the required NC machining codes. This process is programmed and
simulated to achieve repeatability of the program without any errors.
In the beginning in automated method (refer figure 3), the parametric model is designed in Catia
V5 software. The first set of parameters are created for the model. The code must be written for
the model initially by analysing the dimension of the model, tool path, size of the tool and position
of the tool etc. The standard methods to write the CNC code with respect to the CNC machining
standards are explained in chapter 3.7.
Once the code is analysed, second set of parameters are created on Catia V5. These set of
parameters are created for the variables present in code such as X and Y coordinates, depth of cut
etc. The first set of parameters and second set of parameters are linked to each other using formulas
or rules in Catia V5. This links code to the geometry which plays an important step. These
parameters are also called in VBA. The names given for parameters should be the same in Catia
V5 and VBA. By running the script, values of the specific provided parameters are being extracted
by VBA from Catia V5. . By using the method for automating NC script, the code is generated
automatically.
8 Linkoping University | Design automation for CNC machining
Thus, by analysing the code for any one of the dimensions of the design, new codes can be
generated automatically at a time when the dimension of the model is changed. The dimension of
the model is changed by changing the main parameters of the model. This is done based on the
design requirements. The code is generated automatically in text format. This format is changed
to ‘.NC’ file format to run the code in CNC machine. The similar approach will be made for HAAS
VM 3 CNC machine to produce any given model.
Using this code, the simulation is made in the CNC machine display panel to check if the code is
accurate. During this simulation the required changes are made as desired according to the design
demands and machine standards such as change of tool, tool size, setting the origin etc. After the
final simulation the operation in the CNC machine is processed to get the desired output as a final
product.
Figure 4 CAM System Flowchart (Image inspired from Omuz, S,2009, accessed 2019-10-22)
9 Linkoping University | Design automation for CNC machining
In the manufacturing unit, the fabrication of the workpiece is processed by using a process plan
which provides a specific and sequential direction. By this method, the design of the manufacturing
unit and the construction of the production process are influenced. Process planning develops by
reducing manufacturing activities. Optimal selection and setting the processes, machines, tools are
indicated by process planning for most of the production methods.
A process plan for manufacturing a part includes instructions such as descriptions and the
sequences of operations, a workshop where the work is to be done, raw materials, manufacturing
equipment, process time. Process planning is dependent on an accuracy of product model and the
skilled planners. The basic tasks of process planning are as follows, initially the information on
the product design is analysed. The selection is made for machining processes, cutting tools and
machine tools. The required setup is made and set of operations are arranged. The production limits
and cutting conditions are determined to avoid the variation in the process. To hold the workpiece
more accurately, devices such as jigs and fixtures are designed. The time needed for the entire
process is calculated. Tool path is set and finally generation of NC programs is performed. All the
data are documented in a process route sheet (Ching. C, 2008).
A CAPP system with a database of generic standard process plans uses almost the same steps taken
as manual process planning. By comparison, CAPP offers several potential advantages such as the
10 Linkoping University | Design automation for CNC machining
use of fewer skilled planners, smaller process planning times and a higher level of flexibility.
(Ching. C, 2008). The design could be an essential procedure that happens at varied life-cycle
phases of a product. CAD Software refers to the type of software program used by engineers and
designers in handling computers to help with the varied functions within the specific method to
create models. Engineers take into consideration CAD data as the information, that represents a
product of mechanical aspects and drawn as engineering drawings or a solid model of a part
(Kafashi S, 2011 and Ji. Q, Marefat M. M., 1997).
CAD supports all the varied tasks and CAPP indicates the grouping of tasks where the design of
the part is converted into a producing direction. This describes the part to be manufactured and to
reach the planning specifications. Within the domain of machined components, method designing
involves finding the sequence of processes with the components that are to be machined (such as
edge, grinding, drilling, etc.). To support and secure the part, fixturing configuration are selected
for every method and therefore with specific sequence the tools used to do every operation.
To realize this task for a part, method planners interpret the planning information, (the form,
surface end, tolerances, etc.) supported method and gear capabilities. Computer-integrated
manufacturing (CIM) systems integrate techniques, method designing, and alternative functions
(material handling, industrial plant management, etc.) in an exceeding production atmosphere.
However, developing integrated manufacturing systems has been established not to be an
irrelevant effort. One basic reason has been that CAD information consisting of defined
engineering drawings or the solid model of a part are not manufacturing-specific and usually
represent pure mathematics by a basic description of edges, vertices, and faces of a part. The
method planners work with properties such as dimensions and surface finish of primitives like
slots and holes created (Ji. Q and Marefat M. M., 1997).
To reduce the integration barriers between the design and process planning, the work which
depended on a manual process, several efforts were made by an engineer using all the ideas of
machining features. As explained later in chapter 3, the approach is either to include or extract
machining features in the CAD data during the design process or a combination of both, also
machining features and what they refer to are explained.
With the speedy development in archive, simulation and computing technology, CAD's functions
have evolved from simple and computer-aided drawing and drafting to the advanced 3D graphical
illustration, analysis, and simulation. Current CAD systems enable a user to design a 3D model,
study the mechanical action of the model through simulation and mechanically manufacture
engineering drawings of the model. The user also can analyse stresses and deflection of the model
using finite part analysis techniques.
11 Linkoping University | Design automation for CNC machining
Geometric models have pictured using wireframes, that represent the model shape with
interconnected edge segments or by using 3D solid models. Since solid models carry additional
data than wireframe representations, most analysis on machining features has used solid models
as an input. During a standard solid-modelling system, the model is constructed with building
blocks of shapes described as primitives. The user might generate and/or modify a model by size,
adding, and subtracting geometric solid primitives from a base part.
The base part is often a solid rectangular block referred to as the stock. A spread of economic solid
modelers and design batches are on the market. However, a crucial distinction should be created
between solid-modelling packages and design batches. At the centre of a solid modelling package
may be a core that supports the solid-modelling operations like intersections, variations, etc. A
normal CAD tool usually permits the development of design models might not enable access to
any of the preceding solid modelling operations. There are packages that mix a solid-modelling
and a design tool additionally. (Ji. Q and Marefat M. M., 1997).
Several operations are included while preparing the model using CAM software for machining
such as checking the errors in model geometry, toolpath creation for the model, setting up the
design parameters, cutting speed, feed rate etc. Once the model is prepared for machining all the
information is sent to the machine to physically produce the part. Since the machine has its own
language all the machining information is converted into codes known as G-codes.
12 Linkoping University | Design automation for CNC machining
roller is used.
• Spindle mounting
At the high cutting speed and the rate of materials removed, the spindle carrying the tool or
workpiece are subjected to deflection. To increase the stability and minimize strain, the design
of machine spindle should be small and stiff and the drive to the spindle should be placed closer
to the front bearing. The spinning of the spindle in dependent on the design and quality of the
bearings
• Drive units
Two functions are performed in the drive motors that is to drive the main spindle and to drive
the saddle or the carriage. With the help of an electric motor and gear mechanism the spindle
is rotated which provides the required cutting speed. The movement of the axis drive is made
to move the cutting tool or the workpiece to the required position. A stepper motor is used for
axis drive to reach the accurate control of position and velocity.
• Transmission and positioning slides
In CNC the re-circulating ball screws and nut arrangements are used for motion transmission.
The method is applied to replace sliding friction by rolling friction, the connection between
the screw and nut is through a re-circulating steel ball. The advantage of using ball screw and
nut are high efficiency, wear and life and reversibility. The rigidity of the drive system and the
positioning can be improved by pre-loading the nut assembly.
• Location od transducer/control elements
The control of all the machine functions in CNC are transferred to computerized control system
and the unit should be easier to use for the operator. The facilities present is the control system
are indicating the position of the tool features, allow manual control of the machine tool
elements, enable machine to be programmed.
• Tool holding devices
The machine tools should be specially designed as tools are the important part of CNC
machines where maximum time is used for cutting process.
• Metal chips removal
CNC machines are developed to work at optimum cutting conditions with improved cutting
tools. Since the cutting process takes longer time, the volume of the metals chips also increases.
Unless these metal chips are removed quickly it can affect the cutting process, quality of the
product and machine tools. To overcome this problem, a control system should be provided to
remove the waste metal chips from the cutting zone and disposal from machine tool area.
• Safety of operator
Safety of the operator is an important aspect, to ensure the working conditions the machines
tools are provided with metallic or plastic guards. The following safety protections are,
Perimeter guards: This guard serve as an enclosure of the machine tool. It protects against the
flying of metal chips while performing the cutting process. The access to the machine is
provided with sliding doors with the transparent window where the setting up tool and
workpiece can be seen. If the door is open before the process starts, a warning signals will be
14 Linkoping University | Design automation for CNC machining
Disadvantages
• The cost of CNC machines is high as it is a more of a complex technology that some small
companies may be able to afford.
• Higher maintenance cost is required because of CNC being complex, maintenance problem
becomes more difficult.
• Operators need to be highly skilled to compose computer control program.
2.3.4.3. Operation procedure of CNC machine
The figure 5 shows the simplified operation procedure of CNC machine. In the beginning the
preparation of engineering drawing is prepared according to the design of the workpiece. CAD
software such as CATIA or Creo can be used at this stage. Based on the engineering drawings, the
computer numerical controlled machinery program will be written or composed on text document.
This program includes all the geometrical and technical information. The geometrical information
decides the position of the tool movement, cutting direction, etc. The technical information
includes the choice of tools, rotational speed and direction, cutting speed, etc.
15 Linkoping University | Design automation for CNC machining
Figure 5 simplified operation procedures of CNC machine (Image inspired from Introduction to Computer aided manufacturing
n.d., (accessed on 2019-11-10))
The CNC machinery program will input all the above information into the controllers. After the
controller has processed all the information, the moving path of the tools and the suitable procedure
will be available. The raw material is placed in the working area using a workbench or a clamp.
Finally, the controller will control the whole machine and its tools to process the raw material into
a required product. (Introduction to Computer aided manufacturing, n.d.,)
2.3.4.4. CNC Programming
CNC programming is an important component in the CNC system. The shape of the manufactured
components is depending on how specifically the program has been prepared. Codes are set of
instructions which tells the machine tool to perform the motion of manufacturing the components.
There are several approaches to unite a program by using ISO codes. The most commonly used is
the ISO standardized words and address format. Programming is the procedure by which the
processing data, to be performed in the CNC machine is documented. The collection of characters
used to compose set of instruction refers NC words. A group of NC words are called blocks. The
goal of NC-code program is to produce products in the safest and efficient way. The NC code
blocks are arranged in a very specific order and it is as follows. Firstly, CNC program is started,
check for the required tool and then load the tool. Next step is to turn on the spindle and coolant.
Movement of the tool position is made above a part and then start the machining process. Once
the process is finished turn off the coolant and then spindle. Move away the tool from the part to
a safe location. Finally, end of CNC program. NC words are classified into codes that represent
different functions, for example, G codes and M codes. Table 2 and 3 shows some of G and M
codes that are used in CNC machines. M codes are nothing but set of machine codes which controls
16 Linkoping University | Design automation for CNC machining
the functions of CNC machine, for example, coolant and spindle direction. (HAAS automation
book, 2011).
M08 Coolant on
In the case 2, the operator designs a model in CAM software for instance Catia V5. There is a need
for changing few settings to generate NC code interactively in this case. Then by using advanced
machining process few selections are made such as plan selection, tool axis selection etc to
generate the code in the software by running the machining process. These codes will not include
the standard CNC machine codes and the tool origin and tool path will be different. Hence, these
changes have to be made in the CNC machine before machining during the simulation. The code
generated using CAM software will be too long and this case also consumes more time as there
are long procedures to be followed to get the output as NC code.
The concepts of these principles and how this case study aims at accomplishing them are discussed
below. (Mohajan, 2017)
2.5.1. Validity
Validity is the degree to which the findings are truthful. It needs research questionnaire to precisely
measure the concepts during the case study. Validity encircles the whole empirical concepts and
provides if the results meet all the essentials of the scientific research method. In qualitative
research, the researcher utilizes certain methods to check for the efficiency of the research results.
But the quantitative research is the degree to which any measuring instrument that measures what
is expected to measure. (Mohajan, 2017). In accordance to this, the construct validity depends on
utilizing precise operational measures on the cases of studies that are to be considered. The
construct validity increases by establishing a group of evidence is a compatible plan during the
composition and collection of data (Yin, 2014). This technique was used during the model
selection phase to eliminate the influence of a pre-determined result to be achieved during the
research. In this context, the code was executed for simulation before the actual machining and
then the results of the machining were compared to that of the simulation and the measurement of
the prototype was checked with the geometry of the CAD model.
2.5.2. Reliability
The Reliability indicates the stability of findings. Reliability measures precision, repeatability,
consistency and trustworthiness of a research. It refers to a measurement that provides steady
results with equal values. Few qualitative researchers use the word dependability instead of
reliability. It is an extent to which assessment tool has an outcome of stable and steady results. The
reliability is referred to stability, consistency and repeatability of results, i.e., the results are
considered as reliable if steady results are obtained in similar situations but distinct circumstances.
Whereas, in the qualitative research it is reliable when the researcher’s approach is persistent
beyond different projects and different researchers (Mohajan, 2017). The reliability is a database
created for storing the relevant documents and any coding done during the research work. The
information i.e., software used, the method used for automating NC script which generates the
CNC codes was documented and made available. This would allow further development in the
work and to validate the present work by another researcher. (Yin, 2014).
20 Linkoping University | Design automation for CNC machining
Chapter 3
3. Theoretical framework
This chapter is inclusive of description of main theoretical concepts, a broad illustration of related
theory and empirical findings.
3.1. Description of main theoretical concepts
There is a major efforts made to automate the part program generation. The interactive graphics
system is combined with the CNC part programming with the advancement of CAD/CAM
systems. A geometrical model in the CAM package can be created by a part programmer or the
part programmer can precisely select the geometrical model from CAD/CAM data basis. The tool
paths can be calculated using the built-in tool motion command by a part programmer. The part
programmer can establish the tool paths over the graphic display using the animation function of
CAM system which in turn reinforce the accuracy and speed in tool path generation (Ji. Q and
Marefat M., 1997)
The basic features of CAD/CAM systems applicable in the market are Geometric Modelling / CAD
Interface, Tool motion definition, Data processing, Post processing, Data transmission and the
explanation for above these are as given below.
3.1.1. Geometric Modelling / CAD Interface
Using basic geometrical elements such as points, lines, surfaces, arcs or splines the geometry of
the workpiece can be defined. The 2D or 3D geometrical elements in the form of a mathematical
model can be stored in the computer memory. This mathematical model can be a surface model, a
solid model or a wireframe model.
The geometric models can be carried from the other CAD/CAM system using standard CAD/CAM
interface formats like Initial Graphic Exchange Specification (IGES). IGES administers the
transportability of 3D geometry data among different systems. The Geometrical elements can be
translated from one system to a neutral file standard and then translate from this standard to another
format throughout this system (Ji. Q and Marefat M., 1997)
3.1.2. Tool motion definition
After the geometric modelling, in order to machine the workpiece, the machining data such as
operation set up, job set up and motion definition are entered into the computer to produce cutting
location file (Omuz, S.,2009).
• Job setup
This is used to feed the home position, machine datum and cutter diameter for the Cutting
location file.
• Operation setup
The operation parameters such as tolerance, feed rate, retract planes, coolant ON/OFF,
spindle speed, tool selection and stock offset, etc, are inputted into the system.
21 Linkoping University | Design automation for CNC machining
• Motion definition
To machine the products, the built-in machining commands are used to deal with the tool
motion. This includes the profile machining, surface machining, hole processing,
pocketing, gouge checking, etc.
3.1.3. Data processing
The input data is translated into a computer valid format. The desired part surface, computing the
paths of cutter location data file and cutter offset surface are processed by computer. The tool path
can be typically animated graphically for verification purpose on the display.
Moreover, for the user’s reference, the production planning data such as set up sheet, machining
time and tool list are also calculated.
3.1.4. Post processing
The different CNC machines have different capabilities and features and the format of the CNC
program may vary from each other. Post-processing is a process that is required to change the
generic instructions from the Cutting location file to a definite format for a machine tool
particularly. The cutter location data file can be converted into a format in which the machine
controller can illustrate accurately. The conversion is made using a post-processor which is
computer software.
The two types of post processors are:
• Specific post processor
Specific post processor is a software used to obtain output the code for specific CNC
machine without changing the program.
• Generic post processor/Universal post processor
Generic/Universal post-processor is a set of derived rules that needs the user to
customize to a format that will satisfy the need of the specific CNC machine.
• Data transmission
After the post processing, the CNC program can be transmitted to CNC machine
either by the online or offline process.
• Offline Process
The CNC programs are transmitted to the CNC machine using the data carriers. It
consists of magnetic tape, paper tape or magnetic disc.
• Online Process
In online processes the data is transmitted either by serially or parallel using data
cables. The online processes are commonly used in DNC operation. NC operation is
direct numerical control/ distributed numerical control which possess data connection
between a computer and a CNC control. Two different tasks of DNC are safe data
transfer between a CNC and a computer in both the directions and data management
systems for NC programs. It is always necessary when CAM programs are made to
run on the CNC machine control. (Direct numerical control, n.d)
22 Linkoping University | Design automation for CNC machining
CAD is combined with the use of a computer graphics system, referred to as a CAD system. The
drawing by CAD system is almost the same as the manual method. The improvement of the
product is provided by specific draw commands, such as Box, which draws squares/rectangles of
any sizes. By doing this the designer will save time. The methods of CAD provide both automating
and creating designs in new ways (Ching. C, 2008)
The use of these procedures permits the subsequent functions that result in several advantages.
• The use of engineering analysis to provide a larger variety of design alternatives,
builds up the quality of the design.
• To improve the design documentation, standard engineering drawings need to be
created.
• To support manufacturing system, a common database is created from CAD
drawings which contains product details.
• Prototyping process minimizes the lead time of making a part by providing the
specific CAD geometric model.
Simulation is an essential output generated by CAM, where the production system ideas are
Studied. To evaluate the nature under varied conditions of models of a production system,
23 Linkoping University | Design automation for CNC machining
simulation is developed. To eliminate two separate activities, the combination of CAD and CAM
is applied where they contribute an integration of the design and manufacturing functions into a
sequence of activities.
In the production system, the bounding of product design and manufacturing is required, and this
is established by using CAD/CAM technologies (Ching. C, 2008). In all the manufacturing
industries CAD and CAM are extensively applied. The data of design drawings are directly applied
to produce the finished parts. This process involves three main procedures:
• Designing of the machine parts by sketching in CAD software and drawing
techniques.
• The geometry information is transferred to the CAM workstation from the CAD
drawing file.
• The CAM software generates NC code to perform the machining operation on CNC
machine.
CATIA is most commonly used in industries where both CAD and CAM are integrated. Using this
software, the original format of CAD file can be transferred to CAM, and further analyzed to
automate the steps involved in design and manufacturing, also automate the development from
them. The design specification of the product is developed by CAD/CAM systems and applies it
to a process plan to make the product automatically (Ching. C, 2008).
VBA is an application that is relatively easier when compared to other macros languages. By using
VBA, the applications can become extensible where accessing and changing the properties of the
model are customized and tasks can be automated. Another major objective of using VBA is to
create VBA-enabled applications in cooperation with the first VBA- enabled application and
controls all the operations within the office applications. For example: Data can be generated
between VBA-enabled applications and automation can be achieved using a computer system.
Visual Basic programming primarily a program that is designed to run when the developer
generates a stimulus. By using this application, the different aspects of the program will not be
interdependent so that any addition or removal of procedures will not affect the whole applications.
Accordingly, before writing the VB application there is a need of an arrangement how the aspects
of the application are going to interact. Therefore, the accurate documentation of the VB
application advances the ability of reading and maintenances of the VB code (Ching. C, 2008).
24 Linkoping University | Design automation for CNC machining
Figure 8 (a) Several common prismatic manufacturing features which can be defined volumetrically or geometrically; (b) part
with interacting features. (Ji. Q and Marefat M., 1997).
Although there is enormous form of patterns for machining features, it is possible to divide them
into categories. Such a classification would be helpful for machining feature support, for
developing a regular language, and for information exchange. As an example, machining features
25 Linkoping University | Design automation for CNC machining
could also be classified as solid or non-polyhedral. It can also be classified as prismatic. The
attributes related to this could embrace dimension, orientation, tolerance, abstraction relationship,
and topologic components.
Figure 9 Component modules in automatic feature recognition. (Ji. Q and Marefat M., 1997)
From the figure 9 for instance if the verification fails, the feature recognition method should be
repetitive to look for a special set of features and the new features must be verified successively.
We tend to note that for a variety of systems, some or all the tasks of feature recognition are
enclosed inside the function of (computer-aided) method designing. For instance, feature
verification or feature recognition itself could also be thought about a liability of the method
planner. For accuracy, we tend to separate the feature recognition task from alternative method
designing tasks (e.g., tool selection) and focus on that.
Several techniques for automatic feature recognition are planned, but there are difficulties related
to an absence of ordinary definitions. The multiplicity of feature definitions has typically
contributed to completely different classifications for the identical form inside the literature. For
instance, figure 10 has been classified as a slot and as a pocket or a depression (Ji. Q and Marefat
M., 1997).
Figure 10 Example of the simple part with a slot ((Ji. Q and Marefat M., 1997)
Another issue in finding out and proposing feature-recognition techniques has been strength in
handling feature interactions. Sometimes two or more features come across geometrically and
produce a typically termed feature interaction. The definition of feature interaction depends on the
approach taken in the process. For volumetrically feature definitions, a feature interaction
corresponds to associate degree intersection of the volumes of two or more features. For instance,
Figure 8(b) shows a part with the interaction between its two options, i.e., two slots.
26 Linkoping University | Design automation for CNC machining
Another natural outcome that is necessary to explain a part per its features, either by having various
sets of matches among the geometric model of the part and the representations for features. For
instance, the machining features are shown in Figure 8(a), the part in Figure 8(b) is understood as
having two interacting through slots. However, associate degree equally valid interpretation (based
on geometric instances of shown features) would be four blind slots and a pocket within the middle.
Having the ability to get alternate interpretations consistently is incredibly helpful as a result it
permits producing method planners to profit from the knowledge and generate process plans that
are superior in terms of value and quality.
The procedures for automatic feature recognition are allocated into many classifications such as
graph, rule, volume and evidence-based reasoning. Such a casual grouping is helpful to perceive
the progressive technology associated with feature recognition from CAD geometric models.
3.4.2. Feature-Based Machining
Feature-based machining (FBM) is expected to generate NC programming easier and faster with
automated programming. Feature-based machining can provide greater quality, appropriately of
less error and give higher standardization using verified and preferred resources and processes.
The FBM approach needs a software that can perceive machining features, determine the preferred
machining processes for each feature and then generate the tool path for each operation
automatically (Scutter.,2019).
A part modelled in the CATIA V5 part modelling module is recognized in the VB script generated
for NC coding and the machining features can be recognized. The script allows the user to extract
the required data from the CAD model and use that data for NC programming. The data can be
machining parameters, machining features or stock volume. Once these parameters are recognized,
the script can generate a relevant code for tool paths and machining sequences which can be then
exported to the CNC machine. Appendix shows the programming done for simple objects for CNC
machining.
Figure 12 Machine tool co-ordinate system for NC, Source: Integrated manufacturing n.d (accessed on 2019-10-04)
28 Linkoping University | Design automation for CNC machining
The figure 13 shows the coordinate axes of the CNC machine with respect to the table movements
in 3-dimensional view. The spindle axis is Z axis and the 6dof (degrees of freedom) represent X,
Y, Z and rotational axes a, b, c .
Figure 13 Coordinate axes of the CNC machine w.r.t the CNC table movement in 3D view
Figure 14 The actual CNC display panel showing center point (+)
The co-ordinates axes (X, Y) at the centre (+) is always (0,0) as shown in the figure 15. The X co-
ordinate axis to the left of the centre and the Y co-ordinate axis directed downwards from the
centre is negative. The X co-ordinate axis to the right of the centre and the Y coordinate axis
directed upwards is positive.
29 Linkoping University | Design automation for CNC machining
Now let us consider a square with two imaginary lines (line A and line B) that are used to represent
the end points as shown in the figure 16. The lines are intersected at a point which is the centre
(+). The points 1,2,3,4,5,6,7 and 8 represents the end points with a certain distance from the centre.
In terms of X and Y coordinates lying on these points according to the CNC machine standards
are represented as shown in the figure 17. On the points 2 and 6 along the line A, the X is 0.
Because, along the line A, on the two end points (2,6) there is no movement in the X direction
whereas Y is not 0 as points 2 and 6 are in a certain distance from the centre in Y direction.
Similarly, on the points 8 and 4 along the line B, Y is 0. Because, along the line B, on the two
points (4,8) there is no movement in the Y-direction, but X is not 0 as points 8 and 4 are in a certain
distance from the centre in X-direction. In general, from the centre the value of Y, lying on X-axis
is 0 and the value of X, lying on Y-axis is 0.
30 Linkoping University | Design automation for CNC machining
The standard way of analysing and writing the X and Y coordinate axes is followed with respect
to the CNC machine standards. Considering all the above steps required for writing the coordinate
axes, an example is showed to illustrate how it works on the models.
Example: Consider a Triangle as shown in figure 18.
• Assume the dimension of the triangle as 30mm height and 30mm at the bottom as shown.
• The X and Y coordinates on all the three edges is shown in the figure. These are the
points that are required to machine the triangle.
• These techniques are used to write the code format.
The appendix at the end of the report shows the scripting done using these basic steps for CNC
machining of simpler models.
31 Linkoping University | Design automation for CNC machining
It is written as:
Open FilePath For Output As #FileNumber.
By indicating the mode as output, then the VBA will overwrite any file that has the same name.
The unique number is given to the file number which tells the VBA which file to write as output.
There are two methods- print or write command. Print command is user friendly and write
command is program friendly. The print command prints the statement as it is. Thus, print
command is used. The format is:
Print #FileNumber, statement to be printed
The file number should be the same number used in open statement.
To generate the G-codes in text file,
• A path is created in the VB script as shown:
• In the VB script we write “Print #1” followed by the codes.
• To print the code automatically in text file print #1 is written on each line followed by the
g-code format.
• For example:
Open "X:\ Code.text " For Output As #1
Print #1, "G28 G91 Z0"
Print #1, "G0 G40 G80 G90"
Print #1, "M30"
• The #1 is the output, which is assigned to every line while creating the path.
• This prints the code in the notepad automatically as output when you run the program in
the VB script.
The printed code is as follows:
G28 G91 Z0
G0 G40 G80 G90
M30
• Once the code is generated, the file name will be saved as “Code.txt”.
• This file can be opened in notepad and the file is converted to “.NC” format to run on a
CNC machine.
• This is important as other file formats cannot be run on the CNC machine.
• This file format can be easily obtained by using ‘Save as’ option in notepad. While saving
the file, click on “All files” and rename the file as “code.NC”.
• The file will be saved as “Code.NC”
(VBA write to text file using print statement., 2016)
32 Linkoping University | Design automation for CNC machining
3.9. Sub-Program
The sub-program is called in the main program which is used to create number of loops (number
of cycle of operation during the machining). Consider the figure 19, The m-code ‘M97’ is used to
call the sub-program. ‘L’ is used for the number of times the machining operation to be processed.
In this case , when the machine reads the line M97, it jumps to the line N901 and reads the
following codes 16 times which reaches the desired depth of cut as ‘L16’ is given. One cycle of
operation of the cut (depth) is 2.5mm (Z-2.5). Hence, as it is L16. Then 2.5*16=40mm depth.
Using sub-program, the code is written once and the machine reads the same code 16 times which
makes the task easier and also the code will be short. If the sub-program is not used, then the codes
shown in the figure 19 has to be written 16 times to reach the desired depth which makes the code
too long and consumes more time to write this. This is how the sub-program is beneficial.
Chapter 4
4. Results
This chapter includes the results based on the main objectives of the thesis and output of the case
study. It also includes the prototypes of the models.
Present work deals with the automation of CNC code generation process to reduce the time taken
to generate the CNC codes. The main objective was to create a framework to generate CNC code
which would then be used in MDX 40A milling machine. From the results obtained by checking
the code in MDX 40A, the same approach is used on the HAAS VM3 CNC machine.
During the case study considering the difference between the MDX 40A machine and HAAS VM3
machine, it was found that in the MDX 40A, there is no limit for the operator to produce any CAD
geometries as the workbench used can be rotated as desired. This allows the machining operation
to machine the workpiece on both sides (Example: Hollow cylinder). But there is a limit for the
size of the workpiece as only one tool of limited length is used. Whereas in the HAAS VM3
machine there is a limit for producing complex geometries. Because, this machine is a 3-axis
machine. But by installing the workbench of 5 axis, certain milling operations could be made.
In the MDX 40A machine, there is a built-in software called SRP pro software. The machining
process was carried out by designing a model in the SRP and it was directly used for machining
by manually setting up the initial settings for machining operations. In this project, initially, a
model (refer appendix II) is designed in CATIA V5 for the MDX 40A machine. This model is
imported to the SRP using suitable file format to generate the codes.
Using SRP software, the output code generated by importing the Model A is shown in the table 4
and table 5.
Table 4 Output Code for roughing process
Z582,7496,20000;
Z582,7496,1100;
V50.0;Z582,7496,1100;
V15.0;Z582,7496,1000;
Z580,7496,1000;
Z590,7496,999;
Z580,7496,998;
Z590,7496,997;
34 Linkoping University | Design automation for CNC machining
Z580,7496,996;
Z590,7496,995;
Z580,7496,995;
Z590,7496,994;
Z580,7496,993;
Z590,7496,992;
Z580,7496,991;
Z590,7496,990;
Z-7536,-4048,20000;
Z-7536,-4048,520;
V15.0;Z-7536,-4048,520;
Z-7536,-4048,290;
V7.5;Z-7536,-4048,-30;
V15.0;Z-7511,-4050,-30;
Z-7487,-4050,-30;
Z7498,-4050,-30;
Z7523,-4049,-30;
Z7547,-4046,-30;
Z7571,-4041,-30;
Z7596,-4034,-30;
Z7607,-4030,-30;
Z7620,-4025,-30;
Z7645,-4013,-30;
Z7656,-4006,-30;
As seen from the table 4 and table 5, the code generated from SRP are completely different from
NC codes. The table 4 shows the codes generated for roughing machining process whereas the
table 5 refers to the finishing machining process. The depth of cut is too small for every cycle of
operation which makes the code too long for each of the machining process such as roughing,
facing etc. Only few lines of the codes are shown in the table. To speed up the machining process
the automatic generation of code is required.
Hence, a framework is created to generate a NC code automatically. This code is generated easily.
The time required to generate the NC code is less compared to the manually generated in SRP
(refer Appendix II for the MDX 40A milling machine). This code is then used in the MDX 40A
milling machine to check how the machining operation works.
35 Linkoping University | Design automation for CNC machining
The table 6 represents the code generated for the machining of cuboid. This code must be repeated
until the required depth of cut is reached. As the sub-program cannot be used in this machine, the
code is reduced by using the increased range of depth values (Z). For example, for the first cycle
the depth value Z will be -5. And for the next cycle of operation the Z value is -10. This is continued
until the required depth is achieved. This is how the code can be reduced and helps speed up the
machining process in MDX 40A (refer Appendix II). The table 7 are the codes for the machining
of pocket.
Using the framework of automatic code generation, the prototype is built in the production lab
using MDX 40A for the model A (refer figure 20).
The similar approach of automating generation of CNC codes are then used for HAAS VM3 CNC
machine. This method is carried out by designing simple models to verify the effectiveness of
using the automation process. The codes that are generated using CATIA V5 are long and cannot
be modified further. But the automatic codes that are generated in this case study are reduced by
calling the sub-programs in the main program, it makes the operator to understand the codes easily
and this enables to easily link the parameters of the geometry to the parameters of the code. The
models are parameterized and are linked to the code in VB script. The automation is made possible
in such a way that when the parameterized model changes the dimension, then the values of the
parameters are extracted in the VBA and using the method of automating NC script, the new CNC
code will be generated automatically. The codes that are generated in SRP pro software, CATIA
V5 and the framework for automation for Model A are shown in Appendix II. And the differences
between the manual method and automated methods are shown in Appendix III for three selected
models.
The first model used was a cube with a hole at the centre. This model was a simple hole operation
on a cube. The parameters like dimensions of the model, tool speed, feed etc., were set during the
modelling phase in CATIA V5 and then they were called in excel. Using the procedures for
automated method mentioned in Appendix III, the CNC code is generated automatically.
The brief explanation of how the automation is achieved, is explained below for couple of models
with examples of showing how the new code generates when there is change in the geometry of
the model. The complete illustration of automating the CNC codes are shown in Appendix III.
1. Model 1: A cube with a hole at the centre (refer Appendix III)
After the design of model, the code is initially written by understanding the design
requirements such as design dimensions, tool size, tool movement, tool position, tool speed,
operation feed rate etc., to produce the prototype. The G-codes are written according to the
CNC machine standards. The X and Y directions, tool movement, feed rate and speed are
denoted by using different variables as mentioned in the table. The parameters are created in
the Catia V5 for these variables. These parameters are extracted in VB script.
pointl= length/2
pointhb=Length/2
• These parameters that are created for point in CATIA V5 are assigned to the parameters
X3 and Y3 of the code using rules from Knowledge ware.
pointl= X3
pointhb=Y3
• Therefore, by changing the formula in CATIA V5, the hole position is changes and X3, Y3
values also changes.
• The rules are created for X3 and Y3 and are shown in the figure 43 (Appendix III).
Case 2: If the hole is to be positioned below the centre point then Y3 is acting downwards (-)
pointl= length/2= 40mm
pointhb=Length/3=26mm
X3= 0
-Y3 = 14mm i.e., Y3= -14. (negative sign refers to downward movement).
The two cases are illustrated figure 22
38 Linkoping University | Design automation for CNC machining
The codes generated automatically for these two cases are illustrated below:
Case 1 Case 2
T6 M6 T6 M6
G54 X0. Y14. S1100 M03 G54 X0. Y-14. S1100 M03
M08 M08
• The result of the CNC code generated automatically for the change in the dimension or
position of the hole is seen in the table 8
Similar to the model 1, with respect to the parameters created, rules given to the parameters and
by linking the parameters of the code to the parameters of the geometry, the example of new codes
generated automatically for all the new change in the geometry of the model 4 are shown in the
table 9.
39 Linkoping University | Design automation for CNC machining
Model 4
Changes in geometry of the model Codes generated
automatically
Case 1 T6 M6
G54 X25 Y25 S1100 M3
G43 Z3 H6 M8
G83 Z-40 Q5 R3 F120
X-25 Y25
X0 Y-25
G80 M9
Case 2 T6 M6
G54 X25 Y25 S1100 M3
G43 Z3 H6 M8
G83 Z-40 Q5 R3 F120
X25 Y0
X0 Y25
G80 M9
Case 3 T6 M6
G54 X25 Y25 S1100 M3
G43 Z3 H6 M8
G83 Z-40 Q5 R3 F120
X-25 Y0
X0 Y0
G80 M9
The difference in the CNC codes for case 1, case 2 and case 3 of the model 4 are seen. The position
of the holes has changed in each of the cases when the formulas of the parameters are changed.
Due to these changes, in VBA the parameters for the X and Y coordinate axes of the holes extracts
the value from the CATIA V5 and generates the CNC code automatically using the method of
automating NC script as shown in the table 9.
40 Linkoping University | Design automation for CNC machining
This is how the CNC codes are generated automatically. These codes will not have any errors as
the codes that are analysed in the beginning was already simulated to eliminate the errors. The
automatic generation of CNC codes results in better accuracy and reliability.
The following models were designed for generating CNC codes as accurately as possible with
reduction in effort during the modelling and execution phase of the case study. (refer Appendix
III). The models listed below (apart from Model A (Appendix II), Model 1 and Model 4 (Appendix
III)) increased in complexity to better understand the extent of the coding process used in the case
study.
1) Model 2: A hollow cylinder
2) Model 3: A cube having three fixed holes of same radius
3) Model 5: A cube having three fixed holes of different radius
4) Model 6: A cube having three movable holes of different radius
5) Model 7: A Pyramid
The design automation for generating CNC codes results in generating a new code automatically
for every new change in the design of the model. This automated method of generating CNC codes
resulted in less time consumption for generating codes and speeds up the machining process. This
approach can also be used to generate many CNC codes at a time based on the design requirements.
For instance, consider producing different sized ‘wrench or spanner’.
If a manual method is used to produce this product, then designing a wrench or spanner and then
by using the advanced machining process in CATIA V5 takes lot of time. Even though it is possible
to generate a code for one of the sizes of the product, to produce the next sized product the design
must be done again, or the machining procedures has to be carried out again (refer the general
procedures mentioned in Appendix I (c)). This procedure takes more time for generating the code.
On the other hand, if the operator writes the code manually, writing the codes for all the sizes of
the product or changing the values manually consumes lot of time.
If an automated method (refer Appendix III) is used for producing CNC codes for such products
having different sizes. The design is made once, and the parametric model is linked to the code
using the parameters. Thus, using the method of automating NC script in the VB script, the codes
for all the sizes of the wrench or spanner can be generated at a time within a fraction of second by
running the program on the VB script. These CNC codes can be used to produce the wrench or
spanner of different sizes in the CNC machine. This method reduces the effort of the operator and
requires less time for generation of CNC codes as mentioned and therefore speeds up the
machining process.
The three models are used for prototyping in the HAAS VM3 CNC machine are Model 2, Model
3 and Model 7. The final measurement of the machined components indicate that the code
generated for machining the respective models was accurate and there was no interference or
unnecessary tool movement during the machining process. The Model 2 was a hollow cylinder
which was machined from a solid rectangular block with the work piece origin at the centre of the
workpiece. The dimensions of the component such as height, outer radius, inner radius was
measured and then verified with the CAD model. Subsequently, the same procedure was carried
out for rest of the models.
41 Linkoping University | Design automation for CNC machining
The resulting machined model showed that the speed, feed and depth of cut selection for the
machining process based on the tools used was within the acceptable range of the material used
during machining. The prototypes were built in the production lab at Linkoping university.
43 Linkoping University | Design automation for CNC machining
Chapter 5
5. Discussions
The discussion is made on the presented results and the research questions are answered.
The improper NC programming results in damage of the tool or the workpiece. Due to the improper
programming, the part cutting errors may not be seen for the new operators working with the
machines. This might result in interrupted performance in the machine (AMMC., 2016).
Most of the issues arise during NC programming because of lack of understanding of G and M
codes used for the CNC controller, irregular set up, use of inappropriate variables during NC
programming, lack of skilled operators and improper tool path selection. (10 Common problems
with CNC machine tools (And how to fix them)., 2019).
As there are more common G and M codes, it makes operator to take more time to understand the
codes and make proper use of the NC codes that are appropriate for the machining operations. In
other words, analysing the appropriate codes for the respective models takes more time. The
sequencing of NC programming is difficult for the beginners and it might result in inaccurate codes
that may lead to improper machining of the workpiece. The manual generation of NC codes
consumes more time to generate the code and the possibility of errors will be more. These errors
may or may not be detected during the simulation in the CNC machine which might damage the
tool without the presence of the skilled operator. In the manual NC code generation process, there
will be a need to change the initial set ups for every new programming, create new tool path
generation for new program and during these each process of making new changes there will be
more chances of errors in the NC codes.
On the other hand, the NC code generation using CAD/CAM consumes more time as the process
involves designing the model, using the advanced machining process and making the initial set up
to generate output using advanced machining and then generate the code. This code from CAM
will be too long and it is difficult to understand the NC codes generated in CAM. It is not possible
to use the code directly in the CNC machine for machining operation, as there will be a need to
change few lines with respect to the standard machine programming. Hence, the initial changes to
the code must be done such as setting of origin, tool selection etc., before running it in the machine.
Thus, the main challenge of NC code generation in the current state with respect to the codes
44 Linkoping University | Design automation for CNC machining
written by an operator or generation of codes from CAM is time consuming and this results in less
effective machining operation.
5.2. The benefits to automate NC code generation directly from CAD models
There are several benefits to automate the NC code generation from CAD. The model designed is
parameterized, such that the change in parameters tends to change the geometry of the model. This
is linked to the code using automatic NC script method and thus by running the script the NC codes
will be generated. Therefore, when there is a new change in the design the new code will be
generated. This approach eliminates the need of tasks that are done manually by a programmer
/operator such as analysing the changes in the design and writing the code from the beginning,
changing the variables of the code, checking for the errors in the code, assigning values to the
variables such as speed, feed rate and changing the coordinate axis , or repeating the advanced
machining processes in CAM software etc.
The disadvantages are the automated NC codes cannot be used in the 5-axis CNC machine. The
5-axis machine requires the CAM programmed NC codes for the machining operation. The
designer should be aware of the common G and M codes and their functions or the program will
be improper which might lead to the damage of the machine. Though the NC code is generated
automatically, the initial settings in the CNC machine before running the program such as
positioning of the tool could be made automatic but positioning it manually is preferred.
The automation of the NC codes from a CAD model is flexible to the changes in the design and
the changes can be introduced easily. The automated codes are easy to understand and analyse.
Example: Production of several different sized bolts and nuts. Using this approach, codes for all
the sizes of bolts and nuts can be generated. Therefore, many different codes can be generated for
different dimensions of the CAD model at a time. This consumes less time to generate the code
and this results in the increase of the speed in the machining operation resulting in efficient
production. The code generated automatically results in better accuracy and reliability.
45 Linkoping University | Design automation for CNC machining
Chapter 6
6. Conclusion and Future work
The conclusions of the thesis work are presented here by considering the results obtained from the
different cases of the study.
In the process of the Roland MDX 40A milling machine, the design of a model is done using an
in-built software called ‘SRP Pro software’. Every model is designed using this software in the
provided display panel of the milling machine and after machining process the output code can be
generated manually. The code that is generated for the ‘model A’ by importing the model to the
SRP is shown in Appendix II. The code generated in the SRP for the model are too long and hence
these codes cannot be modified. By running the same code, it gives the same result i.e., same model
will be obtained. Therefore, in order to produce a new model, design was carried out again
manually in the SRP which is not a good solution.
Whereas in the HAAS VM3 CNC machine, the codes are written manually using the display panel
in the CNC machine by the operator. For a new model or to change the dimension of the existing
model or to change the certain values in the existing codes, it must be done manually. This is a
time-consuming process as the operator needs to simulate the codes in a repeated process after
every change in the code to check for the errors. On the other hand, the codes are generated from
CATIA V5 manually by an operator by following procedures using advanced machining
process(refer Appendix I (c)). Analysing and understanding these long codes is very difficult. This
method is not efficient enough.
Therefore, by comparing the results of the codes generated in manual method for both the
machines, it is seen that there are several procedures that must be followed which requires more
time to generate the code. And the code generated cannot be modified or cannot be linked to the
geometry as the codes are too long having about more than 300 to 4000 lines approximately.
Additionally, the code generated from CATIA V5 is not possible to be used directly in the machine
as these codes does not follow the set of standard programming instructions. The tool path,
coordinate axis, tool movement will be completely different. Hence, these are changed manually
in the CNC machine during simulation.
To overcome these issues in both the machines, this project has mainly focused on automatic
generation of CNC codes to speed up the machining operation. A framework is created that
generates g-codes automatically for a given model and are used in the MDX 40A milling machine
to check how well the machining operation takes place and this is compared with the manually
created code in the SRP software. The aim is to derive a similar approach that can be used for
larger CNC machines (in this case HAAS VM3 CNC machine).
From the results, in the automated approach for generation of CNC codes for MDX 40A machine,
the sub-programs cannot be called as this machine does not read the sub-program. Therefore, by
using the technique of increasing the depth of cut (Z value) the code generated is reduced and
made easy to make the changes to the code automatically by changing the design which speeds up
the machining process. Similarly, in the automated approach for HAAS VM3 machine, initially
the parametric model was designed and linked to the parameter of the code. By using the method
46 Linkoping University | Design automation for CNC machining
of automating NC script, CNC codes are automatically generated for the given model. The code
generated automatically has lesser number of lines as the sub-programs are used in the main
programs.
Adding to this, the automatic method is flexible to the changes in the dimension of the model. That
is, the new code will be generated automatically whenever the dimension of the model is changed.
Hence, new CNC codes can be generated automatically at a time when the dimension of the model
is changed by changing the main parameters depending on the design demands. This makes the
operator to easily generate the codes for different dimensions of the model and complete the
machining operation with less time consumption without the need to modify the codes manually.
As the automated method requires less time to generate the code, it speeds up the machining
operation. Even though there are certain limits, the potential of automatic CNC code generation
from a CAD model is assessed in this project.
Future work
• In the future, the code generation should be automated even for the automatically
instantiated CAD models.
• The code generation for the 5-axis machine should also be automated.
• A complete CNC part programming procedure should be able to automate.
• The method of automating NC code generation should be made more universal.
• Given the model that has been detailed during the product design, the computer automated
system would retain adequate decision-making capability to perform CNC part
programming for the integrated part without any human support.
47 Linkoping University | Design automation for CNC machining
Bibliography
Shankar,R., Automation & Numerical control machines, available online at
https://www.academia.edu/23716574/AUTOMATION_and_NUMERICAL_CONTROL_MAC
HINES_1.0_AUTOMATION_IN_MANUFACTURING_MODULE-I, pp. 1.
Turley, S., Diederich, D., Jayanthi, B., Datar,A., Ligetti,C., Finke,D., Saldana, C ., Joshi,S.,
(2014), Automated Process Planning and CNC-Code Generation, pp. 1-2.
Ji, Q., Marefat, M.,(1997). Machine interpretation of CAD data for manufacturing applications,
ACM Computing Surveys (CSUR), v.29 n.3, p.264-311.
Babic, B., Nesic, N., Miljkovic, Z., (2008). A re-view of automated feature recognition with rule-
based pattern recognition. Computers in Industry 59(4), p.321–337.
Shah J. J., Anderson D., Kim Y. S., Joshi S. (2001).A discourse on geometric feature recognition
from CAD models. Journal Computer. Info. Sci. Engineering 1, pp. 41-51.
Kafashi, S., (2011). Integrated setup planning and operation sequencing (ISOS) using genetic
algorithm. International Journal of Advanced Manufacturing Technology, pp. 1-5.
Bryman, A. & Bell, E., (2003). Business Research Methods. New York: Oxford University Press.
Omuz, S,2009. Computer numerical control (CNC), IC professional training series, Copyright
reserved by Industrial centre, The Hong Kong polytechnic university
Available online at https://www.academia.edu/19624449/Cnc_1_0 (accessed on 2019-10-22)
Ching, C., (2008). Semi-automated process planning and cost estimation of turned components
based on CATIA V5 machining, pp. 8-13.
Santoki, K., (2018). Computer-aided manufacturing, Dept of mechanical engineering, pp. 13-15.
48 Linkoping University | Design automation for CNC machining
Lynch, M., (2016). The basics of computer numerical control , available online at
https://www.cncci.com/post/the-basics-of-computer-numerical-control (accessed on 2019-11-04)
HAAS automation. Inc- Milling operator’s manual.(2011), pp.103-140, available in production lab
at Linkoping university.
Yin, R.K., 2014. Case study research: Design and methods. 5th edition red. London: sage
publications.
Mohanjan. H., 2017. Two criteria for good measurements in research: Validity and Reliability, pp
10-15
VBA write to text file using print statement, 2016., Introduction- write text file- available online
at https://wellsr.com/vba/2016/excel/vba-write-to-text-file-print-statement/
(accessed on 2019-10-21)
49 Linkoping University | Design automation for CNC machining
Rosso,R., Allen,R., Newman,S., (2002), Future issues for CAD/CAM and intelligent CNC
manufacture
10 Common Problems With CNC Machine Tools (And How To Fix Them) ., 2019,
available online at- https://hwacheonasia.com/10-common-problems-with-cnc-machine-tools-
and-how-to-fix-them/ (accessed on 2019-11-12)
50 Linkoping University | Design automation for CNC machining
Appendix
A framework is created that generates g-codes automatically to run the MDX 40A CNC machine
and produce any given CAD model (Appendix II). Once this was successful the same result was
used in a HAAS VM3 CNC machine to produce any given CAD model and is explained in Appendix
III. The differences between the manual method and automated methods are shown in Appendix
III for three models. Appendix I shows the table of common G-codes and M-codes, general formula
used to calculate Speed and the general procedure followed to generate CNC code from CATIA
V5.
Appendix I
a) The G-codes and M-codes used for the thesis work are shown in the table 10 and table
11. These codes are the standard CNC machining codes used commonly and globally.
G-
SL NO DESCRIPTION
CODES
1 G28 Return to reference point
2 G91 Incremental coordinate position
3 G00 Rapid motion positioning
4 G40 Cutter compensation cancel
5 G80 Canned cycle cancel
6 G90 Absolute coordinate positioning
7 G54 Select work coordinate system
8 G43 Tool length compensation with spindle approach + side
9 G01 Linear interpolation motion
10 G83 Normal peck drilling canned cycle
11 G02 Clockwise interpolation motion
12 G03 Counter-clockwise interpolation motion
13 G29 Return from reference point
14 G41 Cutter compensation to the left of the programmed path
15 G42 Cutter compensation to the right of the programmed path
16 G81 Basic drilling cycle
17 T3 Tool number
18 T6 Tool number
51 Linkoping University | Design automation for CNC machining
19 T9 Tool number
20 T2 Tool number
Distance between the tool tip and workpiece (example Z3= tool is
21 Z
placed 3mm above workpiece, Z0 = Tool placed on the workpiece)
Tool length offset (This should be as same as the tool number.
22 H
Example: When tool, T14 is used then it should be H14.
23 F Feed rate
24 R Arc Radius
Drill peck (example Q5= 5 times drilling process is performed and
25 Q also it helps in removing the metal chips) Q value should be lesser
than tool diameter
26 S Spindle speed
27 L Number of cycles to run the sub-program
28 X X coordinate
29 Y Y coordinate
30 I X arc centre
31 J Y arc centre
Determines the diameter of the tool and enables radius compensation
32 D
to machine.
33 G00 Rapid motion positioning
34 G82 Counter bore cycle
35 G83 Normal peck drilling canned cycle
36 G84 Tapping cycle- Feed in, spindle stop, reverse, feed out
M-
SL NO DESCRIPTION
CODES
1 M00 Program start
2 M01 Optional program stop
3 M03 Start the spindle in forward direction
4 M04 Start the spindle in reverse direction
5 M05 Stop the spindle
6 M06 Tool change command
7 M08 Coolant on
8 M09 Coolant off
9 M30 End of program
52 Linkoping University | Design automation for CNC machining
Vc*1000
n=
3.142*D
c) The general procedure followed to generate the NC code from CATIA V5 is shown
below. This is a manual method of generating CNC codes from CATIA V5 using the option
‘generate NC output interactively’.
Step 4: After the selection of advanced machining process by clicking on the ‘part operation’, a
new dialog box opens as shown in the figure 28.
Step 5: After the selection is made as mentioned from the figure 28 (b), the tool (End mill) is
inserted using the insert option.
Step 6: The tool dialog box will be opened after clicking on the inserted tool as shown in the figure
29.
• The tool length, diameter and radius of the tool tip is changed based on the requirement in the
tool change dialog box.
Step 7: After making the changes for the tool, a machining process is inserted such as roughing,
facing, boring etc.
• By clicking on the roughing process, a new roughing dialog box opens as shown in the figure
30(b).
• From the figure 30 (c), the sign ‘*’ refers to the selection of the options that are available from
the process tree shown in figure 30 (a) similar to that of step 4.
a) ‘Part’ refers to selection of the ‘part body’.
b) ‘Rough stock’ refers to the selection of ‘Body’.
c) ‘Safety plane’ refers to the selection of a ‘safety plane’ of the model.
d) ‘Bottom’ refers to the selection of the ‘bottom plane’, where the model is built.
Step 8: After the selection process, by clicking on the roughing process in figure 30 (a), the
option called tool replay path is clicked to check the tool path of the machining.
Step 10: After ‘replaying the tool path definition’, the settings such as: Machining output and
NC code settings has to be changed. This step is very important to get the output NC code.
Step 10: After the settings is changed, to generate NC code, click on the ‘Manufacturing
program.1’ and click on ‘Generate NC output interactively’. Such that a new dialog box opens
as shown in the figure 31.
• This step generates NC code and saves it in the provided directory in the dialog box.
This is the procedure followed to generate NC code from CATIA V5. This is a manual
method of generating NC code from CATIA V5
56 Linkoping University | Design automation for CNC machining
The codes that are generated using the manual method in CATIA V5 are very long. These codes
cannot be modified again. To have a different dimension of the same model, then the whole process
must be repeated again. The steps from step 2 to step 10 must be followed every time whenever
the new design is designed. Even if the parameters of the model are changed, it is not possible to
generate NC code directly without following these steps again.
Appendix II
This chapter illustrates how the code is generated to run the Roland MDX 40A.
• Before working with the HAAS VM3 machine (Bigger CNC machine), the MDX 40A
milling machine was used for milling the models using the design of the models in NCF
and SPJ file formats. The SRP pro software is being used to design the models in the display
panel of the milling machine.
• In the thesis project, the design was made using CATIA V5 and the design model was used
in the MDX 40A milling machine by using the file formats that works in the milling
machine. That is, the design was saved in a step file format (.stl). And the code is saved in
NC file (.NC) file format.
• These files are used as the input files for the machining process.
• The length of the cuboid is 100mm, breadth is 60mm and height is 20mm.
• The pocket is having length of 80mm, breadth 50mm and height 15mm.
• The body is inserted as shown in figure 33.
57 Linkoping University | Design automation for CNC machining
• By following the general procedure mentioned in the Appendix I (c), the machining is
processed, and the NC code is generated.
%
O1000
(
**********************************************************************
)
( * INTELLIGENT MANUFACTORY SOFTWARE WWW.IMS-SOFTWARE.COM *)
( * IMSPOST VERSION : 8.1Q *)
( * USER VERSION : 1 *)
(
**********************************************************************
)
N1 G49 G64 G17 G80 G0 G90 G40 G99
( TOOL DATA : T1 END MILL D 1 )
N2 T0001 M6
( OPERATION : ROUGHING.2 )
N3 X103.999 Y38.751 S70 M3
N4 G43 Z10.01 H1
N5 G1 G94 Z.01 F300.
N6 Y20.053 Z-5.
N7 Y59.905 F1000.
N8 X103.989 Y60.301
N9 X103.908 Y60.853
N10 X103.751 Y61.388
…..continued
….
…..
…..
N2241 X85.
N2242 Y35.
N2243 X35.
N2244 Y45.
N2245 X59.69
N2246 Y43.75
N2247 Y42.5
N2248 X82.5
N2249 Y37.5
N2250 X37.5
N2251 Y42.5
N2252 X59.69
N2253 Z0
N2254 M30
%
Using SRP player pro software, the output code generated by inputting the model is shown in the
tables below
Table 13 Output Code for roughing process from SRP pro software for the Model A
;;^IN;!MC0;V50.0;^PR;Z0,0,20000;^PA;!RC8000;!MC1;
Z582,7496,20000;
Z582,7496,1100;
V50.0;Z582,7496,1100;
V15.0;Z582,7496,1000;
Z580,7496,1000;
Z590,7496,999;
Z580,7496,998;
Z590,7496,997;
Z580,7496,996;
59 Linkoping University | Design automation for CNC machining
Z590,7496,995;
Z580,7496,995;
Z590,7496,994;
Z580,7496,993;
Z590,7496,992;
Z580,7496,991;
Z590,7496,990;
Z580,7496,989;
Z590,7496,988;
Z580,7496,987;
Z590,7496,987;
Z580,7496,986;
Z590,7496,985;
Table 14 Output Code for finishing process from SRP pro software for the Model A
;;^IN;!MC0;V50.0;^PR;Z0,0,20000;^PA;!RC8000;!MC1;
Z-7536,-4048,20000;
Z-7536,-4048,520;
V15.0;Z-7536,-4048,520;
Z-7536,-4048,290;
V7.5;Z-7536,-4048,-30;
V15.0;Z-7511,-4050,-30;
Z-7487,-4050,-30;
Z7498,-4050,-30;
Z7523,-4049,-30;
Z7547,-4046,-30;
Z7571,-4041,-30;
Z7596,-4034,-30;
Z7607,-4030,-30;
Z7620,-4025,-30;
Z7645,-4013,-30;
Z7656,-4006,-30;
Z7669,-3998,-30;
Z7694,-3979,-30;
Z7717,-3957,-30;
Z7738,-3932,-30;
Z7743,-3926,-30;
• This code is generated for the machining of roughing finishing process (refer table 13 and table
14). Each machining process such as roughing, facing etc., will increase the length of the code
proportionally. The code generated is very long and hence part of the code is shown here to
show how the SRP code is generated. It is completely different from NC codes.
• The depth of cut for each cycle of operation is too small. This is the reason for the long codes.
60 Linkoping University | Design automation for CNC machining
By following the method of generating NC code automatically, the code generated is as shown
below.
Table 15 NC code for cuboid
%
O00000001(RectangleWithPocket)
G28 G91 Z0
G0 G40 G80 G90
T1 M06
G54 X-60 Y60 S80 M3( for cuboid)
G43 Z0 H1 M08
G01 Z-5 F90
G01 G41 X-60 Y50 D1
G01 X50
G01 Y-30
G01 X-50
G01 Y30
G01 G40 X-60 Y60
• As the sub-program cannot be called for MDX 40A, the depth value is increased to make
the code short and easy to understand and modify for automation. By increasing the depth
value (for instances Z=-5,-10,-15,-20) at each machining operation the codes in the table
15 are repeated until the required depth is achieved to machine the cuboid.
• Similarly, the codes in the table 16 are repeated until the required depth of pocket is
obtained.
• By comparing the codes that are generated in SRP pro software and the automated codes,
there are more than 2000 lines of codes from SRP pro software and only 67 lines of codes
in automated method (to check the whole code refer the link provided at the end of
appendix).
The prototype is built using the Roland MDX 40A milling machine (refer figure 14)
61 Linkoping University | Design automation for CNC machining
Appendix III
a) This chapter illustrates how the automation is achieved using the methods and steps
followed to generate the g-code automatically.
This consists of:
• Explanation of the entire program of generating the G code automatically for every model.
• Importance is given to the concept of achieving automation to make the production more
efficient i.e., generating g-code automatically. Thus, only important steps that are
necessary are explained in detail.
• The procedures in different steps for automated method are explained for all the models as
each model has different cases. Only few important parameters from Catia and VB script
that changes the geometry of the model and helps to generate G-code are mentioned and
explained among several other parameters.
• In depth explanation for the difference between the programs and G-codes that changes
automatically when slight changes are made to the geometrical parameters (Between
Model 3 and 4, Model 5 and 6).
• G-codes generated automatically for all the models is linked to a folder at the end of this
chapter.
• This is a method of automated generation of CNC codes. Thus, the time consumption or
time taken to generate the codes are less and the codes are very small in length when
compared to the codes that are generated manually from CATIA V5.
• Using this method many G-codes can be generated automatically at a time when the
dimension of the model is changed by changing the main parameters depending on the
design demands.
• Prototypes of Model 2-Hollow cylinder, model 3- Cube having three holes of same radius
and model 7-pyramid are built in the production lab at Linkoping university. These models
are explained in detail.
•
The different models designed to generate the G-codes are:
Model 1: Cube with a hole
Model 2: A hollow cylinder
Model 3: A cube having three fixed holes of same radius
Model 4: A cube having three movable holes of same radius
Model 5: A cube having three fixed holes of different radius
Model 6: A cube having three movable holes of different radius
Model 7: A Pyramid
62 Linkoping University | Design automation for CNC machining
b) This chapter also illustrates the manual method of generating g-codes from CATIA
V5 using the advanced machining process.
a) Manual method
By following the procedure as mentioned in the Appendix I (c), the NC code is generated for the
model ‘Cube with a hole’. The code is shown in the table 17.
%
O1000
(
**********************************************************************
)
( * INTELLIGENT MANUFACTORY SOFTWARE WWW.IMS-SOFTWARE.COM *)
( * IMSPOST VERSION : 8.1Q *)
( * USER VERSION : 1 *)
(
**********************************************************************
)
N1 G49 G64 G17 G80 G0 G90 G40 G99
(TOOL DATA : T1 END MILL D 1 )
N2 T0001 M6
(OPERATION : ROUGHING.1 )
N3 X39.067 Y-41.753 S70 M3
N4 G43 Z10.01 H1
N5 G1 G94 Z.01 F300.
N6 X38.854 Y-41.635 Z-.055
N7 X38.597 Y-41.425 Z-.144
N8 X38.346 Y-41.124 Z-.249
N9 X38.158 Y-40.779 Z-.354
N10 X38.041 Y-40.405 Z-.459
…continued
…
…
N382 X39.221 Y-38.158
N383 X39.595 Y-38.041
N384 X39.985 Y-38.
N385 X40. Y-38.001
N386 Z-15.
N387 G0 Z0
N388 M30
%
• As it is seen, there are about 388 lines in this code just for the one of the machining
processes. So only the beginning of the code and the end of the program are shown here
just to illustrate the differences.
b) Automated method
After the design in Catia, the G-code is initially written by understanding the design requirements
such as design dimensions, tool size, tool movement, tool position, tool speed, operation feed rate
etc., to produce the prototype. The G-codes are written according to the CNC machine standards.
The X and Y directions, tool movement, feed rate and speed are referred by using different
variables. Using these variables, the parameters are created in the Catia V5. These parameters are
also called in VB script.
64 Linkoping University | Design automation for CNC machining
Step 1: Creating parameters and linking the parameters in Catia V5 and Excel VB script to
the geometry.
The figure 36 refers to the parameters linked to the above sketch.
• As this is the cube, the length and breadth are equal and is 80mm in dimension. The hole
is having a diameter of 6mm and hole depth is 30mm. The height of the cube is 40mm.
From the table 18 and figure 37, the parameters such as X1, Y1, X2, Y2 belongs to the profile of
cube whereas X3 and Y3 belongs to the hole. These are the parameters that are required for the G
code. The parameters called in the VB script in excel is shown in the table 18. The names of these
parameters used in Catia V5 should be used in the same way when it is written on the script.
x_2val = parameters1.Item("x2").Value
y_2val = parameters1.Item("y2").Value
x_1val = parameters1.Item("x1").Value
y_1val = parameters1.Item("y1").Value
x_3val = parameters1.Item("x3").Value
y_3val = parameters1.Item("y3").Value
.
65 Linkoping University | Design automation for CNC machining
For example: x_2val is the parameter in VB script that gets the value for X coordinate from a
parameter x2 in Catia.
i.e., If x2 is 40mm.
Then from the Line "G01 X" & -x_2val; ""
The output will be: G01 X-40
Thus, the value of X is obtained from the parameter x2 which is 40mm. The negative symbol
denotes the movement of X to the left from the centre point.
Similarly, all other parameters that are called in the VB script obtains the value from the parameter
that is linked to it as shown.
As the cube has dimension of 80mm, we need the value of X and Y in terms of half of the total
length/breadth (40mm). Hence, we make sure to get that value by assigning these parameters with
a formula linked to the length /breadth of the cube.
• The parameters X1, Y1, X2 is equal to 40 mm and the required directions of tool path is
given using “+” or “-” signs. (refer figure 40)
• Thus, according to points shown in the figure 16, the values of X and Y on these points of
a cube of dimension 80mm are as shown in the figure 38.
The figure 39 illustrates the reason for the value of Y2 being 52mm. If the value of Y2 is 40mm,
then the tool will move away from the machining zone 16mm before it reached the required point.
This is because the tool automatically considers the tool radius and immediately goes to the origin
point G54 (Line 6 in the step 4). Thus, by adding the value of tool radius(16mm) + 1mm of
tolerance, the required point can be reached during machining. This also makes the tool move
away easily after the last cut and will have fine surface finish.
The G-code is generated automatically by running the program and automation is achieved by
changing the main parameters shown in the figure 36. This tends to change the entire parameters
that are created for G-code as they are interlinked to each other. Thus, for different dimensions of
the model G-code will be generated automatically.
67 Linkoping University | Design automation for CNC machining
Figure 42 Image showing the two parameters of the point- pointl and pointhb.
From the figure 42, parameter pointl is created for the distance of the point from the vertical
outer edge of the cube. i.e., Point X and parameter pointhb is created for the distance of
point from the horizontal outer edge of the cube i.e., point Y. Thus, Thus, when the formula
of the parameter ‘pointl’ changes the hole moves parallel to the length of cube in the X
direction. When the formula of the parameter ‘pointhb’ changes the hole moves parallel to
the breadth of cube in the Y direction.
68 Linkoping University | Design automation for CNC machining
• This rule created will assign the value of X3=0, Y3=0, if the hole is placed on the centre.
• If the formula is changed in the figure 41, the hole changes its position and is placed at
some distance away from the centre, then the value of X3 and Y3 changes accordingly.
For example:
Consider length =80mm. And to move the hole to the right from the centre then,
The formula of the parameter from figure 41 is changed to:
pointl= length/3= 26mm (positive sign as it is moved to right).
pointhb=Length/2=40mm
so according to the rule given,
Y3 is not equal to 0.
X3 = Length/2-pointl
i.e., X3= 80/2-26=14mm.
• So, the hole moves to the right at a distance of 14mm from the centre in X coordinate.
Thus, the X and Y coordinates will be: X3=14, Y3=0. This is shown in the figure 44.
Figure 44 Hole moved to the right from the centre by changing the parameter.
69 Linkoping University | Design automation for CNC machining
• From the figure 45, the parameters “XW” and “yw” are created with a formula linking to
the workpiece length and breadth. These are the parameters that are used to position the
tool in a specific point (tool reference point) as required before machining to obtain the
profile of the cube. This is illustrated in figure 46.
• There are few other parameters used such as hole depth, hole radius, speed and feed rates.
The values of the speed and feed are decided during the simulation of the G code program
in the CNC machine.
• From the table 19, the parameter “xw_val” and “yw_val” are the parameters called in the
VB script to obtain the value from the parameter “XW” and “yw” respectively.
Table 19 Parameters called in for workpiece length and breadth of model 1
xw_val = parameters1.Item("XW").Value
yw_val = parameters1.Item("yw").Value
Figure 46 Machine and work piece origin shown as Point A and Point B
• The point A is the origin point/reference point of the tool on the workpiece.
• This is done using a command work coordinate shift offset (example: G54 X## Y##).
70 Linkoping University | Design automation for CNC machining
• The values and directions of X and Y are chosen by deciding where we want the origin of
the tool.
• For each line in a G code, the tool operates with respect to this origin point.
• In other words, the tool movement starts from this point (point A) and returns to this point
after the operation and again it repeats the same way to do the next operation.
• The point B is the centre point where the value of the X and Y coordinates at this point are
always 0.
Step 4: Code explanation
• The column A represents the way of writing g-code in VB script and column B represents
the final g-code generated automatically.
To generate the G-codes on a notepad, in the VB script we write “Print #1” followed by the codes.
A path is created as shown below to generate the code automatically, when you run the program.
#1 is the output, which is assigned to each lines of the code using “Print #1”. This prints the code
in the notepad automatically as output. This is explained in chapter 3.8.
The path created:
Open "X:\Temp9.txt" For Output As #1
• Line 1: This “%” is used in the beginning and end of the program as it should be present in
order to run the program in the CNC machine. Otherwise there will be an error while
running the program.
• Line 2: The name of the program is written in this format starting with an alphabet “O”
followed by numbers and name of the model.
Line 3 to Line 4: The program is initialized by giving these standard codes which is mandatory for
all CNC machines. These codes are standards in all the programs. The descriptions for these codes
are given in the table 2.
A B
Line 1 Print #1, "%" %
O00004(CubeWithSingle
Line 2 Print #1, "O00004 (CubeWithSingleHole)"
Hole)
Line 3 Print #1, "G28 G91 Z0" G28 G91 Z0
Line 4 Print #1, "G0 G40 G80 G90" G0 G40 G80 G90
Line 5 Print #1, "T14 M6" T14 M06
Print #1, "G54 X" & -xw_val; "Y" & yw_val; "S" &
Line 6 G54 X-80 Y80 S1200 M3
s_1val; "M3"
Line 7 Print #1, "G43 Z3 H14 M88" G43 Z3 H14 M88
Line 8 Print #1, "G01 Z0. F" & f_1val; "" G01 Z0. F120
71 Linkoping University | Design automation for CNC machining
• Line 5: “T14” is the specific tool selected and “M6” is the tool change command.
• Line 6: G54 is work coordinate shift offset that is used to set the origin/reference point of
the tool on the workpiece by giving the X and Y values. The values and directions of X
and Y are chosen by deciding where we want the origin of the tool. In this case the values
for X is obtained from a parameter XW and value for cycles obtained from the parameter
YW that are already called in the beginning of the VB script as explained in the step 3.
• “S” is the spindle speed,”M3” to start the spindle.
• Line 7: To set the tool distance from the workpiece with the coolant on. M88 is the coolant
flow through/inside the tool.
• Line 8: To run the tool at the level zero on the workpiece for the X and Y from line 6.
• Line 9: This is used for Calling the sub program and L16 denotes the number of cycles of
operation to get the profile of cube and it is clearly explained in the line 24
When the sub program is called, the machining process jumps to Line 23 to run the sub-program
that is being called.
Table 21 VBA script and its output from Line 23 to Line 32
Line 24 Print #1, "G91 Z-2.5 F" & f_1val; " M08" G91 Z-2.5 F120 M08
Line 26 Print #1, "G01 G41 X" & -xw_val; " Y" & y_1val; " D14" G01 G41 X-80 Y40 D14
Line 27 Print #1, "G01 X" & x_1val; "" G01 X40
Line 28 Print #1, "G01 Y" & -y_1val; "" G01 Y-40
Line 29 Print #1, "G01 X" & -x_2val; "" G01 X-40
Line 30 Print #1, "G01 Y" & y_2val; "" G01 Y57
Line 31 Print #1, "G01 G40 X" & -xw_val; " Y" & yw_val; G01 G40 X-80 Y80
• Line 23: This is referred to the sub-program which is called in the line 9.
• Line 24: The value for “Z” is given as -2.5mm (downward movement). The number of
cycles of operation is given as 16 times while calling the sub-program, which means the at
every cycle of operation, about 2.5mm depth is being cut during the machining until the
required depth is achieved.
It is good to choose the optimal Z value in order to get the fine finish and reduce the risk of tool
damage. The Optimal Z value is between 2-3mm. As we need the height of the cube of about
72 Linkoping University | Design automation for CNC machining
40mm, we have called the sub-program to operate 16 times the Z value which is 40mm
(2.5mm*16).
• Line 26 to Line 30: These are used to perform the operation on the workpiece to obtain the
cube by removing the extra material in the workpiece.
D is used to determine the diameter of the tool and enables radius compensation for machining.
Initially the tool is positioned at a point (X= -80, Y=+80), away from the workpiece by using the
line 6 as explained in figure 28.
The tool movements along the lines 26 to 31 are shown in the figure 47.
After the machining process of cube Line 32 is the end of sub-program and the program reads line
10.
• Line 10: It is used to stop the sub-program after the machining process and Line 11 turns
off the coolant flow through the tool.
Table 22 VBA script and its output from Line 11 to Line 17
• Line 14: A specific tool is used to make the hole on the workpiece.
• Line 15: The tool is set in the centre as the origin.
Print #1, "G83 Z" & -D_val; " R" & h_rad; " Q5"; " F"
Line 18 G83 Z-30. R3. Q5. F100.
& f_2val; ""
Line 19 Print #1, "G80 M9" G80 M9
Line 20 Print #1, "G28 G91 Z0" G28 G91 Z0
Line 21 Print #1, "G28 G91 Y0" G28 G91 Y0
Line 22 Print #1, "M30" M30
• Line 18: Drilling process of a hole is performed with the hole radius of 3mm till the depth
of 30mm. Q is used to perform the number of drilling cycles. This is used to remove the
chips off from the drilling spot in order to achieve clean surface and fine finish.
• Line 19: To stop the drilling process.
• Line 20 and 21 are used in the end of program to move the tool away from the workpiece
after the machining process.
• Line 22: This denotes the end of program.
The explanation of each of the G-codes and the variables like Q, D, S, R etc are mentioned in the
table 1 and table 2.
By comparing the codes generated for the Model 1 in manual method (a) and automated
method (b), it is seen that:
• Even though the end result is the same, the manual method code has 388 lines
and the automated method has just 32 lines for the same model.
• The code in the automated method is reduced using the sub-programs and also
the automated method requires less time to generate the code.
• Adding to this, the automatic method is flexible to the changes in the dimension
of the model. That is, the new code will be generated automatically whenever
the dimension of the model is changed.
• Whereas, in the manual method it consumes more time to generate the code as
every procedure have to be repeated for every change in the dimension of the
model and the code generated will be too long for different machining
operations.
74 Linkoping University | Design automation for CNC machining
a) Manual method
By following the procedure as mentioned in the Appendix I (c), using CATIA V5 the NC code is
generated for the model ‘A hollow cylinder’. The code is shown in the table 24 below.
Table 24 NC code for model 2 from CATIA V5
%
O1000
(
**********************************************************************
)
( * INTELLIGENT MANUFACTORY SOFTWARE WWW.IMS-SOFTWARE.COM *)
( * IMSPOST VERSION : 8.1Q *)
( * USER VERSION : 1 *)
(
**********************************************************************
)
N1 G49 G64 G17 G80 G0 G90 G40 G99
( TOOL DATA : T1 END MILL D 1 )
N2 T0001 M6
( OPERATION : ROUGHING.1 )
N3 X-3.541 Y-1.854 S70 M3
N4 G43 Z10.01 H1
N5 G1 G94 Z.01 F300.
N6 X-3.275 Y-2.296 Z-.128
N7 X-2.924 Y-2.73 Z-.278
N8 X-2.516 Y-3.11 Z-.427
N9 X-2.058 Y-3.43 Z-.577
N10 X-1.561 Y-3.683 Z-.726
….continued
N264 X.003
N265 Z-10.
N266 G0 Z0
N267 M30
%
• As it is seen in the table, there are about 267 lines in this code. It is difficult to understand
such codes with respect to the tool movements on the coordinate axes.
b) Automated method
Step1: Linking the parameters in Catia and VB script to the geometry:
In Catia:
• These are the design parameters.
• The hole depth, outer radius and inner radius of the cylinder is assigned by using parameters
in Catia and these parameters are called in VB script.
• Inner radius is half of the outer radius and are linked to each other by giving the formula.
• These parameters are linked to the geometry and hence the dimensions of the cylinder are
changed by changing these parameters shown in the figure 49.
In VB script:
The same parameters hole depth, Inner radius and outer radius which are created in Catia V5 are
called in the VB script as shown below.
• The required parameters for g-code for the inner hole are created by analysing the tool
movement, tool size and dimensions. These parameters are shown in the figure 51.
• These parameters are called in the VB script as shown in the table 26.
• Circular interpolation (G02/G03) are used in this program, which is used to make the cutter
to run from the current point to the target point required along counter clockwise direction
G03 or in clockwise direction G02. (explained below in figure)
• The centre of the arc or the radius is also needed besides the target point.
• The parameters of the centre of circular arc is labelled b I, J and K.
• “I” is the X axis whereas “J” is the distance along Y.
• All these parameters in Catia V5 are called in the VB script as mentioned above.
Step 3: G-code explanation
• The G-code pattern using the parameters that are called are written in this format and the
output is generated by creating a path file. This is a common step in all the models.
78 Linkoping University | Design automation for CNC machining
• Few lines which are explained here are the important steps that is required to understand
the concept and working of the program.
• The column A represents the way of writing g-code in VB script and column B represents
the final g-code generated automatically.
Table 27 VBA script and its output from Line 4 to Line 6 for model 2
A B
Line
Print #1, "G28 G91 Z0" G28 G91 Z0
4
Line
Print #1, "G0 G40 G80 G90" G00 G40 G80 G90
5
Line
Print #1, "T6 M6" T6 M06
6
Print #1, "G54 X" & x_start_val; " Y" & y_start_val; " S" &
Line 7 G54 X0. Y0. S1100 M03
s_1val; " M3"
Line 8 Print #1, "G43 Z3 H6 " G43 Z3. H06
Line 9 Print #1, "M08" M08
• Line 7: This line uses the work coordinate shift command G54, to make the origin point.
The tool is placed at the centre.
Table 29 VBA script and its output from Line 10 to Line 11 for model 2
Print #1, "G83 Z" & -Z_val; " R" & rad_drill; " Q5"; " F" & G83 Z-20. R3. Q5.
Line 10
f_1val; "" F100.
Line 11 Print #1, "G80 M9" G80 M09
• Line 10: The drilling operation to make a hole of radius 3mm is done using this command.
Even though the inner radius is 10mm, to make the operation easy and fine surface finish,
the hole is drilled at the centre as shown in the figure 53 .And then, the operation to get the
desired radius of 10mm is processed.
Table 30 VBA script and its output from Line 12 to Line 14 for model 2
• Line 14: This is to change the tool to machine the inner radius. The size of the tool is
selected based on the design demands.
Table 31 VBA script and its output from Line 15 to Line 19 for model 2
Print #1, "G54 X" & x_start_val; " Y" & y_start_val; " S" &
Line 15 G54 X0 Y0 S4000 M03
s_2val; " M3"
Line 16 Print #1, "G43 Z3 H3 M08 " G43 Z3. H03 M08
Line 17 Print #1, "G01 Z0 F" & f_1val; "" G01 Z0 F100.
Line 18 Print #1, "M97 P901 L5" M97 P901 L5
Line 19 Print #1, "M01" M01
• Line 15: This line uses the work coordinate shift command G54, to make the origin
point. The tool is placed at the centre.
• Line 18: The sub-program is called and the number of cycles of machining operation
is given as 5 times(L5). This makes the machine to go to the line 33.
Table 32 VBA script and its output from Line 33 to Line 41 for model 2
• Line 33: N901 is referred to the sub program that is called in the main program.
• Line 34: G91 is incremental coordinate position. This means that the tool goes 4mm depth
at every cycle. As number of cycles is 5(L5), then 4*5 is 20mm is the total depth that is
80 Linkoping University | Design automation for CNC machining
Table 33 VBA script and its output from Line 23 to Line 28 for model 2
• After the end of sub-program P901, the machine reads the next codes mentioned in the
lines (line 20 to 23).
• Line 23: The tool is changed to machine the outer part of the cylinder and to remove the
extra material in the workpiece.
• Line 24: Setting the origin point of the tool over the workpiece for machining process of
outer part of the cylinder.
81 Linkoping University | Design automation for CNC machining
• Line 27: The second sub-program is called and the number of cycles of operation is 5(L5).
• The machine goes to the line 42, to run the sub-program called in the main program.
Table 34 VBA script and its output from Line 42 to Line 50 for model 2
After the machining, G80 M09 defines the end of program and coolant off and the machine
completes all the operation and goes to the position G28 G91 Z0, G28 G91 Y0.
The manual method has 267 lines of code and the automated method has just 50 lines
The comparison between the manual method(a) and automated method (b) are same as that of the
comparison made for the model 1.
Comparison
Model 3 Model 4
1 G-code generated for a Cube of dimension G-code generated for a cube of dimension
=100mm =100mm
2 Three fixed holes of same radius Three movable holes of same radius
3 Each hole has a point and each point has Each hole has a point and each point has two
two parameters. parameters
4 The parameters of the three points of the The parameters of the three points of the holes
holes are assigned with a value without are linked to the dimensions of the cube using
any formula linked to it. Thus, the holes formula. It works like model 1, when the
are fixed from a certain distance from the formula is changed, the point changes the
side edges of the cube. This is illustrated position and thus the hole changes the position
in section A and moves with respect to the dimension of the
cube. This is illustrated in section B
83 Linkoping University | Design automation for CNC machining
Section A: Illustration of the Model 3 where the holes of same radius are fixed in Catia V5.
• Design of cube of
dimension 100mm
• Design of cube of
dimension 80mm
Step 2: Parameters created and linked to the geometry using Catia and VB script.
a) For cube:
Figure 56 Parameters used for 100mm cube having three fixed holes
• The parameters used for 100mm cube are shown in figure 56. There is no formula given to
these parameters.
• If the parameter of the cube “length of box” changes, the dimension of the cube changes
and thus, the new g-code will be generated automatically for the new dimension of the
cube.
b) For holes:
• The parameters created for making three different holes of having same radius are:
a) X5 and Y5 for point 1
b) X6 and Y6 for point 2
c) X7 and Y7 for point 3
These parameters are shown in figure 59. 53-59
The point will not have length and breadth. But the names of the parameters such as ‘length
of point’ and ‘breadth of point’ are given in order to understand the concept of hole
movement easily. Therefore, the parameters for point 1 such as ‘length of point 1’ and
86 Linkoping University | Design automation for CNC machining
‘breadth of point 1’ corresponds to the distance of the point 1 from two outer edges (L*B)
of the cube. That is, ‘Length of point 1’ corresponds to the horizontal distance of the point
1 from outer vertical edge of the cube as shown in the figure (1 in figure 60). Similarly,
Breadth of point 1 corresponds to the vertical distance of the point 1 from the outer
horizontal edge of the cube (2 in figure 60). Thus, when the formula of the parameter
‘length of point 1’changes the hole moves parallel to the length of cube in the X direction.
When the formula of the parameter ‘Breadth of point 1’changes the hole moves parallel to
the breadth of cube in the Y direction.
This is same for the parameters created for point 2 and point 3.
• The figure 60 shows the image of three holes having three points each and its parameters.
• Point 1 has two parameters – ‘length of point 1’ and ‘breadth of point 1’.
• As X5 and Y5 are assigned for point 1, parameter X5 is linked to ‘length of point 1’, and
Y5 is linked to ‘breadth of point 1’ using rules and is illustrated in figure 61 and figure 62.
• The rules given will assign a value for X5 and Y5 and the position of the hole is obtained
from these values of the parameters.
• Similarly, the rules are given to the parameters X6, X7,Y6,Y7 w.r.t their respective points.
• Obtaining values for these parameters using the rules are illustrated in ‘step 2’ of ‘Model
1’.
• The other parameters like speed, feed is also created in Catia V5.
87 Linkoping University | Design automation for CNC machining
• These parameters are called in VB script as they are very important for the g-code. The
procedure to call the parameters in the VB script are same in all the models and are
explained in previous models.
If I_nr = 1 Then
Open "X:\same1.txt" For Output As #1
Else
Open "X:\Temp2.txt" For Output As #1
End If
Table 39 VBA script and its output from Line 5 to Line 10 for model 3
Column A Column B
Line 5 Print #1, "T14 M6" T14 M6
Line 6 Print #1, "G54 X" & -x_val; " Y" & y_val; " S" & s_1val; " M3" G54 X-80 Y80 S4000 M3
Line 7 Print #1, "G43 Z3 H14 M88" G43 Z3 H14 M88
Line 8 Print #1, "G01 Z0 F" & f_1val; "" G01 Z0 F120
Line 9 Print #1, "M97 P901 L16" M97 P901 L16
Line 10 Print #1, "M01" M01
Table 40 VBA script and its output from Line 33 to Line 41 for model 3
• Line 34: The depth of 2.5mm is machined at every cycle until 16 cycles to reach the target
depth of 40mm using an incremental coordinate positioning command G91.
• Line 36 to Line 41 operates the same way as illustrated in figure 41.
• After machining the profile of cube, the tool is changed in line 14 for the drilling operation
of the hole.
• By using the values of parameters X5 to X7 and Y5 to Y7 , the different positions of the
holes are obtained.
89 Linkoping University | Design automation for CNC machining
Table 41 VBA script and its output from Line 14 to Line 20 for model 3
• Line 15 to line 20 is the drilling process to mark the position of the holes at a depth of 5mm
at radius of 3mm.
Table 42 VBA script and its output from Line 23 to Line 28 for model 3
• Line 23 is the tool change to drill the hole to reach the desired depth.
• Line 24 to Line 28: The drilling operations of the holes is processed to reach the required
depth of 40mm at a radius of 3mm.
• The prototype of the model Cube having three holes of same radius is built in the
production lab.
90 Linkoping University | Design automation for CNC machining
Section B: Illustration of the Model 4 where the holes of same radius are movable in Catia
V5.
Step 1: Design differences in Catia V5
• This shows how the holes are movable when the dimension of the cube is changed.
• Design of cube of
dimension 80mm
• Design of cube of
dimension 100mm
• From table 36 and table 43, it is seen that the holes in model 3 are fixed and the holes in
model 4 are movable w.r.t the change in dimension of the cube. Thus, even though the g-
code format is same for the both models, the final g-code generated will be different from
91 Linkoping University | Design automation for CNC machining
one another. This is automatically generated. It is difficult to measure the minute changes
in dimensions and write the g-code manually by analyzing the changes or by using Catia
V5 machining process, but this method illustrates how the automatic g-code generation
process takes place.
Step 2: Parameters created and linked to the geometry using Catia and VB script.
• The formulas given to the parameters corresponding to holes are shown in the figure 45.
Figure 63 Parameters used for cube having three movable holes along with formulas used
• The parameters used for 100mm cube are shown in figure 63, (where ‘Length of
box=breadth of box’)
• The formula is given as seen in the figure. If these formulas are changed then the hole
position changes respectively. This is the main difference between model 3 and model 4.
Therefore, the g-code generated will have the automatic changes without any modification
to the code format in VB script.
• If the parameter of the cube “length of box” changes, the dimension of the cube changes
and thus, the new g-code will be generated automatically for the new dimension of the
cube.
• Creating parameters for the cube and holes are same as that of model 3.
• As the holes are of same radius, one tool can drill all the holes.
• All the other procedures like creating rules for assigning the values to X and Y coordinates
of the holes, code format in VB script are similar to that of model 3.
92 Linkoping University | Design automation for CNC machining
The difference in the g-code generated for 100mm dimension of the cube between Model 3
and Model 4.
• The hole positions changes in model 4 as the holes move and change its position when the
dimension of the cube is changed unlike model 3. This is illustrated below.
Table 44 Difference in g-code between model 3 and model 4
Line 30
Pictorial
view of
hole
positions
• The differences in the distance of the hole position from the center point of the CNC
machine is clearly seen in the lines 24, 27 and 28 and they are illustrated in line 30.
• This is how g-code is generated automatically.
The main differences are each hole has different radius. Therefore, tools must be changed to
drill the different holes.
Comparison
Model 5 Model 6
1 G-code generated for a Cube of dimension G-code generated for a cube of dimension
=100mm =100mm
2 Three fixed holes of different radius Three movable holes of different radius
3 Each hole has a point and each point has Each hole has a point and each point has two
two parameters. parameters.
4 The parameters of the three points of the The parameters of the three points of the holes
holes are assigned with a value without are linked to the dimensions of the cube using
any formula linked to it. Similar to model formula. Similar to model 4. Illustrated in
3. Illustrated in Section C Section D
Section C: Illustration of the Model 5 where the holes of different radius are fixed in Catia
V5.
Step 1: Design differences in Catia V5
• This shows how the holes are fixed even if there is change in the dimension of the cube.
• Design of cube of
dimension 100mm
• Design of cube of
dimension 80mm
• Creating parameters in Catia V5, calling the parameters, creating rules are similar to that
of model 3.
Table 47 VBA script and its output from Line 5 to Line 11 for model 5
Column A Column B
Line 5 Print #1, "T14 M6" T14 M6
Print #1, "G54 X" & -x_val; " Y" & y_val; " S" &
Line 6 s_1val; " M3" G54 X-80 Y80 S4000 M3
Line 7 Print #1, "G43 Z3 H14 M88" G43 Z3 H14 M88
Line 8 Print #1, "G01 Z0 F" & f_1val; "" G01 Z0 F120
Line 9 Print #1, "M97 P901 L16" M97 P901 L16
Line 10 Print #1, "M01" M01
Line 11 Print #1, "M89" M89
Table 48 VBA script and its output from Line 14 to Line 15 for model 5
• Line 14: Tool is changed to mark the position of the hole. This is done the same way to
other two holes.
Table 49 VBA script and its output from Line 21 to Line 25 for model 5
• Line 21: The tool is selected to drill the hole of 3mm until the target depth is reached.
• Similarly, using different tools the other two holes are drilled.
• All the other procedures are similar to model 3.
Section D: Illustration on the Model 6 where the holes of different radius are movable in
Catia V5.
Step 1: Design differences in Catia V5
• This shows how the holes are movable when the dimension of the cube is changed.
• Design of cube of
dimension 100mm
• Design of cube of
dimension 80mm
• From table 31 and 35, the design differences are clearly seen.
• All the other procedures are similar to model 4. As this model is having different radius
holes, the tool is changed like the model 5 to drill different holes.
Difference between the g-codes generated for 100mm cube between fixed and movable holes
having different radius.
• The difference in the code is as same as mentioned in the table 29.
• The radius will be different in size.
Example: The figure 64 shows the cube having three holes of different radius:
97 Linkoping University | Design automation for CNC machining
Model 7: A Pyramid
A pyramid having ten boxes of height 5mm each is designed in Catia V5. The topmost box is
10*10mm (Length*Breadth) and second step is 20*20mm(L*B) and the last step is
100*100mm(L*B). The total height of the pyramid is 50mm (10*5mm =50mm). The figure 65
shows the pictorial view of the pyramid.
a) Manual method
By following the procedure as mentioned in the Appendix I (c), using CATIA V5 the NC code is
generated for the model ‘A Pyramid’. The code is shown in the table 51 below.
98 Linkoping University | Design automation for CNC machining
%
O1000
( ********************************************************************** )
( * INTELLIGENT MANUFACTORY SOFTWARE WWW.IMS-SOFTWARE.COM *)
( * IMSPOST VERSION : 8.1Q *)
( * USER VERSION : 1 *)
( ********************************************************************** )
N1 G49 G64 G17 G80 G0 G90 G40 G99
( TOOL DATA : T1 END MILL D 1 )
N2 T0001 M6
( OPERATION : ROUGHING.1 )
N3 X99.999 Y-6.01 S70 M3
N4 G43 Z5. H1
N5 G1 G94 Z-5. F300.
N6 Y0
N7 Y100. F1000.
N8 X97.058
…. continued
Workpiece 100
Top box length 10
Top 2nd Box length 20
Top 3rd Box length 30
Top 4th Box length 40
Top 5th Box length 50
Top 6th Box length 60
Top 7th Box length 70
Top 8th Box length 80
Top 9th Box length 90
Top 10th Box length 100
• The Figure 67 shows the parameters of top first box required for g-code
• The formula given is top first box length/2=10/2=5mm. As we need half of the length for
the g-code. Because, the length is considered from the center point of the CNC machine as
explained in the model 1.
• Y3 is the last cut of the first box. Therefore, tolerance and tool radius must be considered.
100 Linkoping University | Design automation for CNC machining
• Similarly, the parameters are created to all the 10 boxes. Therefore, there are a greater
number of parameters as there are 10 boxes in the pyramid.
• Therefore, there is a necessity to remove the excess material using g-code automatically.
Otherwise, the tool may damage when it goes deeper during the machining process due to
the varying height of the pyramid at each step.
• Thus, the parameters that are created for the purpose of removing excess material are
shown in figure 69.
• The values are calculated based on the dimension of the workpiece. There are many ways
to do the machining process to remove the excess material based on the size of the tool.
• From the top 4th box to the bottom, the workpiece material can be machined in single run
of the tool of diameter 32mm. Thus, only the top three boxes require the consideration of
the parameters that are used to remove excess material.
101 Linkoping University | Design automation for CNC machining
I_nr =1 to 2. So, the parameter ‘base_length’ changes twice. Hence, there are two different
dimensions. One is 100*100mm(length*breadth) and other one is 120 *120mm (length*breadth)
based on the formula used as shown. The g-code will be automatically generated for both the
change in dimensions of the pyramid.
• If loop statement using write statement to text file method by creating a path for the
output to be generated.
Table 54 Using if loop in model 7
If I_nr = 1 Then
Open "X:\Temp1.txt" For Output As #1
Else
Open "X:\Temp3.txt" For Output As #1
End If
• The column A represents the way of writing g-code format in VB script and column B
represents the final g-code generated automatically.
Table 55 VBA script and its output from Line 5 to Line 8 for model 7
Column A Column B
Line 5 Print #1, "T14 M6" T14 M06
Line 6 Print #1, "G54 X" & -x_val; " Y" & y_val; " S" & s_val; " M3" G54 X-80. Y80. S4000 M03
Line 7 Print #1, "G43 Z3 H14 M88" G43 Z3. H14 M88
Line 8 Print #1, "G01 Z0 F120" G01 Z0 F120.
• When the sub-program is called in the main program, the program reads the line 40.
Table 57 VBA script and its output from Line 40 to Line 53 for model 7
• Same as before, the last cut i.e., parameter y_3val in this step has the value of 22mm. This
is obtained by considering the tolerance of 1mm+ the tool radius of 16mm.
• Line 53: End of sub-program.
Table 58 VBA script and its output from Line 11 to Line 13 for model 7
Line 11 Print #1, "G01 Z" & -Z_1val; " F120" G01 Z-5. F120.
Line 12 Print #1, "M97 P902 L2" M97 P902 L2
Line 13 Print #1, "M01" M01
103 Linkoping University | Design automation for CNC machining
• After machining the first top box, the depth of 5mm will be cut already in the first sub-
program. Hence, for the next operation the tool should go downward (Z direction) to 5mm.
That is the reason for line 11 having the value of Z as Z-5. The Z values are obtained by
the parameters that are created in Catia V5 and being called in VB script as shown in figure
70.
• Then the second sub-program is called similar to the first sub-program. The second box is
also machined the same way as that of first box.
• These steps are repeated until the machining is done for the last box (10th box).
• The tool movement for machining the first top box of the pyramid as described in the g-
code (lines 43 to 53) is illustrated in the figure 71.
Table 59 End of coding for model 7
The manual method has 1206 lines of code and the automated method has just 142 lines. There are
about 9 sub-programs that are called in the model 7 in automated method.
The designs, NC script and final g-codes generated for all the models is available online at-
https://liuonline-my.sharepoint.com/:f:/g/personal/chako332_student_liu_se/EmIspCBh-
ltIo1Jaukk7DJUBEv3RYEGPuxM4D3O9U5EirQ?e=WQx1o6