Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: nickcnc on November 27, 2017, 04:12:39 PM

Title: Reference all home help.
Post by: nickcnc on November 27, 2017, 04:12:39 PM
Hello. Would anyone be able to help me piece together a simple homing script. Clicking reference all home homes all axiis X Y Z. Great. How can i have X then move like 10 inches to center the table? seems pretty simple and is pretty normal on industrial machines.... i found some mention of using something like a Gcode execute in the homing sequence in load screen? nothing seems to work and anything mach4 / lua "noob" documentation is few and far between... :-\  I have successfully got psychical cycle start feed hold stop buttons programmed and working (cant figure out single block tho..) Any help with getting this thing working correctly would be so awesome.!

- Nick

Pictures of my machine build for internist!!

(https://i.imgur.com/uip7Btol.jpg)

(https://i.imgur.com/pArMo2xl.jpg)

(https://i.imgur.com/Yw6UF2bl.jpg)
Title: Re: Reference all home help.
Post by: joeaverage on November 28, 2017, 01:26:16 AM
Hi,
very clean tidy build, congratulations.

Couple of ways to do want you want:
1) Add code to the Ref All Home script
2) Add a button that goes to the center of the table

I think in the first instance I would add a button. Gives you the chance to do some coding without modifying too greatly any existing functions of Mach.
If you screw it up just delete your work and Mach is back to normal. Once you've got the code spot on and had a chance to use it you could then graft it
onto the Ref All Home script if you still think it desirable.

I don't know what screenset you use, mine is based on wx4.set. Immediately under the DRO block on the Program Run Tab there are five buttons and a couple of
LEDs. One of the buttons is blank. May I suggest using it....rename it and attach your code. You can make your own button of course but the screen is already pretty full,
its not easy trying to squeeze another button in anywhere.

Your machine looks like its got a button block, if there is a spare one you could use that instead or even as well as a screen button.

Does that idea appeal?

Craig
Title: Re: Reference all home help.
Post by: joeaverage on November 28, 2017, 01:37:03 AM
Hi,
go to Edit screen I renamed the button...

Craig
Title: Re: Reference all home help.
Post by: nickcnc on November 28, 2017, 07:01:02 PM
Hello Joeaverage! Thanks for the response. I will fill you in with where Im currently at in my "lua" journey. Wx4 screen set.

I have psychical Cycle start, feed hold, stop buttons coded and working as they should..  I also have coolant and "mist" buttons working correctly and triggering mach. Single block appears to work as well! Everything I have come up with so far is self modified / figured out versions of code that i have copied from around the web. After much head scratching i have made some small success. I will post all the code i have currently to make the buttons work, could you look at them and see if anything is crazy out of sorts? Everything appears to be working great.

The Homing part is what i do not understand. I like you idea for mapping to to one of my spare buttons on the HMI. I would like for the script to be in the homing sequence so it does it automatically... regardless of how it happens is the code the same? Something like after homing, X axis moves to center of table and Y axis moves a few inches... "reference complete". I sure do appreciate you time, let me know what you thoughts are!

The picture you posted.. Did you create this button? or is this a factory feature I'm not seeing?

Thanks again - Nick


SigLib = {
[mc.OSIG_MACHINE_ENABLED] = function (state)
    machEnabled = state;
    ButtonEnable()
end,

[mc.ISIG_INPUT0] = function (state)
    if (state == 1) then
        CycleStart()
    end
   
end,

[mc.ISIG_INPUT1] = function (state)
   if (state == 1) then   
        mc.mcCntlFeedHold (inst)
        mc.mcCntlSetLastError (inst, "Do Feed Hold")
    end

end,

[mc.ISIG_INPUT2] = function (state)
    if (state == 1) then
        CycleStop()
    end

end,






----------Input 3------------
------Toggle Coolant---------
[mc.ISIG_INPUT3] = function (state)
if (state == 1) then
     local inst = mc.mcGetInstance();
     local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_COOLANTON);
     local sigState = mc.mcSignalGetState(sigh);
     if (sigState == 0) then
         local OSigCool = mc.mcSignalGetHandle (inst,mc.OSIG_COOLANTON)
         mc.mcSignalSetState(OSigCool,1)
         mc.mcCntlSetLastError(inst, "Coolant On")
     else
         local OSigCool = mc.mcSignalGetHandle (inst,mc.OSIG_COOLANTON)
         mc.mcSignalSetState(OSigCool,0)
         mc.mcCntlSetLastError(inst, "Coolant Off")
     end
end
   
end,

----------Input 4------------
------Toggle MIST - AIR Coolant---------
[mc.ISIG_INPUT4] = function (state)
if (state == 1) then
     local inst = mc.mcGetInstance();
     local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_MISTON);
     local sigState = mc.mcSignalGetState(sigh);
     if (sigState == 0) then
         local OSigMist = mc.mcSignalGetHandle (inst,mc.OSIG_MISTON)
         mc.mcSignalSetState(OSigMist,1)
         mc.mcCntlSetLastError(inst, "Mist On")
     else
         local OSigMist = mc.mcSignalGetHandle (inst,mc.OSIG_MISTON)
         mc.mcSignalSetState(OSigMist,0)
         mc.mcCntlSetLastError(inst, "Mist Off")
     end
