- Posts: 97
- Thank you received: 0
Unexpected variables behavior when program is aborted (stopped)
- ContinenteCNC
- Topic Author
- Offline
- Premium Member
-
Less
More
3 years 2 months ago #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
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
Please Log in to join the conversation.
3 years 2 months ago #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.
Please Log in to join the conversation.
- ContinenteCNC
- Topic Author
- Offline
- Premium Member
-
Less
More
- Posts: 97
- Thank you received: 0
3 years 2 months ago #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 to join the conversation.
3 years 2 months ago #276705
by MaHa
Replied by MaHa on topic Unexpected variables behavior when program is aborted (stopped)
You can work with queue-buster, eg. 'M66 E0 L0'
and the result is:
Code:
#<counter_1> = [ #<counter_1> - 1 ]
M66 E0 L0
and the result is:
Attachment not found
Please Log in to join the conversation.
3 years 2 months ago #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.
Macro
postgui.hal
custom.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
Code:
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
Code:
net number <= motion.analog-out-00 => motion.analog-in-00 => pyvcp.number
Code:
<label>
<text>"Variables"</text>
<font>("Helvetica",24)</font>
</label>
<number>
<halpin>"number"</halpin>
<font>("Helvetica",24)</font>
<format>"+6.0f"</format>
</number>
Attachment not found
Please Log in to join the conversation.
- ContinenteCNC
- Topic Author
- Offline
- Premium Member
-
Less
More
- Posts: 97
- Thank you received: 0
3 years 2 months ago #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 to join the conversation.
- ContinenteCNC
- Topic Author
- Offline
- Premium Member
-
Less
More
- Posts: 97
- Thank you received: 0
3 years 2 months ago #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!
Please Log in to join the conversation.
3 years 2 months ago #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 to join the conversation.
- ContinenteCNC
- Topic Author
- Offline
- Premium Member
-
Less
More
- Posts: 97
- Thank you received: 0
3 years 2 months ago #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 to join the conversation.
- ContinenteCNC
- Topic Author
- Offline
- Premium Member
-
Less
More
- Posts: 97
- Thank you received: 0
3 years 2 months ago #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
Please Log in to join the conversation.
Time to create page: 2.577 seconds
