oldbeginner 发表于 2014-3-25 16:23:05

Arduino机械坊学习笔记04 补充资料(CNC编程 G code)_2014_3_25

*****************************
G code

CNC 的语言
*****************************

在学习 GRBL 过程中,遇到了很多新知识,CNC 编程对我来说也是需要补充学习的。

首先,坐标系统,

G90: Set to Absolute Positioning 设置成绝对定位

Example: G90

All coordinates from now on are absolute relative to the origin of the machine. (This is the RepRap default.)
所有坐标从现在开始变成绝对坐标,即与机器原始位置相对的..
G91: Set to Relative Positioning 设置成相对定位

Example: G91

All coordinates from now on are relative to the last position
所有坐标从现在开始变成相对于当前位置的相对坐标
G92: Set Position 设置位置

Example: G92 X10 E90


可用来设定绝对0点,或者重置现在的位置到规定的坐标。

没有指定坐标的G92命令会重置所有轴到0 ‘

*********************************

G00



For rapid linear motion, program G0 X… Y… Z… A… B… C…, where all the axis words are
optional, except that at least one must be used. The G0 is optional if the current motion mode is
G0. This will produce coordinated linear motion to the destination point at the current traverse
rate (or slower if the machine will not go that fast). It is expected that cutting will not take place
when a G0 command is executing.

******************************

G01 可控移动





这个G01 仿真有点错误(坐标系),不过不影响理解。商用仿真还没学会。

******************************

G0203









**********************************

内容比较多,先开始再说吧。

shihaipeng04 发表于 2014-3-25 22:42:16

每天都能看到这么多好东西。。除了感觉脑子容量不够用外,一切都让人非常高兴。

shenhaiyu 发表于 2014-3-26 09:33:22

赞一个,理论联系实际就更完美了

darkorigin 发表于 2014-3-26 13:47:39

不错啊~~~楼主~~~~

oldbeginner 发表于 2014-3-26 17:59:17

*****************************
GROUP1 一览

在 GRBL 中的代码实现
*****************************

按照顺序,已经理解 G00 G01 G02 G03命令后下一个要理解的命令是 G80,

原因是他们 是同一组的。

group 1= {G0, G1, G2, G3, G38.2, G80, G81, G82, G83, G84, G85, G86, G87, G88, G89} motion

因为GRBL 只是实现了部分命令,

group 1= {G0, G1, G2, G3, G80}


Cancel Modal Motion — G80

Program G80 to ensure no axis motion will occur. It is an error if:
• Axis words are programmed when G80 is active, unless a modal group 0 G code is programmed which uses axis words.

g80是取消固定循环指令。网上搜了一下 华中数控,G80不是这个功能,看来华中数控并没有遵循RS274规范。

*******************************

在GRBL 中(gcode.c)的实现,

    switch(letter) {
      case 'G':
       // Set modal group values
      switch(int_value) {

          case 0: case 1: case 2: case 3: case 80: group_number = MODAL_GROUP_1; break;
         。。。。

遇到 G0, G1, G2, G3, G80 命令时,把 变量 group_number 赋值 MODAL_GROUP_1。

然后,再具体指令,

      switch(int_value) {
          case 0: gc.motion_mode = MOTION_MODE_SEEK; break;
          case 1: gc.motion_mode = MOTION_MODE_LINEAR; break;
          case 2: gc.motion_mode = MOTION_MODE_CW_ARC; break;
          case 3: gc.motion_mode = MOTION_MODE_CCW_ARC; break;
          。。。。
          case 80: gc.motion_mode = MOTION_MODE_CANCEL; break;
          。。。

设置 相应 的 gc.motion_mode 变量。

剩下是如何具体执行的,可能要把 gcode.c 看完才可以理解。

其中,gc 是一个结构体,
结构
typedef struct {
uint8_t status_code;             // Parser status for current block

uint8_t motion_mode;             // {G0, G1, G2, G3, G80}

uint8_t inverse_feed_rate_mode;// {G93, G94}

uint8_t inches_mode;             // 0 = millimeter mode, 1 = inches mode {G20, G21}

uint8_t absolute_mode;         // 0 = relative motion, 1 = absolute motion {G90, G91}

uint8_t program_flow;            // {M0, M1, M2, M30}

int8_t spindle_direction;      // 1 = CW, -1 = CCW, 0 = Stop {M3, M4, M5}

uint8_t coolant_mode;            // 0 = Disable, 1 = Flood Enable {M8, M9}

float feed_rate;               // Millimeters/min

//float seek_rate;               // Millimeters/min. Will be used in v0.9 when axis independence is installed
float position;               // Where the interpreter considers the tool to be at this point in the code
uint8_t tool;
//uint16_t spindle_speed;          // RPM/100

uint8_t plane_axis_0,
          plane_axis_1,
          plane_axis_2;            // The axes of the selected plane
uint8_t coord_select;            // Active work coordinate system number. Default: 0=G54.
float coord_system;      // Current work coordinate system (G54+). Stores offset from absolute machine

                                 // position in mm. Loaded from EEPROM when called.
float coord_offset;      // Retains the G92 coordinate offset (work coordinates) relative to
                                 // machine zero in mm. Non-persistent. Cleared upon reset and boot.      
} parser_state_t;

这个结构体包含的指令 就是要理解的,不包含的则不增加学习负担。
*****************************

另外,GRBL 没有实现 刀具补偿指令,是个大遗憾。好消息是,学习难度小了些。


宋征宇 发表于 2014-3-27 16:51:01

:lol:):D好啊

honyfox 发表于 2014-4-8 20:48:38

这个必须收藏,有空尝试一下

tt1yy1 发表于 2014-8-10 18:01:31

你好。是不是 研究一下 脱机 CNC ??不用上位机

chenchunbo 发表于 2015-4-24 14:51:40

开启学习模式。:lol

heavens78 发表于 2017-6-3 08:59:47

这个有点难了,很多不懂

逐风 发表于 2017-10-12 16:48:04

请问CNC编程你是用什么仿真软件学习的?我刚刚接触雕刻机
页: [1]
查看完整版本: Arduino机械坊学习笔记04 补充资料(CNC编程 G code)_2014_3_25