end
   
end,

----------Input 5------------
------Toggle SingleBlock---------
[mc.ISIG_INPUT5] = function (state)
if (state == 1) then
     local inst = mc.mcGetInstance();
     local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SINGLE_BLOCK);
     local sigState = mc.mcSignalGetState(sigh);
     if (sigState == 0) then
         local OSigSingle = mc.mcSignalGetHandle (inst,mc.OSIG_SINGLE_BLOCK)
         mc.mcSignalSetState(OSigSingle,1)
         mc.mcCntlSetLastError(inst, "Single Block On")
     else
         local OSigSingle = mc.mcSignalGetHandle (inst,mc.OSIG_SINGLE_BLOCK)
         mc.mcSignalSetState(OSigSingle,0)
         mc.mcCntlSetLastError(inst, "Single Block Off")
     end
end
   
end,
Title: Re: Reference all home help.
Post by: joeaverage on November 28, 2017, 07:11:30 PM
Hi,
no the button was already there but not named or assigned any function. I just renamed it.

Allows you to 'hang some code on it'. Whether you use a physical button or a screen button you will need some
code and it ocurred to me that this is a simple way to do it. Given that you've got your head around the signal scrpit/lib
then this code will be very very simple.

At work at the moment so won't try to write code on the fly. Will post some ideas tonite.

Craig
Title: Re: Reference all home help.
Post by: nickcnc on November 28, 2017, 07:34:45 PM
Awesome!!! Thanks Craig. Look forward to hearing from you!  - Nick
Title: Re: Reference all home help.
Post by: joeaverage on November 29, 2017, 01:01:19 AM
Hi,
couple of preliminary items:
1) If the machine has not been referenced you CAN'T use the Go_Center function. When you first turn Mach on the machine co-ordinates could be any where.
If the machine drives to a specific machine co-ordinate location it could easily go outside its envelope and crash. Soft Limits won't help either as they ONLY make
sense and do any good once the machine has been referenced.
2) You will direct the machine to execute some Gcode but if one of the axes is not enabled then the machine can't do as you've asked and it will hang up and
you'll have to crash it to get it to unblock, not desirable. Before executing Gcode need to establish that all required axes have been enabled so the code doesn't block.
3) The machine co-ordinates of the center of the table should be held in registers. It makes it easy to tweak, just edit a register rather than delve into a script.
4) The Go_Center function should probably go in the screen load script rather than the signal script or a macro, the screen load script functions are visible throughout
Machs GUI. Having said that I propose to write it as a macro initially, it allows a convenient set of editing and debug functions.

Two API calls of use to us:
Title: Re: Reference all home help.
Post by: joeaverage on November 29, 2017, 01:03:50 AM
Hi,
oops... posted before I'd completed...

Quote
LUA Syntax:
enabled, rc = mc.mcAxisIsEnabled(
      number mInst,
      number axisId)

and:
Quote
LUA Syntax:
homed, rc= mc.mcAxisIsHomed(
      number mInst,
      number axisId)

Craig
Title: Re: Reference all home help.
Post by: nickcnc on November 29, 2017, 01:28:52 AM
Craig,

Lua is mostly greek to me, I have made it this far via trail error / copy paste. With that being said I'm hopeful.

This "go to center" function will only happen when the machine is homed. Like the machine is homed and ready to work.

I know nothing of registers currently, would this be apposed to something like G0 X10 Y-10 in the code?

What ever you recommend im all ears on how best to get it done. Warpt9 ess instructions say "a lua script is necessary to back of home switches after homing" I believe mach3 had this functionality, home axis.. back off prescribed amount. only on homing.
Title: Re: Reference all home help.
Post by: joeaverage on November 29, 2017, 02:36:19 AM
Hi,
writing code as we speak.

Yes the function can only work IF the machine has been homed or referenced otherwise you could crash. Also trying to stop the function from running if
any of the axes are not enabled otherwise the GUI will block.

You could hard code the numbers in the code but if you ever wish to change them you'd have to delve into the code to change the numbers. If you use
registers you can use the Diagnostics of Mach and edit the numbers directly and easily, no messing around editing Lua code and recompiling.

If you go to Configure/Plugins/Regfile and create three new registers (the little green plus sign adds a new line)...

Craig
Title: Re: Reference all home help.
Post by: joeaverage on November 29, 2017, 03:53:39 AM
Hi,
this code seems to work...haven't really tested it fully

