sanity check

If you have a question about the software please ask it here.

Re: sanity check

Postby dezsoe » Wed Oct 17, 2018 10:12 am

I'm on the other side... :lol:
dezsoe
 
Posts: 2049
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: sanity check

Postby cncdrive » Wed Oct 17, 2018 10:21 am

You're on the dark side. :)
cncdrive
Site Admin
 
Posts: 4695
Joined: Tue Aug 12, 2014 11:17 pm

Re: sanity check

Postby dezsoe » Wed Oct 17, 2018 10:29 am

:twisted:
dezsoe
 
Posts: 2049
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: sanity check

Postby ger21 » Wed Oct 17, 2018 12:47 pm

Isn't this what
While...IsMoving() is for?
Gerry
UCCNC 2022 Screenset - http://www.thecncwoodworker.com/2022.html
ger21
 
Posts: 2663
Joined: Sat Sep 03, 2016 2:17 am

Re: sanity check

Postby dezsoe » Wed Oct 17, 2018 12:49 pm

There's no chaos if you know what your're doing. Your example will be:

Code: Select all
exec.Code("G1 X10");
while (exec.IsMoving());
exec.Setvar(exec.Getfielddouble(226),500); (Set #500 to the value of the Xpos DRO)

The "while (exec.IsMoving());" will wait for the end of the movement. But if you have two movements like this:

Code: Select all
exec.Code("G1 X10");
double newY = some terrible and long calculation, maybe with some data read from a file;
while (exec.IsMoving());
exec.Code("G1 Y" + newY.ToString());
while (exec.IsMoving());

You start the first movement and while that is going you have time to calculate the terrible value. If it is calculated faster than the movement, the macro will wait for the movement to finish and starts the next movement.
dezsoe
 
Posts: 2049
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: sanity check

Postby stirling » Wed Oct 17, 2018 4:48 pm

Vmax549 wrote:Lets take Ian's example. WHY would I want teh message to display BEFORE the motion line actually finished?


The simplest program that demonstrates an issue is a common technique in bug chasing. Don't take it as anything else.

There will (and has) always be two camps on the threading/synching thing and its place in macros in Mach3/UCCNC/etc. but trust me Terry, if you're finding it necessary to sprinkle waits/sleeps all over the place then something is very wrong. Either with your programming or with the system. It's impossible for me to check out the system at the moment because according to what @cncdrive told you in your thread about the way it should be working, it's currently broken.

Ian
UC300ETH_5LPT
Razordance DTHC
http://www.razordance.co.uk/THC.htm
stirling
 
Posts: 32
Joined: Mon Jul 23, 2018 12:54 pm

Re: sanity check

Postby dezsoe » Wed Oct 17, 2018 6:46 pm

You don't need to check if the calculation is finished. If the movement is ready then nothing happens (with the movements) until the macro starts the new movement.

Imagine that you ask a friend (say Joe) to go to the shop for a bottle of wine. He walks away and you start cooking. You want to drink the wine together, but only when the dinner is ready, so there are two possibilities:

1. You finish first -> you wait for Joe to come back. You get into the loop while (exec.JoesMoving());.
2. Joe arrives before you finish with the cooking -> nothing happens until you finish, Joe waits patiently.

After one of these you can sit down to drink the wine.
dezsoe
 
Posts: 2049
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: sanity check

Postby dezsoe » Wed Oct 17, 2018 8:43 pm

Line1 starts the movement. The movement command is sent to the motion controller so the macro will continue with line2.
Line2 makes the calculation. Not only starts, but completes it. When completed, line3 comes.
Line3 loops if the motion controller is doing its job (the motion buffer is not empty). When IsMoving() goes false, the loop ends, line4 comes.
Line4 ...

If Joe meets Betty, then you'll wait with the dinner till the end of time... :)

That's why after the while (exec.IsMoving()); line there should be a line to check exec.IsMacrostopped(). A classic sample:

Code: Select all
exec.Code("G31 Z-1.0000 F25");              // Send command to the motion controller
while(exec.IsMoving());                     // Wait for the controller to finish
if (exec.Ismacrostopped())                  // If there was a STOP do something
{
  exec.AddStatusmessage("Probe stopped!");
  return false;
}
// code continues

You send a G31 to the motion controller and wait for it to finish. It will also finish if you press stop, so you have to check if the movement was stopped.
dezsoe
 
Posts: 2049
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: sanity check

Postby dezsoe » Wed Oct 17, 2018 9:28 pm

C#. The whole IT world. :shock: The execution cannot skip lines. How could line4 execute before line2 and line3 finished?!
dezsoe
 
Posts: 2049
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: sanity check

Postby stirling » Thu Oct 18, 2018 11:54 am

Code: Select all
Line1 exec.Code("G1 X10");
Line2 double newY = some terrible and long calculation, maybe with some data read from a file;
Line3 while (exec.IsMoving());
Line4 exec.Code("G1 Y" + newY.ToString());
Line5 while (exec.IsMoving());

Terry, I think I see where you misunderstand things. Let me try:

I think you think exec.Code() exectues gcode. Am I right?

It doesn't, all it does is pass a string to the gcode interpreter. Once it's done that it's finished.

So the next line runs and does the big calcualtion. When that's done, the next line runs.

So what exactly does while (exec.IsMoving()); do?

IsMoving() asks the gcode interpreter "are you busy doing anything?"

The gcode interpreter replies either "yes, I'm working my butt off" or "no, I'm just twiddling my thumbs"

The while loop just keeps it asking until it get's the "no, I'm just twiddling my thumbs"

It's the gcode interpreter and your macro that are running in parallel NOT individual lines of your macro running together.
Individual lines of your macro run one after another, one at a time.

Make sense?
UC300ETH_5LPT
Razordance DTHC
http://www.razordance.co.uk/THC.htm
stirling
 
Posts: 32
Joined: Mon Jul 23, 2018 12:54 pm

PreviousNext

Return to Ask a question from support here

Who is online

Users browsing this forum: No registered users and 17 guests