Download as pdf or txt
Download as pdf or txt
You are on page 1of 116

Linkoping University | IEI - Department of Management and Engineering

Master Thesis, 30 ECTS | Mechanical Engineering| Design and Product Development


Autumn 2019| LIU-IEI-TEK-A--19/03618—SE

Master’s Thesis

Design Automation for CNC Machining


A case study for generating CNC codes from geometric CAD models

Authors
Changappa Kongiranda Ganapathi (chako332)
Vivek Mandanna Balapanda Erappa (vivbe598)

Supervisors: Medhi Tarkian


Examiners: Johan Ölvander
Linköping University
SE–581 83 Linköping
+46 13 28 10 00,
www.liu.se
Authors: Changappa Kongiranda Ganapathi
M.Sc. Mechanical Engineering
Linköping University| Sweden
chako332@student.liu.se

Vivek Mandanna Balapanda Erappa


M.Sc. Mechanical Engineering
Linköping University| Sweden
vivbe598@student.liu.se

Supervisor: Mehdi Tarkian


Associate Professor IEI |
Division of Machine Design
Linkoping University | Sweden
mehdi.tarkian@liu.se

Examiner: Johan Ölvander


IEI | Division of Machine Design
Linköping University | Sweden
Johan.olvander@liu.se
I Linkoping University | Design automation for CNC machining

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.

Changappa Kongiranda Ganapathi


Vivek Mandanna Balapanda Erappa

Linköping, December 2019


III Linkoping University | Design automation for CNC machining

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

3.1. Description of main theoretical concepts ....................................................................... 20


3.1.1. Geometric Modelling / CAD Interface ................................................................... 20
3.1.2. Tool motion definition ............................................................................................ 20
3.1.3. Data processing ....................................................................................................... 21
3.1.4. Post processing........................................................................................................ 21
3.2. Design Automation: CAD, CAM, CAD/CAM .............................................................. 22
3.3. Visual Basic Programming............................................................................................. 23
3.4. Machining Features ........................................................................................................ 24
3.4.1. Interpreting geometric models to obtain machining features ................................. 25
3.4.2. Feature-Based Machining ....................................................................................... 26
3.5. NC Programming Automation ....................................................................................... 26
3.5.1. Catia V5 Automation for improved NC coding ...................................................... 26
3.6. Co-ordinate system and machine motions: .................................................................... 27
3.7. Basic steps for generating CNC codes. .......................................................................... 28
3.8. Method for automating NC script .................................................................................. 31
3.9. Sub-Program................................................................................................................... 32
4. Results ................................................................................................................................... 33
5. Discussions ........................................................................................................................... 43
5.1. Current challenges for generating NC code ................................................................... 43
5.2. The benefits to automate NC code generation directly from CAD models ................... 44
6. Conclusion and Future work ................................................................................................. 45
Bibliography ................................................................................................................................. 47
Appendix ....................................................................................................................................... 50
Appendix I .................................................................................................................................... 50
Appendix II ................................................................................................................................... 56
Appendix III .................................................................................................................................. 61
V Linkoping University | Design automation for CNC machining

List of figures and tables


Figure 1 Current problem statement ............................................................................................... 2
Figure 2 Thesis outline.................................................................................................................... 5
Figure 3 Overall process in automated approach ............................................................................ 7
Figure 4 CAM System Flowchart (Image inspired from Omuz, S,2009, accessed 2019-10-22) .. 8
Figure 5 simplified operation procedures of CNC machine (Image inspired from Introduction to
Computer aided manufacturing n.d., (accessed on 2019-11-10)) ................................................. 15
Figure 6 Current process in MDX 40A machine .......................................................................... 17
Figure 7 Current process in HAAS VM3 machine ....................................................................... 18
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).
....................................................................................................................................................... 24
Figure 9 Component modules in automatic feature recognition. (Ji. Q and Marefat M., 1997) .. 25
Figure 10 Example of the simple part with a slot ((Ji. Q and Marefat M., 1997)......................... 25
Figure 11 Communication flowchart (Source: Catia V5 automation, 2009) ................................ 26
Figure 12 Machine tool co-ordinate system for NC, Source: Integrated manufacturing n.d
(accessed on 2019-10-04) ............................................................................................................. 27
Figure 13 Coordinate axes of the CNC machine w.r.t the CNC table movement in 3D view ..... 28
Figure 14 The actual CNC display panel showing center point (+) ............................................. 28
Figure 15 Representing signs of X and Y co-ordinate axes with respect to center. ..................... 29
Figure 16 Representation of co-ordinate axes points .................................................................... 29
Figure 17 Representation of X and Y axes according to the machine standards. ......................... 30
Figure 18 Example of writing X and Y coordinates for a triangle. .............................................. 30
Figure 19 Example of using Sub-program .................................................................................... 32
Figure 20 The finished machined part for Model A ..................................................................... 35
Figure 21 Model 1 Parameters ...................................................................................................... 36
Figure 22 Illustration on the results of two cases ......................................................................... 38
Figure 23 Finished machine part for model 2 ............................................................................... 41
Figure 24 Finished machine part for model 3 ............................................................................... 41
Figure 25 Finished machine part for model 7 ............................................................................... 42
Figure 26 Selecting 'Part design' to design the model .................................................................. 52
Figure 27 Selecting Advanced machining process ....................................................................... 53
Figure 28 Dialog box of part operation......................................................................................... 53
Figure 29 Tool change dialog box ................................................................................................ 54
Figure 30 Roughing dialog box .................................................................................................... 54
Figure 31 Dialog box for Generating NC Output Interactively .................................................... 55
Figure 32 A Cuboid with rectangular pocket ................................................................................ 56
Figure 33 Inserting Body .............................................................................................................. 57
Figure 34 Machining process of the model for Roland machine .................................................. 57
Figure 35 Sketch of the cube with a hole ...................................................................................... 62
Figure 36 Base parameters of the sketch ...................................................................................... 64
Figure 37 Set of parameters required for the G-code ................................................................... 64
Figure 38 Stock position with respect to origin ............................................................................ 65
Figure 39 Tool movement with tolerance in Y2 direction ............................................................ 66
Figure 40 Illustration of total length in X and Y direction of the cube-. ...................................... 66
VI 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

Table 59 End of coding for model 7 ........................................................................................... 104


IX Linkoping University | Design automation for CNC machining

Nomenclature

Abbreviation Meaning

CNC Computer numerically controlled

G-code General purpose code

M-code Miscellaneous or Machine code

NC Numerical control

CAM Computer-aided manufacturing

CAD Computer-aided design

FBR Future based recognition

CAPP Computer-aided process planning

DNC Direct numerical control

OEM Original equipment manufacturer

VBA Visual basics for applications

VB Visual basics

CATIA Computer aided three-dimensional interactive application

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.

1.1. Problem statement


In the present situation, the generation of CNC code is carried out manually or the operator writes
the code manually for the CAD model by first designing the model. Then the code is simulated to
check for the errors before machining operation in CNC machine.
2 Linkoping University | Design automation for CNC machining

Figure 1 Current problem statement

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.

1.2. Project goals


• Setting up the environment and defining the kinematics for the CNC machining.
• Defining the tool parameters & operations.
• Customized post processor for path generation.
• To automatically generate g-code that matches the controller of the machine on the
shop floor.
• Simulating the code against manual set up and to derive if an identical approach can be
used for larger machines.
1.3. Deliverables
• Significant literature studies on suitable methods and techniques for CNC, CAM and
generating G-code. Including fundamentals with respect to the above mentioned to do
these operations efficiently and automatically.
• Creating a framework that can automatically generate CNC code necessary to run the
MDX-40A and produce any given CAD model.
• To automatically produce the same result in the HAAS VM3 CNC machine in the lab.
Work is done using CATIA V5 and Microsoft Excel VBA script.
• A presentation and final report of the thesis work.

1.4. Limitations and challenges


a) For the Roland MDX 40A milling machine,
• Only one tool can be used. Z axis is the spindle axis.
• The material such as metals cannot be used in this CNC machine as it may
damage the tool.
• The maximum tool length is 25mm. Therefore, the depth of cut should not
exceed more than the tool length.
3 Linkoping University | Design automation for CNC machining

