Hello Guest it is April 23, 2024, 07:12:56 AM

Author Topic: M3 macro does not start spindle  (Read 1052 times)

0 Members and 1 Guest are viewing this topic.

M3 macro does not start spindle
« on: October 21, 2021, 04:07:45 PM »
I have created a macro that is activated every time the M03 g code occurs. It works as it should.
The two commands I have inserted in the macro also work.
However, the spindle is not started. The G code continues without the spindle rotating.

Do I need a command to activate the spindle

Code: [Select]
function m3()
    inst=mc.mcGetInstance()
mc.mcCntlGcodeExecute(inst, "G00 Z36.000");
mc.mcCntlGcodeExecute(inst, "G04 P3.00");
end
 
if (mc.mcInEditor() == 1) then
    m3()
end
Re: M3 macro does not start spindle
« Reply #1 on: October 22, 2021, 03:31:10 AM »
when you override M3 its mean now you are the boss of m3 ,nothing remind from original m3
Re: M3 macro does not start spindle
« Reply #2 on: October 22, 2021, 10:03:29 AM »
Okay. Thanks for the information.

How do I read spindle speed from the g code so I can start the spindle afterwards.
Re: M3 macro does not start spindle
« Reply #3 on: October 22, 2021, 10:15:23 AM »
I suggest you instead of override it ,just add m function before the m3
Its seem for you much easier
If you consider override m3 don't forget not only cheack the frequency value
But much other points
Like cheack accl deccl
Cheack if reach speed
Set thr cw or ccw
Etc...
All this are build in in m3
And i think acording yours question bater add m function begore m3
Re: M3 macro does not start spindle
« Reply #4 on: October 23, 2021, 10:01:59 AM »
I get your point.
Why make it harder than necessary.
Unfortunately, it does not make you any wiser.

So, whether I need to use it for something or not, I still would like to know how to read spindle speed from the g code.
Re: M3 macro does not start spindle
« Reply #5 on: October 23, 2021, 01:22:29 PM »
Thought I posted this yesterday,

Haven't tested this but add these from the m4 API manual to your m3 macro:

rc = mc.mcSpindleSetCommandRPM(number mInst, number RPM)

rc = mc.mcSpindleSetDirection(number mInst, number dir)
or
rc = mc.mcSpindleSetDirectionWait(number mInst, number dir)

to find out what the true spindle speed is (assuming you have feedback setup):
RPM, rc = mc.mcSpindleGetTrueRPM(number mInst)

Also, from the screen load script you could add the applicable lines to your macro:

---------------------------------------------------------------
function SpinCW()
    local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
    local sigState = mc.mcSignalGetState(sigh);
   
    if (sigState == 1) then
        mc.mcSpindleSetDirection(inst, 0);
    else
        mc.mcSpindleSetDirection(inst, 1);
    end
end
---------------------------------------------------------------

this is called from the 'Spindle CW' button

HTH

RT
Re: M3 macro does not start spindle
« Reply #6 on: October 24, 2021, 06:00:12 AM »
The following code works as it should.
Speed is set and the spindle starts.

Now I just need to read the speed of the spindle from the g code.

Code: [Select]
function m3()
    inst=mc.mcGetInstance()

local lRPM = 5000; -- How do I read the rpm from the g code?

mc.mcSpindleSetCommandRPM (inst, lRPM);
mc.mcSpindleSetDirection(inst, 1);

end
 
if (mc.mcInEditor() == 1) then
    m3()
end
Re: M3 macro does not start spindle
« Reply #7 on: October 24, 2021, 10:49:38 AM »
take a look at the examples in C:\Mach4Hobby\LuaExamples\UseVarsFromMcodeLine folder.

Assuming your gcode is 'm3 s5000'
You would read the 's' parameter mc.SV_S

THT
RT
Re: M3 macro does not start spindle
« Reply #8 on: October 24, 2021, 12:52:34 PM »
mc.SV_S returns a value of 19 not 5000 as it should.

A have used this macro to test it.

Code: [Select]
function m3()
    inst=mc.mcGetInstance()

        local lRPM = mc.SV_S
lRPM = math.tointeger(lRPM)
mc.mcCntlSetLastError(inst, tostring(lRPM))

end
 
if (mc.mcInEditor() == 1) then
    m3()
end
Re: M3 macro does not start spindle
« Reply #9 on: October 24, 2021, 01:07:09 PM »
Well...S would be the 19th letter in the alphabet,  SV_S is an enumerator.
The example shows that you need to test for parameters (hParam~= nil) then
get the local param:  local pVal = mc.mcCntlGetLocalVar(inst, hParam, mc.SV_P)
test to see if value was passed:   local pFlag = mc.mcCntlGetLocalVarFlag(inst, hParam, mc.SV_P)
if so then convert to number and use it.
Study the examples