Hello Guest it is March 29, 2024, 09:39:26 AM

Author Topic: Script Debugging  (Read 395 times)

0 Members and 1 Guest are viewing this topic.

Script Debugging
« on: February 28, 2023, 06:15:39 PM »
I managed to get a small M6 macro to work in a sense. I dont understand how the debugger helps me with my mistakes though. A section of this code is working on my machine. Call a toolchange it goes to position. Tool changes. All good.

What doesnt work is the tool will not return to its original position this line:

--mc.mcCntlGcodeExecuteWait (inst, "G90 G53 G0 X"..xstart.. Y"..ystart..") Take the tool back to original position this doesnt seem to work.

My other scripting problem. If the machine is not homed, (obviously) on first attempt my 150kg gantry almost raced right off the machine. E-Stop - pleased I have one of those.

if yhomed = true then = return -- check if y is homed
else mc.mcCntlSetLastError (inst "Please home your Y Axis")
end

I tried debugging but dont know what to do. if someone has time to give me the bits I went wrong on would be appreciated. I know this is a standard M6 thing. But if I can get this sorted I would be able to use the same info for the other bits and pieces I need to program into my machine. Know what I mean? Big thanks in advance. B

Full Code:

function m6()

   local inst = mc.mcGetInstance()
   local selectedTool = mc.mcToolGetSelected(inst)
   selectedTool = math.tointeger(selectedTool)
   local currentTool = mc.mcToolGetCurrent(inst)
   currentTool = math.tointeger(currentTool)
   local ystart = mc.mcAxisGetPos (inst, 1)
   local xstart = mc.mcAxisGetPos (inst, 0)
   local zhomed = mcAxisIsHomed (mInst, Z_AXIS, 2)
   local xhomed = mcAxisIsHomed (mInst, X_AXIS, 0)
   local yhomed = mcAxisIsHomed (mInst, Y_AXIS, 1)
   
if zhomed == true then = return -- check if z is homed
else mc.mcCntlSetLastError (inst "Please home your Z Axis")
end

if xhomed = true then = return -- check if x is homed
else mc.mcCntlSetLastError (inst "Please home your X Axis")
end

if yhomed = true then = return -- check if y is homed
else mc.mcCntlSetLastError (inst "Please home your Y Axis")
end
      
               
if selectedTool == currentTool then
   mc.mcCntlSetLastError(inst, "Current tool == Selected tool so there is nothing to do Dork")
else
      --Remove this line if you would not like the Z axis to move
   mc.mcCntlGcodeExecuteWait (inst, "G90 G53 G0 Z-10");--Move the Z axis all the way up
   mc.mcCntlGcodeExecuteWait (inst, "G90 G53 G0 Y60 X35") -- Move to tool change position
   mc.mcCntlSetLastError(inst, "Change to tool " .. tostring(selectedTool) .. " and press start to continue") --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.mcCntlGcodeExecuteWait (inst, "G90 G53 G0 X"..xstart.. Y"..ystart..") Take the tool back to original position this doesnt seem to work.
   mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedTool) .. "   Previous Tool == " .. tostring(currentTool)) --Message that shows after Cycle Start
   mc.mcToolSetCurrent(inst, selectedTool)
   end
end

if (mc.mcInEditor() == 1) then
                m6()
end


Re: Script Debugging
« Reply #1 on: February 28, 2023, 09:28:43 PM »
Hi,

Quote
--mc.mcCntlGcodeExecuteWait (inst, "G90 G53 G0 X"..xstart.. Y"..ystart..")

At a quick glance this looks faulty....should it not be?:

--mc.mcCntlGcodeExecuteWait (inst, "G90 G53 G0 X"..mc.tostring(xstart).." Y"..mc.tostring(ystart.))

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Script Debugging
« Reply #2 on: March 01, 2023, 08:19:03 AM »
Instead of using mc.mcAxisGetPos for getting the xstart and ystart position, use mc.mcAxisGetMachinePos. You are currently getting the axis position for the current work offset and then using these positions with G53 which moves the machine in machine coordinates.

By using mc.mcAxisGetMachinePos, you will get the start positions in machine coordinates and then the G53 will work correctly.

