当前位置:网站首页>Introduction to NC machine tool programming [G-code]
Introduction to NC machine tool programming [G-code]
2022-06-24 08:27:00 【User 5687508】
If your work or hobby is related to CNC machine tools (CNC) or 3D Printer related , So understanding G -code What it is and how it works is important to you . In this tutorial , We will learn G -code Basic knowledge of language and common G-code command , And explain these G-code How commands work .
1、 What is? G-code?
G-code yes CNC( Computer numerical control ) Programming language of machine tool .G-code refer to Geometric Code, Geometric code . We use this language to tell machines what to do or how to do something .G-code The command indicates the machine moving position 、 Moving speed and path to follow .
For CNC machine tools , The cutting tool consists of these G-code Command driven , Cut the material in a specific path to obtain the desired shape .
Allied , about 3D The printer ,G-code The command instructs the machine to deposit the material layer by layer , Form a precise geometry .
2、 How to read G-code command ?
When you first see a G-code When you file , It may seem quite complicated , But it's actually not difficult to understand .
If you look at the code carefully , You can see that most lines of code have the same structure . look G-code Of " complex " The part is mainly the digital part , And these numbers are Cartesian coordinates .
Let's look at one line of code , And explain how it works .
G01 X247.951560 Y11.817060 Z-1.000000 F400.000000
The row has the following structure :
G#x##Y#Z## F##
- First of all G-code command , In the above example, it is G01, intend " Move a straight line to a specific position ".
- We declare the location we want to move to X、Y and Z coordinate .
- Last , utilize F Value we set Feed rate , That is, the speed at which the movement is performed .
To sum up , Code G01 X247.951560 Y11.817060 Z-1.000000 F400.000000
The CNC machine tool is required to move linearly from the current position to the coordinates X247.951560、Y11.817060 and Z-10000000, Speed is 400 mm/min.
Note that the unit is mm/min, Because in front of G-code Example , We used the command to set the unit to MM G21. If we want to be in inches , have access to G20 Command instead of .
3、 common G-code command
Now we know how to read a line G-code Code , Next, you can learn the most important or commonly used G-code command . We'll look at each with a few examples G-code How commands work , By the end of this tutorial , We will be able to fully understand G-code How it works 、 The way of reading 、 Modify the way , And be able to write your own G-code Program .
3.1 G00– Rapid positioning
G00 The command moves the machine from the current position to the specified coordinates at maximum speed . The machine will move all axes at the same time , In order to complete the journey at the same time . The result is a straight line moving to a new location point .
G00 It's a non cutting motion , The purpose is to move the machine quickly to the desired position , Start some kind of work , Such as cutting or printing .
3.2 G01– linear interpolation
G01 The command instructs the machine to move in a straight line at the set speed . We use it X、Y and Z Value specifies the final position , use F Value specifies the speed .CNC The controller calculates ( interpolation ) The coordinates of the middle point to go through , To get a straight line . Although these G-code The order is simple 、 Intuitive and easy to understand , But behind it CNC The controller performs thousands of calculations per second , For these movements .
And for positioning only G00 Different commands ,G01 The command is used when the machine performs the main task . For example, machine tools cut materials in a straight line , or 3D The printer extrudes the material in a straight line .
3.3 G02– Clockwise circular interpolation
G02 The command requires the machine to move clockwise in circular mode . It is associated with G01 The concept of command is the same , Use... When performing the appropriate machining process . In addition to the end parameter , Here we also need to define the center of rotation , Or the distance between the starting point of the arc and the center point of the arc . The start point is actually the end point of the previous command or the current point .
To better understand , We'll look at... In the previous example G01 Add... After the command G02 command .
therefore , In the example , First of all, we use G01 Command to move the machine to X5、Y12 spot . Now? , This will be G02 The starting point of the command . adopt G02 Ordered X and Y Parameters , We set the end . Now? , In order to reach the end by circular motion or arc , We need to define the central point . We use I and J Parameters to do this .I and J The value of is relative to the starting point or the end point of the previous command . therefore , To get X5 and Y7 The center of , We need to go along X Axis progress 0 The migration , Along the Y Axis progress -5 The migration .
Of course , We can set the center point elsewhere , You'll get a different arc , And end at the same end . Here is an example :
therefore , ad locum , We still have the same end point as the previous example, that is (X10,Y7), But the center point is now in a different position (X0,Y2). So we get a wider arc .
3.4 G00、G01、G02 Example – Manual G Code programming
Let's take a look at a simple example of NC milling , Use these three main G-code command ,G00,G01 and G02.
To get the path of the shape shown above , We need to follow G Code command :
G00 X5 Y5 ; point B G01 X0 Y20 F200 ; point C G01 X20 Y0 ; point D G02 X10 Y-10 I0 J-10 ; point E G02 X-4 Y-8 I-10 J0 ; point F G01 X-26 Y-2 ; point B
first G00 Command to quickly take the machine from its initial position to B spot (5,5). So let's start here , We use G01 Command to 200 Feed rate " cutting ". We can notice here , From you to B spot (5,5) To C spot (5,25), We use X and Y Relative to the starting point B The point is worth . therefore ,Y The direction of the +20 A unit will point us to C spot (5,25). actually , It depends on whether we interpret coordinates as absolute or relative . We will explain this later .
Once we reach the point C (5,25), Just use the other one G01 Command arrival point D (25,25). then , We use G02 command ( Circular motion ) arrive E spot (35,15), In the middle by (25,15). actually , For the next G02 command , We have the same center point (25,15), To reach the point F (31,7). But we should pay attention to ,I and J Parameters are different from previous commands , Because we start from the last destination or point E Offset the center . Let's use another G01 The command completes the entire path , This order will take us from F spot (31,7) Back to B spot (5,5).
The above is what we wrote for making this shape G-code Program . But be careful , This is not a complete G-code Program , Because there are a few more basic commands missing . We'll write the complete... In a later example G-code Program .
3.5 G03– Counterclockwise circular interpolation
And G02 equally ,G03 The command instructs the machine to move in circular mode , The difference lies in G03 It's counterclockwise . All other functions and rules are similar to G02 The same command .
Use these three main G-code command ,G01、G02 and G03, In theory, we can generate paths of any shape . You may now wonder how this is possible , But this is actually for computers and CAM Software is really a simple task . Yes , We do sometimes make it by hand G-code Program , But most of the time , We use simpler 、 Safer software to generate G-code Program .
Anyway , Next, continue to explain the common commands , And implement a real... Before the end of the tutorial G-code Example .
3.6 G20/G21 – Unit selection
G20 and G21 Command definition G-code Company , Inches or millimeters .
- G20 = Inch
- G21 = mm
We need to pay attention , The unit... Must be set at the beginning of the program . If no unit is specified ,CNC The default value set by the previous program will be considered .
3.7 G17/G18/G18 – Face selection
Through these G-code command , We choose the working plane of the machine :
- G17–XY Plane
- G18–XZ Plane
- G19–YZ Plane
For most CNC machines, the default is G17, But the other two can also be used to achieve specific motion .
3.8 G28– return home
G28 The command requires the machine to move to its reference point or home Location . In order to avoid collision , We can include one with X、Y and Z The middle point of the parameter . The tool will pass through the reference point before going to it . G28 X##Y##Z##
home The position can be controlled by the command G28.1 X# Y # Z # Definition .
3.9 G90/G91 – Positioning mode
Use G90 and G91 command , We tell the machine how to parse coordinate values .G90 by Absolute mode ,G91 by The relative pattern .
In absolute mode , The positioning of the tool is always relative to the absolute point or zero point . therefore , command G01 X10 Y5
Move to the exact point (10,5), Whatever your previous position .
In relative mode , The tool is positioned relative to the last point . therefore , If the machine is currently at point (10,10), command G01 X10 Y5
Point the tool to the point (20,15). This mode is also called " Incremental mode ".
3.10 More commands and rules
As we explained above G-code Command is the most common command , But there are more orders , Such as cutter compensation 、 The zoom 、 Working coordinate system, etc .
except G-code outside , It also needs to be M-code Command to generate a truly complete G-code Program . Here are some common M-code command :
- M00– The program to stop
- M02– Program end
- M03– Spindle open – Clockwise
- M04– Spindle open – Anti-clockwise
- M05– The spindle stops
- M06– Tool change
- M08– Enable Flood Colant
- M09– Ban Flood Colant
- M30 – Program end
3D Additional commands for the printer :
- M104– Start extrusion heating
- M109– Wait until the extruder arrives T0
- M140– Start heating the base plate
- M190– Wait until the bottom plate arrives T0
- M106– Set fan speed
Some of these commands require appropriate parameters . for example , When used M03 When the command opens the spindle , We can use S Parameter sets the spindle speed . therefore ,M30 S1000
Will be with 1000 RPM Open the spindle at the speed of .
We can also notice , Many codes are Modality Of , This means that they are always effective , Until cancelled or replaced by another code . for example , Suppose we have a linear cutting motion G01 X5 Y7 F200
Code . If the next action is still linear cutting , We can type X and Y coordinate , Without having to write G01.
G01 X5 Y7 F200 X10 Y15 X12 Y20 G02 X5 Y5 I0 J-5 X3 Y6 I-2 J0
The same applies to the feed rate parameter F. Unless you want to change its value , Otherwise, you don't have to include it in every line .
In some G-code In file , You can also see in front of the command "N##", This is the number of lines or blocks of code , It helps to identify specific lines of code when errors occur in large programs .
4、G-code Program example
After learning the above , Now we can make a real one manually G-code Procedure . Here's an example :
% G21 G17 G90 F100 M03 S1000 G00 X5 Y5 ; point B G01 X5 Y5 Z-1 ; point B G01 X5 Y15 Z-1 ; point C G02 X9 Y19 Z-1 I4 J0 ; point D G01 X23 Y19 Z-1 ; point E G01 X32 Y5 Z-1 ; point F G01 X21 Y5 Z-1 ; point G G01 X21 Y8 Z-1 ; point H G03 X19 Y10 Z-1 I-2 J0 ; point I G01 X13 Y10 Z-1 ; point J G03 X11 Y8 Z-1 I0 J-2 ; point K G01 X11 Y5 Z-1 ; point L G01 X5 Y5 Z-1 ; point B G01 X5 Y5 Z0 G28 X0 Y0 M05 M30 %
G-code A description of the procedure :
- Code initialization . This character (%) Always exist at the beginning and end of the program .
- Safety wire : Set program parameters , Such as metric system ( In millimeters )、XY Plane 、 Absolute positioning 、100 Inch / Minute feed rate .
- With 1000 RPM Rotate clockwise at the speed of .
- Quick positioning to B (5,5).
- Control motion in the same position , But reduce the tool to -1.
- Linear cutting motion position C (5,15).
- Clockwise circular motion to point D (9,19), The center point is (9,15).
- Linear cut to point E (23,19).
- Linear cut to point F (32,5).
- Continue cutting straight to point G(21,5).
- Continue cutting straight to H spot (21,8).
- Counterclockwise circular interpolation to position I (19,10), The center point is (19,8).
- Linear cut to point J (13,10).
- Cut the circle counterclockwise to position K (11,8), The center point is (13,8).
- Linear cut to position L (11,5).
- Finally, the linear cutting moves to the position B (5,5).
- Lift the tool .
- return home.
- The spindle is closed .
- The main program ends .
The following is the code in Universal G-code Sender The software is ready to send to us CNC:
therefore , Use the above explanation of these main G-code command , We have written a complete G-code Program . Of course , This example is very simple , For more complex shapes , We definitely need to use CAM Software . Here's a complex example of cutting a horse G-code Examples of programs :
The above code has about 700 That's ok , But with Inkscape Automatically generated . give the result as follows :
Link to the original text :G-code NC machine tool programming tutorial — BimAnt
边栏推荐
- 487. 最大连续1的个数 II ●●
- Permission model DAC ACL RBAC ABAC
- Three categories of financial assets under the new standards: AMC, fvoci and FVTPL
- Optimization and practice of Tencent cloud EMR for cloud native containerization based on yarn
- Opening chapter of online document technology - rich text editor
- Vscode topic recommendation
- LabVIEW查找n个元素数组中的质数
- Opencv实现图像的基本变换
- For a detailed explanation of flex:1, flex:1
- The applet reads more than 20 data, and the cloud function reads more than 100 restrictions
猜你喜欢
2021-03-04 COMP9021第六节课笔记
12-- merge two ordered linked lists
PAT 1157:校庆
Question 3 - MessageBox pop-up box, modify the default background color
2021-03-16 COMP9021第九节课笔记
2022年流动式起重机司机特种作业证考试题库及在线模拟考试
搜索与推荐那些事儿
5分钟,客服聊天处理技巧,炉火纯青
Utilisation de la fermeture / bloc de base SWIFT (source)
权限模型 DAC ACL RBAC ABAC
随机推荐
Learning event binding of 3D visualization from scratch
2022年流动式起重机司机特种作业证考试题库及在线模拟考试
VR is destined to reappear in the Jianghu?
Question 1: the container that holds the most water
Swift Extension ChainLayout(UI的链式布局)(源码)
根据网络上的视频的m3u8文件通过ffmpeg进行合成视频
[graduation season] Hello stranger, this is a pink letter
jwt(json web token)
软件过程与项目管理期末复习与重点
普通token
A preliminary study of IO model
OpenCV get(propId) 常用的值
Pat 1157: school anniversary
复习SGI STL二级空间配置器(内存池) | 笔记自用
【无标题】
List of Li Bai's 20 most classic poems
Qt导出PDF文件的两种方法
Industrial computer anti cracking
Swift 基础 闭包/Block的使用(源码)
QTimer定时器不起作用的原因