• Sub-program cannot be called as the machine fails to read the sub-program.


(refer section 3.9 for the explanation of Sub-program)
• The file formats such as NCF/.NC and SPJ/.stl (step files) are used to run the
program.

b) For the HAAS VM3 CNC machine,


• Z axis is the spindle axis and hence every machining process should be done
with respect to Z axis.
• Optimal size of the workpiece is 100mm in square shape. So, larger designs
were not considered during the thesis work.
• Detailed and complex designs are not possible due to the single tool axis (Z
axis).

1.5. Purpose and research questions


The purpose of the thesis is to develop an automated process for CNC code generation for CATIA
using VB scripting.
The purpose of the thesis is fulfilled by answering the following research questions:
Research question 1: What are the current challenges while generating NC code?
Research question 2: What are the benefits to automate NC code generation directly from CAD
models?

1.6. Thesis Background


Standard manufacturing needs significant effort and time using Computer Numerically Controlled
(CNC) machines from design inputs. The manufacturers must understand and describe the
Computer-aided design (CAD) inputs, describe these to machinable features, generate process
plans, determine setup directions, select appropriate tools and machining parameters. This data is
uploaded to computer-aided manufacturing (CAM) system for generation of CNC code. This will
increase the need for automating the process to reduce the lead time, improve quality, product
development life cycles and productivity globally. Concerning this, computer-aided process
planning (CAPP) was introduced as a link between CAD and CAM systems that were developed
independently. CAPP indicate the activities done automatically or with minimal human
intervention to convert the component designs into manufacturing instructions that explain how
components are to be produced (Turley,S et al., 2014)
The current trend at the industries is to increase product modification and minimize the cost, time
and manufacturing errors. A lot of CAPP systems were developed and the literature in this field is
relatively significant. These systems are classified depending on whether they are feature,
knowledge, agent-based or genetic algorithms. Among these, the feature-based technologies are
used in CAD/CAM combinations as most CAM systems recognize features as input data. Feature-
based technologies are classified into three types such as design by features (DBF), automated
feature recognition (AFR) and interactive form feature recognition (Babic, et al., 2008). In the
DBF approach, the parts are designed using features from libraries. Whereas in interactive form
4 Linkoping University | Design automation for CNC machining

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)

1.7. Ethical Aspects


Although automation of CNC code generation process reduces the time taken for generating code
and the machining, it greatly reduces the human interaction in the machining process by shifting
most of the tasks to a computational body. The ethical issue of this is that it eliminates the need
for a highly skilled labour during the code generation process and the data required would be
extracted from the design phase of the process. But it would also require the initial recruitment of
highly skilled labours during the design phase of the process to better understand what kind of data
is to be extracted. The process of automation although reduces the total time during machining it
does not affect the manpower needed for the whole process.
1.8. The structure of the report
The procedures and techniques followed for the configuration of the thesis is shown in the figure
2. The case study is carried out by initially executing a plan and studying the different literatures
about the case. It is then being implemented in the whole process wherever required. The
methodology chapter explains the steps taken to demonstrate how the work is being carried out
using the methods to get the desired results in detail. This is followed by theoretical framework
which builds a base for analysing the objective that is declared. The techniques from different
studies made are being used in the whole process of design and code generation. The continuous
improvements were made to the theory during the entire project as creative vision and perspectives
were encountered. The theoretical framework chapter explains all the empirical findings related to
design automation and automatic code generation that results in efficient production. The research
questions are answered in the discussions chapter by analysing the documentation made from the
literatures and the results obtained. The conclusion of the thesis includes the results that are
obtained in order to meet the objective of the thesis. The further research or future work for the
improvements are suggested based on the results of this study.
5 Linkoping University | Design automation for CNC machining

Figure 2 Thesis outline


6 Linkoping University | Design automation for CNC machining

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.

2.2. Overall process and steps carried out in automated approach


As shown in the figure 3, the work is done in two different machines. The framework is created
that generates g-codes automatically to run the MDX 40A milling machine and produce any given
CAD model. Initially, the model is designed and imported to the SRP pro software of the MDX
40A milling machine using suitable file formats. The code is generated in the SRP pro software
manually. Using automation for CNC machining, the framework is created that generates CNC
codes automatically . This code is compared with the manually created code in SRP software to
see the differences between them regarding time and accuracy. This is done by gathering the
theories from the literature studies and applying them in practice.
7 Linkoping University | Design automation for CNC machining

Figure 3 Overall process in automated approach

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.

2.2.1. CAM system flowchart


From the figure 4, the process consists of 3-dimensional CAD model designed using a CAD
interface. The model is then exported to a CAM interface for operation sequence and parameter
definition. In the post processing, the parameters defined for the model are linked to the NC code
script in VBA. This is how the geometry is linked to the code. The values of parameters are
extracted using VBA by running the program to generate the NC code . The NC code is then
exported to the CNC machining. The scripting allows to identify machining parameters like
spindle speed, feed rate, depth of cut etc. Theory development was concentrated in the early phases
of the thesis project, but the theory also kept continuously developing during the entire project as
new insights and perspectives where encountered (Omuz, S,2009).

Figure 4 CAM System Flowchart (Image inspired from Omuz, S,2009, accessed 2019-10-22)
9 Linkoping University | Design automation for CNC machining

2.3. Pre study


2.3.1. Introduction
A production engineer accomplishes a process planning to create a document where the
appropriate resources, manufacturing processes and production flow are determined. A document
of the detailed product is prepared, and the process starts with a part or group of parts for a finished
product and both are reported at planning. The production engineer decides whether to produce or
buy a part. When the part is built in the manufacturing plant, the selection and definition of the
operation are made to make the workpiece to a finished part. Initially, the process is decided is
based on the part material. The list of operations and the machines used for the machining surfaces
is shown is table 1 (Ching. C, 2008).

Table 1 Manufacturing processes ((Ching. C, 2008)


Operation Most commonly used machines
Shaping Horizontal shaper
Planning Planer
Milling Milling machine
Facing & Turning Lathe
Grinding Cylindrical grinding
Drilling Drill press
Boring Lathe/boring mill
Sawing Contour saw

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.

2.3.2. Computer- aided design (CAD) and Geometric Modelling


Design is a repetitive method that involves proposing a design solution, testing and evaluating the
planning solution, modifying the planned solution, and eventually optimizing the solution. Within
CAD, the graphics capabilities of a computer are substituted for the work that is historically carried
through with pencil and paper. Moreover, the simulation capabilities of the computer facilitate the
design and value of a planned design solution. The CAD will cut-off the planning cycle, increase
design accuracy, and free the operators from repetitive work.

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).

2.3.3. Computer-aided manufacturing (CAM)


