开源改变世界

Visualizer 无法识别来自 T2Laser 的 g 代码 #236

推推 grbl 3年前 (2023-02-02) 226次浏览
关闭
12 个任务中的第 4 个
danowar 打开了这个问题 2017 年 12 月 3 日 · 15条评论
关闭
12 个任务中的第 4 个

Visualizer 无法识别来自 T2Laser 的 g 代码#236

danowar 打开了这个问题 2017 年 12 月 3 日 · 15条评论

注释

Visualizer 无法识别来自 T2Laser 的 g 代码 #236

描述

T2Laser 是一款激光凸轮软件,设计用于低功率二极管激光雕刻机。该软件在每个 G0 运动中使用 M3 命令来控制激光功率(请参见下面的 g 代码片段)。此 M3 命令阻止可视化工具显示刀具路径。我通过从文件中删除所有 M3 命令并重新加载来验证这是原因。然后显示刀具路径,但没有它们激光不会打开。

是否可以让可视化工具忽略 M3 命令?

版本

  • CNCjs:1.9.11
  • 节点.js:7.10.1
  • NPM:5.5.1

你如何安装CNCjs?

  • NPM
  • 下载 CNCjs 桌面应用程序

数控系统

  • Grbl
  • 冰沙
  • TinyG/g2核心

硬件

  • 树莓派
  • 台式机或笔记本电脑
  • 移动设备

操作系统

  • 不适用
  • 视窗
  • 苹果
  • Linux
Visualizer 无法识别来自 T2Laser 的 g 代码 #236

您是要附上 gcode 示例吗?我没有看到一个。

Visualizer 无法识别来自 T2Laser 的 g 代码 #236
合作者

@danowar

请将您的 G 代码文件拖放到评论字段中,以便我们帮助解决此问题。

Visualizer 无法识别来自 T2Laser 的 g 代码 #236

@cheton – 我意识到我的电脑上有一份 T2Laser 的评估版,所以我用它来生成一些示例 GCode。它有这样一行:

G0 X1.1 M03 S0

维基百科关于 gcodes 和 mcodes 的文章包括一个同时包含 G 和 M 代码的行示例,因此该公式至少是合理的。

如果你愿意,我可以调查一下这个问题。我对 GCode 解析有一些经验。

Visualizer 无法识别来自 T2Laser 的 g 代码 #236
合作者
奇顿 评论了 2017 年 12 月 3 日  

gcode-toolpath生成的刀具路径gcode-interpreter预处理。在解释器内部,它按照G词和M词将词分成组。

https://github.com/cncjs/gcode-interpreter/blob/master/src/Interpreter.js#L36

const partitionWordsByGroup = (words = []) => {
    const groups = [];

    for (let i = 0; i < words.length; ++i) {
        const word = words[i];
        const letter = word[0];

        if ((letter === 'G') || (letter === 'M')) {
            groups.push([word]);
            continue;
        }

        if (groups.length > 0) {
            groups[groups.length - 1].push(word);
        } else {
            groups.push([word]);
        }
    }

    return groups;
};

@MitchBradley
作为您的示例,结果应该是[['G0', 'X1.1'], ['M03', 'S0']]. 我可能需要一个完整的示例来了解如何微调解释器。

Visualizer 无法识别来自 T2Laser 的 g 代码 #236
( Generated by T2Laser ) 
( Image2Gcode for Grbl )
( Start Point: LL      )
( Frame Mode : Abs.    )
( X Maximum  : 5.9     )
( Y Maximum  : 5.9     )
( Laser Max  : 255     )
( Feed Rate  : 1000    )
( Resolution : 0.1     )
( Image Name : Digit2.bmp )
G21
G90
F1000
M05
M03 S0
G01 X4.9 Y5.6 M03 S0
X4.8 M03 S255
X1 Y5.6 M03 S255
X0.9 M03 S0
X0.7 Y5.5 M03 S0
... many repetitions of similar lines with different coordinates
M03 S0
M05
G00 X0 Y0

