Hello Guest it is December 10, 2019, 02:12:04 AM

Author Topic: Reference all home help.  (Read 4783 times)

0 Members and 1 Guest are viewing this topic.

Re: Reference all home help.
« Reply #30 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
My wife left with my best friend...
     and I miss him!
Re: Reference all home help.
« Reply #31 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
My wife left with my best friend...
     and I miss him!
Re: Reference all home help.
« Reply #32 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
Re: Reference all home help.
« Reply #33 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);
Re: Reference all home help.
« Reply #34 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
My wife left with my best friend...
     and I miss him!
Re: Reference all home help.
« Reply #35 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
My wife left with my best friend...
     and I miss him!
Re: Reference all home help.
« Reply #36 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
My wife left with my best friend...
     and I miss him!
Re: Reference all home help.
« Reply #37 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
Re: Reference all home help.
« Reply #38 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
My wife left with my best friend...
     and I miss him!
Re: Reference all home help.
« Reply #39 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
My wife left with my best friend...
     and I miss him!