Computer-aided manufacturing is an application technology that uses computer to control the
machines and automate manufacturing processes in production. CAM is closely related to
computer-aided design (CAD) because the product output obtained from CAD can support to build
production program. The main purpose of using CAM is to create an agile production process,
components, tooling with more accurate dimensions, material flexibility, and decreasing error
rates. With the help of CAM, the required amount of raw material is used resulting in waste
minimization. Energy consumption is also reduced at the same time. Almost all industries now use
CAM, where the automated plants have provided a clean environment to number of processes
which is not fully reached by manual processes (Santoki.K, 2018).
First thing to know is what is computer-aided engineering (CAE). This is an extensive use of
application with computer software to assist in design and engineering analysis tasks where CAD
and CAM are included. CAM is a successive computer-aided process where the design engineers
creates a 2D or 3D of any models using CAD which contains set of physical properties that is used
in CAM system. These models are verified in computer-aided engineering (CAE) and can be input
into CAM software, which controls the machine tools. One of the major known technique used
here is computer numerical control (CNC) which involves the use of machinery that automatically
guides the tool head across the workpiece such as cutting, drilling, facing or lathe. The detailed
explanation of CNC is illustrated in session 2.3.4.

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

2.3.4. Computer numerical control (CNC)


As the technology is improved, electronic and computer technologies have been applied to a vast
number of production machines to reduce the production time and increase the product quality and
efficiency, as most of the machines needs a control system to operate. When it comes to mass
production, the machine needs to repeat precise, more speed and automatic actions continuously.
So, the industries usually use numerical control machines and along with computer it is called
computer numerical control (CNC), which is first introduced around 1970. CNC is a computer
technique of providing instructions to the machine in form of codes which consists of letters,
numbers, punctuation marks and certain symbols. There are various kinds of CNC machines some
of them are drilling machine, lathe, milling machine, CNC machining centre, press brake, spot
welder, electro-discharge machine, electron beam machine, laser cutting machine, etc (Mike lynch,
2016).
2.3.4.1. Construction details of CNC machine
The design of a conventional machine tool is not suitable for CNC machine. A new design is
required to suit the needs of automation. The manual hand wheel controls are replaced by axis
drive motors in CNC machine. Firstly, CNC machine needs a perfect path measuring system. So
that the computer can observe the position of the tools and workpieces automatically.
High cutting speed, feed rate and improved tooling used, subjects the machine tool to high
multidirectional forces. The set up and change over time between the work is reduced and only
time is spent for cutting the workpiece. Besides, to increase the perfectness, the tools should be
highly strong and should have good vibration absorbance. Reducing the friction within the drive
system can cut down the energy loss, increase efficiency, accuracy and maximum load.
CNC machines need more supporting machinery components, for example, a tool’s clamp, an
automatic tool changing system, a tool holding device and transfer system etc., are required to
make the tool change easier. Some machine uses a turntable to store the tools, other advanced
machines use robotic arm to change tools and workpiece automatically. Higher rate of cutting time
will result in wear and tear in the machine parts and at the same time higher rate of removal of
metal chips from the machining area. The most important point to be considered is safety of the
operator as well as the CNC machine while working with it.
Special considerations are needed to be given to the design of the CNC machine tools to take care
of some factors. They are as follows (Santoki.K, 2018).
• Machine structure
The construction of the CNC machine needs to meet the demands of high accuracy, high
efficiency and reliability, the design of tools must have to cope-up with weight distribution.
The cutting speed and feed results in high acceleration and deceleration of the slides and
machines face fluctuations and variation in forces during operations. Thermal distortion should
be minimum in the design of machine tool and tools should be protected from internal and
external heat sources. Therefore, there is a need for lubrication and cooling system.
• Slide ways
The slide ways are on highly need due to the rapid movement and high use of machine. The
design of slide ways in CNC machine should increase the drive precision and reduce friction
and wear. To meet this requirement, a hydrostatic slide ways or linear bearings with ball or
13 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

displayed on the screen.


Pressure mats: Pressure mats are used on milling, drilling where machine is moved both sides
of the machine. Since the table moves rapidly, it may cause some accidents if the operator is
standing close to the machine. The pressure mats are placed around the machine and if someone
goes closer, a warning signal is generated.
Light barrier: It consists of infra-red light, sending a beam to light sensitive cells. If anything
obstructs the light, a warning signal is generated.
2.3.4.2. Advantages and disadvantages of CNC machine (Santoki.K, 2018)
Advantages
• The computer can design the best tool path, spinning and cutting speed of the tool according
to the information of the product.
• The elimination of error is made when the program is checked before sending to the
machine so no error will occur in the job.
• CNC machine usually has an automatic changing tool function.
• Labor cost can be reduced where one operator can run two or more machines.
• With the help of various input devices and data from computer, a CNC machine can modify
program efficiently. So, the procedure for production is made quickly.
• A product with high quality and reliability is obtained from CNC. Thus, this will help
decrease in number of disqualified product and cost of inspection.
• Smaller batches are found to be economical by periodic machining, so large storage
facilities for workpiece is not required.
• Longer tool life is obtained due to the optimum speeds and feeds applied on tools which
are controlled by part programming.
• Flexibility in change of component design can be readily adapted by re-programming and
altering the desired instruction.
• Less Scrap is obtained as operator’s error are eliminated, since the tools are operating under
controlled optimum condition the incidence of breakage is very small.

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).

Table 2 Common G codes ( HAAS automation book, 2011).

G-Code Preparatory Functions

G28 Return to reference point

G91 Incremental coordinate position

G00 Rapid motion positioning

G40 Cutter compensation cancel

G80 Canned cycle cancel

G90 Absolute coordinate positioning

G54 Select work coordinate system

G43 Tool length compensation with spindle approach + side

G01 Linear interpolation motion

G83 Normal peck drilling canned cycle

G02 Clockwise interpolation motion

G03 Counter-clockwise interpolation motion

G29 Return from reference point

G41 Cutter compensation to the left of the programmed path

G42 Cutter compensation to the right of the programmed path

G81 Basic drilling cycle

Table 3 Common M codes (HAAS automation book, 2011).

M00 Program start

M01 Optional program stop


17 Linkoping University | Design automation for CNC machining

M03 Start the spindle in forward direction

M04 Start the spindle in reverse direction

M05 Stop the spindle

M06 Tool change command

M08 Coolant on

M09 Coolant off

M30 End of program

2.4. Current process


2.4.1. Current process in Roland MDX 40A machine (Manual approach)
In the current process of MDX 40A machine, the operator designs a model in the SRP player
software. The SRP player is the in-built software in this machine. Every model is designed using
this software in the provided display panel of the milling machine by giving few instructions such
as type of milling, creating tool path etc as shown in the figure 6. VPanel is used to set the origin
by adjusting the X and Y coordinate axes manually. By using SRP pro software after the machining
process, the output can be generated in the form of a code. Without machining a model, the code
cannot be generated in SRP.

Figure 6 Current process in MDX 40A machine


18 Linkoping University | Design automation for CNC machining

2.4.2. Current process in HAAS VM3 machine (Manual approach)


There are two cases in current process of HAAS VM3 machine. In the case 1, the operator designs
a model and analyses the model to write the code manually. The codes written are simulated before
machining to check for the errors. And then the machining is processed. Here the operator needs
to repeat these procedures whenever a new model is designed which consumes lot of time and
there are more chances of errors in the code as the operator changes the code manually.

Figure 7 Current process in HAAS VM3 machine

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.

2.5. Model validity and reliability


The validity and reliability are used to determine the quality of the case study and can be judged
using criteria internal validity, construct validity, external validity and reliability (Yin, 2014). The
validity and reliability are required to present in this chapter in short but precisely.
19 Linkoping University | Design automation for CNC machining

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