Code: [Select]
function GoCenter();
local inst=mc.mcGetInstance();
local Xhand=mc.mcRegGetHandle(inst,'iRegs0/Xcenter');
local Xcenter=mc.mcRegGetValue(Xhand);
local Yhand=mc.mcRegGetHandle(inst,'iRegs0/Ycenter');
local Ycenter=mc.mcRegGetValue(Yhand);
local Zhand=mc.mcRegGetHandle(inst,'iRegs0/Zcenter');
local Zcenter=mc.mcRegGetValue(Zhand);
local homed=0;
local enabled=0;
if (mc.mcAxisIsEnabled(inst,mc.X_AXIS)==1) then enabled=enabled+1 end;
if (mc.mcAxisIsEnabled(inst,mc.Y_AXIS)==1) then enabled=enabled+1 end;
if (mc.mcAxisIsEnabled(inst,mc.Z_AXIS)==1) then enabled=enabled+1 end;
local Xhomed,rc=mc.mcAxisIsHomed(inst,mc.X_AXIS);
local Yhomed,rc=mc.mcAxisIsHomed(inst,mc.Y_AXIS);
local Zhomed,rc=mc.mcAxisIsHomed(inst,mc.Z_AXIS);
if Xhomed==1 then homed=homed+1 end;
if Yhomed==1 then homed=homed+1 end;
if Zhomed==1 then homed=homed+1 end;
if (homed+enabled)==6 then
    mc.mcCntlGcodeExecuteWait(inst,"g53 g0 z"..Zcenter.."\n g53 g0 x"..Xcenter.."y"..Ycenter)
end
end
if (mc.mcInEditor() == 1) then
    GoCenter()
end

Craig
Title: Re: Reference all home help.
Post by: joeaverage on November 29, 2017, 03:57:01 AM
Hi,
I suggest putting this in your profile/macro folder. Allows you to debug and work on it. Once you get it polished then we'll put it in the screen load script
and attach it to the button.

Craig
Title: Re: Reference all home help.
Post by: joeaverage on November 29, 2017, 03:46:29 PM
Hi,
realised this morning that if the machine axes are not enabled and homed then a message should pop up to tell
you why the function didn't proceed.

Craig
Title: Re: Reference all home help.
Post by: nickcnc on November 29, 2017, 11:29:01 PM
WOW! thanks Craig! I super appreciate it. I will put the code in the macro folder.. in the mach4/hobby folder? I have yet to mess with or research anything about macros as of yet. Once the code is in the macro folder, is the next step tying the code to a button to test it out? This is getting exciting now! - Nick
Title: Re: Reference all home help.
Post by: nickcnc on November 29, 2017, 11:31:26 PM
I just went back a page and read the post i missed about registers! I will create the 3 registers like you show tomorrow and we can proceed with testing code. Thanks Craig.

- Nick
Title: Re: Reference all home help.
Post by: joeaverage on November 30, 2017, 12:42:54 AM
Hi Nick,
for the moment put it in the Macro folder of your current profile.

This is in fact a modification and extension of your screen set wx4.set  In a few months time when you download and install the latest build of Mach4
it will be overwritten by a new copy of wx4.set and your work, this and other tweaks will be lost.

For this reason I recommend that you make a copy of wx4.set and call it something distinct like Nickswx4.set and use that as your screen set. Then any tweaks
you make will not be overwritten. Create a copy of wx4.set in Mach4Hobby\Screens and rename. Run Mach4 Loader and copy your current profile, you can give
it a new name, and also select your newly created screen set.

The function code should be put in Mach4Hobby\Profiles\NicksProfile\Macros

Craig
Title: Re: Reference all home help.
Post by: nickcnc on November 30, 2017, 01:14:26 AM
Craig. I created a screen set with a custom name, it no longer says wx4 when i open and run mach. I read about about the importance of saving your profile right! I hope i did it the right way. I will copy the function code to the macros profiles and go from there! 

- Nick
Title: Re: Reference all home help.
Post by: joeaverage on November 30, 2017, 01:22:50 AM
Hi Nick,
I learnt the hard way...blithely editing my screenset for a few months (Mach4 was new to me) only to find that I had inadvertently overwritten it all when I got
a later build. It did cause me to re-read and more importantly UNDERSTAND the recommendations about having not only your own profile but screenset as well.

Craig
Title: Re: Reference all home help.
Post by: nickcnc on November 30, 2017, 01:40:19 AM
The thought of that pains me! =)  ... So, Am i correct in thinking after the function code is in the  macros folder... then I will need something to link the button to the function? possibly  something like GoCenter() in the left up on a custom button?
Title: Re: Reference all home help.
Post by: joeaverage on November 30, 2017, 01:51:13 AM
Hi,
yes that is the idea. Tempted to strip it out of the macros folder and put it in the screen load script. It would then be possible to call the function from
the left-up script of a screen button but also from the signal script if you wanted it to be accessible from a physical button.

Craig
Title: Re: Reference all home help.
Post by: DazTheGas on November 30, 2017, 12:07:34 PM
Quote
The function code should be put in Mach4Hobby\Profiles\NicksProfile\Macros

