- GCode and Part Programs
- O Codes (subroutines) and NGCGUI
- Unexpected variables behavior when program is aborted (stopped)
Unexpected variables behavior when program is aborted (stopped)
- ContinenteCNC
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 34
- Thank you received: 19
31 Jul 2023 19:47 - 31 Jul 2023 19:48 #276656
by ContinenteCNC
Unexpected variables behavior when program is aborted (stopped) was created 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
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
Last edit: 31 Jul 2023 19:48 by ContinenteCNC.
Please Log in or Create an account to join the conversation.
- chris@cnc
- Offline
- Platinum Member
Less
More
- Posts: 529
- Thank you received: 139
01 Aug 2023 11:06 #276690
by chris@cnc
Replied by chris@cnc on topic Unexpected variables behavior when program is aborted (stopped)
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.
- ContinenteCNC
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 34
- Thank you received: 19
01 Aug 2023 14:48 #276702
by ContinenteCNC
Replied by ContinenteCNC on topic Unexpected variables behavior when program is aborted (stopped)
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
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.
- MaHa
- Offline
- Platinum Member
Less
More
- Posts: 394
- Thank you received: 156
01 Aug 2023 15:27 #276705
by MaHa
Replied by MaHa on topic Unexpected variables behavior when program is aborted (stopped)
Attachments:
The following user(s) said Thank You: chris@cnc, ContinenteCNC
Please Log in or Create an account to join the conversation.
- chris@cnc
- Offline
- Platinum Member
Less
More
- Posts: 529
- Thank you received: 139
01 Aug 2023 16:54 #276712
by chris@cnc
Replied by chris@cnc on topic Unexpected variables behavior when program is aborted (stopped)
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.
Macropostgui.halcustom.xml
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
net number <= motion.analog-out-00 => motion.analog-in-00 => pyvcp.number
<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.
- ContinenteCNC
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 34
- Thank you received: 19
02 Aug 2023 19:05 #276790
by ContinenteCNC
Replied by ContinenteCNC on topic Unexpected variables behavior when program is aborted (stopped)
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!
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.
- ContinenteCNC
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 34
- Thank you received: 19
02 Aug 2023 19:10 #276791
by ContinenteCNC
Replied by ContinenteCNC on topic Unexpected variables behavior when program is aborted (stopped)
Thank you, Chris!
Neate!
I'll be switching to pyvcp! It looks much better!
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.
- MaHa
- Offline
- Platinum Member
Less
More
- Posts: 394
- Thank you received: 156
03 Aug 2023 11:17 #276833
by MaHa
Replied by MaHa on topic Unexpected variables behavior when program is aborted (stopped)
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
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.
- ContinenteCNC
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 34
- Thank you received: 19
03 Aug 2023 13:37 #276835
by ContinenteCNC
Replied by ContinenteCNC on topic Unexpected variables behavior when program is aborted (stopped)
Hi, MaHa!
Thanks! It makes sense.
Next monday I will be testing it in the actual machine.
Then I will come back with feedback.
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.
- ContinenteCNC
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 34
- Thank you received: 19
09 Aug 2023 20:34 #277473
by ContinenteCNC
Replied by ContinenteCNC on topic Unexpected variables behavior when program is aborted (stopped)
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
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.
- GCode and Part Programs
- O Codes (subroutines) and NGCGUI
- Unexpected variables behavior when program is aborted (stopped)
Time to create page: 0.092 seconds