Unexpected variables behavior when program is aborted (stopped)

More
31 Jul 2023 19:47 - 31 Jul 2023 19:48 #276656 by ContinenteCNC
Good morning/evening!

I have been experiencing a weird behavior with variables in ngcgui routines and I couldn’t find any topic with similar issues in forum.

Whenever I happen to stop a program before its natural end, every variable that I might set will assume the value as if the program had ran until the very end!

I believe this is not an expected behavior. I don’t know if it is a bug or not, but it looks like one. I have attached configuration files with a sample able to reproduce the issue.

To use it, please, go to the only ngcgui tab available (so called “macro”), create a feature and then finalize it. Proceed to run the program. The only thing it does is decrement the variable #1000 by 1 every time it loops. (The variable #1000 has been added to linuxcnc.var and its starting value will be =1000)

If one let the program run until the end the variable #1000 will end up =900.However, if you stop the program mid execution, it will also end up =900! Even if you stop it in some other value, like 998. No matter how long the program runs, it will end up 100 units less than it started.

For test conveniency the program will print variables states in every loop. There are two auxiliary pyvcp buttons as well. One to show variables states (useful for immediately after one aborts the program) and another one for restoring the value of variable #1000 back to 1000.

I hope this will help solving this issue.

Thank you all in advance!

Bruno
Attachments:
Last edit: 31 Jul 2023 19:48 by ContinenteCNC.

Please Log in or Create an account to join the conversation.

More
01 Aug 2023 11:06 #276690 by chris@cnc
Unfortunately that is correct. You call the subprogram 100 times and don't exit the loop. Linuxcnc is much faster internally than the output. Maybe it helps if you exit the subprogram after each calculation and don't set the loop in the subprogram.
The following user(s) said Thank You: ContinenteCNC

Please Log in or Create an account to join the conversation.

More
01 Aug 2023 14:48 #276702 by ContinenteCNC
Thank you, Chris!

Hm, that's unfortunate.

I will try to think of something. Maybe a hal module to monitor the variable states and restore their values automatically when the program is aborted. Right now I can't think of a more elegant way.

Thank you!

Bruno

Please Log in or Create an account to join the conversation.

More
01 Aug 2023 15:27 #276705 by MaHa
You can work with queue-buster, eg. 'M66 E0 L0'
    #<counter_1> = [ #<counter_1> - 1 ]
    M66 E0 L0

and the result is:

 
 
Attachments:
The following user(s) said Thank You: chris@cnc, ContinenteCNC

Please Log in or Create an account to join the conversation.

More
01 Aug 2023 16:54 #276712 by chris@cnc
Yes, pretty good idea.
Bonus option you could you use M68 and show the variable direct in pyvcp panel. Don't need the debug line in your macro. Clean up that debug mess.
Macro
o100 while[ #<counter_1> GT 0 ]
    M68 E0 Q#1000    
    
    #1000 = [ #1000 - 1 ]
    
    G4 P[1.0]
    #<counter_1> = [ #<counter_1> - 1 ]
    M66 E0 L0

o100 endwhile
postgui.hal
net number   <= motion.analog-out-00  => motion.analog-in-00     =>    pyvcp.number
custom.xml
<label>
        <text>"Variables"</text>
        <font>("Helvetica",24)</font>
    </label> 
    <number>
        <halpin>"number"</halpin>
           <font>("Helvetica",24)</font>
        <format>"+6.0f"</format>
    </number>

 
Attachments:
The following user(s) said Thank You: ContinenteCNC

Please Log in or Create an account to join the conversation.

More
02 Aug 2023 19:05 #276790 by ContinenteCNC
Holy cow, MaHa!

That's what I'm talking about!

Much more elegant (and easier to implement) than what I had in mind.

Great, great!

Would you mind to explain me why it works? The M66 breaks something in LinuxCNC guts? xD

Thank you very much!

Please Log in or Create an account to join the conversation.

More
02 Aug 2023 19:10 #276791 by ContinenteCNC
Thank you, Chris!

Neate!

I'll be switching to pyvcp! It looks much better!
The following user(s) said Thank You: chris@cnc

Please Log in or Create an account to join the conversation.

More
03 Aug 2023 11:17 #276833 by MaHa
I think this line from the manual explains:

M66 wait on an input stops further execution of the program, until the selected event (or the programmed timeout) occurs.

and all about M66:

linuxcnc.org/docs/stable/html/gcode/m-code.html#mcode:m66

Please Log in or Create an account to join the conversation.

More
03 Aug 2023 13:37 #276835 by ContinenteCNC
Hi, MaHa!

Thanks! It makes sense.

Next monday I will be testing it in the actual machine.

Then I will come back with feedback.

Please Log in or Create an account to join the conversation.

More
09 Aug 2023 20:34 #277473 by ContinenteCNC
Hi forum!

I'm here to provide feedback: It worked flawlessly. Not a single drawback.

I was afraid it would mess up with preview, but no. Everthing worked as I was expecting.

Thank you very much, MaHa and Chris!

Bruno
The following user(s) said Thank You: tommylight

Please Log in or Create an account to join the conversation.

Time to create page: 0.179 seconds
Powered by Kunena Forum