I would highly recommend against using the macros directory and use a temp dir, when you start mach4 it will compile the scripts into one file called mcLua.mcc. If for any reason the script you are trying to debug/test has an error then you have a good chance of stopping the legit M Codes being compiled.

DazTheGas
Title: Re: Reference all home help.
Post by: joeaverage on November 30, 2017, 12:15:51 PM
Hi Daz,
where would you put some code that as being worked on? The reason I suggested the Macro folder is that the lua editor can be used  for debugging.

Craig
Title: Re: Reference all home help.
Post by: DazTheGas on November 30, 2017, 12:33:17 PM
Make a temp dir in your profile directory, when you go to Operator/Edit Scripts it will open up a dialog allowing you to choose what script to load and debug.

DazTheGas
Title: Re: Reference all home help.
Post by: joeaverage on November 30, 2017, 12:46:09 PM
Hi Daz,
kool, that's certainly simple enough and the temp directory doesn't get compiled....and potentially screw up mclua.mcc

Craig
Title: Re: Reference all home help.
Post by: nickcnc on December 01, 2017, 01:22:54 AM
Hey Craig! What would you say is now the best way to proceed?  Thanks so much - Nick
Title: Re: Reference all home help.
Post by: joeaverage on December 01, 2017, 01:33:52 AM
Hi Nick,
I will be doing as Daz has suggested. Try the code to see if it does what you want. If it does bung the function, excluding the mcInEditor bit, in the screen
load script. Put 'GoCenter()' as left-up script on the events tab of the screen button.

Craig
Title: Re: Reference all home help.
Post by: joeaverage on December 01, 2017, 01:42:11 AM
Hi Nick,
shifted the code into a  folder 'temp' (I know...a really original name!). Also added a message box if the function declines to run because the axes aren't enabled
or homed.

Code: [Select]
function GoCenter();
local inst=mc.mcGetInstance();
local Xhand=mc.mcRegGetHandle(inst,'iRegs0/Xcenter');
local Xcenter=mc.mcRegGetValue(Xhand);
local Yhand=mc.mcRegGetHandle(inst,'iRegs0/Ycenter');
local Ycenter=mc.mcRegGetValue(Yhand);
local Zhand=mc.mcRegGetHandle(inst,'iRegs0/Zcenter');
local Zcenter=mc.mcRegGetValue(Zhand);
local homed=0;
local enabled=0;
if (mc.mcAxisIsEnabled(inst,mc.X_AXIS)==1) then enabled=enabled+1 end;
if (mc.mcAxisIsEnabled(inst,mc.Y_AXIS)==1) then enabled=enabled+1 end;
if (mc.mcAxisIsEnabled(inst,mc.Z_AXIS)==1) then enabled=enabled+1 end;
local Xhomed,rc=mc.mcAxisIsHomed(inst,mc.X_AXIS);
local Yhomed,rc=mc.mcAxisIsHomed(inst,mc.Y_AXIS);
local Zhomed,rc=mc.mcAxisIsHomed(inst,mc.Z_AXIS);
if Xhomed==1 then homed=homed+1 end;
if Yhomed==1 then homed=homed+1 end;
if Zhomed==1 then homed=homed+1 end;
if (homed+enabled)==6 then;
    mc.mcCntlGcodeExecuteWait(inst,"g53 g0 z"..Zcenter.."\n g53 g0 x"..Xcenter.."y"..Ycenter);
else
    wx.wxMessageBox('Axes not enabled/homed');
end
end
if (mc.mcInEditor() == 1) then
    GoCenter()
end

Craig
Title: Re: Reference all home help.
Post by: joeaverage on December 01, 2017, 01:59:59 AM
Hi Nick,
have added the code to the screen load script and put GoCenter() as left-up script in our Go Center button. It works but there is an issue. When I was debugging
I could watch the DROs change as the mc.CntlGcodeExecuteWait() statement did its thing.

As a Gcode function it is rightly executed by the Gcode Interpreter but while it does so the GUI doesn't see any service and it appears to block. It does
block for the length of time that the Gcode takes to run and while that is the case you can't see the DROs move.

Smurph has made some highly informative posts about this over the last week or ten days. I may go back and re-read to see if any simple solution exists.
I suspect that it will require a co-routine which is beyond my skill at present. Besides, 'making something simple complex' and therefore  losing any interest by you and
any others who may be following rather defeats the purpose of helping others.
Title: Re: Reference all home help.
Post by: nickcnc on December 02, 2017, 12:49:19 PM
Craig, Im not sure i follow you... Does the code move the axis but the dro does not move with it? If this is the case then is the code ok to use? I'm determined to make my machine function properly so count me in for the long haul! lol. But i could see how people could get overwhelmed by all the info.. or lack of. Mach4 could actually be something if it only came with standard machine functions built in, no coding. Thanks Craig for answering all my silly questions. - Nick
Title: Re: Reference all home help.
Post by: joeaverage on December 02, 2017, 07:42:03 PM
Hi Nick,
been away for a day or two. What it means is while the move is happening the GUI is stopped, that is to say the DROs don't keep up. When the move finishes
and the Gcode interpreter returns to the GUI then the DROs catch up.

