返回列表 发新帖

【教程】开发快无线控制激光雕刻机

[复制链接]
  • TA的每日心情
    开心
    2018-9-20 10:48
  • 签到天数: 189 天

    [LV.7]常住居民III

    392

    主题

    1442

    帖子

    6972

    积分

    版主

    Rank: 7Rank: 7Rank: 7

    积分
    6972
    QQ
    发表于 2018-5-30 12:25:52  | 显示全部楼层 | 阅读模式

    公开设备实时看 这是什么->

    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    22:41
    匿名用户
    通过微信控制多彩灯光
    17:16
    187****2226
    通过微信查询温湿度
    17:16
    187****2226
    通过微信查询温湿度
    17:15
    187****2226
    通过微信查询温湿度
    17:12
    187****2226
    通过微信控制多彩灯光
    17:12
    187****2226
    通过微信控制多彩灯光
    17:12
    187****2226
    通过微信控制多彩灯光
    17:12
    187****2226
    通过微信控制多彩灯光
    17:12
    187****2226
    通过微信控制多彩灯光
    17:12
    187****2226
    通过微信控制多彩灯光
    17:12
    187****2226
    通过微信控制多彩灯光
     

    马上注册,免费领取开发板,一周变智能硬件开发达人!

    您需要 登录 才可以下载或查看,没有帐号?立即注册

    x
    本帖最后由 STM64 于 2018-6-14 16:32 编辑

    产品名前:开发快小e无线控制激光雕刻机
    效果图:
    写字机.jpg


    简介:随着科技的发展,越来越多的量产产品流向市场,为了使产品质量受控,以及分辨每一个产品,往往需要在产品中加入标记符号,制作标记符号可以是记号笔随便mark的一行字,也可以是不干胶贴纸,钢印或者激光蚀刻。记号笔随便标记虽然方便,不过大多数情况下会让产品产生低端感,影响产品观感,传统制作不干胶打印标签的手法不但耗费多一个不干胶贴的成本,而且贴纸后膜随意扔造成环境的污染,不是很环保,而钢印和激光蚀刻直接把产品表面作为标记介质,不会产生多余介质废弃物,而且看上去能让产品更高端。钢印往往需要钢印模,如果是时间日期可变钢印,需要旋转机构等,制作比较复杂,而激光蚀刻相对制作方便,经设计优化和装配工艺流程优化,普通人也能按照图纸搭建一个,因为优化后的搭建过程动作都是普通人的手能够做的动作,相对来说比较轻松,同样用机械手组装优化后的装配流程,也更有效率。

    成本性能比例系数:
                           89/320   低成本,高性价比

    操作难度:
             一颗星    适合6-83的普通人操作,6-14小孩需在家长指导下操作,14+可在家长陪护下操作,极限简化装配过程,同样适合女性操作。

    材料准备:
    1.开发快小e一枚  
    2.arduino开发板一枚 uno r3   10.5-15
    3.cnc 扩展板一枚   2.9-4.3
    4.a4988两枚   2-4每个
    5.激光头一枚     .5-359(部分需额外适配器及散热器,推荐开发过程中用.5的,.5不会明显伤眼,尤其是小孩操作时别用大功率)
    6.继电器模块一枚   1.2-3  (3pin 2pin in out)
    7.12V电源一匹  6-25  (一般用适配器,12v5A,按电机一般2A一个,两电机加激光一般5A够用,小孩操作用电池串联到12v左右也可以的)
    8.橡皮筋一根  .03-.1
    9.紧致弹簧一枚  .05-.25
    10.步进电机两匹  5-39 (功率不用太大,够用就好)
    11.直径5mm光轴杆子两条 2-11每条(或差不多大的烤肉串棒棒或其他代替物)12.同步轮两只 .7-3每只 (宽度5mm差不多,直径fin5,20齿,模数别太夸张就行)
    13.同步带一条  1-3每米 (宽度5mm差不多)
    14.杜邦线若干
    15.电机到板的连接线
    16.电源到板的连接线或接线端子
    17.12v to 5v 模块或元件
    18.螺丝若干19.图纸打印件或机加工件若干
    笔夹激光通用款额外:
    20.笔夹小棒棒两根,圆珠笔弹簧两只
    21.9g舵机一枚及相应螺丝
    22.笔夹相应打印件或机加工件
    23.差不多大小的笔一支(尽量合适且轻盈)
    制作流程工具:(可不用)
    24.热熔胶枪和胶,或502
    25.烙铁,或全用杜邦线或铜端子冷压好的或标准接口直接插
    26.橡皮章雕刻套装或剪刀一把
    27.护具:手套,护目镜等

    先上一部分图纸,二楼继续:
    10g-xzj.stl (1.5 MB, 下载次数: 4)

    目录:
    1.总速及效果图 (材料准备与大致介绍)
    2.机械部件装配过程
    3.电路部件装配过程
    4.软件部分
    5.测试文件及各种不同效果的测试专用图片



    stm32,FPGA
    回复

    使用道具 举报

  • TA的每日心情
    开心
    2018-9-20 10:48
  • 签到天数: 189 天

    [LV.7]常住居民III

    392

    主题

    1442

    帖子

    6972

    积分

    版主

    Rank: 7Rank: 7Rank: 7

    积分
    6972
    QQ
    发表于 2018-6-14 10:27:50  | 显示全部楼层
    本帖最后由 STM64 于 2018-6-14 10:31 编辑

    话不多说,上个图纸先,方便有些拿到图纸就会用的技术宅

    笔夹滑台.stl (364.93 KB, 下载次数: 0)
    笔架主.stl (847.84 KB, 下载次数: 0)
    电机光杆接口右.stl (422.84 KB, 下载次数: 0)
    电机光杆接口左.stl (422.84 KB, 下载次数: 0)
    尾部同步带接口.stl (271.76 KB, 下载次数: 0)
    主核心.stl (1.5 MB, 下载次数: 0)








    上面这些下载好后是这些个:(说明txt里的内容就是本文,一样的)
    798798798.jpg

    stm32,FPGA
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2018-9-20 10:48
  • 签到天数: 189 天

    [LV.7]常住居民III

    392

    主题

    1442

    帖子

    6972

    积分

    版主

    Rank: 7Rank: 7Rank: 7

    积分
    6972
    QQ
    发表于 2018-6-14 11:18:56  | 显示全部楼层
    组装过程图解:

    将笔夹的小棒棒穿上弹簧并插入,形成小组件装配:
    9.jpg

    然后压入光轴条,记得中间插入核心部件哦!
    8.jpg

    然后装上9g舵机,并穿上钩簧到笔尖顶出板:
    (如果您的光轴较松,舵机前装也可以,较紧就先压入光轴吧,微型舵机太脆,一压即爆)
    7.jpg

    再把步进电机跟光轴的套套也组装起来,拧上螺丝,如果步进电机配了四个螺丝,就把另两个也拧上,平衡重量:
    1.jpg

    然后把前面组装好的支架横条组件安装上去,如果前面夹大笔,那后面吊点配重块平衡下:
    5.jpg

    把同步带穿入:(若打印间隙紧,加个紧固弹簧反力一下即可,如若宽,添点502)
    3.jpg


    重要提示:
    上面光轴那些通过同步带就能拉紧,如果松到有牙签放牙罐之感,那适当滴点502于缝隙间,其余部件亦同
    WARING:
    若核心部件处孔过小或光轴过大,造成紧,可修边刀扩孔或烙铁扩孔,切勿烙铁热光轴强插入,否则会导致产品变形。

    stm32,FPGA
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2018-9-20 10:48
  • 签到天数: 189 天

    [LV.7]常住居民III

    392

    主题

    1442

    帖子

    6972

    积分

    版主

    Rank: 7Rank: 7Rank: 7

    积分
    6972
    QQ
    发表于 2018-6-14 11:31:05  | 显示全部楼层
    本帖最后由 STM64 于 2018-6-14 14:38 编辑

    然后是电路部分的连接,接线图画成三维不好看懂,二维的标准图纸估计普通人拿到手连元件符号识别都难,
    用与实物轮廓线相似的,带注释的手绘图表示一下,各种部件都标记上了:
    简体中文版:
    稻荷之春秋_20180614_140318.jpg

    (这张大约是半年前左右写的,记得当时笔墨水残量低于5%写不出来了,有些看不清的字不必纠结,重要的东西都写明表述出来了,看不清的看下面几张参考图是互补的)


    其他参考资料图片:
    894984.jpg

    987987.jpg

    4988.jpg


    stm32,FPGA
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2018-9-20 10:48
  • 签到天数: 189 天

    [LV.7]常住居民III

    392

    主题

    1442

    帖子

    6972

    积分

    版主

    Rank: 7Rank: 7Rank: 7

    积分
    6972
    QQ
    发表于 2018-6-14 15:48:32  | 显示全部楼层
    本帖最后由 STM64 于 2018-6-14 16:06 编辑

    软件部分:

    编译好的固件:(小e)
    固件(写入时去掉中文).bin (101.5 KB, 下载次数: 0)
    编译好的固件:(Uno r3)
    gl bl.hex (81.03 KB, 下载次数: 1)
    手机端控制器(Android1.1以上):
    手机版控制端.apk (2.08 MB, 下载次数: 0)
    后台服务软件(Windows3.1以上,通过命令行可查看工作信息):
    无线控制后台服务.exe (1.82 MB, 下载次数: 0)
    刷固件软件:(WindowsPE1.0以上)
    XLoader(下载固件用).rar (443.33 KB, 下载次数: 1)
    刷固件软件:(Windows95以上)
    XLoader.exe (271 KB, 下载次数: 0)
    刷固件时连电脑所需要的驱动:(Windows98以上)
    CH340SER.EXE (227.56 KB, 下载次数: 0)


    下面是编译前的源码,篇幅有限,上局部:
    1. #define MAX_LINE_NUMBER 9999999

    2. #define AXIS_COMMAND_NONE 0
    3. #define AXIS_COMMAND_NON_MODAL 1
    4. #define AXIS_COMMAND_MOTION_MODE 2
    5. #define AXIS_COMMAND_TOOL_LENGTH_OFFSET 3 // *Undefined but required

    6. // Declare gc extern struct
    7. parser_state_t gc_state;
    8. parser_block_t gc_block;

    9. #define FAIL(status) return(status);


    10. void gc_init()
    11. {
    12.   memset(&gc_state, 0, sizeof(parser_state_t));
    13.   
    14.   // Load default G54 coordinate system.
    15.   if (!(settings_read_coord_data(gc_state.modal.coord_select,gc_state.coord_system))) {
    16.     report_status_message(STATUS_SETTING_READ_FAIL);
    17.   }
    18. }


    19. // Sets g-code parser position in mm. Input in steps. Called by the system abort and hard
    20. // limit pull-off routines.
    21. void gc_sync_position()
    22. {
    23.   system_convert_array_steps_to_mpos(gc_state.position,sys.position);
    24. }


    25. static uint8_t gc_check_same_position(float *pos_a, float *pos_b)
    26. {
    27.   uint8_t idx;
    28.   for (idx=0; idx<N_AXIS; idx++) {
    29.     if (pos_a[idx] != pos_b[idx]) { return(false); }
    30.   }
    31.   return(true);
    32. }
    33.          
    34. // Executes one line of 0-terminated G-Code. The line is assumed to contain only uppercase
    35. // characters and signed floating point values (no whitespace). Comments and block delete
    36. // characters have been removed. In this function, all units and positions are converted and
    37. // exported to grbl's internal functions in terms of (mm, mm/min) and absolute machine
    38. // coordinates, respectively.
    39. uint8_t gc_execute_line(char *line)
    40. {
    41.   /* -------------------------------------------------------------------------------------
    42.      STEP 1: Initialize parser block struct and copy current g-code state modes. The parser
    43.      updates these modes and commands as the block line is parser and will only be used and
    44.      executed after successful error-checking. The parser block struct also contains a block
    45.      values struct, word tracking variables, and a non-modal commands tracker for the new
    46.      block. This struct contains all of the necessary information to execute the block. */

    47.   memset(&gc_block, 0, sizeof(parser_block_t)); // Initialize the parser block struct.
    48.   memcpy(&gc_block.modal,&gc_state.modal,sizeof(gc_modal_t)); // Copy current modes
    49.   uint8_t axis_command = AXIS_COMMAND_NONE;
    50.   uint8_t axis_0, axis_1, axis_linear;
    51.   uint8_t coord_select = 0; // Tracks G10 P coordinate selection for execution
    52.   float coordinate_data[N_AXIS]; // Multi-use variable to store coordinate data for execution
    53.   float parameter_data[N_AXIS]; // Multi-use variable to store parameter data for execution
    54.   
    55.   // Initialize bitflag tracking variables for axis indices compatible operations.
    56.   uint8_t axis_words = 0; // XYZ tracking
    57.   uint8_t ijk_words = 0; // IJK tracking

    58.   // Initialize command and value words variables. Tracks words contained in this block.
    59.   uint16_t command_words = 0; // G and M command words. Also used for modal group violations.
    60.   uint16_t value_words = 0; // Value words.

    61.   /* -------------------------------------------------------------------------------------
    62.      STEP 2: Import all g-code words in the block line. A g-code word is a letter followed by
    63.      a number, which can either be a 'G'/'M' command or sets/assigns a command value. Also,
    64.      perform initial error-checks for command word modal group violations, for any repeated
    65.      words, and for negative values set for the value words F, N, P, T, and S. */
    66.      
    67.   uint8_t word_bit; // Bit-value for assigning tracking variables
    68.   uint8_t char_counter = 0;  
    69.   char letter;
    70.   float value;
    71.   uint8_t int_value = 0;
    72.   uint16_t mantissa = 0;

    73.   while (line[char_counter] != 0) { // Loop until no more g-code words in line.
    74.    
    75.     // Import the next g-code word, expecting a letter followed by a value. Otherwise, error out.
    76.     letter = line[char_counter];
    77.     if((letter < 'A') || (letter > 'Z')) { FAIL(STATUS_EXPECTED_COMMAND_LETTER); } // [Expected word letter]
    78.     char_counter++;
    79.     if (!read_float(line, &char_counter, &value)) { FAIL(STATUS_BAD_NUMBER_FORMAT); } // [Expected word value]

    80.     // Convert values to smaller uint8 significand and mantissa values for parsing this word.
    81.     // NOTE: Mantissa is multiplied by 100 to catch non-integer command values. This is more
    82.     // accurate than the NIST gcode requirement of x10 when used for commands, but not quite
    83.     // accurate enough for value words that require integers to within 0.0001. This should be
    84.     // a good enough comprimise and catch most all non-integer errors. To make it compliant,
    85.     // we would simply need to change the mantissa to int16, but this add compiled flash space.
    86.     // Maybe update this later.
    87.     int_value = trunc(value);
    88.     mantissa =  round(100*(value - int_value)); // Compute mantissa for Gxx.x commands.
    89.         // NOTE: Rounding must be used to catch small floating point errors.

    90.     // Check if the g-code word is supported or errors due to modal group violations or has
    91.     // been repeated in the g-code block. If ok, update the command or record its value.
    92.     switch(letter) {
    93.    
    94.       /* 'G' and 'M' Command Words: Parse commands and check for modal group violations.
    95.          NOTE: Modal group numbers are defined in Table 4 of NIST RS274-NGC v3, pg.20 */
    96.          
    97.       case 'G':
    98.         // Determine 'G' command and its modal group
    99.         switch(int_value) {
    100.           case 10: case 28: case 30: case 92:
    101.             // Check for G10/28/30/92 being called with G0/1/2/3/38 on same block.
    102.             // * G43.1 is also an axis command but is not explicitly defined this way.
    103.             if (mantissa == 0) { // Ignore G28.1, G30.1, and G92.1
    104.               if (axis_command) { FAIL(STATUS_GCODE_AXIS_COMMAND_CONFLICT); } // [Axis word/command conflict]
    105.               axis_command = AXIS_COMMAND_NON_MODAL;
    106.             }
    107.             // No break. Continues to next line.
    108.           case 4: case 53:
    109.             word_bit = MODAL_GROUP_G0;
    110.             switch(int_value) {
    111.               case 4: gc_block.non_modal_command = NON_MODAL_DWELL; break; // G4
    112.               case 10: gc_block.non_modal_command = NON_MODAL_SET_COORDINATE_DATA; break; // G10
    113.               case 28:
    114.                 switch(mantissa) {
    115.                   case 0: gc_block.non_modal_command = NON_MODAL_GO_HOME_0; break;  // G28
    116.                   case 10: gc_block.non_modal_command = NON_MODAL_SET_HOME_0; break; // G28.1
    117.                   default: FAIL(STATUS_GCODE_UNSUPPORTED_COMMAND); // [Unsupported G28.x command]
    118.                 }
    119.                 mantissa = 0; // Set to zero to indicate valid non-integer G command.
    120.                 break;
    121.               case 30:
    122.                 switch(mantissa) {
    123.                   case 0: gc_block.non_modal_command = NON_MODAL_GO_HOME_1; break;  // G30
    124.                   case 10: gc_block.non_modal_command = NON_MODAL_SET_HOME_1; break; // G30.1
    125.                   default: FAIL(STATUS_GCODE_UNSUPPORTED_COMMAND); // [Unsupported G30.x command]
    126.                 }
    127.                 mantissa = 0; // Set to zero to indicate valid non-integer G command.
    128.                 break;
    129.               case 53: gc_block.non_modal_command = NON_MODAL_ABSOLUTE_OVERRIDE; break; // G53
    130.               case 92:
    131.                 switch(mantissa) {
    132.                   case 0: gc_block.non_modal_command = NON_MODAL_SET_COORDINATE_OFFSET; break; // G92
    133.                   case 10: gc_block.non_modal_command = NON_MODAL_RESET_COORDINATE_OFFSET; break; // G92.1
    134.                   default: FAIL(STATUS_GCODE_UNSUPPORTED_COMMAND); // [Unsupported G92.x command]
    135.                 }
    136.                 mantissa = 0; // Set to zero to indicate valid non-integer G command.
    137.                 break;      
    138.             }
    139.             break;
    140.           case 0: case 1: case 2: case 3: case 38:
    141.             // Check for G0/1/2/3/38 being called with G10/28/30/92 on same block.
    142.             // * G43.1 is also an axis command but is not explicitly defined this way.
    143.             if (axis_command) { FAIL(STATUS_GCODE_AXIS_COMMAND_CONFLICT); } // [Axis word/command conflict]
    144.             axis_command = AXIS_COMMAND_MOTION_MODE;
    145.             // No break. Continues to next line.
    146.           case 80:
    147.             word_bit = MODAL_GROUP_G1;
    148.             switch(int_value) {
    149.               case 0: gc_block.modal.motion = MOTION_MODE_SEEK; break; // G0
    150.               case 1: gc_block.modal.motion = MOTION_MODE_LINEAR; break; // G1
    151.               case 2: gc_block.modal.motion = MOTION_MODE_CW_ARC; break; // G2
    152.               case 3: gc_block.modal.motion = MOTION_MODE_CCW_ARC; break; // G3
    153.               case 38:
    154.                 switch(mantissa) {
    155.                   case 20: gc_block.modal.motion = MOTION_MODE_PROBE_TOWARD; break; // G38.2
    156.                   case 30: gc_block.modal.motion = MOTION_MODE_PROBE_TOWARD_NO_ERROR; break; // G38.3
    157.                   case 40: gc_block.modal.motion = MOTION_MODE_PROBE_AWAY; break; // G38.4
    158.                   case 50: gc_block.modal.motion = MOTION_MODE_PROBE_AWAY_NO_ERROR; break; // G38.5
    159.                   default: FAIL(STATUS_GCODE_UNSUPPORTED_COMMAND); // [Unsupported G38.x command]
    160.                 }
    161.                 mantissa = 0; // Set to zero to indicate valid non-integer G command.
    162.                 break;
    163.               case 80: gc_block.modal.motion = MOTION_MODE_NONE; break; // G80
    164.             }            
    165.             break;
    166.           case 17: case 18: case 19:
    167.             word_bit = MODAL_GROUP_G2;
    168.             switch(int_value) {
    169.               case 17: gc_block.modal.plane_select = PLANE_SELECT_XY; break;
    170.               case 18: gc_block.modal.plane_select = PLANE_SELECT_ZX; break;
    171.               case 19: gc_block.modal.plane_select = PLANE_SELECT_YZ; break;
    172.             }
    173.             break;
    174.           case 90: case 91:
    175.             if (mantissa == 0) {
    176.               word_bit = MODAL_GROUP_G3;
    177.               if (int_value == 90) { gc_block.modal.distance = DISTANCE_MODE_ABSOLUTE; } // G90
    178.               else { gc_block.modal.distance = DISTANCE_MODE_INCREMENTAL; } // G91
    179.             } else {
    180.               word_bit = MODAL_GROUP_G4;
    181.               if ((mantissa != 10) || (int_value == 90)) { FAIL(STATUS_GCODE_UNSUPPORTED_COMMAND); } // [G90.1 not supported]
    182.               mantissa = 0; // Set to zero to indicate valid non-integer G command.
    183.               // Otherwise, arc IJK incremental mode is default. G91.1 does nothing.
    184.             }
    185.             break;
    186.           case 93: case 94:
    187.             word_bit = MODAL_GROUP_G5;
    188.             if (int_value == 93) { gc_block.modal.feed_rate = FEED_RATE_MODE_INVERSE_TIME; } // G93
    189.             else { gc_block.modal.feed_rate = FEED_RATE_MODE_UNITS_PER_MIN; } // G94
    190.             break;
    191.           case 20: case 21:
    192.             word_bit = MODAL_GROUP_G6;
    193.             if (int_value == 20) { gc_block.modal.units = UNITS_MODE_INCHES; }  // G20
    194.             else { gc_block.modal.units = UNITS_MODE_MM; } // G21
    195.             break;
    196.           case 40:
    197.             word_bit = MODAL_GROUP_G7;
    198.             // NOTE: Not required since cutter radius compensation is always disabled. Only here
    199.             // to support G40 commands that often appear in g-code program headers to setup defaults.
    200.             // gc_block.modal.cutter_comp = CUTTER_COMP_DISABLE; // G40
    201.             break;
    202.           case 43: case 49:
    203.             word_bit = MODAL_GROUP_G8;
    204.             // NOTE: The NIST g-code standard vaguely states that when a tool length offset is changed,
    205.             // there cannot be any axis motion or coordinate offsets updated. Meaning G43, G43.1, and G49
    206.             // all are explicit axis commands, regardless if they require axis words or not.
    207.             if (axis_command) { FAIL(STATUS_GCODE_AXIS_COMMAND_CONFLICT); } // [Axis word/command conflict] }
    208.             axis_command = AXIS_COMMAND_TOOL_LENGTH_OFFSET;
    209.             if (int_value == 49) { // G49
    210.               gc_block.modal.tool_length = TOOL_LENGTH_OFFSET_CANCEL;
    211.             } else if (mantissa == 10) { // G43.1
    212.               gc_block.modal.tool_length = TOOL_LENGTH_OFFSET_ENABLE_DYNAMIC;
    213.             } else { FAIL(STATUS_GCODE_UNSUPPORTED_COMMAND); } // [Unsupported G43.x command]
    214.             mantissa = 0; // Set to zero to indicate valid non-integer G command.
    215.             break;
    216.           case 54: case 55: case 56: case 57: case 58: case 59:
    217.             // NOTE: G59.x are not supported. (But their int_values would be 60, 61, and 62.)
    218.             word_bit = MODAL_GROUP_G12;
    219.             gc_block.modal.coord_select = int_value-54; // Shift to array indexing.
    220.             break;
    221.           case 61:
    222.             word_bit = MODAL_GROUP_G13;
    223.             if (mantissa != 0) { FAIL(STATUS_GCODE_UNSUPPORTED_COMMAND); } // [G61.1 not supported]
    224.             // gc_block.modal.control = CONTROL_MODE_EXACT_PATH; // G61
    225.             break;
    226.           default: FAIL(STATUS_GCODE_UNSUPPORTED_COMMAND); // [Unsupported G command]
    227.         }      
    228.         if (mantissa > 0) { FAIL(STATUS_GCODE_COMMAND_VALUE_NOT_INTEGER); } // [Unsupported or invalid Gxx.x command]
    229.         // Check for more than one command per modal group violations in the current block
    230.         // NOTE: Variable 'word_bit' is always assigned, if the command is valid.
    231.         if ( bit_istrue(command_words,bit(word_bit)) ) { FAIL(STATUS_GCODE_MODAL_GROUP_VIOLATION); }
    232.         command_words |= bit(word_bit);
    233.         break;
    234.         
    235.       case 'M':
    236.       
    237.         // Determine 'M' command and its modal group
    238.         if (mantissa > 0) { FAIL(STATUS_GCODE_COMMAND_VALUE_NOT_INTEGER); } // [No Mxx.x commands]
    239.         switch(int_value) {
    240.           case 0: case 1: case 2: case 30:
    241.             word_bit = MODAL_GROUP_M4;
    242.             switch(int_value) {
    243.               case 0: gc_block.modal.program_flow = PROGRAM_FLOW_PAUSED; break; // Program pause
    244.               case 1: break; // Optional stop not supported. Ignore.
    245.               case 2: case 30: gc_block.modal.program_flow = PROGRAM_FLOW_COMPLETED; break; // Program end and reset
    246.             }
    247.             break;
    248.           #ifndef USE_SPINDLE_DIR_AS_ENABLE_PIN
    249.             case 4:
    250.           #endif
    251.           case 3: case 5:
    252.             word_bit = MODAL_GROUP_M7;
    253.             switch(int_value) {
    254.               case 3: gc_block.modal.spindle = SPINDLE_ENABLE_CW; break;
    255.               #ifndef USE_SPINDLE_DIR_AS_ENABLE_PIN
    256.                 case 4: gc_block.modal.spindle = SPINDLE_ENABLE_CCW; break;
    257.               #endif
    258.               case 5: gc_block.modal.spindle = SPINDLE_DISABLE; break;
    259.             }
    260.             break;            
    261.          #ifdef ENABLE_M7  
    262.           case 7:
    263.          #endif
    264.           case 8: case 9:
    265.             word_bit = MODAL_GROUP_M8;
    266.             switch(int_value) {      
    267.              #ifdef ENABLE_M7
    268.               case 7: gc_block.modal.coolant = COOLANT_MIST_ENABLE; break;
    269.              #endif
    270.               case 8: gc_block.modal.coolant = COOLANT_FLOOD_ENABLE; break;
    271.               case 9: gc_block.modal.coolant = COOLANT_DISABLE; break;
    272.             }
    273.             break;
    274.           default: FAIL(STATUS_GCODE_UNSUPPORTED_COMMAND); // [Unsupported M command]
    275.         }
    276.       
    277.         // Check for more than one command per modal group violations in the current block
    278.         // NOTE: Variable 'word_bit' is always assigned, if the command is valid.
    279.         if ( bit_istrue(command_words,bit(word_bit)) ) { FAIL(STATUS_GCODE_MODAL_GROUP_VIOLATION); }
    280.         command_words |= bit(word_bit);
    281.         break;
    282.       
    283.       // NOTE: All remaining letters assign values.
    284.       default:
    285.   
    286.         /* Non-Command Words: This initial parsing phase only checks for repeats of the remaining
    287.            legal g-code words and stores their value. Error-checking is performed later since some
    288.            words (I,J,K,L,P,R) have multiple connotations and/or depend on the issued commands. */
    289.         switch(letter){
    290.           // case 'A': // Not supported
    291.           // case 'B': // Not supported
    292.           // case 'C': // Not supported
    293.           // case 'D': // Not supported
    294.           case 'F': word_bit = WORD_F; gc_block.values.f = value; break;
    295.           // case 'H': // Not supported
    296.           case 'I': word_bit = WORD_I; gc_block.values.ijk[X_AXIS] = value; ijk_words |= (1<<X_AXIS); break;
    297.           case 'J': word_bit = WORD_J; gc_block.values.ijk[Y_AXIS] = value; ijk_words |= (1<<Y_AXIS); break;
    298.           case 'K': word_bit = WORD_K; gc_block.values.ijk[Z_AXIS] = value; ijk_words |= (1<<Z_AXIS); break;
    299.           case 'L': word_bit = WORD_L; gc_block.values.l = int_value; break;
    300.           case 'N': word_bit = WORD_N; gc_block.values.n = trunc(value); break;
    301.           case 'P': word_bit = WORD_P; gc_block.values.p = value; break;
    302.           // NOTE: For certain commands, P value must be an integer, but none of these commands are supported.
    303.           // case 'Q': // Not supported
    304.           case 'R': word_bit = WORD_R; gc_block.values.r = value; break;
    305.           case 'S': word_bit = WORD_S; gc_block.values.s = value; break;
    306.           case 'T': word_bit = WORD_T; break; // gc.values.t = int_value;
    307.           case 'X': word_bit = WORD_X; gc_block.values.xyz[X_AXIS] = value; axis_words |= (1<<X_AXIS); break;
    308.           case 'Y': word_bit = WORD_Y; gc_block.values.xyz[Y_AXIS] = value; axis_words |= (1<<Y_AXIS); break;
    309.           case 'Z': word_bit = WORD_Z; gc_block.values.xyz[Z_AXIS] = value; axis_words |= (1<<Z_AXIS); break;
    310.           default: FAIL(STATUS_GCODE_UNSUPPORTED_COMMAND);
    311.         }
    312.         
    313.         // NOTE: Variable 'word_bit' is always assigned, if the non-command letter is valid.
    314.         if (bit_istrue(value_words,bit(word_bit))) { FAIL(STATUS_GCODE_WORD_REPEATED); } // [Word repeated]
    315.         // Check for invalid negative values for words F, N, P, T, and S.
    316.         // NOTE: Negative value check is done here simply for code-efficiency.
    317.         if ( bit(word_bit) & (bit(WORD_F)|bit(WORD_N)|bit(WORD_P)|bit(WORD_T)|bit(WORD_S)) ) {
    318.           if (value < 0.0) { FAIL(STATUS_NEGATIVE_VALUE); } // [Word value cannot be negative]
    319.         }
    320.         value_words |= bit(word_bit); // Flag to indicate parameter assigned.
    321.       
    322.     }   
    323.   }
    324.   // Parsing complete!
    325.   

    326.   /* -------------------------------------------------------------------------------------
    327.      STEP 3: Error-check all commands and values passed in this block. This step ensures all of
    328.      the commands are valid for execution and follows the NIST standard as closely as possible.
    329.      If an error is found, all commands and values in this block are dumped and will not update
    330.      the active system g-code modes. If the block is ok, the active system g-code modes will be
    331.      updated based on the commands of this block, and signal for it to be executed.
    332.      
    333.      Also, we have to pre-convert all of the values passed based on the modes set by the parsed
    334.      block. There are a number of error-checks that require target information that can only be
    335.      accurately calculated if we convert these values in conjunction with the error-checking.
    336.      This relegates the next execution step as only updating the system g-code modes and
    337.      performing the programmed actions in order. The execution step should not require any
    338.      conversion calculations and would only require minimal checks necessary to execute.
    339.   */

    340.   /* NOTE: At this point, the g-code block has been parsed and the block line can be freed.
    341.      NOTE: It's also possible, at some future point, to break up STEP 2, to allow piece-wise
    342.      parsing of the block on a per-word basis, rather than the entire block. This could remove
    343.      the need for maintaining a large string variable for the entire block and free up some memory.
    344.      To do this, this would simply need to retain all of the data in STEP 1, such as the new block
    345.      data struct, the modal group and value bitflag tracking variables, and axis array indices
    346.      compatible variables. This data contains all of the information necessary to error-check the
    347.      new g-code block when the EOL character is received. However, this would break Grbl's startup
    348.      lines in how it currently works and would require some refactoring to make it compatible.
    349.   */  
    350.   
    351.   // [0. Non-specific/common error-checks and miscellaneous setup]:
    352.   
    353.   // Determine implicit axis command conditions. Axis words have been passed, but no explicit axis
    354.   // command has been sent. If so, set axis command to current motion mode.
    355.   if (axis_words) {
    356.     if (!axis_command) { axis_command = AXIS_COMMAND_MOTION_MODE; } // Assign implicit motion-mode
    357.   }
    358.   
    359.   // Check for valid line number N value.
    360.   if (bit_istrue(value_words,bit(WORD_N))) {
    361.     // Line number value cannot be less than zero (done) or greater than max line number.
    362.     if (gc_block.values.n > MAX_LINE_NUMBER) { FAIL(STATUS_GCODE_INVALID_LINE_NUMBER); } // [Exceeds max line number]
    363.   }
    364.   // bit_false(value_words,bit(WORD_N)); // NOTE: Single-meaning value word. Set at end of error-checking.
    365.   
    366.   // Track for unused words at the end of error-checking.
    367.   // NOTE: Single-meaning value words are removed all at once at the end of error-checking, because
    368.   // they are always used when present. This was done to save a few bytes of flash. For clarity, the
    369.   // single-meaning value words may be removed as they are used. Also, axis words are treated in the
    370.   // same way. If there is an explicit/implicit axis command, XYZ words are always used and are
    371.   // are removed at the end of error-checking.  
    372.   
    373.   // [1. Comments ]: MSG's NOT SUPPORTED. Comment handling performed by protocol.
    374.   
    375.   // [2. Set feed rate mode ]: G93 F word missing with G1,G2/3 active, implicitly or explicitly. Feed rate
    376.   //   is not defined after switching to G94 from G93.
    377.   if (gc_block.modal.feed_rate == FEED_RATE_MODE_INVERSE_TIME) { // = G93
    378.     // NOTE: G38 can also operate in inverse time, but is undefined as an error. Missing F word check added here.
    379.     if (axis_command == AXIS_COMMAND_MOTION_MODE) {
    380.       if ((gc_block.modal.motion != MOTION_MODE_NONE) || (gc_block.modal.motion != MOTION_MODE_SEEK)) {
    381.         if (bit_isfalse(value_words,bit(WORD_F))) { FAIL(STATUS_GCODE_UNDEFINED_FEED_RATE); } // [F word missing]
    382.       }
    383.     }
    384.     // NOTE: It seems redundant to check for an F word to be passed after switching from G94 to G93. We would
    385.     // accomplish the exact same thing if the feed rate value is always reset to zero and undefined after each
    386.     // inverse time block, since the commands that use this value already perform undefined checks. This would
    387.     // also allow other commands, following this switch, to execute and not error out needlessly. This code is
    388.     // combined with the above feed rate mode and the below set feed rate error-checking.

    389.     // [3. Set feed rate ]: F is negative (done.)
    390.     // - In inverse time mode: Always implicitly zero the feed rate value before and after block completion.
    391.     // NOTE: If in G93 mode or switched into it from G94, just keep F value as initialized zero or passed F word
    392.     // value in the block. If no F word is passed with a motion command that requires a feed rate, this will error
    393.     // out in the motion modes error-checking. However, if no F word is passed with NO motion command that requires
    394.     // a feed rate, we simply move on and the state feed rate value gets updated to zero and remains undefined.
    395.   } else { // = G94
    396.     // - In units per mm mode: If F word passed, ensure value is in mm/min, otherwise push last state value.
    397.     if (gc_state.modal.feed_rate == FEED_RATE_MODE_UNITS_PER_MIN) { // Last state is also G94
    398.       if (bit_istrue(value_words,bit(WORD_F))) {
    399.         if (gc_block.modal.units == UNITS_MODE_INCHES) { gc_block.values.f *= MM_PER_INCH; }
    400.       } else {
    401.         gc_block.values.f = gc_state.feed_rate; // Push last state feed rate
    402.       }
    403.     } // Else, switching to G94 from G93, so don't push last state feed rate. Its undefined or the passed F word value.
    404.   }
    405.   // bit_false(value_words,bit(WORD_F)); // NOTE: Single-meaning value word. Set at end of error-checking.
    406.   
    407.   // [4. Set spindle speed ]: S is negative (done.)
    408.   if (bit_isfalse(value_words,bit(WORD_S))) { gc_block.values.s = gc_state.spindle_speed; }
    409.   // bit_false(value_words,bit(WORD_S)); // NOTE: Single-meaning value word. Set at end of error-checking.
    410.    
    411.   // [5. Select tool ]: NOT SUPPORTED. Only tracks value. T is negative (done.) Not an integer. Greater than max tool value.
    412.   // bit_false(value_words,bit(WORD_T)); // NOTE: Single-meaning value word. Set at end of error-checking.

    413.   // [6. Change tool ]: N/A
    414.   // [7. Spindle control ]: N/A
    415.   // [8. Coolant control ]: N/A
    416.   // [9. Enable/disable feed rate or spindle overrides ]: NOT SUPPORTED.
    417.   
    418.   // [10. Dwell ]: P value missing. P is negative (done.) NOTE: See below.
    419.   if (gc_block.non_modal_command == NON_MODAL_DWELL) {
    420.     if (bit_isfalse(value_words,bit(WORD_P))) { FAIL(STATUS_GCODE_VALUE_WORD_MISSING); } // [P word missing]
    421.     bit_false(value_words,bit(WORD_P));
    422.   }
    423.   
    424.   // [11. Set active plane ]: N/A
    425.   switch (gc_block.modal.plane_select) {
    426.     case PLANE_SELECT_XY:
    427.       axis_0 = X_AXIS;
    428.       axis_1 = Y_AXIS;
    429.       axis_linear = Z_AXIS;
    430.       break;
    431.     case PLANE_SELECT_ZX:
    432.       axis_0 = Z_AXIS;
    433.       axis_1 = X_AXIS;
    434.       axis_linear = Y_AXIS;
    435.       break;
    436.     default: // case PLANE_SELECT_YZ:
    437.       axis_0 = Y_AXIS;
    438.       axis_1 = Z_AXIS;
    439.       axis_linear = X_AXIS;
    440.   }   
    441.             
    442.   // [12. Set length units ]: N/A
    443.   // Pre-convert XYZ coordinate values to millimeters, if applicable.
    444.   uint8_t idx;
    445.   if (gc_block.modal.units == UNITS_MODE_INCHES) {
    446.     for (idx=0; idx<N_AXIS; idx++) { // Axes indices are consistent, so loop may be used.
    447.       if (bit_istrue(axis_words,bit(idx)) ) {
    448.         gc_block.values.xyz[idx] *= MM_PER_INCH;
    449.       }
    450.     }
    451.   }
    452.   
    453.   // [13. Cutter radius compensation ]: G41/42 NOT SUPPORTED. Error, if enabled while G53 is active.
    454.   // [G40 Errors]: G2/3 arc is programmed after a G40. The linear move after disabling is less than tool diameter.
    455.   //   NOTE: Since cutter radius compensation is never enabled, these G40 errors don't apply. Grbl supports G40
    456.   //   only for the purpose to not error when G40 is sent with a g-code program header to setup the default modes.
    457.   
    458.   // [14. Cutter length compensation ]: G43 NOT SUPPORTED, but G43.1 and G49 are.
    459.   // [G43.1 Errors]: Motion command in same line.
    460.   //   NOTE: Although not explicitly stated so, G43.1 should be applied to only one valid
    461.   //   axis that is configured (in config.h). There should be an error if the configured axis
    462.   //   is absent or if any of the other axis words are present.
    463.   if (axis_command == AXIS_COMMAND_TOOL_LENGTH_OFFSET ) { // Indicates called in block.
    464.     if (gc_block.modal.tool_length == TOOL_LENGTH_OFFSET_ENABLE_DYNAMIC) {
    465.       if (axis_words ^ (1<<TOOL_LENGTH_OFFSET_AXIS)) { FAIL(STATUS_GCODE_G43_DYNAMIC_AXIS_ERROR); }
    466.     }
    467.   }
    468.   
    469.   // [15. Coordinate system selection ]: *N/A. Error, if cutter radius comp is active.
    470.   // TODO: An EEPROM read of the coordinate data may require a buffer sync when the cycle
    471.   // is active. The read pauses the processor temporarily and may cause a rare crash. For
    472.   // future versions on processors with enough memory, all coordinate data should be stored
    473.   // in memory and written to EEPROM only when there is not a cycle active.
    474.   memcpy(coordinate_data,gc_state.coord_system,sizeof(gc_state.coord_system));
    475.   if ( bit_istrue(command_words,bit(MODAL_GROUP_G12)) ) { // Check if called in block
    476.     if (gc_block.modal.coord_select > N_COORDINATE_SYSTEM) { FAIL(STATUS_GCODE_UNSUPPORTED_COORD_SYS); } // [Greater than N sys]
    477.     if (gc_state.modal.coord_select != gc_block.modal.coord_select) {
    478.       if (!(settings_read_coord_data(gc_block.modal.coord_select,coordinate_data))) { FAIL(STATUS_SETTING_READ_FAIL); }
    479.     }
    480.   }
    481.   
    482.   // [16. Set path control mode ]: N/A. Only G61. G61.1 and G64 NOT SUPPORTED.
    483.   // [17. Set distance mode ]: N/A. Only G91.1. G90.1 NOT SUPPORTED.
    484.   // [18. Set retract mode ]: NOT SUPPORTED.
    485.   
    486.   // [19. Remaining non-modal actions ]: Check go to predefined position, set G10, or set axis offsets.
    487.   // NOTE: We need to separate the non-modal commands that are axis word-using (G10/G28/G30/G92), as these
    488.   // commands all treat axis words differently. G10 as absolute offsets or computes current position as
    489.   // the axis value, G92 similarly to G10 L20, and G28/30 as an intermediate target position that observes
    490.   // all the current coordinate system and G92 offsets.
    491.   switch (gc_block.non_modal_command) {
    492.     case NON_MODAL_SET_COORDINATE_DATA:  
    493.       // [G10 Errors]: L missing and is not 2 or 20. P word missing. (Negative P value done.)
    494.       // [G10 L2 Errors]: R word NOT SUPPORTED. P value not 0 to nCoordSys(max 9). Axis words missing.
    495.       // [G10 L20 Errors]: P must be 0 to nCoordSys(max 9). Axis words missing.
    496.       if (!axis_words) { FAIL(STATUS_GCODE_NO_AXIS_WORDS) }; // [No axis words]
    497.       if (bit_isfalse(value_words,((1<<WORD_P)|(1<<WORD_L)))) { FAIL(STATUS_GCODE_VALUE_WORD_MISSING); } // [P/L word missing]
    498.       coord_select = trunc(gc_block.values.p); // Convert p value to int.
    499.       if (coord_select > N_COORDINATE_SYSTEM) { FAIL(STATUS_GCODE_UNSUPPORTED_COORD_SYS); } // [Greater than N sys]
    500.       if (gc_block.values.l != 20) {
    501.         if (gc_block.values.l == 2) {
    502.           if (bit_istrue(value_words,bit(WORD_R))) { FAIL(STATUS_GCODE_UNSUPPORTED_COMMAND); } // [G10 L2 R not supported]
    503.         } else { FAIL(STATUS_GCODE_UNSUPPORTED_COMMAND); } // [Unsupported L]
    504.       }
    505.       bit_false(value_words,(bit(WORD_L)|bit(WORD_P)));
    506.       
    507.       // Determine coordinate system to change and try to load from EEPROM.
    508.       if (coord_select > 0) { coord_select--; } // Adjust P1-P6 index to EEPROM coordinate data indexing.
    509.       else { coord_select = gc_block.modal.coord_select; } // Index P0 as the active coordinate system
    510.       if (!settings_read_coord_data(coord_select,parameter_data)) { FAIL(STATUS_SETTING_READ_FAIL); } // [EEPROM read fail]
    511.    
    512.       // Pre-calculate the coordinate data changes. NOTE: Uses parameter_data since coordinate_data may be in use by G54-59.
    513.       for (idx=0; idx<N_AXIS; idx++) { // Axes indices are consistent, so loop may be used.
    514.         // Update axes defined only in block. Always in machine coordinates. Can change non-active system.
    515.         if (bit_istrue(axis_words,bit(idx)) ) {
    516.           if (gc_block.values.l == 20) {
    517.             // L20: Update coordinate system axis at current position (with modifiers) with programmed value
    518.             parameter_data[idx] = gc_state.position[idx]-gc_state.coord_offset[idx]-gc_block.values.xyz[idx];
    519.             if (idx == TOOL_LENGTH_OFFSET_AXIS) { parameter_data[idx] -= gc_state.tool_length_offset; }
    520.           } else {
    521.             // L2: Update coordinate system axis to programmed value.
    522.             parameter_data[idx] = gc_block.values.xyz[idx];
    523.           }
    524.         }
    525.       }
    526.       break;
    527.     case NON_MODAL_SET_COORDINATE_OFFSET:
    528.       // [G92 Errors]: No axis words.
    529.       if (!axis_words) { FAIL(STATUS_GCODE_NO_AXIS_WORDS); } // [No axis words]
    530.    
    531.       // Update axes defined only in block. Offsets current system to defined value. Does not update when
    532.       // active coordinate system is selected, but is still active unless G92.1 disables it.
    533.       for (idx=0; idx<N_AXIS; idx++) { // Axes indices are consistent, so loop may be used.
    534.         if (bit_istrue(axis_words,bit(idx)) ) {
    535.           gc_block.values.xyz[idx] = gc_state.position[idx]-coordinate_data[idx]-gc_block.values.xyz[idx];
    536.           if (idx == TOOL_LENGTH_OFFSET_AXIS) { gc_block.values.xyz[idx] -= gc_state.tool_length_offset; }
    537.         } else {
    538.           gc_block.values.xyz[idx] = gc_state.coord_offset[idx];
    539.         }
    540.       }
    541.       break;
    542.       
    543.     default:

    544.       // At this point, the rest of the explicit axis commands treat the axis values as the traditional
    545.       // target position with the coordinate system offsets, G92 offsets, absolute override, and distance
    546.       // modes applied. This includes the motion mode commands. We can now pre-compute the target position.
    547.       // NOTE: Tool offsets may be appended to these conversions when/if this feature is added.
    548.       if (axis_command != AXIS_COMMAND_TOOL_LENGTH_OFFSET ) { // TLO block any axis command.
    549.         if (axis_words) {
    550.           for (idx=0; idx<N_AXIS; idx++) { // Axes indices are consistent, so loop may be used to save flash space.
    551.             if ( bit_isfalse(axis_words,bit(idx)) ) {
    552.               gc_block.values.xyz[idx] = gc_state.position[idx]; // No axis word in block. Keep same axis position.
    553.             } else {
    554.               // Update specified value according to distance mode or ignore if absolute override is active.
    555.               // NOTE: G53 is never active with G28/30 since they are in the same modal group.
    556.               if (gc_block.non_modal_command != NON_MODAL_ABSOLUTE_OVERRIDE) {
    557.                 // Apply coordinate offsets based on distance mode.
    558.                 if (gc_block.modal.distance == DISTANCE_MODE_ABSOLUTE) {
    559.                   gc_block.values.xyz[idx] += coordinate_data[idx] + gc_state.coord_offset[idx];
    560.                   if (idx == TOOL_LENGTH_OFFSET_AXIS) { gc_block.values.xyz[idx] += gc_state.tool_length_offset; }
    561.                 } else {  // Incremental mode
    562.                   gc_block.values.xyz[idx] += gc_state.position[idx];
    563.                 }
    564.               }
    565.             }
    566.           }
    567.         }
    568.       }
    569.          
    570.       // Check remaining non-modal commands for errors.
    571.       switch (gc_block.non_modal_command) {        
    572.         case NON_MODAL_GO_HOME_0:
    573.           // [G28 Errors]: Cutter compensation is enabled.
    574.           // Retreive G28 go-home position data (in machine coordinates) from EEPROM
    575.           if (!axis_words) { axis_command = AXIS_COMMAND_NONE; } // Set to none if no intermediate motion.
    576.           if (!settings_read_coord_data(SETTING_INDEX_G28,parameter_data)) { FAIL(STATUS_SETTING_READ_FAIL); }
    577.           break;
    578.         case NON_MODAL_GO_HOME_1:
    579.           // [G30 Errors]: Cutter compensation is enabled.
    580.           // Retreive G30 go-home position data (in machine coordinates) from EEPROM
    581.           if (!axis_words) { axis_command = AXIS_COMMAND_NONE; } // Set to none if no intermediate motion.
    582.           if (!settings_read_coord_data(SETTING_INDEX_G30,parameter_data)) { FAIL(STATUS_SETTING_READ_FAIL); }
    583.           break;
    584.         case NON_MODAL_SET_HOME_0: case NON_MODAL_SET_HOME_1:
    585.           // [G28.1/30.1 Errors]: Cutter compensation is enabled.
    586.           // NOTE: If axis words are passed here, they are interpreted as an implicit motion mode.
    587.           break;
    588.         case NON_MODAL_RESET_COORDINATE_OFFSET:
    589.           // NOTE: If axis words are passed here, they are interpreted as an implicit motion mode.
    590.           break;
    591.         case NON_MODAL_ABSOLUTE_OVERRIDE:
    592.           // [G53 Errors]: G0 and G1 are not active. Cutter compensation is enabled.
    593.           // NOTE: All explicit axis word commands are in this modal group. So no implicit check necessary.
    594.           if (!(gc_block.modal.motion == MOTION_MODE_SEEK || gc_block.modal.motion == MOTION_MODE_LINEAR)) {
    595.             FAIL(STATUS_GCODE_G53_INVALID_MOTION_MODE); // [G53 G0/1 not active]
    596.           }
    597.           break;
    598.       }
    599.   }
    600.       
    601.   // [20. Motion modes ]:
    602.   if (gc_block.modal.motion == MOTION_MODE_NONE) {
    603.     // [G80 Errors]: Axis word exist and are not used by a non-modal command.
    604.     if ((axis_words) && (axis_command != AXIS_COMMAND_NON_MODAL)) {
    605.       FAIL(STATUS_GCODE_AXIS_WORDS_EXIST); // [No axis words allowed]
    606.     }

    607.   // Check remaining motion modes, if axis word are implicit (exist and not used by G10/28/30/92), or
    608.   // was explicitly commanded in the g-code block.
    609.   } else if ( axis_command == AXIS_COMMAND_MOTION_MODE ) {
    610.   
    611.     if (gc_block.modal.motion == MOTION_MODE_SEEK) {
    612.       // [G0 Errors]: Axis letter not configured or without real value (done.)
    613.       // Axis words are optional. If missing, set axis command flag to ignore execution.
    614.       if (!axis_words) { axis_command = AXIS_COMMAND_NONE; }

    615.     // All remaining motion modes (all but G0 and G80), require a valid feed rate value. In units per mm mode,
    616.     // the value must be positive. In inverse time mode, a positive value must be passed with each block.
    617.     } else {      
    618.       // Check if feed rate is defined for the motion modes that require it.
    619.       if (gc_block.values.f == 0.0) { FAIL(STATUS_GCODE_UNDEFINED_FEED_RATE); } // [Feed rate undefined]
    620.      
    621.       switch (gc_block.modal.motion) {
    622.         case MOTION_MODE_LINEAR:
    623.           // [G1 Errors]: Feed rate undefined. Axis letter not configured or without real value.
    624.           // Axis words are optional. If missing, set axis command flag to ignore execution.
    625.           if (!axis_words) { axis_command = AXIS_COMMAND_NONE; }

    626.           break;
    627.         case MOTION_MODE_CW_ARC: case MOTION_MODE_CCW_ARC:
    628.           // [G2/3 Errors All-Modes]: Feed rate undefined.
    629.           // [G2/3 Radius-Mode Errors]: No axis words in selected plane. Target point is same as current.
    630.           // [G2/3 Offset-Mode Errors]: No axis words and/or offsets in selected plane. The radius to the current
    631.           //   point and the radius to the target point differs more than 0.002mm (EMC def. 0.5mm OR 0.005mm and 0.1% radius).   
    632.           // [G2/3 Full-Circle-Mode Errors]: NOT SUPPORTED. Axis words exist. No offsets programmed. P must be an integer.        
    633.           // NOTE: Both radius and offsets are required for arc tracing and are pre-computed with the error-checking.
    634.         
    635.           if (!axis_words) { FAIL(STATUS_GCODE_NO_AXIS_WORDS); } // [No axis words]
    636.           if (!(axis_words & (bit(axis_0)|bit(axis_1)))) { FAIL(STATUS_GCODE_NO_AXIS_WORDS_IN_PLANE); } // [No axis words in plane]
    637.         
    638.           // Calculate the change in position along each selected axis
    639.           float x,y;
    640.           x = gc_block.values.xyz[axis_0]-gc_state.position[axis_0]; // Delta x between current position and target
    641.           y = gc_block.values.xyz[axis_1]-gc_state.position[axis_1]; // Delta y between current position and target

    642.           if (value_words & bit(WORD_R)) { // Arc Radius Mode  
    643.             bit_false(value_words,bit(WORD_R));
    644.             if (gc_check_same_position(gc_state.position, gc_block.values.xyz)) { FAIL(STATUS_GCODE_INVALID_TARGET); } // [Invalid target]
    645.          
    646.             // Convert radius value to proper units.
    647.             if (gc_block.modal.units == UNITS_MODE_INCHES) { gc_block.values.r *= MM_PER_INCH; }
    648.             /*  We need to calculate the center of the circle that has the designated radius and passes
    649.                 through both the current position and the target position. This method calculates the following
    650.                 set of equations where [x,y] is the vector from current to target position, d == magnitude of
    651.                 that vector, h == hypotenuse of the ** formed by the radius of the circle, the distance to
    652.                 the center of the travel vector. A vector perpendicular to the travel vector [-y,x] is scaled to the
    653.                 length of h [-y/d*h, x/d*h] and added to the center of the travel vector [x/2,y/2] to form the new point
    654.                 [i,j] at [x/2-y/d*h, y/2+x/d*h] which will be the center of our arc.
    655.    
    656.                 d^2 == x^2 + y^2
    657.                 h^2 == r^2 - (d/2)^2
    658.                 i == x/2 - y/d*h
    659.                 j == y/2 + x/d*h
    660.    
    661.                                                                      O <- [i,j]
    662.                                                                   -  |
    663.                                                         r      -     |
    664.                                                             -        |
    665.                                                          -           | h
    666.                                                       -              |
    667.                                         [0,0] ->  C -----------------+--------------- T  <- [x,y]
    668.                                                   | <------ d/2 ---->|
    669.               
    670.                 C - Current position
    671.                 T - Target position
    672.                 O - center of circle that pass through both C and T
    673.                 d - distance from C to T
    674.                 r - designated radius
    675.                 h - distance from center of CT to O
    676.    
    677.                 Expanding the equations:

    678.                 d -> sqrt(x^2 + y^2)
    679.                 h -> sqrt(4 * r^2 - x^2 - y^2)/2
    680.                 i -> (x - (y * sqrt(4 * r^2 - x^2 - y^2)) / sqrt(x^2 + y^2)) / 2
    681.                 j -> (y + (x * sqrt(4 * r^2 - x^2 - y^2)) / sqrt(x^2 + y^2)) / 2
    682.    
    683.                 Which can be written:
    684.    
    685.                 i -> (x - (y * sqrt(4 * r^2 - x^2 - y^2))/sqrt(x^2 + y^2))/2
    686.                 j -> (y + (x * sqrt(4 * r^2 - x^2 - y^2))/sqrt(x^2 + y^2))/2
    687.    
    688.                 Which we for size and speed reasons optimize to:

    689.                 h_x2_div_d = sqrt(4 * r^2 - x^2 - y^2)/sqrt(x^2 + y^2)
    690.                 i = (x - (y * h_x2_div_d))/2
    691.                 j = (y + (x * h_x2_div_d))/2      
    692.             */      

    693.             // First, use h_x2_div_d to compute 4*h^2 to check if it is negative or r is smaller
    694.             // than d. If so, the sqrt of a negative number is complex and error out.
    695.             float h_x2_div_d = 4.0 * gc_block.values.r*gc_block.values.r - x*x - y*y;

    696.             if (h_x2_div_d < 0) { FAIL(STATUS_GCODE_ARC_RADIUS_ERROR); } // [Arc radius error]
    697.    
    698.             // Finish computing h_x2_div_d.
    699.             h_x2_div_d = -sqrt(h_x2_div_d)/hypot_f(x,y); // == -(h * 2 / d)
    700.             // Invert the sign of h_x2_div_d if the circle is counter clockwise (see sketch below)
    701.             if (gc_block.modal.motion == MOTION_MODE_CCW_ARC) { h_x2_div_d = -h_x2_div_d; }  

    702.             /* The counter clockwise circle lies to the left of the target direction. When offset is positive,
    703.                the left hand circle will be generated - when it is negative the right hand circle is generated.
    704.          
    705.                                                                    T  <-- Target position
    706.                                                    
    707.                                                                    ^
    708.                         Clockwise circles with this center         |          Clockwise circles with this center will have
    709.                         will have > 180 deg of angular travel      |          < 180 deg of angular travel, which is a good thing!
    710.                                                          \         |          /   
    711.             center of arc when h_x2_div_d is positive ->  x <----- | -----> x <- center of arc when h_x2_div_d is negative
    712.                                                                    |
    713.                                                                    |
    714.                                                    
    715.                                                                    C  <-- Current position                                
    716.             */  
    717.             // Negative R is g-code-alese for "I want a circle with more than 180 degrees of travel" (go figure!),
    718.             // even though it is advised against ever generating such circles in a single line of g-code. By
    719.             // inverting the sign of h_x2_div_d the center of the circles is placed on the opposite side of the line of
    720.             // travel and thus we get the unadvisably long arcs as prescribed.
    721.             if (gc_block.values.r < 0) {
    722.                 h_x2_div_d = -h_x2_div_d;
    723.                 gc_block.values.r = -gc_block.values.r; // Finished with r. Set to positive for mc_arc
    724.             }        
    725.             // Complete the operation by calculating the actual center of the arc
    726.             gc_block.values.ijk[axis_0] = 0.5*(x-(y*h_x2_div_d));
    727.             gc_block.values.ijk[axis_1] = 0.5*(y+(x*h_x2_div_d));
    728.          
    729.           } else { // Arc Center Format Offset Mode  
    730.             if (!(ijk_words & (bit(axis_0)|bit(axis_1)))) { FAIL(STATUS_GCODE_NO_OFFSETS_IN_PLANE); } // [No offsets in plane]
    731.             bit_false(value_words,(bit(WORD_I)|bit(WORD_J)|bit(WORD_K)));  
    732.          
    733.             // Convert IJK values to proper units.
    734.             if (gc_block.modal.units == UNITS_MODE_INCHES) {
    735.               for (idx=0; idx<N_AXIS; idx++) { // Axes indices are consistent, so loop may be used to save flash space.
    736.                 if (ijk_words & bit(idx)) { gc_block.values.ijk[idx] *= MM_PER_INCH; }
    737.               }
    738.             }         

    739.             // Arc radius from center to target
    740.             x -= gc_block.values.ijk[axis_0]; // Delta x between circle center and target
    741.             y -= gc_block.values.ijk[axis_1]; // Delta y between circle center and target
    742.             float target_r = hypot_f(x,y);

    743.             // Compute arc radius for mc_arc. Defined from current location to center.
    744.             gc_block.values.r = hypot_f(gc_block.values.ijk[axis_0], gc_block.values.ijk[axis_1]);
    745.             
    746.             // Compute difference between current location and target radii for final error-checks.
    747.             float delta_r = fabs(target_r-gc_block.values.r);
    748.             if (delta_r > 0.005) {
    749.               if (delta_r > 0.5) { FAIL(STATUS_GCODE_INVALID_TARGET); } // [Arc definition error] > 0.5mm
    750.               if (delta_r > (0.001*gc_block.values.r)) { FAIL(STATUS_GCODE_INVALID_TARGET); } // [Arc definition error] > 0.005mm AND 0.1% radius
    751.             }
    752.           }
    753.           break;
    754.         case MOTION_MODE_PROBE_TOWARD: case MOTION_MODE_PROBE_TOWARD_NO_ERROR:
    755.         case MOTION_MODE_PROBE_AWAY: case MOTION_MODE_PROBE_AWAY_NO_ERROR:
    756.           // [G38 Errors]: Target is same current. No axis words. Cutter compensation is enabled. Feed rate
    757.           //   is undefined. Probe is triggered. NOTE: Probe check moved to probe cycle. Instead of returning
    758.           //   an error, it issues an alarm to prevent further motion to the probe. It's also done there to
    759.           //   allow the planner buffer to empty and move off the probe trigger before another probing cycle.
    760.           if (!axis_words) { FAIL(STATUS_GCODE_NO_AXIS_WORDS); } // [No axis words]
    761.           if (gc_check_same_position(gc_state.position, gc_block.values.xyz)) { FAIL(STATUS_GCODE_INVALID_TARGET); } // [Invalid target]
    762.           break;
    763.       }
    764.     }
    765.   }
    766.   
    767.   // [21. Program flow ]: No error checks required.

    768.   // [0. Non-specific error-checks]: Complete unused value words check, i.e. IJK used when in arc
    769.   // radius mode, or axis words that aren't used in the block.  
    770.   bit_false(value_words,(bit(WORD_N)|bit(WORD_F)|bit(WORD_S)|bit(WORD_T))); // Remove single-meaning value words.
    771.   if (axis_command) { bit_false(value_words,(bit(WORD_X)|bit(WORD_Y)|bit(WORD_Z))); } // Remove axis words.
    772.   if (value_words) { FAIL(STATUS_GCODE_UNUSED_WORDS); } // [Unused words]

    773.    
    774.   /* -------------------------------------------------------------------------------------
    775.      STEP 4: EXECUTE!!
    776.      Assumes that all error-checking has been completed and no failure modes exist. We just
    777.      need to update the state and execute the block according to the order-of-execution.
    778.   */
    779.   
    780.   // [0. Non-specific/common error-checks and miscellaneous setup]:
    781.   gc_state.line_number = gc_block.values.n;
    782.   
    783.   // [1. Comments feedback ]:  NOT SUPPORTED
    784.   
    785.   // [2. Set feed rate mode ]:
    786.   gc_state.modal.feed_rate = gc_block.modal.feed_rate;
    787.   
    788.   // [3. Set feed rate ]:
    789.   gc_state.feed_rate = gc_block.values.f; // Always copy this value. See feed rate error-checking.

    790.   // [4. Set spindle speed ]:
    791.   if (gc_state.spindle_speed != gc_block.values.s) {
    792.     // Update running spindle only if not in check mode and not already enabled.
    793.     if (gc_state.modal.spindle != SPINDLE_DISABLE) { spindle_run(gc_state.modal.spindle, gc_block.values.s); }
    794.     gc_state.spindle_speed = gc_block.values.s;
    795.   }
    796.    
    797.   // [5. Select tool ]: NOT SUPPORTED. Only tracks tool value.
    798.   gc_state.tool = gc_block.values.t;

    799.   // [6. Change tool ]: NOT SUPPORTED

    800.   // [7. Spindle control ]:
    801.   if (gc_state.modal.spindle != gc_block.modal.spindle) {
    802.     // Update spindle control and apply spindle speed when enabling it in this block.   
    803.     spindle_run(gc_block.modal.spindle, gc_state.spindle_speed);
    804.     gc_state.modal.spindle = gc_block.modal.spindle;   
    805.   }

    806.   // [8. Coolant control ]:  
    807.   if (gc_state.modal.coolant != gc_block.modal.coolant) {
    808.     coolant_run(gc_block.modal.coolant);
    809.     gc_state.modal.coolant = gc_block.modal.coolant;
    810.   }
    811.   
    812.   // [9. Enable/disable feed rate or spindle overrides ]: NOT SUPPORTED

    813.   // [10. Dwell ]:
    814.   if (gc_block.non_modal_command == NON_MODAL_DWELL) { mc_dwell(gc_block.values.p); }
    815.   
    816.   // [11. Set active plane ]:
    817.   gc_state.modal.plane_select = gc_block.modal.plane_select;  

    818.   // [12. Set length units ]:
    819.   gc_state.modal.units = gc_block.modal.units;

    820.   // [13. Cutter radius compensation ]: G41/42 NOT SUPPORTED
    821.   // gc_state.modal.cutter_comp = gc_block.modal.cutter_comp; // NOTE: Not needed since always disabled.

    822.   // [14. Cutter length compensation ]: G43.1 and G49 supported. G43 NOT SUPPORTED.
    823.   // NOTE: If G43 were supported, its operation wouldn't be any different from G43.1 in terms
    824.   // of execution. The error-checking step would simply load the offset value into the correct
    825.   // axis of the block XYZ value array.
    826.   if (axis_command == AXIS_COMMAND_TOOL_LENGTH_OFFSET ) { // Indicates a change.
    827.     gc_state.modal.tool_length = gc_block.modal.tool_length;
    828.     if (gc_state.modal.tool_length == TOOL_LENGTH_OFFSET_ENABLE_DYNAMIC) { // G43.1
    829.       gc_state.tool_length_offset = gc_block.values.xyz[TOOL_LENGTH_OFFSET_AXIS];
    830.     } else { // G49
    831.       gc_state.tool_length_offset = 0.0;
    832.     }
    833.   }
    834.   
    835.   // [15. Coordinate system selection ]:
    836.   if (gc_state.modal.coord_select != gc_block.modal.coord_select) {
    837.     gc_state.modal.coord_select = gc_block.modal.coord_select;
    838.     memcpy(gc_state.coord_system,coordinate_data,sizeof(coordinate_data));
    839.   }
    840.   
    841.   // [16. Set path control mode ]: G61.1/G64 NOT SUPPORTED
    842.   // gc_state.modal.control = gc_block.modal.control; // NOTE: Always default.
    843.   
    844.   // [17. Set distance mode ]:
    845.   gc_state.modal.distance = gc_block.modal.distance;
    846.   
    847.   // [18. Set retract mode ]: NOT SUPPORTED
    848.    
    849.   // [19. Go to predefined position, Set G10, or Set axis offsets ]:
    850.   switch(gc_block.non_modal_command) {
    851.     case NON_MODAL_SET_COORDINATE_DATA:   
    852.       settings_write_coord_data(coord_select,parameter_data);
    853.       // Update system coordinate system if currently active.
    854.       if (gc_state.modal.coord_select == coord_select) { memcpy(gc_state.coord_system,parameter_data,sizeof(parameter_data)); }
    855.       break;
    856.     case NON_MODAL_GO_HOME_0: case NON_MODAL_GO_HOME_1:
    857.       // Move to intermediate position before going home. Obeys current coordinate system and offsets
    858.       // and absolute and incremental modes.
    859.       if (axis_command) {
    860.         #ifdef USE_LINE_NUMBERS
    861.           mc_line(gc_block.values.xyz, -1.0, false, gc_state.line_number);
    862.         #else
    863.           mc_line(gc_block.values.xyz, -1.0, false);
    864.         #endif
    865.       }
    866.       #ifdef USE_LINE_NUMBERS
    867.         mc_line(parameter_data, -1.0, false, gc_state.line_number);
    868.       #else
    869.         mc_line(parameter_data, -1.0, false);
    870.       #endif
    871.       memcpy(gc_state.position, parameter_data, sizeof(parameter_data));
    872.       break;
    873.     case NON_MODAL_SET_HOME_0:
    874.       settings_write_coord_data(SETTING_INDEX_G28,gc_state.position);
    875.       break;
    876.     case NON_MODAL_SET_HOME_1:
    877.       settings_write_coord_data(SETTING_INDEX_G30,gc_state.position);
    878.       break;
    879.     case NON_MODAL_SET_COORDINATE_OFFSET:
    880.       memcpy(gc_state.coord_offset,gc_block.values.xyz,sizeof(gc_block.values.xyz));
    881.       break;
    882.     case NON_MODAL_RESET_COORDINATE_OFFSET:
    883.       clear_vector(gc_state.coord_offset); // Disable G92 offsets by zeroing offset vector.
    884.       break;
    885.   }

    886.   
    887.   // [20. Motion modes ]:
    888.   // NOTE: Commands G10,G28,G30,G92 lock out and prevent axis words from use in motion modes.
    889.   // Enter motion modes only if there are axis words or a motion mode command word in the block.
    890.   gc_state.modal.motion = gc_block.modal.motion;
    891.   if (gc_state.modal.motion != MOTION_MODE_NONE) {
    892.     if (axis_command == AXIS_COMMAND_MOTION_MODE) {
    893.       switch (gc_state.modal.motion) {
    894.         case MOTION_MODE_SEEK:
    895.           #ifdef USE_LINE_NUMBERS
    896.             mc_line(gc_block.values.xyz, -1.0, false, gc_state.line_number);
    897.           #else
    898.             mc_line(gc_block.values.xyz, -1.0, false);
    899.           #endif
    900.           break;
    901.         case MOTION_MODE_LINEAR:
    902.           #ifdef USE_LINE_NUMBERS
    903.             mc_line(gc_block.values.xyz, gc_state.feed_rate, gc_state.modal.feed_rate, gc_state.line_number);
    904.           #else
    905.             mc_line(gc_block.values.xyz, gc_state.feed_rate, gc_state.modal.feed_rate);
    906.           #endif
    907.           break;
    908.         case MOTION_MODE_CW_ARC:
    909.           #ifdef USE_LINE_NUMBERS
    910.             mc_arc(gc_state.position, gc_block.values.xyz, gc_block.values.ijk, gc_block.values.r,
    911.               gc_state.feed_rate, gc_state.modal.feed_rate, axis_0, axis_1, axis_linear, true, gc_state.line_number);  
    912.           #else
    913.             mc_arc(gc_state.position, gc_block.values.xyz, gc_block.values.ijk, gc_block.values.r,
    914.               gc_state.feed_rate, gc_state.modal.feed_rate, axis_0, axis_1, axis_linear, true);
    915.           #endif
    916.           break;        
    917.         case MOTION_MODE_CCW_ARC:
    918.           #ifdef USE_LINE_NUMBERS
    919.             mc_arc(gc_state.position, gc_block.values.xyz, gc_block.values.ijk, gc_block.values.r,
    920.               gc_state.feed_rate, gc_state.modal.feed_rate, axis_0, axis_1, axis_linear, false, gc_state.line_number);  
    921.           #else
    922.             mc_arc(gc_state.position, gc_block.values.xyz, gc_block.values.ijk, gc_block.values.r,
    923.               gc_state.feed_rate, gc_state.modal.feed_rate, axis_0, axis_1, axis_linear, false);
    924.           #endif
    925.           break;
    926.         case MOTION_MODE_PROBE_TOWARD:
    927.           // NOTE: gc_block.values.xyz is returned from mc_probe_cycle with the updated position value. So
    928.           // upon a successful probing cycle, the machine position and the returned value should be the same.
    929.           #ifdef USE_LINE_NUMBERS
    930.             mc_probe_cycle(gc_block.values.xyz, gc_state.feed_rate, gc_state.modal.feed_rate, false, false, gc_state.line_number);
    931.           #else
    932.             mc_probe_cycle(gc_block.values.xyz, gc_state.feed_rate, gc_state.modal.feed_rate, false, false);
    933.           #endif
    934.           break;
    935.         case MOTION_MODE_PROBE_TOWARD_NO_ERROR:
    936.           #ifdef USE_LINE_NUMBERS
    937.             mc_probe_cycle(gc_block.values.xyz, gc_state.feed_rate, gc_state.modal.feed_rate, false, true, gc_state.line_number);
    938.           #else
    939.             mc_probe_cycle(gc_block.values.xyz, gc_state.feed_rate, gc_state.modal.feed_rate, false, true);
    940.           #endif
    941.           break;
    942.         case MOTION_MODE_PROBE_AWAY:
    943.           #ifdef USE_LINE_NUMBERS
    944.             mc_probe_cycle(gc_block.values.xyz, gc_state.feed_rate, gc_state.modal.feed_rate, true, false, gc_state.line_number);
    945.           #else
    946.             mc_probe_cycle(gc_block.values.xyz, gc_state.feed_rate, gc_state.modal.feed_rate, true, false);
    947.           #endif
    948.           break;
    949.         case MOTION_MODE_PROBE_AWAY_NO_ERROR:
    950.           #ifdef USE_LINE_NUMBERS
    951.             mc_probe_cycle(gc_block.values.xyz, gc_state.feed_rate, gc_state.modal.feed_rate, true, true, gc_state.line_number);
    952.           #else        
    953.             mc_probe_cycle(gc_block.values.xyz, gc_state.feed_rate, gc_state.modal.feed_rate, true, true);
    954.           #endif
    955.       }
    956.    
    957.       // As far as the parser is concerned, the position is now == target. In reality the
    958.       // motion control system might still be processing the action and the real tool position
    959.       // in any intermediate location.
    960.       memcpy(gc_state.position, gc_block.values.xyz, sizeof(gc_block.values.xyz)); // gc_state.position[] = gc_block.values.xyz[]
    961.     }
    962.   }
    963.   
    964.   // [21. Program flow ]:
    965.   // M0,M1,M2,M30: Perform non-running program flow actions. During a program pause, the buffer may
    966.   // refill and can only be resumed by the cycle start run-time command.
    967.   gc_state.modal.program_flow = gc_block.modal.program_flow;
    968.   if (gc_state.modal.program_flow) {
    969.         protocol_buffer_synchronize(); // Sync and finish all remaining buffered motions before moving on.
    970.         if (gc_state.modal.program_flow == PROGRAM_FLOW_PAUSED) {
    971.           if (sys.state != STATE_CHECK_MODE) {
    972.                 bit_true_atomic(sys_rt_exec_state, EXEC_FEED_HOLD); // Use feed hold for program pause.
    973.                 protocol_execute_realtime(); // Execute suspend.
    974.           }
    975.         } else { // == PROGRAM_FLOW_COMPLETED
    976.           // Upon program complete, only a subset of g-codes reset to certain defaults, according to
    977.           // LinuxCNC's program end descriptions and testing. Only modal groups [G-code 1,2,3,5,7,12]
    978.           // and [M-code 7,8,9] reset to [G1,G17,G90,G94,G40,G54,M5,M9,M48]. The remaining modal groups
    979.           // [G-code 4,6,8,10,13,14,15] and [M-code 4,5,6] and the modal words [F,S,T,H] do not reset.
    980.           gc_state.modal.motion = MOTION_MODE_LINEAR;
    981.           gc_state.modal.plane_select = PLANE_SELECT_XY;
    982.           gc_state.modal.distance = DISTANCE_MODE_ABSOLUTE;
    983.           gc_state.modal.feed_rate = FEED_RATE_MODE_UNITS_PER_MIN;
    984.           // gc_state.modal.cutter_comp = CUTTER_COMP_DISABLE; // Not supported.
    985.           gc_state.modal.coord_select = 0; // G54
    986.           gc_state.modal.spindle = SPINDLE_DISABLE;
    987.           gc_state.modal.coolant = COOLANT_DISABLE;
    988.           // gc_state.modal.override = OVERRIDE_DISABLE; // Not supported.
    989.           
    990.           // Execute coordinate change and spindle/coolant stop.
    991.           if (sys.state != STATE_CHECK_MODE) {
    992.                 if (!(settings_read_coord_data(gc_state.modal.coord_select,coordinate_data))) { FAIL(STATUS_SETTING_READ_FAIL); }
    993.                 memcpy(gc_state.coord_system,coordinate_data,sizeof(coordinate_data));
    994.                 spindle_stop();
    995.                 coolant_stop();               
    996.           }
    997.           
    998.           report_feedback_message(MESSAGE_PROGRAM_END);
    999.         }
    1000.     gc_state.modal.program_flow = PROGRAM_FLOW_RUNNING; // Reset program flow.
    1001.   }
    1002.    
    1003.   // TODO: % to denote start of program.
    1004.   return(STATUS_OK);
    1005. }
    1006.         
    复制代码


    stm32,FPGA
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2018-9-20 10:48
  • 签到天数: 189 天

    [LV.7]常住居民III

    392

    主题

    1442

    帖子

    6972

    积分

    版主

    Rank: 7Rank: 7Rank: 7

    积分
    6972
    QQ
    发表于 2018-6-14 16:25:28  | 显示全部楼层
    本帖最后由 STM64 于 2018-6-14 16:43 编辑

    开发快无线控制激光雕刻机
    测试图档:标准框框NC:
    %2.NC (247.92 KB, 下载次数: 0)
    三轴来回NC:(去Z功能)
    %4.NC (574.45 KB, 下载次数: 0)
    四轴转二轴测试NC:
    %5.NC (611.49 KB, 下载次数: 0)
    五轴转二轴测试NC:
    %6.NC (37.43 KB, 下载次数: 0)


    电脑版测试图档:
    渐变色测试图:
    timg.jpg

    标准灰度测试图:
    372840cc.jpg

    大面积黑色区域边缘烧焦均衡测试图:
    734220cb.jpg

    大面积灰度区域测试图:
    t01be2b13d1da9f10b7.jpg

    动图取第一帧测试图:
    20180610135842_8b4f3eca67a9f46661796cd2879a735a_3.gif

    调色板压缩图片解析测试图:
    955.jpg

    带透明数据的轮廓转换测试图:
    95.jpg

    stm32,FPGA
    回复 支持 反对

    使用道具 举报

    发表回复

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    关于我们
    开发快官网
    关于我们
    联系我们
    帮助中心
    开发者中心
    快速入门
    视频教程
    社区活动
    免费开发板
    开发者大赛
    关注我们
    官方微博
    官方空间
    快速回复 返回顶部 返回列表

    湘公网安备 43019002000310号