Page 1 of 3

Toggle Type User Button linked to Macro

PostPosted: Wed Oct 03, 2018 11:30 am
by Robertspark
Anyone got a way of using a toggle type user button to trigger a macro which will check the state of the button and trigger the macro if the button state is True and another part of the macro if the state is false?

I thought about getting the macro to check a var# for a specific value, and if it was not correct to run part A of the macro, and set the var# to say value "9876", and if the var# was = to value "9876" to run part B of the macro and clear the var# for next toggle use.

Is there another way?

Terry got me thinking about an alternative to the default feedhold button, and getting it to run a custom macro which
checks a var# flag, if FALSE {
checks and saves if active to vars# M3,M4, M7, M8, M10+Q{not sure if possible}, M205, M207, M209, M211 (customise as applicable to machine)
run cycle stop (stops the machine with deceleration + runs M5 & M9 & M11)
saves the 6 axis co-ordinates to vars#
saves set feedrate to vars#
saves set spindle speed to vars#
retracts Z to safeZ
sets a var# flag
/return from macro
}
checks a var# flag, if TRUE {
moves machine to safe Z
moves machine to saved vars# X,Y,A,B,C
move machine to saved var#Z
set feedrate to saved var#
set spindle speed to saved var#
enable if saved vars# set M3,M4, M7, M8, M10+Q{not sure if possible}, M205, M207, M209, M211 (customise as applicable to machine)
(presume all set delays are correct to allow sufficient spindle spinup + coolant etc, if plasma, move M3+M10 to suit cyclestart)
clear all vars# (flag, X,Y,Z,A,B,C,feedrate, spindle speed, M3, M4, M7, M8)
run cycle start
/return from macro
}

Re: Toggle Type User Button linked to Macro

PostPosted: Wed Oct 03, 2018 12:10 pm
by ger21
Something like this?

Code: Select all
bool buttonstate = AS3.Getbuttonstate(20328);

if (buttonstate)
{
   AS3.Setcheckboxstate(false, 228);
   AS3.Switchbutton(false,20328);
}
else
{
   AS3.Setcheckboxstate(true, 228);
   AS3.Switchbutton(true,20328);

}

Re: Toggle Type User Button linked to Macro

PostPosted: Wed Oct 03, 2018 2:03 pm
by Robertspark
Thanks Terry,

1) yes, not thought about in my haste.....

2) don't think that will happen

3) see 2, but it would be helpful to allow more options

3B) thats why I proposed gathering the active M-codes before the cycle stop

4) probably

5) .... the thought was for simple jog away tasks, change plasma tip, tool change (replacement) clear swaff whatever..... just jog in feedhold.

6) yes.... but that is why I was highlighting the thought process / consideration.

I see your point with single toggle button operation..... maybe best resort to two buttons

Oh, thanks Gerry, I'll have a think over it tonight

Re: Toggle Type User Button linked to Macro

PostPosted: Wed Oct 03, 2018 5:58 pm
by dezsoe
The Getbuttonstate function is for bi-state buttons (like M3 etc.), you cannot get the "pressed" state with it. Try the Getbutton function.

(From the docs: "Example: while(!AS3.Getbutton(128)); //Waits for the cycle start button press on the main screen.")

Re: Toggle Type User Button linked to Macro

PostPosted: Wed Oct 03, 2018 6:22 pm
by Robertspark
If you were saving the current position, with a view to restoring that position later, would you save the current machine coordinates AND the current work offset, AND the current work offset coordinates.

That way when you returned to the previous position you would ensure it is the ACTUAL previous position.... And if something had happened to the work offsets (for whatever reason) you have a means to restore the ACTUAL previous position.

As I'm just typing and thinking.. :roll: .. If these values were saved to text file.... In theory.... It would be possible to shut everything down and reboot and re-home the machine and pick up from where you left off?

Re: Toggle Type User Button linked to Macro

PostPosted: Wed Oct 03, 2018 8:38 pm
by Robertspark
I don't think I'd be keen about using the cycle stop and cycle start buttons....I'd prefer two separate buttons to avoid confusion.... Stop should be stop.... Start should be start.

Not the same as cycle pause and resume or some other term

Re: Toggle Type User Button linked to Macro

PostPosted: Thu Oct 04, 2018 3:28 am
by Dan911
HI Terry,
I played with this for my own amusement when you posted your remember and resume macro's several months back, IMO to achieve from what a scanned through this discussion a plugin is the way to go, it will offer the maximum flexibility/options. Below I will post a plugin with bare essentials, just change FreeHold button # to 12345. When Freehold is pressed while gcode is running it will stop() and save XYZ axis settings, rpm and set Z axis to safe Z settings, so move axis where you need. A flag will be set for next time Cycle Start is pressed, it will offer and option to continue as normal or use saved settings than continue. Any other variables can easily be added to be written. No loops are running, I know if there were it is not a problem, but it is also my preference.

FreeHold.zip

Re: Toggle Type User Button linked to Macro

PostPosted: Thu Oct 04, 2018 6:26 am
by Robertspark
Dan

Any chance of having a look at your sourcecode?

At the moment we only have 1 template / example from cncdrive installed by default, it would be useful to see a few other examples. Also I presume that there is not a lot to this one codewise so it may be able to be extended or customised to users requirements.

The problem (or benefit) with plugins so the code is all locked away and it's not able to be extended or modified as users in the same way macros can be extended,bcustomised and users can take something away from and learn something from just looking at and reading them.

Re: Toggle Type User Button linked to Macro

PostPosted: Thu Oct 04, 2018 8:36 pm
by cncdrive
That is the correct operation since in G91 mode the endpoint is an increment and so if the TCP is not on the startpoint of the arc then the same arc g-code will mean a totally different arc...

Re: Toggle Type User Button linked to Macro

PostPosted: Thu Oct 04, 2018 8:57 pm
by cncdrive
It not looses the reference, the operation is correct by g-code definition. Just think it through.
Feedhold does not stop and execute the g-code line again. While Stop and Start stops the cycle and executes the same line again which in increment mode means different if the TCP is not on the startpoint of the arc.