Page 1 of 1

feedhold in a macro.

PostPosted: Wed Jul 25, 2018 9:48 am
by Battwell
just wondering on adding feedhold to my toolchange macro using something like below is going to cause problems.
adding before some movements

while(exec. getled(217)); // is feedhold on led
{exec.wait(10);}

can anyone see a problem with this?
i dont want to use stop- as i have that to jump out of the macro if i have a snarl up :-)
the program runs a series of output switched pneumatic ram movements. id like to have the toolchanger pause sequencing if in feedhold
(only has a few controlled xyz axis movements - which will hold but these are at the start and end)

Re: feedhold in a macro.

PostPosted: Wed Jul 25, 2018 1:48 pm
by Battwell
ok. i did some testing- and after loads of compile errors came up with this.
still something i cant work out.
at the end i use the function is macro stopped to clear the output if the stop button has been pressed.
but it switches off anyway- and the button has not been pressed ? (unless stop button led flag doesnt toggle until a cycle start is initiated?)
i couldnt find an led to check for stop.
i want the output to stay on unless the macro was stopped using stop button. ie if the loop is finished by feedhold release.

otherwise- i think its going to be ok.
could someone please test?
pasted below:

//waits and repeats while feedhold is true and stop button not pressed
//otherwise exits when feedhold is switched off- or stop button is pressed
//ps- this took me hours to write! brendon
int Chuckopenport=3;
int Chuckopenpin=3;

bool hold= (AS3.GetLED(217));// is feedhold active

//***start of test loop***//

do{
hold= (AS3.GetLED(217)); //must be re checked inside the loop
if(hold){ // this would be reversed in a real program (not)
exec.Setoutpin(Chuckopenport, Chuckopenpin);} // Open the chuck with pneumatic valve
exec.AddStatusmessage("feedhold "+hold); //confirming hold led status for debugging
exec.Wait(1000);
}while ((hold)&&(!exec.Ismacrostopped())); //and

//***end of test loop***//

exec.Wait(100);
if(exec.Ismacrostopped());
{
exec.Clroutpin(Chuckopenport, Chuckopenpin);
}

Re: feedhold in a macro.

PostPosted: Wed Jul 25, 2018 2:05 pm
by Battwell
i put a status message checking ismacrostopped just before the clear output - and it shows as false.
- so it should not run the if loop clearing the output?

Re: feedhold in a macro.

PostPosted: Wed Jul 25, 2018 2:52 pm
by Battwell
can anyone explain to me why- changing the last few lines to this makes it work ??
ive always used { } brackets around my if statements before

//***end of test loop***//

exec.Wait(100);
stopped=(exec.Ismacrostopped());
exec.AddStatusmessage("stopped?= "+ stopped);
if(exec.Ismacrostopped())
exec.Clroutpin(Chuckopenport, Chuckopenpin);

Re: feedhold in a macro.

PostPosted: Wed Jul 25, 2018 3:14 pm
by cncdrive
The issue is the ; and not the brackets.
You placed a ; after the if statement and so that closes the statement and so the next line will be out of the conditional check.

The
Code: Select all
if(exec.Ismacrostopped())
//Do something


and the

Code: Select all
if(exec.Ismacrostopped());
//Do something


are not the same.
In first case the Do something will be executed if the statement is true and in second case the Do something will be always executed.

Re: feedhold in a macro.

PostPosted: Wed Jul 25, 2018 4:14 pm
by Battwell
Thank you
Now you can see why writing macros takes me so long!
I only learnt the first basic language when I was in school 36 years ago!

Re: feedhold in a macro.

PostPosted: Fri Jul 27, 2018 12:16 pm
by Battwell
i simplified it to this :-)

int port=3; // output to activate
int pin=3;
int holdled=217;
bool hold= (AS3.GetLED(holdled));
//
//
while (hold){exec.Wait(1);hold= (AS3.GetLED(holdled));}; // wait here if feedhold is on. does nothing if feedhold is off.


//continuing here//
// eg.
exec.Setoutpin(port, pin);
exec.Wait(2000);
exec.Clroutpin(port, pin);

Re: feedhold in a macro.

PostPosted: Sat Jul 28, 2018 9:56 am
by Battwell
the above only worked on the first instance of it in a macro- unless the hold was checked just before it.
changing it to a do while loop makes it execute at least once- hence checking the condition of hold inside the loop before evaluating .
(every day is a school day for me)
so this example is better .

do {exec.Wait(1);hold= (AS3.GetLED(217));}while (hold);