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

0 Members and 1 Guest are viewing this topic.

Offline billskeen62

  • Active Member
  • Posts: 21
    • View Profile
How to generate gcode to do pearling
« on: January 18, 2019, 01:37:58 PM »
I've seen this done on many different materials over the past 40 years or so.

I know I can manually create a gcode file to do this. Any suggestions on how to create some type of script that would create a gcode file of the patterns where the x, y, z are automatically generated based some inputs? Can it be done with Lua?


Offline joeaverage

  • Active Member
  • Posts: 4,511
    • View Profile
Re: How to generate gcode to do pearling
« Reply #1 on: January 18, 2019, 02:21:28 PM »
Hi,
yes that could be done easy enough.

One possibility is to write a macro which outputs a Gcode file and that file is then run. That would be
using Lua to do a little bit of maths but mostly composing Gcode text strings and adding them to a file.
Thus your macro is in effect a wizard....it composes a Gcode file to be used at later date.

Another possibility is to write a macro that does the pearling itself. The macro would still effectively be composing
lines of Gcode but they are executed immediately rather than put in a file. This API allows that to happen:

Code: [Select]
LUA Syntax:
rc = mc.mcCntlGcodeExecute(
number mInst,
string commands)

Description:
Execute G code as a unit of work.

Either of these methods will work.

One area that will introduce added complexity is how you enter the data for the required pearling area.
This would be done with .wxWidgets type instructions that open windows that you can enter numbers and so
on. As it turns out using .wxWidgets is more confusing than Lua or Mach4.

My suggestion would be NOT to use .wxWidget data entry but have those numbers fixed in the macro.
If you required a different pearling area then you would have to edit the macro....I know that sounds like a pain
but it need not be hard. The advantage of doing it that way is it vastly simplifies the macro.

Once you have your macro running THEN you could decide to improve it by adding data entry windows.

I suggest give some thought to what data (width, length, tool diameter, tool stepover) you would need to make
your pearling macro useful. Then you can start wring some code.

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

Offline billskeen62

  • Active Member
  • Posts: 21
    • View Profile
Re: How to generate gcode to do pearling
« Reply #2 on: January 18, 2019, 02:32:49 PM »
Awesome! I appreciate the input.

Changing the macro sounds okay for now.

Off to Lua Lua Land.

Offline Cbyrdtopper

  • Active Member
  • Posts: 612
    • View Profile
    • Byrd Tool Corp.
Re: How to generate gcode to do pearling
« Reply #3 on: January 18, 2019, 03:09:13 PM »
How are you achieving this?
Taking a brush and jogging down onto the material?
Chad Byrd

Offline joeaverage

  • Active Member
  • Posts: 4,511
    • View Profile
Re: How to generate gcode to do pearling
« Reply #4 on: January 18, 2019, 03:19:02 PM »
Hi,
I've made a start at writing some code....probably woefully inefficient and I have no idea whether it will work yet:

Code: [Select]
function m120()
local inst=mc.mcGetInstance()
--
-- Pearl Data.....to be edited as required
--
local pearlWidth=50
local pearlLength=100
local toolDiameter=6
local nominalStepover=0.66
--
-- End of data block
--
local startXpos
local startYpos
local pearlZheight
local retract="g0 z2" --Nominal retract is 2mm above the surface
local stepoverX
local stepoverY
-- Save the current position as the start of the pearling area....you have jogged to the start haven't you????
startXpos=mc.mcCntlGcodeInterpGetPos(inst,mc.X_AXIS)
startYpos=mc.mcCntlGcodeInterpGetPos(inst,mc.Y_AXIS)
pearlZheight=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 'pearls'
-- Reduce perlWidth in X and Y by the diameter of the tool
pearlWidth=pearlWidth-toolDiameter
pearlLength=pearlLength-toolDiameter
-- Calculate the exact number of 'pearls' required to match the nomininalSteppover
local numPearlX=pearlWidth / (nominalStepover * toolDiameter)
local numPearlY=pearlLength / (nominalStepover * toolDiameter)
-- Find the integer number of 'pearls'


end
if (mc.InEditor()==1)then
m120()
end

As you can see the first few variable declared, all locals, are the pearl  area data. You may think that there needs to be additional
data, but its a start.

My intention is that you would jog to a location on the workpeice and lower the tool until it just 'pearls' the surface
and then you would MDI your macro, I called it m120(). The location you have jogged to will be the start of the
pearled area and the current Z axis height will be used to mill each 'pearl'.

Does it make sense so far?

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

Offline RICH

  • Global Moderator
  • *
  • Posts: 7,300
    • View Profile
Re: How to generate gcode to do pearling
« Reply #5 on: January 18, 2019, 04:03:39 PM »
How are you achieving this?

It's jeweling. For small diameters , say 1/4",  one could just buy an adapter which holds an
rubber abrasive similar to an eraser on a pencil. If one dose not have a lot of it to be done you can glue emery cloth to a pencil eraser. For big stuff, Mach trailer, I have seen it done manualy with an abrasive pad. 

