Toggle Type User Button linked to Macro

This is where you talk about Macros, show examples of your macro scripting and SHARE handy segments of script code as examples.

Toggle Type User Button linked to Macro

Postby Robertspark » Wed Oct 03, 2018 11:30 am

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
}
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: Toggle Type User Button linked to Macro

Postby ger21 » Wed Oct 03, 2018 12:10 pm

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);

}
Gerry
UCCNC 2022 Screenset - http://www.thecncwoodworker.com/2022.html
ger21
 
Posts: 2663
Joined: Sat Sep 03, 2016 2:17 am

Re: Toggle Type User Button linked to Macro

Postby Robertspark » Wed Oct 03, 2018 2:03 pm

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
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: Toggle Type User Button linked to Macro

Postby dezsoe » Wed Oct 03, 2018 5:58 pm

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.")
dezsoe
 
Posts: 2049
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Toggle Type User Button linked to Macro

Postby Robertspark » Wed Oct 03, 2018 6:22 pm

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?
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: Toggle Type User Button linked to Macro

Postby Robertspark » Wed Oct 03, 2018 8:38 pm

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
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: Toggle Type User Button linked to Macro

Postby Dan911 » Thu Oct 04, 2018 3:28 am

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
Dan911
 
Posts: 613
Joined: Mon Oct 31, 2016 1:22 am
Location: USA

Re: Toggle Type User Button linked to Macro

Postby Robertspark » Thu Oct 04, 2018 6:26 am

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.
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: Toggle Type User Button linked to Macro

Postby cncdrive » Thu Oct 04, 2018 8:36 pm

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...
cncdrive
Site Admin
 
Posts: 4695
Joined: Tue Aug 12, 2014 11:17 pm

Re: Toggle Type User Button linked to Macro

Postby cncdrive » Thu Oct 04, 2018 8:57 pm

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.
cncdrive
Site Admin
 
Posts: 4695
Joined: Tue Aug 12, 2014 11:17 pm

Next

Return to Macros

Who is online

Users browsing this forum: No registered users and 10 guests