while loop doesn't end
-
@OwenD
could very well be I've only just started installing the klicky probe and making the required changes to the firmware.here is my load macros:
; Move to load the klicky onto the eva toolM98 P"/macros/ZProbe/Klicky/klicky_status.g" ; Check the probe's current status
; Check if the status for klicky is already attached if global.klicky_status != "attached" M98 P"/macros/Predefined Locations/klicky_location.g" ; Move to pick up the probe G91 ; Switch to relative positioning G1 X-60 F99999 ; Move X to 0 G1 X60 F99999 ; Move X to 60 G90 ; Switch to absolute positioning M400 ; Wait for all moves to be completed M98 P"/macros/ZProbe/Klicky/klicky_status.g" ; Check for probe status echo sensors.probes[0].value[0] ; Show the probe status if global.klicky_status = "attached" ; Check for the status and make sure it's attached echo "Probe ATTACHED" else echo "Error probe not attached - aborting" ; Abort running task if probe isn't attached successfuly abort
and here is my unload macro (which probably isn't the problem because it doesn't get to this point when the loop runs infinite)
; Dock the klicky probe M98 P"/macros/ZProbe/Klicky/klicky_status.g" ; Check the probe's current status if global.klicky_status != "docked" ; Check if the probe isn't docked already echo "Docking Klicky Probe" G90 ; Switch to Absolute positioning M98 P"/macros/Predefined Locations/klicky_location.g" ; Move in front of probe dock M400 ; Wait for all moves to be completed G91 ; Switch to relative positioning G1 X-60 F99999 ; Move into the dock G1 Y30 F99999 ; Move to unhook probe G90 ; Switch to absolute positioning M98 P"/macros/Predefined Locations/klicky_location.g" ; Move in front of probe dock M400 ; Wait for all moves to be completed M98 P"/macros/ZProbe/Klicky/klicky_status.g" ; Check the probe's current status if global.klicky_status = "docked" ; Check if the probe is docked echo "Probe is DOCKED" else ; Abort the current action if the probe isn't docked correctly echo "Error probe not docked - aborting" abort
-
@mher
The macros themselves look ok
There is a limit to the number of nested macros you can have, but I'm not sure what it is.
I suspect when the main calls your klicky macro, which in turn calls another, then the local variables in the original are lost.Can you try calling your macro before you declare the variables?
-
-
@mher
What firmware version are you running?
Someone else was having similar issues here
https://forum.duet3d.com/topic/29070/weird-macro-behaviour?_=1668050444951 -
@OwenD
I'm running 3.4.0 currently so maybe there is a issue in there as well.
For now I've worked around it by doing the if check in the while loop which works it's just not that clean. -
@mher that's odd, please try this and tell me if it works for you (it works for me):
while iterations < 4 echo iterations G4 S1
-
@dc42
Yeah I already created a macro like that to perform the same test and it was working as expected.Just did the same for the code you shared just to be sured and again it worked like expected.
-
@OwenD said in while loop doesn't end:
I suspect when the main calls your klicky macro, which in turn calls another, then the local variables in the original are lost.
That shouldn't be the case, but of course there may be bugs in the implementation.
@mher said in while loop doesn't end:
Maybe @Phaedrux or @dc42 can comment about what the limit of the macros is, if there is such a thing and if that could be the cause of the while loop not exiting correctly.
There is a limit of 10 nested stack pushes. A macro call (whether explicit or implicit) counts as a push, so does using M120. Within each stack push there is also a block nesting limit of 10, so while- and if-else bodies can't be nested more than 10 deep.
@mher if you can identify what it is that you are doing in your macro that causes the while-loop to misbehave, I will look into it.
-
As far as I can see really quickly i'm max nesting 5 pushes. However lets say i'm inside a while inside an if statement and I call a macro in this if statement and inside the macro itself there are additional if statements. Do they get counted towards the max bodies deep you can nest? If so that might be an issue
I'm also assuming that there isn't a max of how many macros you can call in 1 macro?
So if i would call M98 30 times in succession it should be fine? -
@mher said in while loop doesn't end:
G1 X{var.centerX - sensors.probes[0].offsets[0]} Y{var.centerY - sensors.probes[0].offsets[1]} F99999
It may be unrelated but...
Just as a matter of interest, what happens when you send a command likeG1 X100 Y100 F99999
?
It will no doubt be restricted by the max speed you set with M203, but if that speed is causing an error condition it may be a factor.I think you're going to have to heavily lace your code with echo commands so you can see where in the scheme of things your issue is appearing.
-
@OwenD As far as I understood it it will execute the command and the speed will be capped at the max you set in the firmware. So max speed for x is currently 10800 (for me atleast). So setting it to F999999 will make sure that when I share this in the vcore3 group (I'm running a vcore3) other people can use it with the speeds they have set on their setup.
I've been adding echo's the thing is that it just seems to fail on the "while iterations" check.
Because I've got it working now by just doing a check inside the while to break the code.I even setup a testing file with a while loop and loading/unloading the probe which works as expected.
-
@dc42
Alright it seems like i figured out what is causing the issue.I created a new macro and started adding things one by one.
Everything went fine until I added this line:G91 G1 H2 Z7 G90 ; Set to relative positioning, move Z up 5mm, change back to absolute positioning
after adding this the while loop kept on running. After removing it everything ran as expected again
EDIT:
just confirmed it by creating the following macro. This would just keep running the while loop infinite.G91 G1 Z5 G90 ;Removed H2 to be sure this wasn't the cause while iterations < 4 echo "iteration: " ^ iterations
Then I split the G91/G90 command from single line to multi line and it started working as expected. So it seems there is an issue with the single line implementation for relative/absolute.
Which I read here we should be able to do the way I did
https://forum.duet3d.com/topic/11662/treat-g90-g91-and-m82-m83-like-g53/3