RICH

Offline billskeen62

  • Active Member
  • Posts: 21
    • View Profile
Re: How to generate gcode to do pearling
« Reply #6 on: January 18, 2019, 04:34:36 PM »
RICH

Years ago it was done by hand using a pneumatic drill with a sanding pad and scotch brite cut into 2-3" circles.

I am going to try something similar using 2" ROLOC sanding discs. Have not used them before and may have to go back to scotch brite pads

https://www.amazon.com/gp/product/B06XQTDQPG/ref=ppx_yo_dt_b_asin_title_o04__o00_s00?ie=UTF8&psc=1


Offline billskeen62

  • Active Member
  • Posts: 21
    • View Profile
Re: How to generate gcode to do pearling
« Reply #7 on: January 18, 2019, 04:35:39 PM »
Craig,

Yes it does.

Thank you for that!

Bill

Offline joeaverage

  • Active Member
  • Posts: 4,511
    • View Profile
Re: How to generate gcode to do pearling
« Reply #8 on: January 18, 2019, 05:21:26 PM »
Hi,
well it might be called jeweling but its too bloody late now!!!...its fixed in my head and I cant be bothered editing all the code.

Try this:
Code: [Select]
function m120()
local inst=mc.mcGetInstance()
--
-- Pearl Data.....to be edited as required
--
local pearlWidth=50
local pearlLength=100
local toolDiameter=6
local nominalStepover=0.66
local plungeSpeed=300
--
-- End of data block
--
local startXpos
local startYpos
local pearlZheight

local stepoverX,numPearlX
local stepoverY,numPearlY
local i=0
local j=0
-- Save the current position as the start of the pearling area....you have jogged to the start haven't you????
startXpos=mc.mcCntlGcodeInterpGetPos(inst,mc.X_AXIS)
startYpos=mc.mcCntlGcodeInterpGetPos(inst,mc.Y_AXIS)
pearlZheight=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 'pearls'
-- Reduce perlWidth in X and Y by the diameter of the tool
pearlWidth=pearlWidth-toolDiameter
pearlLength=pearlLength-toolDiameter
-- Calculate the exact number of 'pearls' required to match the nomininalSteppover
numPearlX=pearlWidth / (nominalStepover * toolDiameter)
numPearlY=pearlLength / (nominalStepover * toolDiameter)
-- Find the integer number of 'pearls'
numPearlX=math.modf(numPearlX)
numPearlY=math.modf(numPearlY)
-- Calculate the actual stepover to be used so that an integral number of 'pearls' are perfomed
stepoverX=pearlWidth / numPearlX
stepoverY=pearlLength / numPearlY
--
--
local retract="g0 z "..tostring(pearlZheight+2) --Nominal retract is 2mm above the surface
local safeHeight="g0 z "..tostring(pearlZheight+20) --Nominal Safe Height is 20mm above the surface
mc.mcCntlGcodeExecute(inst,retract..'\n'..
'g1 f'..tostring(plungeSpeed))
for i=1,numPearlX,i+1 do
for j=1,numPearlY,j+1  do
pearlX=startXpos + (i * stepoverX)
pearlY=startYpos + (j * stepoverY)
mc.mcCntlGcodeExecute(inst,'g0 x '..tostring(pearlX)..' y '.. tostring(pearlY)..'\n'..
'g1 z '..tostring( pearlZheight)..'\n'..
'g4 p1000'..'\n'..
retract..'\n')
end
end
mc.mcCntlGcodeExecuteWait(inst,safeHeight)
end
if (mc.mcInEditor()==1)then
m120()
end

This code should be saved as:     m120.mcs    in the Profiles/<Your Profile>/Macros folder.

Jog to the start of the pearling/jeweling area lower the Z axis so the first pearl/jewel is formed and MDI <m120>.

This seems to work on my laptop, I have not tried on my machine.

You could build in extra data values for things like the retract height, safe height and Z down dwell time....but you get the idea.

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

Offline joeaverage

  • Active Member
  • Posts: 4,511
    • View Profile
Re: How to generate gcode to do pearling
« Reply #9 on: January 18, 2019, 05:29:01 PM »
Hi,
the very first bit of code I posted concluded with:

Code: [Select]
end
if (mc.InEditor()==1)then
m120()
end

Which is clearly wrong, the correct syntax is:

Code: [Select]
end
if (mc.mcInEditor()==1)then
m120()
end

Lua has a number of subtle strengths but as smurph has commented 'Lua has syntax that only a mother could love'.
This wee mistake is exactly the sort of wrinkle that can trip you up and cause you to tear your hair out (if you have
any left)

Craig
« Last Edit: January 24, 2019, 01:33:28 AM by Tweakie.CNC »
My wife left with my best friend...
     and I miss him!