Hello Guest it is December 06, 2019, 07:11:55 PM

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

0 Members and 1 Guest are viewing this topic.

Offline DazTheGas

*
  •  750 750
  • DazTheGas
    • View Profile
Re: Reference all home help.
« Reply #20 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
Theres always time for a choccy biccy
Re: Reference all home help.
« Reply #21 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
My wife left with my best friend...
     and I miss him!

Offline DazTheGas

*
  •  750 750
  • DazTheGas
    • View Profile
Re: Reference all home help.
« Reply #22 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
Theres always time for a choccy biccy
Re: Reference all home help.
« Reply #23 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
My wife left with my best friend...
     and I miss him!
Re: Reference all home help.
« Reply #24 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
Re: Reference all home help.
« Reply #25 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
My wife left with my best friend...
     and I miss him!
Re: Reference all home help.
« Reply #26 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
My wife left with my best friend...
     and I miss him!
Re: Reference all home help.
« Reply #27 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.
My wife left with my best friend...
     and I miss him!
Re: Reference all home help.
« Reply #28 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
Re: Reference all home help.
« Reply #29 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
My wife left with my best friend...
     and I miss him!