Hello Guest it is December 12, 2019, 01:52:07 PM

Author Topic: How to generate gcode to do pearling  (Read 709 times)

0 Members and 1 Guest are viewing this topic.

Re: How to generate gcode to do pearling
« Reply #10 on: January 19, 2019, 12:25:26 AM »
I like this.   Very good use for LUA.   I'm curious though, and want to make a macro program out of it.   I'll try this tomorrow and see what happens.   Great code, Craig!   Curious, will this lock the GUI or run fine?   I left my laptop at work so I can't test it.
Chad Byrd
Re: How to generate gcode to do pearling
« Reply #11 on: January 19, 2019, 01:19:18 AM »
Hi Chad,

Quote
Curious, will this lock the GUI or run fine? 

The GUI is busy in the same manner as it is when running a Gcode file. The DRO's update and the <Feed Hold>,<Stop>
and <Enable/Disable> buttons work normally but others like the file ops button are greyed out.

I quite frequently write scripts to do certain things as a macro within Mach.

I have several that when executed (MDI m*********()) it will open a file dialog which will allow me to browse to a Gcode
file for instance, open the file, read line by line and apply a text correction and save the corrected lines
of text in an output file. So despite being a macro it has NO MOTION commands at all, it is just a text manipulation
script.

This example could have been a poor mans Wizard for example. If I had opened a file  instead of using mcCntlGcodeExecuteWait()
I could have saved the lines of text (Gcode) to the file. The file could then have been run in the normal manner.

I must say I struggle with wxLua. I can't find any list of simple examples I can copy/edit. Neither can I find a list
of the useful or relevant options when specifying the parameters. I've looked at the various reference documents
but there is a huge information overload and I come away knowing less than when I started!

It seemed to make sense to me to simplify the script by excluding all the wxWidgets crap....quite aside from the fact I'm
hopeless at wxStuff.

Despite my previous post about not changing 'pearl' to 'jewel' I have done so (find and replace) and introduced a couple
of new variables as well retractZ, safeZ, and jewelDwellTime. Renamed it m121() just to keep it distinct from the previous
one.

I will give some more thought to what wxLua functions may streamlining the data entry stuff, rather than editing the macro.

Code: [Select]
function m121()
local inst=mc.mcGetInstance()
--
-- Jewel Data.....to be edited as required
--
local jewelWidth=50
local jewelLength=100
local toolDiameter=6
local nominalStepover=0.66
local plungeSpeed=300
local retractZ=2
local safeZ=20
local jewelDwellTime=500
--
-- End of data block
--
local startXpos
local startYpos
local jewelZheight

local stepoverX,numjewelX
local stepoverY,numjewelY
local i=0
local j=0
-- Save the current position as the start of the jeweling area....you have jogged to the start haven't you????
startXpos=mc.mcCntlGcodeInterpGetPos(inst,mc.X_AXIS)
startYpos=mc.mcCntlGcodeInterpGetPos(inst,mc.Y_AXIS)
jewelZheight=mc.mcCntlGcodeInterpGetPos(inst,mc.Z_AXIS)
-- Calculate the required step over to meet the nominal step over as closely as possible but be an integral
-- number of 'jewels'
-- Reduce perlWidth in X and Y by the diameter of the tool
jewelWidth=jewelWidth-toolDiameter
jewelLength=jewelLength-toolDiameter
-- Calculate the exact number of 'jewels' required to match the nomininalSteppover
numjewelX=jewelWidth / (nominalStepover * toolDiameter)
numjewelY=jewelLength / (nominalStepover * toolDiameter)
-- Find the integer number of 'jewels'
numjewelX=math.modf(numjewelX)
numjewelY=math.modf(numjewelY)
-- Calculate the actual stepover to be used so that an integral number of 'jewels' are perfomed
stepoverX=jewelWidth / numjewelX
stepoverY=jewelLength / numjewelY
--
--
local retract="g0 z "..tostring(jewelZheight+retractZ) --Nominal retract is 2mm above the surface
local safeHeight="g0 z "..tostring(jewelZheight+safeZ) --Nominal Safe Height is 20mm above the surface
mc.mcCntlGcodeExecute(inst,retract..'\n'..
'g1 f'..tostring(plungeSpeed)..'\n')
for i=1,numjewelX,i+1 do
for j=1,numjewelY,j+1  do
jewelX=startXpos + (i * stepoverX)
jewelY=startYpos + (j * stepoverY)
mc.mcCntlGcodeExecute(inst,'g0 x '..tostring(jewelX)..' y '.. tostring(jewelY)..'\n'..
'g1 z '..tostring( jewelZheight)..'\n'..
'g4 p'..tostring(jewelDwellTime)..'\n'..
retract..'\n')
end
end
mc.mcCntlGcodeExecuteWait(inst,safeHeight)
end
if (mc.mcInEditor()==1)then
m121()
end
My wife left with my best friend...
     and I miss him!
Re: How to generate gcode to do pearling
« Reply #12 on: January 19, 2019, 01:34:50 AM »
Hi,
think I just spotted a mistake....the For loops will cause one extra row and one extra column of 'jewels'.

The code is, as it stands:

for i=1,numjewelX,i+1 do
      for j=1,numjewelY,j+1  do
         jewelX=startXpos + (i * stepoverX)
         jewelY=startYpos + (j * stepoverY)

I think to fit within the boundaries specified the code should be:

for i=0,numjewelX-1,i+1 do
      for j=1,numjewelY-1,j+1  do
         jewelX=startXpos + (i * stepoverX)
         jewelY=startYpos + (j * stepoverY)

Either way use with caution the first time you try it.....the tool may go a bit further than I thought!