3.2. Design Automation: CAD, CAM, CAD/CAM


Computer-aided design (CAD) is an application to build up the product design from
conceptualization to documentation. In the area of product design, this technology is most
frequently used. CAD supports in all the stages of processes in design which includes formulation,
modification, analysis, evolution and documentation.

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.

The activities of manufacturing engineering are supported by Computer-aided manufacturing


(CAM) which is an effective use of computer technology. Usually, in the production area CAM is
used. This method supports planning, management, and control of production for the company
with the automation technology.

Computer-aided manufacturing (CAM) is an effective use of computer technology to support the


activities of manufacturing engineering. Usually in the production area, CAM is used. This method
supports planning, management and control of production for the company with the automation
technology.
The two categories of application of CAM are manufacturing planning and manufacturing control
(Ching. C, 2008).
• The relation between the computer and the process while using CAM in manufacturing
planning is not direct. The production function provides information for planning the
manufacturing activities with the support of a computer. The important applications in
this category are computer-aided process planning (CAPP), computer-assisted NC part
programming and cost estimating.
• With the help of CAM technology, the computer systems are developed to implement
the manufacturing control function. Managing the physical operations in the industry
is considered from manufacturing control. The management areas include process
monitoring and control, quality control, and production system

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).

3.3. Visual Basic Programming


Visual Basic (VB) is a programming language from Microsoft where Visual Basic for Application
(VBA) is the language used. It provides language support and interfaces for modules, objects and
data-access technologies. It is also used in applications, such as CATIA and Excel (Microsoft
Office). When VBA is acting as the main host in the applications, it provides means of interactions,
accessing the object model and components.

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

3.4. Machining Features


Machining feature establishes a shape that represents volume of the material to be removed from
the workpiece to achieve the desired geometrical model by machining operation. The closed
volume of each material which are removed consists of different machining features. For example,
pockets, slots, hole group – a pattern of holes to be drilled, steps, top chamfer, face are some of
common machining features. As shown in Figure 8(a). Pockets and slots could also be created by
grinding method operations, and holes could also be achieved by drilling processes, the concept of
machining features are widened to incorporate such entities as tolerance features, surface end and
material features.
In order to improve systems-handling features, current analysis has approached the definition of
machining features. Some work has regarded these features as closed volumes with bound
characteristics such as rectangular block, with two opposite ends open, etc. Whereas other
machining features such as faces, edges, etc. that are not essentially closed volumes, satisfying
bound geometric relationships (four faces, pairwise parallel, etc). Figure 8(a) shows the identical
set of common machining features. It is necessary to acknowledge the machining features that are
often outlined otherwise as a result of the projected procedures for feature recognition from solid
models that cannot be used interchangeably between the alternate approaches. Procedures for
feature recognition will deal solely with a specific definition of features (Ji. Q and Marefat M.,
1997).

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.

3.4.1. Interpreting geometric models to obtain machining features


Figure 9 shows the part modules of automatic feature recognition. The created features represent
the high-level primitives that contain the produced data used for method designing or assembly.
Once features are hypothetically found, they need to be verified for accuracy. This can be typically
done through either a collection of rules, that verify if any given feature is not valid or through
volume-checking ways that makes sure that every machining feature generated within the amount
to be off from the machined raw stock.

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).

3.5. NC Programming Automation


Although NC programming has improved the efficiency of machining from the earlier days,
further improvement can be made by automating the code generation process. This can be achieved
by using scripting to tell the machine to extract the information required to generate an efficient
machining code. It is also possible to generate many codes as desired by the user for different types
of machining products (for example different dimensions, shapes, slight changes in the design etc)
at a time by automating the code generation process. The scripting once done can be reused for
different operations by slightly modifying it. The final code generated can be verified during
machining and the script can also be improved by accomplishing fine adjustments to it to make
the machining process more efficient.

3.5.1. Catia V5 Automation for improved NC coding


Automation allows communication between several processes. In this work, automation is used
majorly to implement and verify the automation process of NC coding. The flowchart below
represents the interactions between different components in the automation process for improved
NC coding. The code programmer calls the parameters from Catia.

Figure 11 Communication flowchart (Source: Catia V5 automation, 2009)


27 Linkoping University | Design automation for CNC machining

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.

3.6. Co-ordinate system and machine motions:


The standard axis system should be established in order to program the NC processing equipment.
The standard axis system specifies the corresponding positions of the tool with respect to
workbench.
Using a numerically controlled milling machine as an example, the workpiece is fixed using the
workbench. The tool is moved in relative to the workpiece. Respectively, the numerical control
coordinate system with respect to the machine tool table is well-defined.
The figure 12 is shown below where two axes X and Y are prescribed in the plane of the table.
The Z axis is perpendicular to the plane. The positive and negative directions of the motion of the
tool with respect to table along the axes (X, Y and Z) are shown. The vertical motion of the spindle
controls the movement in the Z direction. Depending on the effectiveness of controlling the Z
direction, the CNC machines are classified as either two-axis or three-axis machines. A NC drill
press and other similar machine tools use an axis system as same as that of numerical control
milling machine.
On the other hand, in addition to these three linear axes, the ability to regulate one or more
rotational axes may be possessed by the machine. The three rotational axes defined in the NC
machine are a, b and c as shown in the figure 12. These axes represent the angles about X, Y and
Z axes accordingly. The right-hand rule can be used to categorize the positive and negative angular
motions. Using this rule where thumb pointing in the positive linear axis direction X, Y or Z, the
fingers tend to point in the positive rotational direction as shown. (Integrated manufacturing n.d)

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

3.7. Basic steps for generating CNC codes.


The basic steps required to analyse and write the X and Y coordinates as per the CNC Machine
Standards for generating codes.
The CNC machine program has standard procedures to be followed for the operation of machining.
The “+” sign in the CNC display panel is the centre point. The codes are written with respect to
the centre. The machining process is carried out with respect to this point. The G-code program
having the coordinate axes systems (X, Y, Z) are written with respect to this point. The “+” sign
seen in the display panel is shown in the figure 14.

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

Figure 15 Representing signs of X and Y co-ordinate axes with respect to center.

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.

Figure 16 Representation of co-ordinate axes points

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

Figure 17 Representation of X and Y axes according to the machine standards.

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.

Figure 18 Example of writing X and Y coordinates for a triangle.

• 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

3.8. Method for automating NC script


The open statement in the macro tells the VBA that it is ready for the file (Input/Output). The open
statement should have the directory path, filename, a mode (Input/output) and an integer to refer
to a file. (VBA write to text file using print statement., 2016)

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.

Figure 19 Example of using Sub-program


33 Linkoping University | Design automation for CNC machining

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;

Table 5 Output Code for finishing process

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

Table 6 Code for cuboid of Model A

G01 G41 X-60 Y50 D1


G01 X50
G01 Y-30
G01 X-50
G01 Y30
G01 G40 X-60 Y60

Table 7 Code for pocket of Model A

G01 G41 X-40 Y25 D1


G01 X40
G01 Y-25
G01 X-40
G01 Y25
G01 G40 X-25 Y10

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.

Figure 20 The finished machined part for Model A


36 Linkoping University | Design automation for CNC machining

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.

Figure 21 Model 1 Parameters

• The parameters for the model are shown in figure 21.


• For this model, the hole is created using a point and this point has two parameters ‘pointl’
and ‘pointhb’ in CATIA V5.
• The formula given to the parameters of the point are as follows:
37 Linkoping University | Design automation for CNC machining

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 1: If the formula is changed as follows