Daz has pointed out (PM) that there is two choices for an API call to execute Gcode. The one I chose is:
Code: [Select]
rc = mc.mcCntlGcodeExecute(
number mInst,
string commands)
which passes control to the interpreter and waits until the interpreter is finished. The other alternative is:
Code: [Select]
rc = mc.mcCntlGcodeExecute(
number mInst,
string commands)
where the commands are passed to the interpreter as before but then returns to the GUI immediately. Its not a huge deal either way, the function will work
its just nice to see the DROs responding. We need to do a little bit of experimenting to determine 1) whether my understanding is correct and 2) if returning before
the function completes introduces unwanted side effects.

This is the joy and at the same time the frustration of Lua/Mach...its so very flexible and capable (good) but can easily lead to unintended consequences (bad).
We are extremely fortunate that people like Daz and Smurph have blazed a trail.

Craig
Title: Re: Reference all home help.
Post by: joeaverage on December 02, 2017, 08:36:12 PM
Hi Nick,

Quote
Mach4 could actually be something if it only came with standard machine functions built in, no coding.

NFS has crafted Mach4 with a view to sales to OEM customers. If they were relying on hobbyists sales they might as well sack their employees and call
in the bankruptcy lawyers now as save the rush later.

The consequence  is that there is no such thing as  'standard machine functions', every machine and machine builder will have to determine the required
behavior and code it appropriately. You have, whether you intended it or not, elevated yourself into the category of machine builder/machine integrator,
get used to it.

In years to come there may well be enough code snippets that a newbie can select from a menu of a few hundred or thousands of items to make his installation
fit his machine. Code, such as the substance of this thread, may be reused many times for instance.

You could take the attitude that you shouldn't have to or don't want to do this, or look back a little to the outstanding contributions made by people like Hood, Rich,
BR49 (aka Terry), Tweakie, Gerry and the list goes on...and realize that you have the opportunity to be part of the groundswell of Mach4. I've already made my
decision.

Craig
Title: Re: Reference all home help.
Post by: joeaverage on December 02, 2017, 09:51:34 PM
Hi Nick,
have tried Daz's suggestion and seems to work a treat.

I see I made a typo in an earlier post, the two API calls are:
Quote
rc = mc.mcCntlGcodeExecute(
      number mInst,
      string commands)

and:
Quote
rc = mc.mcCntlGcodeExecuteWait(
      number mInst,
      string commands)


I copied and pasted from the API.chm without noticing the typo in it, namely the missing 'Wait'...

So the code is:
Code: [Select]
--Go To Center of table script Nick Mach4 Gen Discussion 1/12/2017
function GoCenter();
local inst=mc.mcGetInstance();
local Xhand=mc.mcRegGetHandle(inst,'iRegs0/Xcenter');
local Xcenter=mc.mcRegGetValue(Xhand);
local Yhand=mc.mcRegGetHandle(inst,'iRegs0/Ycenter');
local Ycenter=mc.mcRegGetValue(Yhand);
local Zhand=mc.mcRegGetHandle(inst,'iRegs0/Zcenter');
local Zcenter=mc.mcRegGetValue(Zhand);
local homed=0;
local enabled=0;
if (mc.mcAxisIsEnabled(inst,mc.X_AXIS)==1) then enabled=enabled+1 end;
if (mc.mcAxisIsEnabled(inst,mc.Y_AXIS)==1) then enabled=enabled+1 end;
if (mc.mcAxisIsEnabled(inst,mc.Z_AXIS)==1) then enabled=enabled+1 end;
local Xhomed,rc=mc.mcAxisIsHomed(inst,mc.X_AXIS);
local Yhomed,rc=mc.mcAxisIsHomed(inst,mc.Y_AXIS);
local Zhomed,rc=mc.mcAxisIsHomed(inst,mc.Z_AXIS);
if Xhomed==1 then homed=homed+1 end;
if Yhomed==1 then homed=homed+1 end;
if Zhomed==1 then homed=homed+1 end;
if (homed+enabled)==6 then;
    mc.mcCntlGcodeExecute(inst,"g53 g0 z"..Zcenter.."\n g53 g0 x"..Xcenter.."y"..Ycenter);
else
    wx.wxMessageBox('Axes not enabled/homed');
end
end

--

