Machsupport Forum

Mach Discussion => General Mach Discussion => Topic started by: Johnansaro on April 28, 2018, 11:59:04 PM

Title: wait action in macros
Post by: Johnansaro on April 28, 2018, 11:59:04 PM
Hi there

I am wondering what all these wait moves really mean, and how and where should they be used.
I know that they are being used for causing some delays or wait action in macros while some other things are happening.
But what is the difference between the following, that I see in different macros;

Code "G4 P1.0"
While IsMoving()
Wend
WaitForMove        (is this a valid wait command or code?)
Sleep(1000)

regards
Jhonansaro
Title: Re: wait action in macros
Post by: Tweakie.CNC on April 29, 2018, 01:14:14 AM
Quote
WaitForMove

That is not a valid command it is just a comment.

Scripts and Mach do not run in sync so the commands " While IsMoving() / Wend " will cause the script to wait until Mach has completed the previous operation before continuing. There is debate if the command " Sleep(1000) " servers a useful purpose.

Tweakie.
Title: Re: wait action in macros
Post by: Davek0974 on April 29, 2018, 03:02:31 AM
I have boiled my macro waits down to these two options...

IF the macro causes a physical axes move then I use

While IsMoving()
Sleep(10)
Wend

If I am updating a DRO then I use

Sleep(100)

Thats it, and it makes a big difference.

"Sleep" is very similar to "DoEvents" in visual basic, it yields program operation to the processor in order that it can catch up with other things that may or may not be important, without it, the program takes 100% of the CPU and the rest can go to hell :)

Sleep only needs short delays 10-100ms as all it does is yield more often which is good as it gives the macro the impression that it is still fast acting but also allows CPU time for other stuff. It just means "go check for other tasks every 10ms then come back" In CPU time 10ms is a long time.

I would never use sleep(1000) as it will make the macro very lumpy and slow.
Title: Re: wait action in macros
Post by: ger21 on April 29, 2018, 07:45:55 AM
1) It depends on the motion controller that you are using.

2) It depends on where you use it.

Technically, you shouldn't need to use it in a While... IsMoving(), like this.

While IsMoving()
Sleep(10)
Wend

With the parallel port, Smoothstepper, or CNC Drives controllers, you don't need a sleep in the While...IsMoving, from my experience.
Apparently, it's required for many other controllers.

By itself, Sleep(1000) is just a 1 second wait.
With Mach3, it's often desirable to wait at times to allow the DRO's to update, which I think happens 10 times/second.
I'll often add a Sleep(250) whenever this is required.
Like when reading a DRO after a probing or other move.
Title: Re: wait action in macros
Post by: Johnansaro on May 04, 2018, 01:22:59 AM
Hi there

thanks every body, I am a lot clearer on this issue.

regards
jhonansaro