Cancel a macro

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

Re: Cancel a macro

Postby Robertspark » Fri Apr 20, 2018 6:18 pm

Terry, not sure what you want to do exactly...

Option a) is a reverse macro like m5 is to M3/4

Option b) if you want to do it during motion would be either a input sensed via macro loop which checks if iOS are set and clears them or registers / variables etc

Or b viable hot key and macro loop to clear registers / variables (clear a flag which you set it the macro and then monitor in macro loop which if cleared you clear the macro)
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: Cancel a macro

Postby Robertspark » Fri Apr 20, 2018 8:00 pm

Give me an example , what does the macro do?

Code example? (Simple one... )
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: Cancel a macro

Postby Robertspark » Fri Apr 20, 2018 8:51 pm

Ok, so when you cancel the macro, you want the macros output pins to stay latched?

What about having a macro that checks that outputs are enabled at the time. And keeps them active but ends the macro?
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: Cancel a macro

Postby Robertspark » Fri Apr 20, 2018 9:07 pm

Here is a suggestion....

2 macros... (1 macro, 1 X macro loops)

1 with your primary code, when the macro starts it sets a variable, then before the primary macro does anything active it checks a variable to see if it is still set, of it has been cleared it ends the macro (skips to the end / returns... That way your outputs will stay on)

Next a macro loop which checks for a hotkeypess ... If the hotkeypess is pressed it clears the variable.
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: Cancel a macro

Postby Battwell » Tue Apr 24, 2018 7:09 pm

i know how dynomotion handle this. they have 8 threads which run independantly. 7 of them can call threads running different macros starting/stopping etc
thread 1 being the main control loop.
Uc300eth on router and mill.
UK uccnc powered machine sales. https://cncrouter.uk/atc-cnc-routers.htm
Automateanything/duzzit cnc/mercury cnc
Battwell
 
Posts: 867
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk

Re: Cancel a macro

Postby cncdrive » Tue Apr 24, 2018 9:03 pm

You can check with the exec.Ismacrostopped() function which is set when the user stops it with a stop or reset button.
Killing threads is a bad idea, it is a very bad programmers practise which usually ends with unexpected results and under Windows it is not guaranteed in all circumstances that a thread will die when it is killed.
It is always much better if the programmer takes care of stopping threads under control with letting the thread to exit and end it's operation.
The same is with macros. Because they are separate threads killing them is a bad idea, but the macro programmer knows where he wants to check if the user wants to halt execution with checking the macrostop variable.
cncdrive
Site Admin
 
Posts: 4887
Joined: Tue Aug 12, 2014 11:17 pm

Re: Cancel a macro

Postby cncdrive » Tue Apr 24, 2018 10:26 pm

What do you mean by this? "You cannot use {ESC} or {Stop} because they both alter teh output states."
Stop and Reset only sets output states which are setup and has to go to their inactive states when the machine is going to reset.
E.g. a spindle on relay output is a configured output and that pin has to go to it's inactive state on reset.
But unconfigured outputs and which outputs are configured but reset does not matter for them will not change state when a stop or reset is pressed.
cncdrive
Site Admin
 
Posts: 4887
Joined: Tue Aug 12, 2014 11:17 pm

Re: Cancel a macro

Postby cncdrive » Tue Apr 24, 2018 10:31 pm

If a loop is endless then you can't get out of it and there is not even need for it, because it is endless, so it will and should never end. :)
For example while(true){ ... } will be an endless loop and as the condition check will be always true this loop will never end.
However you could create a different condition to stop the loop based on something instead of the really endless while(true) condition check.
Or you could place a conditional break inside the originally endless loop, however that loop will be then still not exactly endless, like:

Code: Select all
while(true)
{
  if(something)
  {
      break;
  }
}
cncdrive
Site Admin
 
Posts: 4887
Joined: Tue Aug 12, 2014 11:17 pm

Re: Cancel a macro

Postby Dan911 » Wed Apr 25, 2018 12:28 am

When something mechanically goes wrong..... Estop?
Dan911
 
Posts: 613
Joined: Mon Oct 31, 2016 1:22 am
Location: USA

Re: Cancel a macro

Postby cncdrive » Wed Apr 25, 2018 12:43 am

Terry, as I said the macro will not bother the outputs just because the macro ends.
I think what probably happens is that you somehow checking that the stop occured, otherwise if not and the macro is in an endless loop then it would not stop.
And so there must be some code after the loop which changes the states of the outputs.
For example:

Code: Select all
while(!exec.Ismacrostopped())
{
 //Do something
}
 //Change outputs states


So, with the example code the while loop runs until you pressing ESC or pressing stop or reset button etc., then the while loop's condition becomes false and so the macro skips the loop and continues to run further until the end of the macro file and if there is a conditionless outputs change code after the loop then that will execute before the macro finishes.

The example code could be fixed to not change the outputs like this:

Code: Select all
while(!exec.Ismacrostopped())
{
 //Do something
}

if(!exec.Ismacrostopped())
{
 //Change outputs states
}



So, then when the loop is skipped because an ESC or stop or reset is pressed and the code execution will go after the loop then there is a condition check to see if the macro was stopped or not and the outputs states change code is only executed if the macro was not stopped, otherwise that code will be also skipped and the macro will end without executing that code.
Ofcourse this is just a simple pseudo code like example...
cncdrive
Site Admin
 
Posts: 4887
Joined: Tue Aug 12, 2014 11:17 pm

Next

Return to Ask a question from support here

Who is online

Users browsing this forum: No registered users and 26 guests