Craig
Title: Re: Reference all home help.
Post by: nickcnc on December 03, 2017, 01:22:22 AM
Craig this is good news! Sorry if this is a dumb question, the typos and then the code you posted, does it contain the typos that need to be corrected as well? Also is the code now going in the screen load? I never tried the first code being startled by what daz said... so now that the new code sound better i will run it tomorrow morning, just wanting to get the sequence of events down again! Thanks again!  - Nick
Title: Re: Reference all home help.
Post by: nickcnc on December 03, 2017, 01:52:30 AM
Also, is it correct is assuming that my x and y back of distances go after thex &y in the code...... X10 and Y-3?

 mc.mcCntlGcodeExecute(inst,"g53 g0 z"..Zcenter.."\n g53 g0 x"..Xcenter.."y"..Ycenter);
Title: Re: Reference all home help.
Post by: joeaverage on December 03, 2017, 01:57:37 AM
Hi Nick,
the code is clean and ready to run. The only change was to remove the GcodeExecuteWait and substitute GcodeExecute per Daz's recommendation.

The typo comes from the fact that in the API.chm the two API calls show exactly the same syntax, ie someone who composed the .chm entry forgot
to put the 'Wait' in one API call and I didn't notice until after I'd posted.

Craig
Title: Re: Reference all home help.
Post by: joeaverage on December 03, 2017, 02:05:50 AM
Hi,
no. The actual number substituted at runtime are the contents of the registers Xcenter, Ycenter, Zcenter.

You can see what they contain by Diagnostic/Regfile and expand iRegs0. You can edit any of the register contents by double clicking and overwriting.
Thus while the center of your table might be 10,3,0 you may decide that you want to change that to match some feature of a jig say located at 12,2.56,0,
it would be a simple matter to type those numbers into the iRegs0 entries and carry on. No need to edit code.

Craig
Title: Re: Reference all home help.
Post by: joeaverage on December 03, 2017, 02:13:40 AM
Hi,
shows the Diagnostic/Regfile with iRegs0 expanded. The entries are the defaults, double click to overwrite.

Craig
Title: Re: Reference all home help.
Post by: nickcnc on December 03, 2017, 12:30:17 PM
Hi Craig, I have created the registers but I'm not clear on where i put the code? Also is it ok for me to put the code in the reference all sequence so it automatically happens when i reference the machine? Thanks - Nick
Title: Re: Reference all home help.
Post by: joeaverage on December 03, 2017, 02:32:53 PM
Hi,
yes you could but I wouldn't advise it, certainly while the code is still being developed. You run the risk of grafting
faulty code into an important Mach function and possibly break Mach in a way that might be hard to fix.

I have the code in two locations. Per Daz's suggestion I have made a temp file in my profile which allows me to use
the editor for debugging.

Once I was happy enough that the code was OK I then put it into the screen load script, just before the Sig Lib
code for convenience. I stripped the  if (mc.InEditor) conditional out but otherwise the code is indentical.

Put GoCenter() as left-up script of your screen button and your'e done.

You may if all is well include a reference to the function from your Sig Lib so that a physical button can be used.

To start with just put it in the screen load script and attach the screen button. Once you've experimented with it
and proven its worth THEN consider how you might extend it and the means of utilising it.

Craig
Title: Re: Reference all home help.
Post by: joeaverage on December 03, 2017, 03:58:51 PM
Hi Nick,
additionally if the code is embedded in another function the only way to get it to run is to run the function in which it
is embedded, ie Ref All.

If however you leave it in the screen load script it is visible to all parts of the GUI. Thus you could call on the GoCenter
function from a screen button, a physical button and if you want to your Ref All script could also call it. Leaving the
GoCenter() function in the screen load script offers you the maximum flexibility.

Craig
Title: Re: Reference all home help.
Post by: nickcnc on December 03, 2017, 04:20:04 PM
Craig, You are the man! I just ran the code on my laptop and it appears to function like it should! so cool! Im going to go do the same thing on the machine now. I will post a video of it working. My end goal is to have this bit of code only happen when the ref all button is clicked. Report back shortly! Thank you Craig. Nick
Title: Re: Reference all home help.
Post by: joeaverage on December 03, 2017, 04:32:02 PM
Hi,
I personally would not have it run automatically with Ref All but be called from a screen button or physical button.
Motion which happens automatically has the tendency to catch you out on occasion and cause a crash.

The good thing about Mach4 is that you can make it do pretty anything you want. Provided you place the code appropriately
you can have any or all of those behaviours.

Craig
Title: Re: Reference all home help.
Post by: nickcnc on December 03, 2017, 05:05:50 PM
Trying to set up the actual machine using my renamed machine profile i dont have the option to access the regfile / create in the plugins drop down..?  its there on the wx4 screenset on my laptop. Is there something I'm missing? I can see the plugin in the c/mach4hobby plugin folder....
Title: Re: Reference all home help.
Post by: joeaverage on December 03, 2017, 05:11:39 PM
Hi,
the Regfile and the functionality it confers is a plugin.

On Configure/Mach/Plugins check Regfile by New Fangeled Solutions. You may have to restart Mach to have it recognise the new
plugin.

Craig
Title: Re: Reference all home help.
Post by: nickcnc on December 03, 2017, 06:45:38 PM
Craig! We have movement!!  ;D ;D ;D .