注释:
M03 S0 保持激光器开启但将功率设置为 0
M03 S255 激光器以全功率开启

不同激光控制器的S值范围不同。

有些激光柱不使用 M03 S0,而是使用 M5 关闭激光。
我最熟悉的激光帖子将 M03 和 M05 命令与 G 动作放在不同的行上,但显然这个没有。

Visualizer 无法识别来自 T2Laser 的 g 代码 #236
合作者
奇顿 评论了 2017 年 12 月 3 日  

给定如下的 G 代码:

G01 X4.9 Y5.6 M03 S0
X4.8 M03 S255
X1 Y5.6 M03 S255

它将被 gcode-interpreter 分成以下几组:

cmd = G01, words = ['X4.9', 'Y5.6']
cmd = M03, words = ['S0']
cmd = M03, words = ['X4.8']
cmd = M03, words = ['S255']
cmd = M03, words = ['Y5.6']
cmd = M03, words = ['S255']

这将解释为什么没有生成刀具路径。

self.cmd我将通过不替换为M字来修复 gcode-interpreter 中的代码。

https://github.com/cncjs/gcode-interpreter/blob/master/src/Interpreter.js#L62-L77

if ((letter === 'G') || (letter === 'M')) {
    self.cmd = cmd;
    args = fromPairs(words.slice(1));
} else {
    // Use the same command if the line does not start with Gxx or Mxx.
    // For example:
    // G0 Z0.25
    //  X-0.5 Y0.
    //  Z0.1
    // G01 Z0. F5.
    //  X0.5 Y0. I0. J-0.5
    //  X0. Y-0.5 I-0.5 J0.
    //  X-0.5 Y0. I0. J0.5
    cmd = self.cmd;
    args = fromPairs(words);
}
Visualizer 无法识别来自 T2Laser 的 g 代码 #236

这似乎是一个很好的解决办法。我很确定 M 命令不应该在后续行中推断出来。

Visualizer 无法识别来自 T2Laser 的 g 代码 #236
Contributor

In fact, it might be better to infer the command only for G0 and G1 motion modes.

Visualizer 无法识别来自 T2Laser 的 g 代码 #236
Collaborator

Will all motion commands (e.g. G0, G1, G2, G3, G38.2, G38.3, G38.4, G38.5, G80) apply the same rule?

Visualizer 无法识别来自 T2Laser 的 g 代码 #236
Author
danowar commented 2017 年 12 月 3 日  

My bad, I forgot the code. Here is the first 50 lines of a job I just ran. It is worth mentioning, the job runs fine, just doesn’t visualize properly.

( Generated by T2Laser )
( Image2Gcode for Grbl )
( Start Point: Center )
( Frame Mode : Abs. )
( X Maximum : 84.4 )
( Y Maximum : 99.9 )
( Laser Max : 1000 )
( Feed Rate : 750 )
( Resolution : 0.1 )
( Image Name : text4272.png )
G21
G90
F750
M05
G00X0Y0F750
G92X42.2Y49.95
G90
G00 X0 Y0
G01
M03 S0
X5.2 Y0.2 M03 S0
X5.3 Y0.1 M03 S1000
X5.4 Y0 M03 S0
X5.5 Y0 M03 S0
X5.4 Y0.1 M03 S1000
X5.2 Y0.3 M03 S1000
X5.1 Y0.4 M03 S0
X5.2 Y0.4 M03 S0
X5.3 Y0.3 M03 S1000
X5.5 Y0.1 M03 S1000
X5.6 Y0 M03 S0
X5.7 Y0 M03 S0
X5.6 Y0.1 M03 S1000
X5.2 Y0.5 M03 S1000
X5.1 Y0.6 M03 S0
X5.2 Y0.6 M03 S0
X5.3 Y0.5 M03 S1000
X5.7 Y0.1 M03 S1000
X5.8 Y0 M03 S0
X5.9 Y0 M03 S0
X5.8 Y0.1 M03 S1000
X5.2 Y0 .7 M03 S1000
X5.1 Y0.8 M03 S0
X5.2 Y0.8 M03 S0
X5.3 Y0.7 M03 S1000
X5.9 Y0.1 M03 S1000
X6 Y0 M03 S0
X6.1 Y0 M03 S0
X6 Y0.1 M03 S1000
X5.2 Y0.9 M03 S1000

