Hello Guest it is April 25, 2024, 11:57:29 PM

Author Topic: Button G code juggle  (Read 900 times)

0 Members and 1 Guest are viewing this topic.

Button G code juggle
« on: September 09, 2020, 12:31:36 PM »
Hello.
I have a problem with programming in LUA for a button that has to juggle between two G codes
For the two codes I have already made two macros, which work perfectly (M15, M16),but I also need a button that when pressed once makes the code for M15 and when pressed again makes the code for M16 and the cycle repeats as many times as needed. The button opens and closes the spindle collet , which helps for machine setup.
I wrote a code, but Lua sometimes overtakes me.
What I really need is that every time I press the button, the B axis juggles between 0 and 100.
At the moment, at one press it goes to 100 but does not return.

local inst = mc.mcGetInstance()
local StartPos = mc.mcCntlDroGetUseAuxPosAxis(inst, mc.B_AXIS)
if (StartPos == 0) then
mc.mcCntlGcodeExecute(inst, "G53 G0 B100")
if (StartPos == 100)then
mc.mcCntlGcodeExecute(inst, "G53 G0 B0")
end
end

Thanks in advance for any help !

Offline Bill_O

*
  •  563 563
    • View Profile
Re: Button G code juggle
« Reply #1 on: September 10, 2020, 04:13:06 PM »
Try using mc.AxisGetPos instead.

Bill
Re: Button G code juggle
« Reply #2 on: September 11, 2020, 12:30:33 AM »
Thanks Bill_O
The result is the same, it goes to 100 but does not return to 0
Re: Button G code juggle
« Reply #3 on: September 11, 2020, 12:37:57 AM »
Okay, we did it. Now it works properly, an ELSE was missing also
Thanks a lot Bill_O


local inst = mc.mcGetInstance()
local StartPos = mc.mcAxisGetPos(inst, mc.B_AXIS)
if (StartPos == 0) then
mc.mcCntlGcodeExecute(inst, "G53 G0 B100") else
if (StartPos == 100)then
mc.mcCntlGcodeExecute(inst, "G53 G0 B0")
end

end

Offline Bill_O

*
  •  563 563
    • View Profile
Re: Button G code juggle
« Reply #4 on: September 11, 2020, 08:39:13 AM »
Sorry I missed that.
Re: Button G code juggle
« Reply #5 on: September 14, 2020, 09:42:56 AM »
Hello Bill_O
Have an idea how I can update the G code in the script from a text, for example I have the tool change macro that I want to update from the tool preparation table.
Code: [Select]
function m6()

local inst = mc.mcGetInstance()
local selectedTool = mc.mcToolGetSelected(inst)
selectedTool = math.tointeger(selectedTool)
local currentTool = mc.mcToolGetCurrent(inst)
currentTool = math.tointeger(currentTool)

if selectedTool == currentTool then
mc.mcCntlSetLastError(inst, "Current tool == Selected tool so there is nothing to do")
else
if selectedTool > 33 then
mc.mcCntlSetLastError(inst, "There is no such tool")
else
if selectedTool == 0 then
mc.mcCntlGcodeExecute(inst, "G53 G0 X0 Y0"); --T0
else
if selectedTool == 1 then
mc.mcCntlGcodeExecute(inst, "G53 G0 X60 Y552"); --T0101
else
if selectedTool == 2 then
mc.mcCntlGcodeExecute(inst, "G53 G0 X40 Y502"); --T0202
else
if selectedTool == 3 then
mc.mcCntlGcodeExecute(inst, "G53 G0 X40 Y452"); --T0303
else
if selectedTool == 4 then
mc.mcCntlGcodeExecute(inst, "G53 G0 X40 Y402"); --T0404
else
if selectedTool == 5 then
mc.mcCntlGcodeExecute(inst, "G53 G0 X40 Y352"); --T0505
else
if selectedTool == 6 then
mc.mcCntlGcodeExecute(inst, "G53 G0 X40 Y300"); --T0606
else
if selectedTool == 7 then
mc.mcCntlGcodeExecute(inst, "G53 G0 X40 Y218"); --T0707
else
if selectedTool == 8 then
mc.mcCntlGcodeExecute(inst, "G53 G0 X40 Y148"); --T0808
else
if selectedTool == 9 then
mc.mcCntlGcodeExecute(inst, "G53 G0 X74 Y56"); --T0909
else
if selectedTool == 10 then
mc.mcCntlGcodeExecute(inst, "G53 G0 X40 Y6"); --T1010
else
if selectedTool == 11 then
mc.mcCntlGcodeExecute(inst, "G53 G0 X108 Y6"); --T1111
else
if selectedTool == 21 then
mc.mcCntlGcodeExecute(inst, "G53 G0 B492"); --T2121
else
if selectedTool == 22 then
mc.mcCntlGcodeExecute(inst, "G53 G0 B432"); --T2222
else
if selectedTool == 23 then
mc.mcCntlGcodeExecute(inst, "G53 G0 B370"); --T2323
else
if selectedTool == 30 then
mc.mcCntlGcodeExecute(inst, "G53 G0 B632"); --T3030
else
if selectedTool == 31 then
mc.mcCntlGcodeExecute(inst, "G53 G0 B242"); --T3131
else
if selectedTool == 32 then
mc.mcCntlGcodeExecute(inst, "G53 G0 B162"); --T3232
else
if selectedTool == 33 then
mc.mcCntlGcodeExecute(inst, "G53 G0 B82"); --T3333



--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.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedTool) .. "   Previous Tool == " .. tostring(currentTool)) --Message that shows after Cycle Start
--mc.mcToolSetCurrent(inst, selectedTool)
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end

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