Hello Guest it is March 28, 2024, 12:07:34 PM

Author Topic: Mach4 Read Current Line and Replace it with Another  (Read 3097 times)

0 Members and 1 Guest are viewing this topic.

Mach4 Read Current Line and Replace it with Another
« on: March 16, 2016, 08:37:44 PM »
Hi everybody!

I'm writing a macro (M11) for Mach4 that must:

> Read current gcode file line (X-26.306 Y-4.449 Z10.603 I-0.05081 J0.094506 K0.994227 M11)
> Derive new line based on its values
> Execute derived line
> Move to next line in gcode file without ever having executed the X, Y, Z, I, J, K values on the original line from the gcode file

I figure that since it has to execute the line to start the M11 macro, it might also have to execute all the X, Y, Z, I, J, K values too.

Is this the case or does the M11 take priority before any other values in the line?
An example of code to achieve this would be bonus point for you if you would be so kind.  ;D

Thanks guys.
Re: Mach4 Read Current Line and Replace it with Another
« Reply #1 on: March 19, 2016, 11:11:46 AM »
The purpose of this macro was to take 5 axis gcode and interpret it in real time so that the tool length can be changed between jobs and not have to regenerate the gcode. I've since learned that apparently Mach has a 500ms delay before execution of the M code script. Each Gcode line moves the machine no more than 1mm, a 500ms delay every 1mm movement is unacceptable.

I've read the M62 and M63 execute the next line immediately, but I don't think that can be used for this purpose. So now my attention is turned to writing a plugin. I don't really know where to start with this... I've got a working 5 axis Gcode interpreter and machine simulator working in Blender (the 3D modelling program) and it works great, but that's written for Blender in Python language, translating the logic over to Mach4 is proving a challenge.

Please, I ask all who have information so share, what's my best course of action at this point? I'm hoping a plugin is the solution, if so, is there documentation to help me get started?
Re: Mach4 Read Current Line and Replace it with Another
« Reply #2 on: March 19, 2016, 12:18:36 PM »
Hi Mate
Unless I misunderstand what you want to do - I think all you need to do is set a tool length offset before each job. Set the tool height to the current job requirements and Mach does the rest. - Look up "setting tool length offsets" or "setting z offsets" something like that.
Steve W.
 
Re: Mach4 Read Current Line and Replace it with Another
« Reply #3 on: March 19, 2016, 04:16:37 PM »
Setting the tool length in Mach is not going to provide what is needed because
it can only compensate for the offset along the Z axis.

When a machine has 5 axes there is more involved such as tilting the spindle head
or a trunnion holding the workpiece. The length of the tool will also affect the
required motion in these axes.

It is traditional for the CAM software to compute the necessary moves along
the 4th and 5th axis to account for the tool length and also the machine
geometry.

In order for the machine controller to tackle the tool length offset in 5 axis
motion, the controller must support Kinematics, and that may not be all that
is required.

Doing endpoint transformations based on tool length may get close enough
in some situations but not all. This what Inertia was attempting with his G code
rewriting on the fly.

I would suggest that instead of trying to rewrite the G code, try recoding it
such that it uses subroutines for the critical moves and have the subroutine
include the end point transforms and utilize a passed parameter that represents
the tool length.
Steve Stallings
www.PMDX.com
Re: Mach4 Read Current Line and Replace it with Another
« Reply #4 on: March 19, 2016, 09:33:36 PM »
You're exactly right Steve. Thanks for clarifying for Wallerawang.

I didn't even know about subroutines until you mentioned them. Putting the entire program in a subroutine and passing the tool length seems like a good solution. After sleeping on my last post I got the idea to write a wizard where you simply select the gcode program, and hit 'Go' and it takes the current tool length and translates the program and posts it to Mach. What are your thoughts?
Re: Mach4 Read Current Line and Replace it with Another
« Reply #5 on: March 23, 2016, 12:35:54 PM »
I can't manage to get a string of the current line, I've got mc.mcCntlGetGcodeLineNbr() working, but I can't get mc.mcCntlGetGcodeLine() to work. It's being executed in a module, I've make test functions in the module work when I click a screen button in Mach, so I know the button is accessing the module file correctly.

I've tried copying the documentation exactly with:

Code: [Select]
char gline[128]
gline[0] = '0'
mc.mcCntlGetGcodeLine(inst, counter, gline, 128)
But when I use a char, the script in the Mach screen button that tries to link to the module file crashes as it tries to link to it, when I switch gline back to a string everything links up fine.

Here's the screen button script:
Code: [Select]
local inst = mc.mcGetInstance()

-- get access to module functions
package.path = wx.wxGetCwd().."\\Modules\\?.mcs;"
if (package.loaded.dialogTest == nil) then
    module = require "dialogTest"
end

local gcodeProgram = getGcode()
mc.mcCntlSetLastError(inst, gcodeProgram[5])
test()    -- just to make sure the module file is being accessed

And here's my module code:
Code: [Select]
function getGcode()
    local inst = mc.mcGetInstance()
    local lineNumber = mc.mcCntlGetGcodeLineNbr(inst) + 1 -- not being used
    local lineCount = mc.mcCntlGetGcodeLineCount(inst)
    local gcodeProgram = {}
    local count = 1
    loca curLine = ""
    while counter <= lineCount do
        mc.mcCntlGetGcodeLine(inst, counter, curLine)
        table.insert(gcodeProgram, curLine)
        counter = counter + 1
    end
    return gcodeProgram
end

function test()
    local inst = mc.mcGetInstance()
    mc.mcCntlSetLastError(inst, "It worked.")
end

Thanks guys.