Craig
« Last Edit: January 19, 2019, 01:46:55 AM by joeaverage »
My wife left with my best friend...
     and I miss him!
Re: How to generate gcode to do pearling
« Reply #13 on: January 19, 2019, 06:05:28 AM »
Thanks very much Craig!

Another planned use for this is drilling holes for a vacuum table
Re: How to generate gcode to do pearling
« Reply #14 on: January 19, 2019, 06:16:14 AM »
Where I found the name:

http://www.kitplanes.com/issues/33_2/shop_talk/Home-Shop-Machinist-Pearling_21465-1.html

But could not find many other examples. However, "jeweling" does appear to get more hits in Google.

"Juuling" also has some negative connotations nowadays. :)

« Last Edit: January 19, 2019, 06:20:03 AM by billskeen62 »
Re: How to generate gcode to do pearling
« Reply #15 on: January 19, 2019, 06:43:02 AM »
Hi,
well pearling or jeweling ...I don't care. I notice near the end of the article it shows the overlap pattern.
I did not consider such a pattern when I wrote the code I've posted. Such a pattern should not be hard
to code.

In fact as you can see there is nothing particularly difficult abut the code I have posted.
Lua itself is reasonably simple, but don't let its simplicity fool you, there are a number of features/ideas,
'functions as first class values, for instance that mean Lua can be used to achieve a very wide range of
programming paradigms despite its simplicity.

A major part in successfully coding in Lua for Mach4 is to know and understand the API. Its made a little more difficult
because the development of features in Mach4 have exceeded the documentation. I know its frustrating but it seems we can
have newly developed features OR up-to-date documentation....but apparently not both. Not withstanding my frustration
with documentation I am delighted with the breadth and scope of newly developed features.

Smurph has indicated that Surface Mapping is close as is THC support functions which should allow much easier implementation
of THC into motion control boards.

Anyway, happy coding.

Craig
My wife left with my best friend...
     and I miss him!
Re: How to generate gcode to do pearling
« Reply #16 on: January 19, 2019, 07:39:58 AM »
I am still learning how to use the script. Going through the Mach4 Scripting Manual now.

I sincerely appreciate your efforts on this. Far exceeded my expectations when I originally posted.

All the best!

Bill
Re: How to generate gcode to do pearling
« Reply #17 on: January 19, 2019, 09:25:21 AM »
Craig,
I took the bolt hole wizard and stripped it down once before, last year sometime so I barely remember what I did, but I took that shell to make a wizard.
Do you know the syntax to make GCode output and to save ot to a file? That would be awesome for some ideas I have in mind for some second op stuff at work; I couldnt find any examples of just outputting to GCode and then saving to a file.   
« Last Edit: January 19, 2019, 09:27:01 AM by Cbyrdtopper »
Chad Byrd
Re: How to generate gcode to do pearling
« Reply #18 on: January 19, 2019, 12:34:34 PM »
Hi Chad,
the only real difficulty in opening existing files or creating new ones is using/having a file dialog which means wxLua.

In the LuaExamples folder are two macros m400() and m401() which are opening, creating and populating a probe file.
The file dialog code I use and have reused is just an edited version of that code.

Code: [Select]
-- create the wxFrame window
    mainframe = wx.wxFrame( wx.NULL,          -- no parent
                        wx.wxID_ANY,          -- whatever for wxWindow ID
                        "DummyFrame", -- frame caption
                        wx.wxDefaultPosition, -- place the frame in default position
                        wx.wxDefaultSize,     -- default frame size
                        wx.wxDEFAULT_FRAME_STYLE ) -- use default frame styles

    -- create a panel in the frame
    panel = wx.wxPanel(mainframe, wx.wxID_ANY)--We are not going to show it but we need to have this to use the File dialog

local file = wx.wxFileDialog(panel, "Select Data File", "", "", "Text files (*.txt)|*.txt|Tap files (*.tap)|*.tap",
                             wx.wxFD_SAVE,wx.wxDefaultPosition,wx.wxDefaultSize, "File Dialog" );
        if(file:ShowModal() == wx.wxID_OK)then
            path = file:GetPath()
            outfile=assert(io.open(tostring(path),'w+'))
        end

This is an example of that code. Note that the frame and panel are nothing special but they need to be present so the
file dialog can happen. This is the critical line:

local file = wx.wxFileDialog(panel, "Select Data .....................................................faultSize, "File Dialog" );

The remaining code is all about using functions of the data structure "file", for instance:

file:ShowModal() == wx.wxID_OK                                 and:

path = file:GetPath()

The line which opens the file is:

outfile=assert(io.open(tostring(path),'w+'))                    but that is inelegant, this is an example of a file opening statement
                                                                                   that I wrote for a job a week or so ago:

local fileHandle=io.open(pathfilename,"w+")                   and some of the statements for writing to, flushing and closing the
                                                                                   file using this syntax are:

fileHandle:write(offset,'\n')
fileHandle:flush()
fileHandle:close()

I'm sort of thinking that opening and closing files is getting a bit away from the subject of this thread and am likely to confuse
the hell out of OP if I start posting code in the same thread. I will start a new thread where I will write the generated Gcode
to a file, sort of a poor mans Wizard.

Craig.

My wife left with my best friend...
     and I miss him!
Re: How to generate gcode to do pearling
« Reply #19 on: February 02, 2019, 05:00:49 AM »
Hi billskeen62,
did you end up using this code?

I have been reading/studying/experimenting with wxLua and have come up with some code that will
accept data from user on-screen input. The data is stored in registers so is persistent between sessions.

I have attached a pic of what the input dialog looks like.

Craig
My wife left with my best friend...
     and I miss him!