pointl= length/2= 40mm
pointhb=Length/3=26mm
then, according to the rule given
X3= 0
Y3 = 14mm. (positive sign refers to upward movement).

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

Figure 22 Illustration on the results of two cases

The codes generated automatically for these two cases are illustrated below:

Table 8 CNC code generated for Case 1 and Case 2

Case 1 Case 2

G28 G91 Z0 G28 G91 Z0

G00 G40 G80 G90 G00 G40 G80 G90

T6 M6 T6 M6

G54 X0. Y14. S1100 M03 G54 X0. Y-14. S1100 M03

G43 Z3. H06 G43 Z3. H06

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

2. Model 4: A cube having three movable holes of same radius

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

Table 9 Automatic generation of codes for Model 4 (for different cases)

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 prototype for Model 2 is shown in figure 23

Figure 23 Finished machine part for model 2

The prototype for Model 3 is shown in figure 24.

Figure 24 Finished machine part for model 3

The prototype for Model 7 is shown in figure 25.


42 Linkoping University | Design automation for CNC machining

Figure 25 Finished machine part for model 7

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.

5.1. Current challenges for generating NC code


To program numerical controlled machines, the technology that is used is still based on the 1950’s
standards. The standard for programming the NC program have no major changes since the first
and foremost numerical control machine was established. These earlier and the current NC
machines tends to use the same standards for the programming such as G and M codes based on
ISO 6893 standard. Presently the CNC machines support the capability of multi-axis, multi-
processes and multi-tool manufacturing. These capabilities have resulted the NC code generation
task more difficult and there is a need for offline software tools such as CAD/CAM for effective
NC code generation. Though these advancements have helped CNC processes and abilities, the
NC programming standards/language is same with the G and M codes that was developed in
1950’s (Rosso. R et al, 2002).

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.

Chetty, P, 2016. Importance of research approach in a research- -(accessed on 2019-10-26)


available online at https://www.projectguru.in/publications/selecting-research-approach-
business-studies/

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)

Introduction to Computer aided manufacturing n.d., available online at Introduction to Computer


aided manufacturing https://resources.hkedcity.net › downloadResource
(accessed on 2019-11-10)

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

Integrated manufacturing n.d., Part III, chapter 8.2, available online at


https://rekadayaupaya.wordpress.com/buku-cim/part-iii-numerical-control-production-
systems/chapter-8-numerical-control/ (accessed on 2019-10-04)

Direct numerical control n.d., available online at http://www.dnc-cnc.com/2016/05/what-is-dnc-


direct-numerical-control.html (accessed on 2019-10-04)

Scutter.,2019, NX CAM Feature-based Machining- available online at


https://avxhm.is/software/NX-CAM-Feature-based-Machining-Starter-Kit-2-21.html (accessed
on 2019-10-04)

Catia V5 Automation, 2009., Version 5. Available online at


http://yvonet.florent.free.fr/SERVEUR/COURS%20CATIA/CATIA%20Infrastructure/VBA_A/
Teacher/EDU_CAT_EN_VBA_AI_V5R19_toprint.pdf (accessed on 2019-10-21)

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

AMMC., 2016, Common CNC machine problems, available online at -


https://ammc.com/common-cnc-machine-problems/ (accessed on 2019-11-12)

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.

Table 10 G-Codes used in the work and their description

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

Table 11 M-codes used in the work and their description

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

10 M97/M98 Call sub-program


11 M99 Sub program off
12 M88 Coolant flow on (coolant flow through the tool)
13 M89 Coolant flow off (coolant flow through the tool)

b) The speed (S) calculation.


The speed (S) and feed rates (F) are calculated depending on the material of the workpiece
used, design specification.
The spindle speed is calculated using the formula,

Vc*1000
n=
3.142*D

Where, D is diameter of tool, Vc is cutting speed, n is spindle speed.


• The speed and feed rate value vary depending on the material of the workpiece used. These
values are obtained by the operator working with the CNC machines in the lab.
• The values can be changed during the simulation depending on the requirements.

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 1: Designing a model.

Figure 26 Selecting 'Part design' to design the model

• The model is design in “part design” as shown in the figure 26


Step 2: After the model is designed, a “Body” is inserted from the outer edges of the model having
a pad of depth equal to the total height of the model. This is shown in the figure 27.
Step 3: The advanced machining is selected in order to generate the G-code from Catia V5. This
is illustrated in the figure 27.
53 Linkoping University | Design automation for CNC machining

Figure 27 Selecting Advanced machining process

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.

Figure 28 Dialog box of part operation

• The tool axis is selected using this dialog box.


• The cutting edge (Zig Zag/helical) and tolerance is changed.
• From the dialog box in figure 28(b), the numbers 1,2 and 3 refers to the selection that has to
be done from the process tree shown in figure 28(a).
From the figure,
a) The number ‘1’ refers to the selection of ‘part body’.
b) The number ‘2’ refers to the selection of ‘Body’ that is inserted.
c) The number ‘3’ refers to the selection of ‘safety plane’ for machining.
Such that the tool will cut the materials except the selected plane of the
model.
54 Linkoping University | Design automation for CNC machining

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.

Figure 29 Tool change dialog box

• 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).

Figure 30 Roughing dialog box


55 Linkoping University | Design automation for CNC machining

• 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 9: The machining process on CATIA V5 is run by clicking on the ‘Manufacturing


Program.1’ and then clicking on the option ‘Replay tool path’. This step proceeds the roughing
machining process. To get the fine surface finish, a new machining process such as facing has
to be selected again and follow the same steps to machine the model.

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.

Figure 31 Dialog box for Generating NC Output Interactively

• 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.

MODEL A: A CUBOID WITH A RECTANGULAR POCKET.


The Model designed for Roland MDX 40A milling machine is as shown in the figure 32.

Figure 32 A Cuboid with rectangular pocket

• 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

Figure 33 Inserting Body

• By following the general procedure mentioned in the Appendix I (c), the machining is
processed, and the NC code is generated.

Figure 34 Machining process of the model for Roland machine

• The figure 34, shows the machining process of the model A.


• The NC code generated using the manual method from CATIA V5 are shown in the table
below.
• As it is seen from the table 12, the code is very long, and it is not possible to modify the code
or change this code when the dimension of the model is changed unlike automated method.
From the table, N1 is the line 1 and N2254 is the line 2254. Each line shows the tool movements
with respect to the coordinate axes X and Y while machining the model.
58 Linkoping University | Design automation for CNC machining

Table 12 NC output from Catia for cuboid with a rectangular pocket.

%
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.

Table 16 NC code for pocket

G54 X-25 Y10 S70 M03 (For pocket)


G43 Z0. H1 M08
G01 Z-5 F90
G01 G41 X-40 Y25 D1
G01 X40
G01 Y-25
G01 X-40
G01 Y25
G01 G40 X-25 Y10

• 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.

• The codes that are generated manually are for:


Model 1: A Cube with a hole
Model 2: A hollow cylinder
Model 7: A Pyramid
• Other models will have the same results hence, codes are generated for only three models
that are mentioned above.
• The manual method takes lot of time to generate the code and the changes to the code is
not possible as the code will be too long. If the model dimension is changed by changing
the parameters, then the whole process of machining, selection of surfaces and planes that
are mentioned in Appendix I (c) has to be repeated again from the scratch for every new
dimension.
• The codes must be re-generated if the new model/ new dimension is required.
• The codes are generated from CATIA V5 and has more than 300 to 2500 lines, therefore,
part of the NC code generated from the Catia are illustrated.
• The procedure followed to generate the codes using this method is illustrated in ‘Appendix
I (c)’.
• These models are then compared with each method (manual and automated) and main
differences are explained specifically for the respective models.
MODEL 1: CUBE WITH A HOLE
The Cube with a hole is designed along with required dimensions by using Catia V5 as shown the
figure 35.

