80
« on: August 25, 2019, 09:57:34 PM »
I wasted a bunch of time testing my changes using the Jog- button and nothing happening LOL. I finally figured out you had it on input 50 instead of 52.
I was able to solve the crashing if the Axis selector switch was in the Off position.
I also fixed the Jog being at 2% on any of the Step-Jog positions by adding a command to set it to 100% when any of the Step-Jog positions are selected.
The one thing I have not fixed yet is getting the "Error starting continuous jog" from popping up at Mach4 boot up.
This may be the only thing left to find a fix!
The error at bootup does not occur if the Axis selector switch is in the Off position, since this stops it from calling the jogAxis function.
[mc.ISIG_INPUT51] = function (state) -- Jog+ Input
local axOff, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT43)
local Off = mc.mcSignalGetState (axOff)
local axisNum = getAxisToJog()
if (Off == 1) then
elseif (state == 1) then
jogAxis(axisNum, mc.MC_JOG_POS)
else
jogAxis(axisNum, mc.MC_JOG_STOP)
end
end,
[mc.ISIG_INPUT52] = function (state) -- Jog- Input
local axOff, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT43)
local Off = mc.mcSignalGetState (axOff)
local axisNum = getAxisToJog()
if (Off == 1) then
elseif (state == 1) then
jogAxis(axisNum, mc.MC_JOG_NEG)
else
jogAxis(axisNum, mc.MC_JOG_STOP)
end
end,
--Control Panel jog 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.mcJogSetRate(inst, axisNum, 100)
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