Hello Guest it is January 27, 2021, 04:15:44 AM

Author Topic: Stop a macro and go to the end.  (Read 446 times)

0 Members and 1 Guest are viewing this topic.

Stop a macro and go to the end.
« on: January 29, 2019, 09:28:02 AM »
I'm setting up my tool changer and I want to stop the macro if one of the SignalWait calls comes back with an error.  I want to move from that point to the end where I have an error message; this works when I debug, but it reads through the rest of the macro, turning on and off my cylinders for the tool change.
I tried mc.mcCntlMacroStop and mc.mcCntlMacroAlarm.  Those don't stop Outputs from coming on, I just tested this; this is not good.  I have it stop because one of the cylinders messed up, I don't want the arm to get out of sync with the remaining cylinders coming on after one is stuck.
So, I'm just looking for a way to stop the Macro either dead in it's tracks with an alarm message or not (I already have a message for the error), or jump to a specified point in the bottom of my macro.
Chad Byrd

Offline Chaoticone

*
  • *
  •  5,626 5,626
  • Precision Chaos
    • View Profile
Re: Stop a macro and go to the end.
« Reply #1 on: January 29, 2019, 10:12:39 AM »
Something like this should be pretty close.

Code: [Select]
--Put this in your macros function
if (rc ~= 0) then
msg = mc.mcCntlGetErrorString(inst, rc) --Get the returned error string
m6.errorOut(msg) --Run the m6.errorOut function passing it the msg parameter
return --Exit the function this is in
end

--Add this function
function m6.errorOut(msg)
local inst = mc.mcGetInstance()
mc.mcCntlMacroAlarm(inst, 3, msg)
end
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Stop a macro and go to the end.
« Reply #2 on: January 29, 2019, 10:37:03 AM »
I couldn't get the m6.errorOut() to work.  Does that go in the Macro as well or does that go in the screen load script?  I tried both, putting it in the screen load script gave me a Script Error and putting it in the macro did nothing.  It didn't read the Function at all.

However, the "return" is exactly what I was looking for; that works perfect.  I would still like to know more about this other function though.
Chad Byrd

Offline Chaoticone

*
  • *
  •  5,626 5,626
  • Precision Chaos
    • View Profile
Re: Stop a macro and go to the end.
« Reply #3 on: January 29, 2019, 11:18:32 AM »
Yup, all goes in the macro. Get rid of the m6. at the beginning of the errorOut function name and where it is called.

Code: [Select]
function m6()

local inst = mc.mcGetInstance()
local rc = -40
--local selectedTool = mc.mcToolGetSelected(inst)
--local currentTool = mc.mcToolGetCurrent(inst)
--local maxDown = -4.0000 --Max distance Z will go down in the touch routine
--local rate = 30 --Feed rate the Z will go down in the touch routine
--local safeZ = 0 --Machine coordinates the Z will rapid to after touch move
--
--if selectedTool == currentTool then
-- mc.mcCntlSetLastError(inst, "Current tool == Selected tool so there is nothing to do")
--else
-- --Remove this line if you would not like the Z axis to move
-- --mc.mcCntlGcodeExecute(inst, "G90 G53 G0 Z0.0");--Move the Z axis all the way up
-- mc.mcCntlSetLastError(inst, "Change to tool " .. tostring(selectedTool) .. " and press start to touch off") --Message at beginning of tool change
-- mc.mcCntlToolChangeManual(inst, true) --This will pause the tool change here and wait for a press of cycle start to continue
-- mc.mcToolSetCurrent(inst, selectedTool)
-- mc.mcCntlSetLastError(inst, "Performing touch routine")
-- mc.mcCntlGcodeExecuteWait(inst, string.format("G31 Z%0.4f F%0.4f\nG0 G53 Z%0.4f", tostring(maxDown), tostring(rate), tostring(safeZ)))
-- mc.mcCntlSetLastError(inst, "Touch move complete")
-- mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedTool) .. "   Previous Tool == " .. tostring(currentTool)) --Message that shows after Cycle Start
-- local didStrike, rc = mc.mcCntlProbeGetStrikeStatus(inst)
-- if (didStrike == 1) then
-- --5063 = User position 5073 = Machine position
-- value, rc = mc.mcCntlGetPoundVar(inst, 5063)
-- mc.mcToolSetData(inst, mc.MTOOL_MILL_HEIGHT, selectedTool, value)
-- mc.mcCntlGcodeExecute(inst, string.format("G43 H" .. tostring(selectedTool)))
-- mc.mcCntlSetLastError(inst, string.format("Tool " .. tostring(selectedTool) .. " H offset set to %0.4f", value))
-- else
-- mc.mcCntlSetLastError(inst, "The touch move did not touch so we did not set a tool offset.") --Message that shows after Cycle Start
-- end
--end
--Put this in your macros function
if (rc ~= 0) then
msg = mc.mcCntlGetErrorString(inst, rc) --Get the returned error string
errorOut(msg) --Run the m6.errorOut function passing it the msg parameter
return --Exit the function this is in
end

end

--Add this function
function errorOut(msg)
local inst = mc.mcGetInstance()
mc.mcCntlMacroAlarm(inst, 3, msg)
end

if (mc.mcInEditor() == 1) then
m6()
end
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Stop a macro and go to the end.
« Reply #4 on: January 29, 2019, 04:44:49 PM »
Ok.  That works great! 
I didn't know you could run another function like that inside a macro.  That's awesome!!
Chad Byrd

Offline Chaoticone

*
  • *
  •  5,626 5,626
  • Precision Chaos
    • View Profile
Re: Stop a macro and go to the end.
« Reply #5 on: January 29, 2019, 06:38:22 PM »
 :)

Yeah, it is handy.
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!