Figure 35 Sketch of the cube with a hole


63 Linkoping University | Design automation for CNC machining

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.

Table 17 Manual method NC code generation for Model 1

%
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.

Figure 36 Base parameters of the sketch

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.

Figure 37 Set of parameters required for the G-code

Table 18 Parameters called in VB 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.

Figure 38 Stock position with respect to origin

• X3 and Y3 is 0 as the hole lies at the centre (origin)


• Y2 is 57mm because, the tool radius of 16mm + 1mm tolerance should be considered when
the tool moves in the direction Y2 and is illustrated below.
66 Linkoping University | Design automation for CNC machining

Figure 39 Tool movement with tolerance in Y2 direction

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.

Figure 40 Illustration of total length in X and Y direction of the cube-.

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

Step 2: Creating rule for the hole


• The cube has a hole at the centre of it. This hole is created using a point.
• This point is placed at the centre of the cube and is assigned with parameters such as
pointl and pointhb in CATIA V5. (refer figure 41)
• When the formula which is linked to this parameter is changed based on the design
requirement, the point changes and therefore the hole changes the position.
• These parameters that are created for point are assigned to the parameters X3 and Y3
using rules from Knowledge ware.
• The rule used on the parameter pointl of the hole is assigned to parameter X3 and is
illustrated in the figure 43.
Similarly, a rule used on the parameter pointhb of the hole is assigned to parameter Y3.

Figure 41 Parameters created for point on the hole with formula.

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

Figure 43 Rule 1 assigned to Parameter X3

• 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

Step 3: Setting the workpiece and tool


• The workpiece is made of 100*100 in mm (L*B) and the tool having 32mm diameter is
used.

Figure 45 Parameters for workpiece and tool

• 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.

Table 20 VBA script and its output from Line 1 to Line 10

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 9 Print #1, "M97 P901 L16" M97 P901 L16


Line 10 Print #1, "M01" M01

• 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 23 Print #1, "N901" N901

Line 24 Print #1, "G91 Z-2.5 F" & f_1val; " M08" G91 Z-2.5 F120 M08

Line 25 Print #1, "G90" G90

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 32 Print #1, "M99" M99

• 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.

Figure 47 Tool movements according to the code

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 11 Print #1, "M89" M89


Line 12 Print #1, "G28 G91 Z0" G28 G91 Z0
Line 13 Print #1, "G0 G40 G80 G90" G00 G40 G80 G90
Line 14 Print #1, "T6 M6" T6 M6
Print #1, "G54 X" & x_3val; " Y" & y_3val; " S" &
Line 15 G54 X0. Y0. S1100 M03
s_2val; " M3"
Line 16 Print #1, "G43 Z3 H6 " G43 Z3. H06
Line 17 Print #1, "M08" M08
73 Linkoping University | Design automation for CNC machining

• 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.

Table 23 VBA script and its output from Line 18 to Line 22

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

MODEL 2: A HOLLOW CYLINDER


The hollow cylinder is designed in CATIA V5. The cylinder having a hole of inner radius 10mm
and outer radius 20mm is shown in the figure 48.

Figure 48 CAD model of hollow cylinder with parameters

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

N259 X-1.941 Y3.497


N260 X-1.435 Y3.734
N261 X-.902 Y3.897
N262 X-.351 Y3.985
N263 X-.169 Y3.994
75 Linkoping University | Design automation for CNC machining

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.

Figure 49 Design parameters of hollow cylinder

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.

Step 2: Parameters created that are required for G-code generation


a) For inner radius (hole)
• The hole is placed at the centre where X and Y coordinates are 0.
• The parameters are named x_start and y_start.
• The figure 50 represents the parameters that are created in Catia V5 and table 25 represents
the parameter being called in VB script.
76 Linkoping University | Design automation for CNC machining

Figure 50 Setting parameter for tool origin


Table 25 Parameters called in for workpiece length and breadth of model 2

• 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.

Figure 51 Setting parameters for machining

• In above figure , the X1 is given a formula as Inner radius-1mm (10-1=9) it is because if


the radius is 10 mm then we need to have 1mm of tolerance and similarly for Y1 it is
y_start+1 (0+1=1).
77 Linkoping University | Design automation for CNC machining

Table 26 Parameters called in for workpiece of model 2

b) For outer radius


• Similar to that of inner radius, the outer profile having outer radius of 20mm will have the
same types of parameters that are required to generate g-code.
• “I” along the distance X and “J” along the distance Y axis is used in this step as well.
• The start point for the outer radius is at X=0 and Y=30 as shown in the figure 52.

Figure 52 Setting parameters for machining the cylinder

• 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

• Line 6: This is the tool selection for the drilling operation.


Table 28 VBA script and its output from Line 7 to Line 9 for model 2

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.

Figure 53 Hole drilling operation shown in Top View


79 Linkoping University | Design automation for CNC machining

Table 30 VBA script and its output from Line 12 to Line 14 for model 2

Line 12 Print #1, "G28 G91 Z0" G28 G91 Z0.


Line 13 Print #1, "G0 G40 G80 G90" G00 G40 G80 G90
Line 14 Print #1, "T3 M6" T3 M06

• 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 Print #1, "N901" N901


Line 34 Print #1, "G91 Z-4 F" & f_2val; "" G91 Z-4. F200.
Line 35 Print #1, "G90" G90
G01 G41 X9. Y1.
Line 36 Print #1, "G01 G41 X" & x_1val; " Y" & y_1val; " D3"
D03
Line 37 Print #1, "G03 X" & x_2val; " Y" & y_2val; " R" & r1_val; "" G03 X0 Y10. R9.
Print #1, "G03 X" & x_3val; " Y" & y_3val; " I" & I_in_val; " J" & - G03 X0 Y10. I0 J-
Line 38
J_in_val; "" 10.
Line 39 Print #1, "G03 X" & -x_4val; " Y" & y_4val; " R" & r1_val; "" G03 X-9. Y1. R9.
Line 40 Print #1, "G03 G40 X" & x_start_val; " Y" & y_start_val; "" G01 G40 X0 Y0
Line 41 Print #1, "M99" M99

• 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

required inside the cylinder.

Figure 54 View of the tool operation inside the cylinder.

• The machining process is illustrated in the figure shown in figure 54.


• Line 37 to 39: The machining inside the cylinder is done in counter clockwise direction
G03.
• Line 40: After the machining process the tool goes back to the origin point created in line
15.
• Line 41: End of the sub-program.

Table 33 VBA script and its output from Line 23 to Line 28 for model 2

Line 23 Print #1, "T17 M6" T17 M06


Print #1, "G54 X" & x_out_val; " Y" & y_out_val; " S" & s_3val; " G54 X0 Y30. S3500
Line 24
M3" M03
Line 25 Print #1, "G43 Z3 H17 " G43 Z3. H17
Line 26 Print #1, "G01 Z0 F" & f_1val; "" G01 Z0 F100.
Line 27 Print #1, "M97 P902 L5" M97 P902 L5
Line 28 Print #1, "M01" M01

• 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

Line 42 Print #1, "N902" N902


