Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: fritzzco on March 10, 2019, 02:16:36 PM

Title: GoToWorkZero
Post by: fritzzco on March 10, 2019, 02:16:36 PM
Hi anyone,  Is there anyway to associate the "GoToWorkZero" button to a keyboard Key?   I got the cyclestart, cyclestop, reset to work with keyboard C, S, R key but cannot for the life of me get any key to work with the GoToWorkZero.   Hmmmmm.  It either gives me either an "axis 3 commanded while disabled" or it just resets my gcode to the first line like a reset or rewind with no axis movement.

Thanks for anyone who has a solution.
Title: Re: GoToWorkZero
Post by: joeaverage on March 10, 2019, 02:39:41 PM
Hi,
open the screen editor and open the screen load script. Scan down through the file till about line 225
until you find the GoToWorkZero function:

Code: [Select]
---------------------------------------------------------------
-- Go To Work Zero() function.
---------------------------------------------------------------
function GoToWorkZero()
    --mc.mcCntlMdiExecute(inst, "G00 X0 Y0 A0")--Without Z moves
    mc.mcCntlMdiExecute(inst, "G00 G53 Z0\nG00 X0 Y0 A0\nG00 Z0")--With Z moves
end

Note that the active line (mc.mcCntlMdiExecute(inst, "G00 G53 Z0\nG00 X0 Y0 A0\nG00 Z)) has an A axis move.
I'm guessing that you don't have an A axis defined in your machine. So either edit the line to delete the A axis
reference or comment it out and add this line instead:

Code: [Select]
mc.mcCntlMdiExecute(inst, "G00 G53 Z0\nG00 X0 Y0 \nG00 Z)

To add a physical button....define a pin on your controller as an input, say ISIG_INPUT10 and then put this in the
SigLib{} in the screen load script:

Code: [Select]
[mc.ISIG_INPUT10]=function(state)
if state==1 then
      GoToWorkZero()
end
end,

Note that this is an entry in the signal library table and the second 'end' statement concludes the in line function definition
and the trailing ',' (comma) concludes the table entry. Don't forget the trailing comma!

Craig
Title: Re: GoToWorkZero
Post by: fritzzco on March 10, 2019, 03:02:01 PM
Hi,   Are you thinking in putting a physical button someplace?   I only want to use the screen button "GoToWorkZero" and also have a keyboard key do the same thing.

Thanks,
Fritz
Title: Re: GoToWorkZero
Post by: joeaverage on March 10, 2019, 03:05:07 PM
Hi,
if you only want  the screen button to work then edit the GoToWorkZero() function as I have
suggested and ignore the signal library addition.

Craig
Title: Re: GoToWorkZero
Post by: fritzzco on March 10, 2019, 03:10:13 PM
couple of pics what I have.
Title: Re: GoToWorkZero
Post by: fritzzco on March 10, 2019, 03:13:37 PM
I have the screen button already, was in the mach4 download, I'm trying to associate it with my keyboard 10' away from my cnc machine.   
Title: Re: GoToWorkZero
Post by: joeaverage on March 10, 2019, 03:23:12 PM
Hi,
looking at the code I would guess you have that in the PLC script?
That works, but is not efficient. The PLC script runs many times a second, and your code will therefore
run many times per second. This type of input is called 'polling' and is common in Mach3.

With Mach4 however there is another way. Whenever a signal (input or output or even an internal Mach signal)
changes state the Signal Script runs, and the signal script looks into the Signal Library (SigLib{}) in the ScreenLoad
script for an entry corresponding to the signal which has changed. If it finds an entry it executes the inline function
defined there. If it doesn't find an entry, ie we are not interested in that signal then it returns without doing anything.

It sounds complicated and it certainly takes some effort to understand at first but thereafter is  very elegant
and programmatically efficient.

Craig

Title: Re: GoToWorkZero
Post by: joeaverage on March 10, 2019, 03:27:53 PM
Hi,
I notice that you have made your own screenset? You have very few Tabs to call on.

May I suggest loading wx4.set and see all those additional screens.....including diagnostics, probing  etc.
Then make a copy of it and THEN customize it. Its all very well making a new set from scratch but is there any need
to do without all those features that NFS has laboriously programmed into Mach?

Craig
Title: Re: GoToWorkZero
Post by: fritzzco on March 10, 2019, 03:32:13 PM
Them codes in my PLC script works great, just can't get this line entry to work, the red arrow.
Title: Re: GoToWorkZero
Post by: fritzzco on March 10, 2019, 03:39:42 PM
Mach4 screen
Title: Re: GoToWorkZero
Post by: joeaverage on March 10, 2019, 03:51:28 PM
Hi,
you should attempt to use the signal library instead.

If you wish to use the PLC script it will still work.

Have a close look at the API you are using:

Quote
LUA Syntax:
rc = mc.mcCntlGotoZero(
      number mInst)

Description:
Move the X,Y,A,B,C and then the Z axis to zero of the current fixture offset.

Parameters: Parameter Description
mInst The controller instance.


Returns: Return Code Description
MERROR_NOERROR No Error.
MERROR_INVALID_INSTANCE The mInst parameter was out of range.
MERROR_NOT_NOW The operation could not be completed at this time.

Note in particular the return codes. Alter you code to test the return code. I will almost guarantee that the machine
is not in 'idle' state and cannot therefore GoToWorkZero because its busy.

Code: [Select]
local rc=mc.mcCntlGotoZero(inst)
if (rc== -180 then
        wx.wxMessageBox('Machine not in idle state')
        do return end
end

Note that if you use the SigLib{} approach you avoid this difficulty because the GoToWorkZero() function is
in the Screen script and does not have to switch chunks as your approach does.

Try wx4.set, it is way more complete/developed.

Craig

Title: Re: GoToWorkZero
Post by: joeaverage on March 10, 2019, 04:02:48 PM
Hi,
apologies, have just noticed a typo in the code, it should read:

Code: [Select]
local rc=mc.mcCntlGotoZero(inst)
if (rc== -18) then
        wx.wxMessageBox('Machine not in idle state')
        do return end
end

I have had another thought, the API you are using calls a standard Mach Action which is programmed in the core and you can't
view or edit it. If it calls for an A axis move you will encounter the same fault, namely that the machine attempts to move
the A axis to zero despite you not having an A axis defined.

If that is the case you will HAVE to use the modified GoToWorkZero() function in the sceern load script as I originally
suggested.

Craig
Title: Re: GoToWorkZero
Post by: fritzzco on March 10, 2019, 04:21:18 PM
Hi,  I put that last script in the siglib and when I exit and hit the Enable button mach4 froze up, so I just now removed that script and back to normal again for now.
Title: Re: GoToWorkZero
Post by: joeaverage on March 10, 2019, 04:24:16 PM
Hi,
then use the screen load function GoToWorkZero().

I have made three suggestions and you have ignored all of them......

Craig
Title: Re: GoToWorkZero
Post by: fritzzco on March 10, 2019, 04:40:37 PM
Hi,   I don't have that screen set wx4.set,   This is all I have in mach folder.  Is there a place to download it because when I googled it, nothing comes up.

Thanks
Title: Re: GoToWorkZero
Post by: joeaverage on March 10, 2019, 04:42:46 PM
Hi,
what build  of Mach are you using? (Help/About wil reveal the build number.)

Craig
Title: Re: GoToWorkZero
Post by: joeaverage on March 10, 2019, 04:49:09 PM
Hi,
look on the ftp site for the latest Mach4Hobby builds:

ftp://ftp.machsupport.com/Mach4/DevlopmentVersions/ (http://ftp://ftp.machsupport.com/Mach4/DevlopmentVersions/)

I'm using 4095 on my laptop but 3805 on my machine.

4095 has the new THC features and Surface features.

Craig
Title: Re: GoToWorkZero
Post by: fritzzco on March 10, 2019, 04:53:23 PM
3804 the latest
Title: Re: GoToWorkZero
Post by: fritzzco on March 10, 2019, 04:57:23 PM
Hi,  Where are you getting all these versions?   I only see the the latest mach4 on mach's website.

Thanks
Title: Re: GoToWorkZero
Post by: fritzzco on March 10, 2019, 05:00:21 PM
Maybe all my problems are because I'm on windows10.  I now see that's not listed under pc requirements for mach4.   shucks.
Title: Re: GoToWorkZero
Post by: joeaverage on March 10, 2019, 05:01:50 PM
Hi,
the latest development version is up to 4118. None the less 3804 should have wx4.set.

Try the ftp site....that's where you get the development versions.

ftp://ftp.machsupport.com/ (http://ftp://ftp.machsupport.com/)

Mai I suggest you download an update. I don't know where wx4.set has gone to in your installation but that
is the go-to screen set for any (up to 4 axis) mill/router.

Quote
Maybe all my problems are because I'm on windows10.  I now see that's not listed under pc requirements for mach4.   shucks.
Bull*********.....Mach4 works perfectly under Windows 10.

Craig
Title: Re: GoToWorkZero
Post by: fritzzco on March 10, 2019, 05:09:39 PM
Trying to connect to that ftp site, no luck.  I'll try later.
Thanks
Title: Re: GoToWorkZero
Post by: joeaverage on March 10, 2019, 05:14:25 PM
Hi,
I have the same problem, my browser wont load the ftp site.

Go to the Mach4 download page and look or the ftp link per attached.

Craig
Title: Re: GoToWorkZero
Post by: fritzzco on March 10, 2019, 05:27:29 PM
yea, their new website don't show it, but I found it by googling it.   Here it is.
Title: Re: GoToWorkZero
Post by: fritzzco on March 10, 2019, 05:28:25 PM
I dwnloaded the 4.2 so I will have to enter my info again, but loaded my screenset, whew......
Title: Re: GoToWorkZero
Post by: fritzzco on March 10, 2019, 05:29:26 PM
Address:  ftp://ftp.machsupport.com/
Title: Re: GoToWorkZero
Post by: joeaverage on March 10, 2019, 05:57:47 PM
Hi,
no, if you have an individualized profile and individualized screenset you should be able to download the latest
build and install it WITHOUT affecting your existing settings.

When you run Mach if you View/Load Screen/wx4.set <open> your screen will redraw with the wx4.set screenset.
If you like it then close Mach. That would flush your newly preferred screenset to the .ini file ie it becomes your
standard screenset thereafter.

You are strongly recommended to make a copy of your preferred screenset, wx4 say, with an individualized name.
Then load that set and close Mach to have it flushed to the .ini file.
Thus all your screen edits and scripts are saved in an individualized file.  When you download and install an even later
build and wx4.set is overwritten by a fresh, and possibly modified coy from NFS, all your screen edits etc are not lost.

Craig
Title: Re: GoToWorkZero
Post by: fritzzco on March 11, 2019, 05:32:19 PM
Hi,  I still had no luck on that screenset so I emailed Mach4 about it.  Also when I put the latest edition of mach in, my windows crashed twice so I removed that and put in my 3408.  Now that I got that up and going I'm back to trying to get that button to associate with a keyboard button so I tried your sigscript entry and this is what I get (in the pics) so I reviewed that sigscript you told me to put in and found the same thing on other forum entries but my machine just won't let me have it. :(

Thanks for your time, maybe I just leave it and walk over to my screen all the time to GoToZero.
Title: Re: GoToWorkZero
Post by: joeaverage on March 12, 2019, 12:58:59 AM
Hi,
where are you putting your code?

In the first instance you displayed code that you were using in the PLC script. Not the best choice in my opinion,
but it works.

Then I posted some code to go in the PLC script and NOW you are trying to put it in the SigLib{}????

First, have you edited and modified the GoToWorkZero() function in the screen load script? If so would you post it so I can
see it.

Now make a choice........either put code in the PLC script OR in the SigLib{}. You tell me which one you want to do
and then we'll do it.

Craig
Title: Re: GoToWorkZero
Post by: joeaverage on March 12, 2019, 01:01:58 AM
Hi,
looking closely at your screen shot and you've placed the code 'outside' the SigLib{} table. No wonder it wont cpmpile.

Post the first 50 or so lines of the screen load script so I can check it out.

Craig
Title: Re: GoToWorkZero
Post by: fritzzco on March 12, 2019, 11:31:29 AM
Hi, good morning, I did some hard reading last night and got that one figured out and seems to work, I did the sigscript.  Took me awhile to see what I was doing wrong.  Had the code at the end for one, now at the top of the siglib.  Then I had syntax errors, and figured that out and now it works.  I tried to do that same thing with refallhome but that I guess is different because of the coroutine.   Hard for me with this mach4, totally diff from mach3.   Have to learn all this programing with my limited time, wish I had 1/10 of your knowledge on this.  Hard for me to go to programing from manufacturing, like switching from a car to a plane to Alaska.  I'll just keep reading, knowledge is power.  Check out my website when you get a chance, fritzzco.com   Thanks for your time.   I'll do more reading and try the coroutine again.
Aloha
Fritz