Invalid characters error when trying to use "IF" statement in GCode

More
3 years 7 months ago #265879 by xph1l
Hi,
My very first post on this forum. Also pretty much my first CNC build - wasn't easy to set everything up in LinuxCNC but I just LOVE it.
I'm using LinuxCNC v2.9.0-pre0 with QtPlasmaC v1.233.249.

The issue I'm having is that when trying to use "if/else/endif" or "while/endwhile" statements in GCode, the QtPlasmaC throws an error "Invalid characters, line has been commented out".

Quick look into the source (main branch) and I found that it is triggered in src/emc/usr_intf/qtplasmac/qtplasmac_gcode.py, in illegal_character() function.
The code that triggered this is:
Code:
    elif line[0].isalpha():         # line starts with two alpha characters (this could be refined)         if line[1].isalpha(): return 1

This check was committed by:
Code:
commit 07f8e0af364e7c9594084e2c2b629f3bc45288bf Author: Phillip Carter <phillcarter54@gmail.com> Date:   Wed Dec 8 14:22:01 2021 +1100     qtplasmac: gcode filter          fix cut recovery bug     add more illegal character checks

My question is: was this behavior intentional, or was it an error? If intentional, then why?

Please Log in to join the conversation.

More
3 years 7 months ago #265880 by phillc54
Can you post the gcode.
 

Please Log in to join the conversation.

More
3 years 7 months ago #265881 by xph1l
Sure thing. The "if" statement at the end of pre-amble is the culprit.
Code:
;     file name: mill_hook_small.tap ; date and time: Sat Mar 04 2023    09:09:11 PM ; postprocessor: LinuxCNC_PlasmaC_Mod_v1.scpost rev: 0.2 ;                                   ;begin pre-amble                     G21 (units: metric)                G40 (cutter compensation: off)      G90 (distance mode: absolute)      M52 P1 (adaptive feed: on)         M65 P2 (enable THC)                 M65 P3 (enable torch)               M68 E3 Q0 (velocity 100%)         G64 P0.254 Q0.025 (tracking tolerances: 0.254mm)                                      if [#5400 eq 0]                     M30                                endif                                                                  ;end pre-amble                     ;                                  ;begin material setup               T0 M6 (select plasma tool)         G43 H0 (apply tool offsets)         F#<_hal[plasmac.cut-feed-rate]>    #<holes> = 2 (over-cut for small holes)  #<oclength> = 3.5 (over-cut length) ;end material setup                 G0 X12.8 Y16.488                  M3 $0 S1 (plasma start)             M67 E3 Q100                        G1 X9.901 Y19.387                   M67 E3 Q60               G3 X9.901 Y19.387 I2.899 J-2.899    M67 E3 Q100                              M5 $0 (plasma end)

Please Log in to join the conversation.

More
3 years 7 months ago #265882 by phillc54
You need to use o codes in that case.
linuxcnc.org/docs/html/gcode/o-code.html
e.g.
Code:
 o100 if [#5400 eq 0]   M30  0100 endif

You can use names instead of numbers:
o<check_m30>  instead of  o100

Please Log in to join the conversation.

More
3 years 7 months ago #265884 by xph1l
Awesome, it works! Thanks!

Sorry for bothering, but I've brushed over the o-codes page and haven't found the reason for having all conditionals under o-codes and not allowing to use IF as-is.
Maybe you know the reason on top of your head?

Please Log in to join the conversation.

More
3 years 7 months ago #265885 by phillc54
Personally I don't know. LinuxCNC follows the RS-274 gcode standards so it is probably part of that standard.

Please Log in to join the conversation.

More
3 years 7 months ago #265886 by xph1l
Got it. Will read up on that. Thanks for the help!

Please Log in to join the conversation.

More
3 years 7 months ago #265992 by andypugh

Sorry for bothering, but I've brushed over the o-codes page and haven't found the reason for having all conditionals under o-codes and not allowing to use IF as-is.
It's partly because of the way G-code consists of single-character commands. The I of "If" is only valid after certain G-codes, but the "F" could be a feed rate command. 

It's also partly because the parser doesn't have a loop / conditional stack to keep track of which IF belongs to which ENDIF. So the numbered O-words mean that if the condition fails the parser just needs to scan through the G-code waiting for the matching O else or O endif.  

Please Log in to join the conversation.

More
3 years 7 months ago #266081 by xph1l
Oh, it makes sense that O-words make parser less complicated. Thanks for the explanation!

Please Log in to join the conversation.

Time to create page: 0.093 seconds
Powered by Kunena Forum