Visualizer 无法识别来自 T2Laser 的 g 代码 #236

所有这些 M03,除了第一个,都是不必要的。主轴速度(或激光功率)应仅随 Sxxx 变化。
@cheton All of the modal commands should persist until another in the same group is issued. A motion mode (G0) will replace a previous motion mode (G3), but it shouldn’t be replaced by a command from a different modal group or an m-code.

Visualizer 无法识别来自 T2Laser 的 g 代码 #236
Collaborator
cheton commented 2017 年 12 月 3 日  

Fixed in gcode-interpreter@2.0.1

G0, G1, G2, G3, G38.2, G38.3, G38.4, G38.5 will update the motion mode, and G80 will clear the motion mode.

if (letter === 'G') {
    cmd = (letter + code);
    args = fromPairs(words.slice(1));

    // Motion Mode
    if (code === 0 || code === 1 || code === 2 || code === 3 || code === 38.2 || code === 38.3 || code === 38.4 || code === 38.5) {
        self.motionMode = cmd;
    } else if (code === 80) {
        self.motionMode = '';
    }
} else if (letter === 'M') {
    cmd = (letter + code);
    args = fromPairs(words.slice(1));
} else if (letter === 'T') { // T1 ; w/o M6
    cmd = letter;
    args = code;
} else if (letter === 'F') { // F750 ; w/o motion command
    cmd = letter;
    args = code;
} else if (letter === 'X' || letter === 'Y' || letter === 'Z' || letter === 'A' || letter === 'B' || letter === 'C' || letter === 'I' || letter === 'J' || letter === 'K') {
    // Use previous motion command if the line does not start with G-code or M-code.
    // @example
    //   G0 Z0.25
    //   X-0.5 Y0.
    //   Z0.1
    //   G01 Z0. F5.
    //   G2 X0.5 Y0. I0. J-0.5
    //   X0. Y-0.5 I-0.5 J0.
    //   X-0.5 Y0. I0. J0.5
    // @example
    //   G01
    //   M03 S0
    //   X5.2 Y0.2 M03 S0
    //   X5.3 Y0.1 M03 S1000
    //   X5.4 Y0 M03 S0
    //   X5.5 Y0 M03 S0
    cmd = self.motionMode;
    args = fromPairs(words);
}
Visualizer 无法识别来自 T2Laser 的 g 代码 #236
Collaborator
cheton commented 2017 年 12 月 3 日  

@danowar

The bug fix will be included in CNCjs 1.9.12. For a temporary workaround, you can follow @neilferreri‘s suggestion to remove all M03s except the first one, as shown below:

M03 S0
X5.2 Y0.2 S0
X5.3 Y0.1 S1000
X5.4 Y0 S0
X5.5 Y0 S0

If you want a hot fix in short, I can give you a patched JavaScript bundle to replace the file for CNCjs 1.9.11.

Visualizer 无法识别来自 T2Laser 的 g 代码 #236 cheton added this to the 1.9 milestone 2017 年 12 月 4 日
Visualizer 无法识别来自 T2Laser 的 g 代码 #236
Author

Wow, that was quick work. Thanks for your help. I had done as you suggested (removing redundant M3s) during my testing and it worked well, but of course it is an extra step.

If the hot fix is simply enough to apply, I would take it. Otherwise I’ll wait for the next version.

Visualizer 无法识别来自 T2Laser 的 g 代码 #236 cheton mentioned this issue 2017 年 12 月 5 日
40 tasks
Visualizer 无法识别来自 T2Laser 的 g 代码 #236
Collaborator

Fixed in 1.9.12