Here is a video.... not sure how to post videos on here the proper way.

https://youtu.be/VIjoA5kOhTg

Title: Re: Reference all home help.
Post by: joeaverage on December 04, 2017, 12:42:17 AM
Hi Nick,
kool, its starting to come together. When you 'go to center' you need to be looking at the DROs displaying Machine Co-ordinates.

In the video the DROs were in work co-ords and no doubt due to non zero numbers in the G54 work offset they display numbers other than 10,-3,0.

Likewise your soft limits are in terms of machine co-ordinates, to have the DROs display work co-ords doesn't tell you anything.

Also if I understand your commentary the soft limits are 'inside' your home switches???? If you hit Ref All part way through a session and the soft limits
are engaged, the normal situation, then the machine will fail to re-reference. Sorry but that means you've just broken perhaps the single most
important motion function in Mach! It is normal to have soft limits at or just 'outside' of the home switch. My soft limits are about 2mm outside of the
X,Y 0,0 home switch positions and the upper Z soft limit is 0, ie coincident with the Z home switch.

Experiment with the function but with the DROs set to display machine co-ordinates, you'll learn a great deal more about your machine and it limits if you
do so.

Craig
Title: Re: Reference all home help.
Post by: nickcnc on December 04, 2017, 12:38:07 PM
I will click it to machine co-oridinates and do some looking. Im not clear on what you are saying about being outside of the home switch. As it stands this is how my machine is configured. 3 home switches at the end of each axis. in the ess plugin I have my soft min max for say the X axis at.... min .250 max 18.0 ... I figured this being the soft limit would after the machine homed keep the machine .250' off the home switch? Does that make sense? Do you think I'm not using the softlimits right? Thanks - Nick
Title: Re: Reference all home help.
Post by: joeaverage on December 04, 2017, 12:54:41 PM
Hi,
if the home switch is at zero and the max that axis can go is 18 inches the I would reckon the soft limits be 0 and 18. Better, -0.1,18. That means that
the homw switch is within the boundaries of the machine. As you have set it up if you called Ref All once the soft limits are active it could not reach the
home switch being at 0 whereas the min softlimit is 0.25.

Craig
Title: Re: Reference all home help.
Post by: nickcnc on December 04, 2017, 01:45:52 PM
I totally understand what you are saying! I guess how i arrived at the .250 was wanting to keep the axis off the switch, like a buffer zone? This could be causing problems with the code after soft limits are turned on.... i might be crazy, but i thought mach would ignore the soft limits when reference all axis was commanded?



"When you Home the machine to the Home switches, Machine Zero is set. The Softlimits are in relation to Machine Zero.
What I do, is set my Home Offset to a small negative value, say -.5".
So after homing, when my home switch is then acting as a limit switch, I can go to the zero position on the axis and still be .5" away from the switch. If you then set softlimit min to 0, the machine will stop before it gets near the physical limit (home) switch."

(Google search) trying to better understand i have found mention of what i think I'm trying to do.. =)
would this interfere with reference all?
Title: Re: Reference all home help.
Post by: joeaverage on December 04, 2017, 03:14:56 PM
Hi,
I believe Mach3 worked that way and its probable that Mach4 does the same, I haven't experimented enough to be
sure.

My home switches are several mm short of the axis stops. I set my softlimit to be at or just outside the home switch.
That means that the home switch is within the allowable machine boundary. Given that is the case, whether the softlimits
are over-ridden when you hit Ref All doesn't matter to me, the home switch is within softlimits in either case.

With the  roller plunger switches widely used for home switches it is normal for the home switches to be well within the
boundaries and dedicated limit switches at the ends of the axes. That the home switches trigger during normal operations
is not going to upset anything.

Craig
Title: Re: Reference all home help.
Post by: nickcnc on December 04, 2017, 04:27:41 PM
I have since went to the machine and and confirmed what you had mentioned! Having the home switch outside the soft limits was causing problems! I have since switched x min soft limit to 0 and can now run the "to center" code as expected with soft-limits enabled right out of the gate! Clicking the machine coordinates helped with seeing what was going on!  :) 
Title: Re: Reference all home help.
Post by: joeaverage on December 04, 2017, 05:21:46 PM
Hi,
kool, life is one big learning experience.

I recall it took a long time for me to get fixed in my mind the difference between machine co-ordinates and those functions
which are implemented in terms of machine co-ordinates and work co-ordinates. Its not so much that I'm a slow learner
but just a quick forgetter!

Craig
Title: Re: Reference all home help.
Post by: nickcnc on December 04, 2017, 05:36:59 PM
hahah "quick forgetter" thats funny! With the current "to center" code and my new changes to the softlimits, i have tested different values, tried different combinations to make it do something odd or miss behave. I feel comfortable and want to make your code execute automatically after the "reference all button" is clicked. How can i call the "GoCenter()" function automatically in the reference all script? ....