Line 43 Print #1, "G91 Z-4 F" & f_2val; "" G91 Z-4. F200.
Line 44 Print #1, "G90" G90
G01 G41 X-10.
Line 45 Print #1, "G01 G41 X" & -x_5val; " Y" & y_5val; " D17"
Y30. D17
Line 46 Print #1, "G03 X" & x_6val; " Y" & y_6val; " R" & r2_val; "" G03 X0 Y20. R10.
Print #1, "G02 X" & x_7val; " Y" & y_7val; " I" & I_Out_val; " J" & - G02 X0 Y20. I0 J-
Line 47
J_out_val; "" 20.
G03 X10. Y30.
Line 48 Print #1, "G03 X" & x_8val; " Y" & y_8val; " R" & r2_val; ""
R10.
Line 49 Print #1, "G01 G40 X" & x_out_val; " Y" & y_out_val; "" G01 G40 X0 Y30.
Line 50 Print #1, "M99" M99

• Line 43 is similar to Line 34.


The machining process from the Line 45 to line 49 is illustrated in the figure 55.

Figure 55 Tool path for Outer part of cylinder

• Line 46 and Line 48 are Counter-clockwise movement of the tool.


• Line 47: The machining outside the cylinder is done in clockwise direction G02.
• Line 50: End of sub-program P902.
82 Linkoping University | Design automation for CNC machining

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.

MODEL 3: A CUBE HAVING THREE FIXED HOLES OF SAME RADIUS


MODEL 4: A CUBE HAVING THREE MOVABLE HOLES OF SAME RADIUS

• Model 3 and Model 4 are similar to each other.

Table 35 Comparison between model 3 and model 4

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.

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.
Table 36 Design differences in model 3

• Design of cube of
dimension 100mm

• Radius of holes 3mm.

• One of the holes


having a point and the
two distances of the
point from the two
side edges (Length and
breadth) of the cube
are shown here.
• The distances are
20mm each for
100mm cube.

• Design of cube of
dimension 80mm

• Radius of holes 3mm.

• The distances remain


the same i.e., 20mm
even for 80mm cube.
84 Linkoping University | Design automation for CNC machining

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.

Figure 57 Parameters used to set the origin point

• Consider a workpiece size of 120mm cube having height of 50mm.


• The figure 57 shows the parameters used to set the origin point of the tool w.r.t workpiece.
The tool diameter is 32mm.
• As the size of cube should be 100mm, whereas workpiece is 120mm. The excess material
is machined to get the profile of cube like that of model 1.
• The parameters used for cube are X2, Y2, X3, Y3, Y4 as shown in figure 58. These are
created in Catia and the formula for all these parameters are X2=Y2=X3=Y3=
(length/2)=(100/2)=50mm where (Length=breadth).
• Y4 is (length/2+tool radius+1mm) tolerance. By adding the value of tool radius(16mm) +
1mm of tolerance, the required point can be reached during machining. This is explained
in figure 39 in model 1.
85 Linkoping University | Design automation for CNC machining

Figure 58 The parameters for g-code of model 3

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

Figure 59 parameters created for making three different holes

Figure 60 The parameters corresponding to three holes

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.

Figure 61 Rule for X5 of model 3

Figure 62 Rule for Y5 of model 3

• 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.

Step 3: G-code explanation


• Using For loop statement to change the dimensions of design in VB script.
This is used to generate g-codes for different dimensions of the cube.

Table 37 For loop for model 3

Set Length_of_box = parameters1.Item("Length_of_box")


Set Length_of_box = parameters1.Item("breadth_of_box")
For I_nr = 1 To 2

parameters1.Item("Length_of_box"). Value = 60 + (20 * I_nr)


• The value of the parameter Length_of_box is given by 60+(20*I_nr)

For I_nr=1 to 2 refers to run the program twice.


a) During the first run at I_nr=1, length of box becomes
60+(20*1) =80mm
b) During the second run at I_nr=2 it becomes
60+(20*2) =100mm
Thus, the parameter ‘length of box’ will have two values 80 and 100mm.
• The path is created to get the g-code as output using If statement.
• If statement is used as shown below
Table 38 If loop for model 3

If I_nr = 1 Then
Open "X:\same1.txt" For Output As #1
Else
Open "X:\Temp2.txt" For Output As #1
End If

• If I_nr=1, then it means dimension of cube is 80mm. Else it is 100mm.


• So, two g-codes will be generated automatically. One for 80mm cube and other for 100mm
cube.
• The column A represents the way of writing g-code format in VB script and column B
represents the final g-code generated automatically.
• As the holes are of same radius, one tool can drill all the holes.
88 Linkoping University | Design automation for CNC machining

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

• Line 5 is selection of tool of diameter 32mm.


• Line 6: Setting the origin of the tool. it is placed away from the workpiece based on the
design demands. Speed and feed are calculated depending on the material of the workpiece.
• Line 9: The sub-program is called and number of cycles of operation is given as 16.

Table 40 VBA script and its output from Line 33 to Line 41 for model 3

Line 33 Print #1, "N901" N901


Line 34 Print #1, "G91 Z-2.5 F" & f_2val; "" G91 Z-2.5 F1200
Line 35 Print #1, "G90" G90
Line 36 Print #1, "G01 G41 X" & -x_val; " Y" & y_2val; " D14" G01 G41 X-80 Y50 D14
Line 37 Print #1, "G01 X" & x_2val; "" G01 X50
Line 38 Print #1, "G01 Y" & -y_3val; "" G01 Y-50
Line 39 Print #1, "G01 X" & -x_3val; "" G01 X-50
Line 40 Print #1, "G01 Y" & y_4val; "" G01 Y67
Line 41 Print #1, "G01 G40 X" & -x_val; " Y" & y_val; "" G01 G40 X-80 Y80

• 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 14 Print #1, "T2 M6" T2 M6


Line 15 Print #1, "G54 X" & x_5val; " Y" & y_5val; " S" & s_2val; " M3" G54 X30 Y30 S2500 M3
Line 16 Print #1, "G43 Z3 H2 M8" G43 Z3 H2 M8
Line 17 Print #1, "G81 Z" & -Z_1val; " R" & rad_val; " F" & f_1val; "" G81 Z-5 R3 F120
Line 18 Print #1, " X" & -x_6val; " Y" & y_6val; "" X-30 Y30
Line 19 Print #1, " X" & x_7val; " Y" & -y_7val; "" X0 Y-30
Line 20 Print #1, "G80 M9" G80 M9

• 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 Print #1, "T6 M6" T6 M6


Line 24 Print #1, "G54 X" & x_5val; " Y" & y_5val; " S" & s_3val; " M3" G54 X30 Y30 S1100 M3
Line 25 Print #1, "G43 Z3 H6 M8" G43 Z3 H6 M8
Print #1, "G83 Z" & -Z_depthval; " Q" & q_val; " R" & rad_val; " F" &
Line 26 f_1val; "" G83 Z-40 Q5 R3 F120
Line 27 Print #1, " X" & -x_6val; " Y" & y_6val; "" X-30 Y30
Line 28 Print #1, " X" & x_7val; " Y" & -y_7val; "" X0 Y-30

• 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.

Table 43 Design differences in model4

• Design of cube of
dimension 80mm

• Radius of holes 3mm.

• One of the holes


having a point and the
two distances of the
point from the two
side edges (Length and
breadth) of the cube
are shown here.
• The distances are
20mm each for 80mm
cube.

• Design of cube of
dimension 100mm

• Radius of holes 3mm.

• The distances have


