Hello Guest it is May 19, 2025, 05:26:03 AM

Author Topic: How to send command to the motion controller while probing?  (Read 4509 times)

0 Members and 1 Guest are viewing this topic.

Offline dibor

*
  •  34 34
How to send command to the motion controller while probing?
« on: December 26, 2024, 04:21:39 PM »
Hello to ALL.
I'd like to engage some pin of motion controller only while probing process.
How can I do this?
Script, LUA ??

Thank U

Offline smurph

*
  • *
  •  1,574 1,574
  • "That there... that's an RV."
Re: How to send command to the motion controller while probing?
« Reply #1 on: December 28, 2024, 06:22:06 PM »
Scripting.  Place probeon.lua and probeoff.lua files in the Mach profile's macro directory.  They are just like M code scripts.  Meaning the file name and the function name inside them need to match.  Case matters.  Make the names all lower case for zero confusion. 

in probeon.lua:
Code: [Select]
function probeon(probenumber)
    -- script any signal or I/O functions here.
end function

in probeoff.lua:
Code: [Select]
function probeoff(probenumber)
    -- script any signal or I/O functions here.
end function

Steve

Offline dibor

*
  •  34 34
Re: How to send command to the motion controller while probing?
« Reply #2 on: December 29, 2024, 12:09:04 AM »
Thank a lot Steve.

Will try this way :)

These functions will be usable for the "Touch" process?

Best Wishes.

Offline dibor

*
  •  34 34
Re: How to send command to the motion controller while probing?
« Reply #3 on: February 05, 2025, 04:45:25 PM »
Doesn't work :(

Code: [Select]

function probeon(G31)
     local inst = mc.mcGetInstance()
     mc.mcCntlSetPokeysOutput(inst, 45, 1)
end


Do not understand :(

Offline dibor

*
  •  34 34
Re: How to send command to the motion controller while probing?
« Reply #4 on: February 12, 2025, 11:31:28 AM »
This code also doesn't work :(

Code: [Select]
function probeon(G31)
local inst = mc.mcGetInstance()
local hSig, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT45)
mc.mcSignalSetState(hSig, 1)
end

Anybody can kick me to the right direction?    ;D

Offline dibor

*
  •  34 34
Re: How to send command to the motion controller while probing?
« Reply #5 on: February 19, 2025, 03:14:55 PM »
Hello to ALL.
I see nobody has anything to say :(
So, after head crash and putting out some part of the hair and taking chat GPT for assistant I got working script.
Have save it as M101.mcs
I have use SMART.MER/2 – signal merger with probe guard function by topcom, he is able to generate ESTOP signal, when connected probe is triggered in the
unexpected moment. It can protect a probe from damage.
This board has inputs that blocks guard function, so I need to provide high level from motion controller while probing process.
Here my script, maybe will useful for somebody else :)

Code: [Select]
local inst = mc.mcGetInstance()  -- Get the Mach4 instance
local outputSig = mc.OSIG_OUTPUT45  -- Define OUTPUT45 signal
local prevState = -1  -- Variable to store the previous state

-- Function to check probing state and control OUTPUT45
function CheckProbingState()
    local state = mc.mcCntlGetState(inst)  -- Get the current system state

    -- Check if the state has changed
    if state ~= prevState then
        mc.mcCntlSetLastError(inst, "Current State Changed: " .. tostring(state))  -- Log state change

        -- Get the handle for OUTPUT45 signal
        local hSig = mc.mcSignalGetHandle(inst, outputSig)

        if state == 202 then 
            mc.mcSignalSetState(hSig, 1) 
            mc.mcCntlSetLastError(inst, "PoKeys57CNC: Probing Active, OUTPUT45 ON!")
        else
            mc.mcSignalSetState(hSig, 0) 
            mc.mcCntlSetLastError(inst, "PoKeys57CNC: Probing Completed, OUTPUT45 OFF!")
        end

        -- Update the previous state
        prevState = state
    end
end

-- Timer checks state but only updates OUTPUT45 on change
wxTimer = wx.wxTimer()
wxTimer:Start(100, wx.wxTIMER_CONTINUOUS)
wxTimer:Connect(wx.wxEVT_TIMER, function(event)
    CheckProbingState()
end)


•   OUTPUT45 turns on only when probing starts (state == 202).
•   OUTPUT45 turns off when probing stops.
•   The signal only changes when the state actually changes.

Best Wishes.
« Last Edit: February 19, 2025, 03:17:19 PM by dibor »

Offline dibor

*
  •  34 34
Re: How to send command to the motion controller while probing?
« Reply #6 on: February 24, 2025, 02:28:08 PM »
Hi to ALL.

Possible to run as PLC script:

Code: [Select]
if not inst then inst = mc.mcGetInstance() end
if not outputSig then outputSig = mc.OSIG_OUTPUT45 end
if not prevState then prevState = -1 end

function CheckProbingState()
    local state = mc.mcCntlGetState(inst)
    if state ~= prevState then
        mc.mcCntlSetLastError(inst, "State: " .. tostring(state))
        local hSig = mc.mcSignalGetHandle(inst, outputSig)
        if hSig ~= 0 then
            if state == 202 then
                mc.mcSignalSetState(hSig, 1)
                mc.mcCntlSetLastError(inst, "PoKeys57CNC: Probing Active, OUTPUT45 ON!")
            elseif prevState == 202 then
                mc.mcSignalSetState(hSig, 0)
                mc.mcCntlSetLastError(inst, "PoKeys57CNC: Probing Completed, OUTPUT45 OFF!")
            end
        end
        prevState = state
    end
end

CheckProbingState()

All the best to ALL

Offline dibor

*
  •  34 34
Re: How to send command to the motion controller while probing?
« Reply #7 on: May 15, 2025, 12:21:15 AM »
Script is WORK!

Here small video: https://www.youtube.com/shorts/a8wUrA06kIQ