Re: Script Debugging
« Reply #3 on: March 05, 2023, 08:43:00 PM »
Shouldn't all of your relational operators be in this format?
Code: [Select]
if (thisThing == thatThing) then 
     doThisotherThing()
end

I think you have a single = sign, which is an assignment not a comparison.

https://www.lua.org/manual/5.1/manual.html#2.5.2
Re: Script Debugging
« Reply #4 on: March 05, 2023, 08:45:43 PM »
I managed to get a small M6 macro to work in a sense. I dont understand how the debugger helps me with my mistakes though. A section of this code is working on my machine. Call a toolchange it goes to position. Tool changes. All good.

What doesnt work is the tool will not return to its original position this line:

--mc.mcCntlGcodeExecuteWait (inst, "G90 G53 G0 X"..xstart.. Y"..ystart..") Take the tool back to original position this doesnt seem to work.

My other scripting problem. If the machine is not homed, (obviously) on first attempt my 150kg gantry almost raced right off the machine. E-Stop - pleased I have one of those.

if yhomed = true then = return -- check if y is homed
else mc.mcCntlSetLastError (inst "Please home your Y Axis")
end

I tried debugging but dont know what to do. if someone has time to give me the bits I went wrong on would be appreciated. I know this is a standard M6 thing. But if I can get this sorted I would be able to use the same info for the other bits and pieces I need to program into my machine. Know what I mean? Big thanks in advance. B

Full Code:

function m6()

   local inst = mc.mcGetInstance()
   local selectedTool = mc.mcToolGetSelected(inst)
   selectedTool = math.tointeger(selectedTool)
   local currentTool = mc.mcToolGetCurrent(inst)
   currentTool = math.tointeger(currentTool)
   local ystart = mc.mcAxisGetPos (inst, 1)
   local xstart = mc.mcAxisGetPos (inst, 0)
   local zhomed = mcAxisIsHomed (mInst, Z_AXIS, 2)
   local xhomed = mcAxisIsHomed (mInst, X_AXIS, 0)
   local yhomed = mcAxisIsHomed (mInst, Y_AXIS, 1)
   
if zhomed == true then return -- check if z is homed
else mc.mcCntlSetLastError (inst "Please home your Z Axis")
end

if xhomed == true then return -- check if x is homed
else mc.mcCntlSetLastError (inst "Please home your X Axis")
end

if yhomed == true then return -- check if y is homed
else mc.mcCntlSetLastError (inst "Please home your Y Axis")
end
      
               
if selectedTool == currentTool then
   mc.mcCntlSetLastError(inst, "Current tool == Selected tool so there is nothing to do Dork")
else
      --Remove this line if you would not like the Z axis to move
   mc.mcCntlGcodeExecuteWait (inst, "G90 G53 G0 Z-10");--Move the Z axis all the way up
   mc.mcCntlGcodeExecuteWait (inst, "G90 G53 G0 Y60 X35") -- Move to tool change position
   mc.mcCntlSetLastError(inst, "Change to tool " .. tostring(selectedTool) .. " and press start to continue") --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.mcCntlGcodeExecuteWait (inst, "G90 G53 G0 X"..xstart.. Y"..ystart..") Take the tool back to original position this doesnt seem to work.
   mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedTool) .. "   Previous Tool == " .. tostring(currentTool)) --Message that shows after Cycle Start
   mc.mcToolSetCurrent(inst, selectedTool)
   end
end

if (mc.mcInEditor() == 1) then
                m6()
end

Try this.  Should be fixed
Re: Script Debugging
« Reply #5 on: March 06, 2023, 01:04:19 AM »
Fantastic. Thankyou. I was a little stumped, so will analyze this (changes that have been made) and install it to try. Big learning curve this Lua but totally worth the effort huh. Regards from NZ. B
Re: Script Debugging
« Reply #6 on: March 06, 2023, 01:24:32 AM »
Shouldn't all of your relational operators be in this format?
Code: [Select]
if (thisThing == thatThing) then 
     doThisotherThing()
end

I think you have a single = sign, which is an assignment not a comparison.

https://www.lua.org/manual/5.1/manual.html#2.5.2

Thanks for the manual too.