changed which means
the hole position is
changed i.e., 25mm
for 100mm cube.

• 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

Model 4 (Movable holes) Model 3 (Fixed holes)


Line 23 T6 M6 T6 M6
Line 24 G54 X25 Y25 S1100 M3 G54 X30 Y30 S1100 M3
Line 25 G43 Z3 H6 M8 G43 Z3 H6 M8
Line 26 G83 Z-40 Q5 R3 F120 G83 Z-40 Q5 R3 F120
Line 27 X-25 Y25 X-30 Y30
Line 28 X0 Y-25 X0 Y-30
Line 29 G80 M9 G80 M9

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.

Model 5: A cube having three fixed holes of different radius


Model 6: A cube having three movable holes of different radius
• Model 5 and Model 6 are similar to each other.
• Model 5 is similar to model 3
• Model 6 is similar to model 4.
93 Linkoping University | Design automation for CNC machining

The main differences are each hole has different radius. Therefore, tools must be changed to
drill the different holes.

Table 45 Comparison of features between model 5 and model 6

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.

Table 46 Design differences in model 5

• Design of cube of
dimension 100mm

• Radius of three holes


3mm, 6mm and 9mm.
• One of the holes
having a point and the
two distances of the
point from the two
side edges (Length and
breadth) of the cube
are shown here.
• The distances are
20mm each for
100mm cube.
94 Linkoping University | Design automation for CNC machining

• Design of cube of
dimension 80mm

• Radius of three holes


3mm, 6mm and 9mm.

• The distances remain


the same i.e., 20mm
even for when the
dimension of the cube
is changed to 80mm.

• Creating parameters in Catia V5, calling the parameters, creating rules are similar to that
of model 3.

Step 2: G-code format in VB script.


• The column A represents the way of writing g-code format in VB script and column B
represents the final g-code generated automatically.
• As the three holes are having different radius, there is a need to change the tool several
times as shown.

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

• Line 5: This is the tool change to machine the cube of 100mm.


• Line 6: Setting origin point for machining the cube.
95 Linkoping University | Design automation for CNC machining

Table 48 VBA script and its output from Line 14 to Line 15 for model 5

Line 14 Print #1, "T2 M6" T2 M6


Print #1, "G54 X" & x_5val; " Y" & y_5val; " S" &
Line 15 s_2val; " M3" G54 X30 Y30 S2500 M3

• 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 Print #1, "T6 M6" T6 M6


Print #1, "G54 X" & x_5val; " Y" & y_5val; "
Line 22 S" & s_3val; " M3" G54 X30 Y30 S1100 M3
Line 23 Print #1, "G43 Z3 H6 M8" G43 Z3 H6 M8
Print #1, "G83 Z" & -Z_depthval; " Q" & q_val;
Line 24 " R" & rad1_val; " F" & f_1val; "" G83 Z-40 Q5 R3 F120
Line 25 Print #1, "G80 M9" G80 M9

• 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.

Table 50 Design differences in model 6

• Design of cube of
dimension 100mm

• Radius of three holes


3mm, 6mm and 9mm.
• One of the holes
having a point and the
two distances of the
point from the two
side edges (Length and
96 Linkoping University | Design automation for CNC machining

breadth) of the cube


are shown here.
• The distances are
25mm each for
100mm cube.

• Design of cube of
dimension 80mm

• Radius of three holes


3mm, 6mm and 9mm.

• The distances have


changed which means
the hole position is
changed i.e., 20mm
for 80mm cube.

• 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

Figure 64 Cube having three different radius holes

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.

Figure 65 The pyramid having 10 steps.

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

Table 51 NC code for model 7 using 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 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

N1196 X1.973 Y96.145


N1197 X2.179 Y96.585
N1198 X2.444 Y96.985
N1199 X2.77 Y97.345
N1200 X2.942 Y97.486
N1201 Y100.
N1202 X.001
N1203 Y0
N1204 Z-30.
N1205 G0 Z0
N1206 M30
%

• The code generated from CATIA V5 has 1206 lines.


Step 1: Creating parameters and linking the parameters in Catia V5 and Excel VB script to
the geometry.
• The figure 66 refers to the main parameters of the pyramid. Each box is linked to this
parameter with a formula. Only this parameter must be changed, so that everything else
changes and g-code will be generated for all the changing dimensions based on the for loop
in VB script.
99 Linkoping University | Design automation for CNC machining

Figure 66 Base parameters of the pyramid

a) The parameters of each step are as follows:

Table 52 Length of 10 boxes of pyramid

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

b) Parameters that are required for X and Y coordinates of G-code are:


• Parameters corresponding to one of the boxes is explained here.

Figure 67 Parameters of top first box

• 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.

c) Parameters required to remove the excess material in the workpiece.


• The workpiece size is 100*100mm(L*B). The top first box is 10*10mm(L*B) as shown in
figure 68.

Figure 68 Workpiece size for 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.

Figure 69 Parameters used to remove excess material

• 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

Step 2: Code format in VB script


• Using For loop
Table 53 Using For loop in model 7

Set Length_of_box = parameters1.Item("base_length")


Set Length_of_box = parameters1.Item("base_breadth")
For I_nr = 1 To 2

parameters1.Item("base_length").Value = 80 + (20 * I_nr)

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.

• Line 5: Selection of tool T14 which has a diameter of 32mm.


• Line 6: Setting the origin point using work coordinate shift command. This point is the
origin for the tool movement. The tool movement begins from this point and ends in this
point after the one cycle of operation.
102 Linkoping University | Design automation for CNC machining

• Line 8: The tool is brought closer to the workpiece.


• Line 9: The sub-program is called and the number of cycles of operation is given as 2(L2)
for reaching the depth of 5mm. About 2.5mm of depth is machined per cycle.

Table 56 First Sub-program in model 7

Line 9 Print #1, "M97 P901 L2" M97 P901 L2


Line 10 Print #1, "M01" M01

• 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

Line 40 Print #1, "N901" N901


Line 41 Print #1, "G91 Z-2.5 F" & f_2val; "" G91 Z-2.5 F800.
Line 42 Print #1, "G90" G90
Line 43 Print #1, "G01 G41 X" & -x_val; " Y" & yw1_val; " D14" G01 G41 X-80. Y34. D14
Line 44 Print #1, "G01 X" & xw1_val; "" G01 X34.
Line 45 Print #1, "G01 Y" & -yw1_val; "" G01 Y-34.
Line 46 Print #1, "G01 X" & -xw1_val; "" G01 X-34.
Line 47 Print #1, "G01 Y" & y_1val; "" G01 Y5.
Line 48 Print #1, " X" & x_1val; "" X5.
Line 49 Print #1, "G01 Y" & -y_2val; "" Y-5.
Line 50 Print #1, "G01 X" & -x_2val; "" X-5.
Line 51 Print #1, "G01 Y" & y_3val; "" Y22.
Line 52 Print #1, "G01 G40 X" & -x_val; " Y" & y_val; "" G01 G40 X-80. Y80.
Line 53 Print #1, "M99" M99

• 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).

Figure 70 Depth values Z

Figure 71 The machining of first top box of the pyramid.


104 Linkoping University | Design automation for CNC machining

• 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

Line 36 Print #1, "G80 M89" G80 M89


Line 37 Print #1, "G28 G91 Z0" G28 G91 Z0
Line 38 Print #1, "G28 G91 Y0" G28 G91 Y0
Line 39 Print #1, "M30" M30

• Line 39: End of main program.


• The prototype of the model pyramid is built in the production lab.

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

You might also like