while(exec.IsMoving()) - can't do anything here?

This is where you talk about Macros, show examples of your macro scripting and SHARE handy segments of script code as examples.

while(exec.IsMoving()) - can't do anything here?

Postby Jason » Sat Nov 25, 2023 11:22 pm

Is it not possible to execute any macro code during the "while(exec.IsMoving())" evaluation? I've seen this question asked slightly differently before when someone attempts to rewrite the G31 probe function, or wanting to stop the motion based on an input - and the answer never resolves why the attempted method didn't work - just "do this instead".

Having open loop motors, on very rare occasions I may miss a few pulses and I'm "off" by x.xxx inches. Depending upon the job setup, I have numerous "park" positions. A simple version of this would be: default "home" for Y is in the front of the machine. A park position would be at Y=48 inches. A second sensor at the park position would allow for either homing off that sensor, or at least "checking" for out of position. With the additional sensor being wired to a different input than the assigned 'probe' input, homing to that sensor would involve executing an exec.stop if that input become true. This would need to be evaluated and executed during the "while(exec.IsMoving())". The other application is to grab the "Y" value on false to true of a second sensor when the Y axis returns to the park position. Again, this would need to be performed during the "while(exec.IsMoving())" logic.

In the code below, the message never displays, even though the LED is lighting up on the UCCNC screen.

Code: Select all
exec.Code("G01 G53 X0 Y48); // Move to park1 position
while(exec.IsMoving()){
   if(AS3.GetLED(37))  // used the z-probe input to easily test before installing an actual 2nd sensor
   {
       exec.AddStatusmessage("hi"); // message that never displays
   }
}


For fun, updated the code to see if I could do anything - and nope, I can't make the macro do anything during the IsMoving:

Code: Select all
exec.Code("G01 G53 X0 Y48); // Move to park1 position
while(exec.IsMoving()){
   exec.AddStatusmessage("status:" + AS3.GetLED(37));  // should see 100's of messages, but none display
}


In the above code, I can replace the exec.addstatusmessage with anything - even exec.StopWithDeccel() - but it will never execute it.

Thanks in advance for any insight.
Jason
 
Posts: 4
Joined: Sat Nov 25, 2023 10:50 pm

Re: while(exec.IsMoving()) - can't do anything here?

Postby fsli » Sun Nov 26, 2023 1:05 pm

I haven't worked with UCCNC in a long while, but I do recall having the same experience. I don't think exec.IsMoving() in the main macro body accomplished much at all. My recollection is that any movement commands don't return until movement is completed. That is, from within the main macro body they are synchronous, not asynchronous.

Where exec.IsMoving() would make a difference is during a background thread (i.e. - a macroloop). There, you know that the macroloop is running in parallel with the machine movement, so checking whether there is movement makes more sense.
Frank
fsli
 
Posts: 97
Joined: Mon Jul 11, 2022 12:36 am

Re: while(exec.IsMoving()) - can't do anything here?

Postby Jason » Mon Nov 27, 2023 3:07 am

The macro waiting for the G-code to complete makes sense. I have some other options, but I was unaware of "macroloops" being available. That might come in handy for this and other ideas.

Thanks!
Jason
 
Posts: 4
Joined: Sat Nov 25, 2023 10:50 pm


Return to Macros

Who is online

Users browsing this forum: No registered users and 6 guests

cron