Can i add something to the REF all home function to call the "GoCenter()" function and make it happen in one fell swoop?

---------------------------------------------------------------
-- Ref All Home() function.
---------------------------------------------------------------
function RefAllHome()
    mc.mcAxisDerefAll(inst)  --Just to turn off all ref leds
    mc.mcAxisHomeAll(inst)
    coroutine.yield() --yield coroutine so we can do the following after motion stops
    ----See ref all home button and plc script for coroutine.create and coroutine.resume
   
--
    wx.wxMessageBox('Referencing is complete')
end


Title: Re: Reference all home help.
Post by: joeaverage on December 04, 2017, 06:01:07 PM
Hi,
yes you can add it to the RefAllHome() function, I would put GoCenter() just before the message box.

The advantage of having the GoCenter function code in the screen load script is that it is visible
throughout the Mach GUI and is therefore perfectly permissable to call it from another function, in this case
RefAllHome(). Not sure how the coroutine part would affect it. Note that the screen button will work per normal,
there is no need to disable it.

Try it and see.

Craig
Title: Re: Reference all home help.
Post by: Chaoticone on December 04, 2017, 06:49:38 PM
Quote
Not sure how the coroutine part would affect it

You will want to add it after the coroutine so it goes to center after homing is complete.

The coroutine and message box was added to the ref all home to be an example of how coroutines can work. They are nice to hold things up until a certain point is reached then continue from there. Without the coroutine the message box would pop up immediately when the RefAllHome function was called (instead of after motion stops after all referencing is complete).
Title: Re: Reference all home help.
Post by: joeaverage on December 04, 2017, 07:47:05 PM
Hi Chaoticone,
I've always avoided the investment in thinking to allow me to make any real sense of co-routines...looks like
that particular 'blissful ignorance' is under assault!

Craig
Title: Re: Reference all home help.
Post by: nickcnc on December 04, 2017, 08:36:16 PM
Chaoticone and Joeaverage hello! Thanks for all the feed back and assistance =)  Doing some searching and playing around with the co-routine in the screen load. placing GoCenter() in the ref all causes like you said for the reference complete message to pop up before the x,y move is complete... Im sure its something very obvious  ;)  but unlike Craig my ignorance is less blissful  ;D  Is it a simple matter of placing the code correctly in the ref all.

- Nick
Title: Re: Reference all home help.
Post by: joeaverage on December 04, 2017, 08:41:46 PM
Hi Nick,
that is what I expect, the machine has to reference and the message 'Referencing Complete' is appropriate
BEFORE the GoCenter() function even starts.

Craig
Title: Re: Reference all home help.
Post by: Chaoticone on December 04, 2017, 09:07:25 PM
Chaoticone and Joeaverage hello! Thanks for all the feed back and assistance =)  Doing some searching and playing around with the co-routine in the screen load. placing GoCenter() in the ref all causes like you said for the reference complete message to pop up before the x,y move is complete... Im sure its something very obvious  ;)  but unlike Craig my ignorance is less blissful  ;D  Is it a simple matter of placing the code correctly in the ref all.

- Nick

Just add another coroutine.yield

function RefAllHome()
    mc.mcAxisDerefAll(inst)  --Just to turn off all ref leds
    mc.mcAxisHomeAll(inst)
    coroutine.yield() --yield coroutine so we can do the following after motion stops
    ----See ref all home button and plc script for coroutine.create and coroutine.resume
    --Do your moves here
     coroutine.yield()
--
    wx.wxMessageBox('Referencing is complete')
end

Hi Chaoticone,
I've always avoided the investment in thinking to allow me to make any real sense of co-routines...looks like
that particular 'blissful ignorance' is under assault!

Craig

 ;D
Title: Re: Reference all home help.
Post by: Third-Gen on December 04, 2017, 10:08:25 PM
why not just move the home switch to the center of the table, like an old MAG VMC? Not sure why you want it to move to center, just for easy loading? My giant VMC has a 30x60 table and homes far back right corner, so a G98.1 X30 Y30 brings it front and center.
Title: Re: Reference all home help.
Post by: joeaverage on December 04, 2017, 10:45:48 PM
Hi,
with this code you can cause the table to go to any location that is convenient just by changing three registers,
no need to shift home switches etc.

Hardly earth shattering to be sure but convenient.

Second, what about the opportunity to do a little Lua coding...learn as you go.

Craig

Title: Re: Reference all home help.
Post by: nickcnc on December 06, 2017, 09:57:34 PM
 ;D ;D ;D Things are moving!! I wanted to give a big shout out to Joeaverage! You have been the utmost help and VERY patient with my questions! Thank you I really appreciate it. seeing the code work make me grin ear to ear! Looking forward to getting this machine going.

- Nick

Live action VIDEO   ;)
https://youtu.be/Dc-_CjMxNgE (https://youtu.be/Dc-_CjMxNgE)