198
« on: August 25, 2019, 05:49:17 PM »
Hi, I think have replicated the control in Mach4 using buttons with your inputs etc. I've done it in a way that can easily be modified, there is a lot more to add to the signal library, but is simpler.
There are four new functions as well to add to the screen load script. I used input 50 as Jog- and 51 as Jog+, not sure if this is correct for your settings.
I have also attached the screen set I modified. There is a tab called 'External Jog' next to MDI/Gcode tab. All the code is in the screen load script right under the signal library. The only thing I don't know is what will happen on startup - if mach will run the signal library code if it see's an input is active on startup
Save what you have, then try this, see if its any help
Signal Library
[mc.ISIG_INPUT19] = function (state) -- Increment Selection 1
if(state == 1) then
setJogInc(1)
end
end,
[mc.ISIG_INPUT20] = function (state) -- Increment Selection 2
if(state == 1) then
setJogInc(0.1)
end
end,
[mc.ISIG_INPUT21] = function (state) -- Increment Selection 3
if(state == 1) then
setJogInc(0.01)
end
end,
[mc.ISIG_INPUT22] = function (state) -- Increment Selection 4
if(state == 1) then
setJogInc(0.001)
end
end,
[mc.ISIG_INPUT23] = function (state) -- Increment Selection 5
if(state == 1) then
setJogInc(0.0001)
end
end,
[mc.ISIG_INPUT24] = function (state) -- Jog Rate Selection 1
if(state == 1) then
setJogRate(2)
end
end,
[mc.ISIG_INPUT25] = function (state) -- Jog Rate Selection 2
if(state == 1) then
setJogRate(5)
end
end,
[mc.ISIG_INPUT26] = function (state) -- Jog Rate Selection 3
if(state == 1) then
setJogRate(10)
end
end,
[mc.ISIG_INPUT27] = function (state) -- Jog Rate Selection 4
if(state == 1) then
setJogRate(25)
end
end,
[mc.ISIG_INPUT28] = function (state) -- Jog Rate Selection 5
if(state == 1) then
setJogRate(50)
end
end,
[mc.ISIG_INPUT29] = function (state) -- Jog Rate Selection 6
if(state == 1) then
setJogRate(75)
end
end,
[mc.ISIG_INPUT30] = function (state) -- Jog Rate Selection 7
if(state == 1) then
setJogRate(100)
end
end,
[mc.ISIG_INPUT50] = function (state) -- Jog- Input
local axisNum = getAxisToJog()
if(state == 1) then
jogAxis(axisNum, mc.MC_JOG_NEG)
else
jogAxis(axisNum, mc.MC_JOG_STOP)
end
end,
[mc.ISIG_INPUT51] = function (state) -- Jog+ Input
local axisNum = getAxisToJog()
if(state == 1) then
jogAxis(axisNum, mc.MC_JOG_POS)
else
jogAxis(axisNum, mc.MC_JOG_STOP)
end
end,
4 new functions
function setJogInc(inc)
local rc, axisNum
local inst = mc.mcGetInstance()
--For each axis set the incremental value and jog type to inc
for axisNum=0,5,1 do -- X = 0, Y = 1, Z = 2
rc = mc.mcJogSetInc(inst, axisNum, inc)
rc = mc.mcJogSetType(inst, axisNum, mc.MC_JOG_TYPE_INC)
end
end
function setJogRate(rate)
local rc, axisNum
local inst = mc.mcGetInstance()
--For each axis set the jog rate value and jog type to cont
for axisNum=0,5,1 do -- X = 0, Y = 1, Z = 2
rc = mc.mcJogSetRate(inst, axisNum, rate)
rc = mc.mcJogSetType(inst, axisNum, mc.MC_JOG_TYPE_VEL)
end
end
function jogAxis(axis, dir)
-- Get states of Inc and Cont outputs
local inst = mc.mcGetInstance()
local rc
-- Below is a work around as there is no mc.mcJogGetType API call
local axisLetters = {[0] = "X", [1] = "Y", [2] = "Z", [3] = "A", [4] = "B", [5] = "C"}
local hReg = mc.mcRegGetHandle(inst, string.format("core/inst/JogType%s", axisLetters[axis]))
local jogType = mc.mcRegGetValue(hReg)
--
if (jogType == mc.MC_JOG_TYPE_INC) and dir ~= mc.MC_JOG_STOP then --If incremental jog
local incVal = mc.mcJogGetInc(inst, axis) --Get increment value for the axis
rc = mc.mcJogIncStart(inst, axis, (incVal*dir)) --Start the inc jog
if (rc ~= mc.MERROR_NOERROR) then
mc.mcCntlSetLastError(inst, "Error starting incremental jog")
end
elseif (jogType == mc.MC_JOG_TYPE_VEL) and dir ~= mc.MC_JOG_STOP then --If continuous and not stopping
rc = mc.mcJogVelocityStart(inst, axis, dir)
if (rc ~= mc.MERROR_NOERROR) then
mc.mcCntlSetLastError(inst, "Error starting continuous jog")
end
elseif (jogType == mc.MC_JOG_TYPE_VEL) and dir == mc.MC_JOG_STOP then
mc.mcJogVelocityStop(inst, axis)
end
end
function getAxisToJog() --This function looks at the inputs for the axis selector and returns the axis number for the one that is selected
local inst = mc.mcGetInstance()
local axisToJog, k, v
--Create table for axis input signals
local axesTbl = {[0] = mc.ISIG_INPUT44, [1] = mc.ISIG_INPUT45, [2] = mc.ISIG_INPUT46, [3] = mc.ISIG_INPUT47, [4] = mc.ISIG_INPUT48, [5] = mc.ISIG_INPUT49}
-- Find the input that is active and return the axis number
for k,v in pairs(axesTbl) do
local hSig = mc.mcSignalGetHandle(inst, v)
if (mc.mcSignalGetState(hSig) == mc.MC_ON) then
axisToJog = k
break
end
end
return axisToJog
end