Hello Guest it is September 27, 2021, 09:21:42 AM

Author Topic: Let Incremental jog finish but still shut off Velocity move if button is let go?  (Read 3778 times)

0 Members and 1 Guest are viewing this topic.

Offline jevs

*
  •  315 315
    • View Profile
Several more hours  wasted with 0 learned and 0 accomplished....tried all of this and nothing works....

Code: [Select]
--FIGURED IT WOULDNT WORK, BUT TRYING ANYTHING
--DOES NOT WORK> CONTINUOUS MODE JOG+ PRESS AND RELEASED WILL NOT STOP RUNNING
--INC JOG WORKS
-- Add Pokeys Input 51 to Mach4 Input 51 for +Jog on Control Panel
[mc.ISIG_INPUT51] = function (state)
local inc, rc = mc.mcSignalGetHandle(inst, mc.OSIG_JOG_INC);
local joginc = mc.mcSignalGetState(inc)
local cont, rc = mc.mcSignalGetHandle(inst, mc.OSIG_JOG_CONT);
local jogcont = mc.mcSignalGetState(cont)

if(state == 1) then
CPJogPlus()
elseif (jogcont == 0) then
rc=mc.mcJogVelocityStop(inst,0)
rc=mc.mcJogVelocityStop(inst,1)
rc=mc.mcJogVelocityStop(inst,2)
end
end,

--DOES NOT WORK
-- Add Pokeys Input 51 to Mach4 Input 51 for +Jog on Control Panel
[mc.ISIG_INPUT51] = function (state)
local inc, rc = mc.mcSignalGetHandle(inst, mc.OSIG_JOG_INC);
local joginc = mc.mcSignalGetState(inc)
local cont, rc = mc.mcSignalGetHandle(inst, mc.OSIG_JOG_CONT);
local jogcont = mc.mcSignalGetState(cont)

if(state == 1) then
CPJogPlus()
elseif (jogcont == 0) then
rc=mc.mcJogVelocityStop(inst,0)
rc=mc.mcJogVelocityStop(inst,1)
rc=mc.mcJogVelocityStop(inst,2)
end
end,
--Control Panel Jogging +
function CPJogPlus()
local in44, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT44)
local axSelX = mc.mcSignalGetState (in44)
local in45, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT45)
local axSelY = mc.mcSignalGetState (in45)
local in46, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT46)
local axSelZ = mc.mcSignalGetState (in46)
local in47, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT47)
local axSel4 = mc.mcSignalGetState (in47)
local in48, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT48)
local axSel5 = mc.mcSignalGetState (in48)
local in49, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT49)
local axSel6 = mc.mcSignalGetState (in49)
local in19, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT19)
local jogSel1 = mc.mcSignalGetState (in19)
local in20, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT20)
local jogSelx1 = mc.mcSignalGetState (in20)
local in21, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT21)
local jogSelx01 = mc.mcSignalGetState (in21)
local in22, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT22)
local jogSelx001 = mc.mcSignalGetState (in22)
local in23, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT23)
local jogSelx0001 = mc.mcSignalGetState (in23)
local in24, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT24)
local contJog2 = mc.mcSignalGetState (in24)
local in25, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT25)
local contJog5 = mc.mcSignalGetState (in25)
local in26, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT26)
local contJog10 = mc.mcSignalGetState (in26)
local in27, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT27)
local contJog25 = mc.mcSignalGetState (in27)
local in28, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT28)
local contJog50 = mc.mcSignalGetState (in28)
local in29, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT29)
local contJog75 = mc.mcSignalGetState (in29)
local in30, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT30)
local contJog100 = mc.mcSignalGetState (in30)
--get current jog set type and settings here if needed
if axSelX == 1 and jogSel1 == 1 then
local Inc, rc = mc.mcSignalGetHandle (inst, mc.OSIG_JOG_INC)
jogInc = mc.mcSignalGetState (Inc)
rc = mc.mcJogIncStart(inst,0,1)
mc.mcSignalSetState (Inc,1)
elseif axSelX == 1 and jogSelx1 == 1 then
rc = mc.mcJogIncStart(inst,0,.1)
elseif axSelX == 1 and jogSelx01 == 1 then
rc = mc.mcJogIncStart(inst,0,.01)
elseif axSelX == 1 and jogSelx001 == 1 then
rc = mc.mcJogIncStart(inst,0,.001)
elseif axSelX == 1 and jogSelx0001 == 1 then
rc = mc.mcJogIncStart(inst,0,.0001)
elseif axSelY == 1 and jogSel1 == 1 then
rc = mc.mcJogIncStart(inst,1,1)
elseif axSelY == 1 and jogSelx1 == 1 then
rc = mc.mcJogIncStart(inst,1,.1)
elseif axSelY == 1 and jogSelx01 == 1 then
rc = mc.mcJogIncStart(inst,1,.01)
elseif axSelY == 1 and jogSelx001 == 1 then
rc = mc.mcJogIncStart(inst,1,.001)
elseif axSelY == 1 and jogSelx0001 == 1 then
rc = mc.mcJogIncStart (inst,1,.0001)
elseif axSelZ == 1 and jogSel1 == 1 then
rc = mc.mcJogIncStart(inst,2,1)
elseif axSelZ == 1 and jogSelx1 == 1 then
rc = mc.mcJogIncStart(inst,2,.1)
elseif axSelZ == 1 and jogSelx01 == 1 then
rc = mc.mcJogIncStart(inst,2,.01)
elseif axSelZ == 1 and jogSelx001 == 1 then
rc = mc.mcJogIncStart(inst,2,.001)
elseif axSelZ == 1 and jogSelx0001 == 1 then
rc = mc.mcJogIncStart(inst,2,.0001)
elseif axSelX == 1 and contJog2 == 1 then
rc = mc.mcJogSetRate(inst,0,2)
rc = mc.mcJogVelocityStart(inst,0,1)
elseif axSelX == 1 and contJog5 == 1 then
rc = mc.mcJogSetRate(inst,0,5)
rc = mc.mcJogVelocityStart(inst,0,1)
elseif axSelX == 1 and contJog10 == 1 then
rc = mc.mcJogSetRate(inst,0,10)
rc = mc.mcJogVelocityStart(inst,0,1)
elseif axSelX == 1 and contJog25 == 1 then
rc = mc.mcJogSetRate(inst,0,25)
rc = mc.mcJogVelocityStart(inst,0,1)
elseif axSelX == 1 and contJog50 == 1 then
rc = mc.mcJogSetRate(inst,0,50)
rc = mc.mcJogVelocityStart(inst,0,1)
elseif axSelX == 1 and contJog75 == 1 then
rc = mc.mcJogSetRate(inst,0,75)
rc = mc.mcJogVelocityStart(inst,0,1)
elseif axSelX == 1 and contJog100 == 1 then
rc = mc.mcJogSetRate(inst,0,100)
rc = mc.mcJogVelocityStart(inst,0,1)
end
    local cont = mc.mcSignalGetHandle(inst, mc.OSIG_JOG_CONT);
    local jogcont = mc.mcSignalGetState(cont)
    local inc = mc.mcSignalGetHandle(inst, mc.OSIG_JOG_INC);
    local joginc = mc.mcSignalGetState(inc)
    local mpg = mc.mcSignalGetHandle(inst, mc.OSIG_JOG_MPG);
    local jogmpg = mc.mcSignalGetState(mpg)
   
    if (jogcont == 1) then
        mc.mcSignalSetState(cont, 0)
        mc.mcSignalSetState(inc, 1)
        mc.mcSignalSetState(mpg, 0)       
    else
        mc.mcSignalSetState(cont, 1)
        mc.mcSignalSetState(inc, 0)
        mc.mcSignalSetState(mpg, 0)
    end
end

--ADDED A WAIT IN THE FUNCTION FOR ONE OF THE INCREMENTAL JOGS TO TEST
--WHO KNOWS IF SYNTAX IS CORRECT DUE TO BAD API MANUAL
  --GIVES AN ERROR, SO I GUESS THE CRAPPY MANUAL STRIKES AGAIN
    -- LUA:Error while running chunk
c:\Mach4Hobby\ScreenScript.Lua:575:Expected a 'number'for parameter 2, but got a 'nil'
Function called \: 'mcSignalHandleWait(number,nil,number)'
01.mcSignalHandleWait(number,number,number)
stack trackback:
[C]: in function 'mc.mcSignalHandleWait'
C:\Mach4Hobby\ScreenScript.lua:575:in function 'CPJogPlus'
C:\Mach4Hobby\ScreenScript.lua:114:in field '?'
C:\Mach4Hobby\ScreenScript.lua:858:in function 'Mach_Signal_Script'

-- Add Pokeys Input 51 to Mach4 Input 51 for +Jog on Control Panel
[mc.ISIG_INPUT51] = function (state)
if(state == 1) then
CPJogPlus()
else
rc=mc.mcJogVelocityStop(inst,0)
rc=mc.mcJogVelocityStop(inst,1)
rc=mc.mcJogVelocityStop(inst,2)
end
end,
--Control Panel Jogging +
function CPJogPlus()
local in44, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT44)
local axSelX = mc.mcSignalGetState (in44)
local in45, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT45)
local axSelY = mc.mcSignalGetState (in45)
local in46, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT46)
local axSelZ = mc.mcSignalGetState (in46)
local in47, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT47)
local axSel4 = mc.mcSignalGetState (in47)
local in48, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT48)
local axSel5 = mc.mcSignalGetState (in48)
local in49, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT49)
local axSel6 = mc.mcSignalGetState (in49)
local in19, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT19)
local jogSel1 = mc.mcSignalGetState (in19)
local in20, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT20)
local jogSelx1 = mc.mcSignalGetState (in20)
local in21, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT21)
local jogSelx01 = mc.mcSignalGetState (in21)
local in22, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT22)
local jogSelx001 = mc.mcSignalGetState (in22)
local in23, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT23)
local jogSelx0001 = mc.mcSignalGetState (in23)
local in24, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT24)
local contJog2 = mc.mcSignalGetState (in24)
local in25, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT25)
local contJog5 = mc.mcSignalGetState (in25)
local in26, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT26)
local contJog10 = mc.mcSignalGetState (in26)
local in27, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT27)
local contJog25 = mc.mcSignalGetState (in27)
local in28, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT28)
local contJog50 = mc.mcSignalGetState (in28)
local in29, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT29)
local contJog75 = mc.mcSignalGetState (in29)
local in30, rc = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT30)
local contJog100 = mc.mcSignalGetState (in30)
--get current jog set type and settings here if needed
if axSelX == 1 and jogSel1 == 1 then
rc = mc.mcJogIncStart(inst,0,1)
rc = mc.mcSignalHandleWait (mc.OSIG_JOG_INC,WAIT_MODE_LOW,10)
elseif axSelX == 1 and jogSelx1 == 1 then
rc = mc.mcJogIncStart(inst,0,.1)
elseif axSelX == 1 and jogSelx01 == 1 then
rc = mc.mcJogIncStart(inst,0,.01)
elseif axSelX == 1 and jogSelx001 == 1 then
rc = mc.mcJogIncStart(inst,0,.001)
elseif axSelX == 1 and jogSelx0001 == 1 then
rc = mc.mcJogIncStart(inst,0,.0001)
elseif axSelY == 1 and jogSel1 == 1 then
rc = mc.mcJogIncStart(inst,1,1)
elseif axSelY == 1 and jogSelx1 == 1 then
rc = mc.mcJogIncStart(inst,1,.1)
elseif axSelY == 1 and jogSelx01 == 1 then
rc = mc.mcJogIncStart(inst,1,.01)
elseif axSelY == 1 and jogSelx001 == 1 then
rc = mc.mcJogIncStart(inst,1,.001)
elseif axSelY == 1 and jogSelx0001 == 1 then
rc = mc.mcJogIncStart (inst,1,.0001)
elseif axSelZ == 1 and jogSel1 == 1 then
rc = mc.mcJogIncStart(inst,2,1)
elseif axSelZ == 1 and jogSelx1 == 1 then
rc = mc.mcJogIncStart(inst,2,.1)
elseif axSelZ == 1 and jogSelx01 == 1 then
rc = mc.mcJogIncStart(inst,2,.01)
elseif axSelZ == 1 and jogSelx001 == 1 then
rc = mc.mcJogIncStart(inst,2,.001)
elseif axSelZ == 1 and jogSelx0001 == 1 then
rc = mc.mcJogIncStart(inst,2,.0001)
elseif axSelX == 1 and contJog2 == 1 then
rc = mc.mcJogSetRate(inst,0,2)
rc = mc.mcJogVelocityStart(inst,0,1)
elseif axSelX == 1 and contJog5 == 1 then
rc = mc.mcJogSetRate(inst,0,5)
rc = mc.mcJogVelocityStart(inst,0,1)
elseif axSelX == 1 and contJog10 == 1 then
rc = mc.mcJogSetRate(inst,0,10)
rc = mc.mcJogVelocityStart(inst,0,1)
elseif axSelX == 1 and contJog25 == 1 then
rc = mc.mcJogSetRate(inst,0,25)
rc = mc.mcJogVelocityStart(inst,0,1)
elseif axSelX == 1 and contJog50 == 1 then
rc = mc.mcJogSetRate(inst,0,50)
rc = mc.mcJogVelocityStart(inst,0,1)
elseif axSelX == 1 and contJog75 == 1 then
rc = mc.mcJogSetRate(inst,0,75)
rc = mc.mcJogVelocityStart(inst,0,1)
elseif axSelX == 1 and contJog100 == 1 then
rc = mc.mcJogSetRate(inst,0,100)
rc = mc.mcJogVelocityStart(inst,0,1)
end
end

--DID THE ABOVE AGAIN, but CHANGED THIS LINE from:
rc = mc.mcSignalHandleWait (mc.OSIG_JOG_INC,WAIT_MODE_LOW,10)
--TO
rc = mc.mcSignalHandleWait (mc.OSIG_JOG_INC,0,10):
--Thanks crap manual
--This completely crashes Mach and generates a report to send when you press the Jog+ button


---Changed
rc = mc.mcSignalHandleWait (mc.OSIG_JOG_INC,0,10)
--TO
rc = mc.mcSignalWait (inst,mc.OSIG_JOG_CONT,10 )
--THIS APPEARS TO DO NOTHING, IT DOES NOT WAIT FOR S#|T, IT JUST STOPS MOVING AS SOON AS YOU LET GO OF THE BUTTON


--USED THE WRONG CODE ABOVE ON ACCIDEING "CONT" instead of "INC"
---Changed
rc = mc.mcSignalWait (inst,mc.OSIG_JOG_CONT,10 )
--TO
rc = mc.mcSignalWait (inst,mc.OSIG_JOG_INC,10 )
--THIS GIVE AN ERROR, THINK IT WANTS THE VALUE OF WHAT IT SHOULD BE WAITING FOR

--CHANGED THIS
rc = mc.mcSignalWait (inst,mc.OSIG_JOG_INC,10 )
--TO
rc = mc.mcSignalWait (inst,mc.OSIG_JOG_INC,0,10 )
--THIS STILL DOES NOT WAIT FOR ANYTHING. USELESS! STILL JUST STOPS MOVING IF YOU LET GO OF THE BUTTON
--I DO FIND THAT IT SEEMS LIKE SOME CHANGES DO NOT WORK RIGHT UNLESS YOU EXIT MACH COMPLETELY ARE REOPEN, I HOPE THIS IS
--NOT MAKING ME SKIP OVER SOMETHING THAT MIGHT WORK>>>


--ADDED TO GET THE VALUE OF mc.OSIG_JOG_INC location and try to use that variable instead of directly using it
---CHANGED CODE TO THIS:
local crap, rc = mc.mcSignalGetHandle (inst, mc.OSIG_JOG_INC)
if axSelX == 1 and jogSel1 == 1 then
rc = mc.mcJogIncStart(inst,0,1)
local FinCrapola = mc.mcSignalGetState (crap)
rc = mc.mcSignalWait (inst,FinCrapola,0,10)
--AGAIN THIS DOES NOTHING AND DOES NOT WAIT FOR ANYTHING
« Last Edit: August 25, 2019, 05:58:04 PM by jevs »

Offline jevs

*
  •  315 315
    • View Profile
SwiftyJ, apparenlty my last post went in after yours LOL. I tried a bunch more stuff since then to no avail :(

It looks like you have been busy with what you did. I thank you a bunch for doing all of that!

I am about to give yours a try and say a little prayer and maybe sacrifice a chicken to the Lua gods or something in hopes that it works :) I will report back!
« Last Edit: August 25, 2019, 06:28:35 PM by jevs »

Offline jevs

*
  •  315 315
    • View Profile
SwiftyJ,
Got it all loaded in. I get an "Error starting continuous jog" when booting up Mach4, but ignore it and continue....

With that said, this is kind of working and certainly must be a step in a better direction? It is actually completing an incremental move!

However, what I notice is that it is changing the Jog Rate and Incremental Jog Step  on the computer screen. My intentions were for this not to do that and only affect the Jog+ and Jog- physical buttons on the control panel. Otherwise you always end up on 2% Continuous jog. You have to cycle through those Continuous Jog positions on the switch to get back to the step jog settings and the last one hit is 2%.

This opens up a lot more for me to think about though. If you have any ideas to make it only affect the control panel and not the "on screen" jogging, please let me know.

I am thinking maybe the jog rate of the screen could be recorded before any of this happens somehow and put back when all the continuous jog inputs are at 0? so that the step jogs default back to whatever is on the screen when you go to those positions?

Again, thanks for taking the time to help me with this! In the mean time I will drink more coffee and brainstorm how to solve the above issues....getting there though...!

« Last Edit: August 25, 2019, 07:07:35 PM by jevs »

Offline jevs

*
  •  315 315
    • View Profile
Missed my editing time window for above....I was going to mention...

I do have an off position on the Axis Selector of control panel. If that is useful for anything...

It looks like I can change this and it will put it back to 100% jog rate for the incrementals when you go there....not sure if this how it should be or not.
I still have to get the feedrate override selector going too....
Code: [Select]
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

Is Step jog usually done at 100% and slowed down with Feedrate Override (if you wanted to slow it down)? I do not have experience with other CNC mills. Maybe other mills only have switches for control and not duplicate "on screen" options?
« Last Edit: August 25, 2019, 07:26:30 PM by jevs »

Offline jevs

*
  •  315 315
    • View Profile
Another note to solve:

If the axis selector knob is on the off position it breaks the code since none of the ones it is looking for is on. Having it in the off position activates pin 43

I will have to see if I can figure out how to make it disable the jog + and - buttons if it is in this position and not break the code for the other positions.

Offline jevs

*
  •  315 315
    • View Profile
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.
Code: [Select]
[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,
Code: [Select]
--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
« Last Edit: August 25, 2019, 10:13:47 PM by jevs »

Offline jevs

*
  •  315 315
    • View Profile
I looked at this for a long time, but I do not understand it well enough to fix why it comes up "Error starting continuous jog" on initial boot of Mach4.
I have to give up for now. It is late. I tried a couple things, but just break stuff worse.

Code: [Select]
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

I am tempted to just comment out the error, because it seems to work fine if you just ignore it on first bootup...
I am down to getting this on first bootup, even though things seem to be working okay and the ESS error seams unrelated to the topic of this thread. It is there even if I disable things for this thread.

-----ESS: Limit Switch triggered on
Error starting continuous jog
Error starting continuous jog

One other thing to note is that every once in awhile if I am on the x1 switch position, a jog will go 2 inches instead of just one...this is random so far as I can tell. Maybe to do with switch bounce while it is still moving? It thinks you hit it twice so it goes 2 inches instead of one. I wonder if there is a way for it not to accept another input until it finishes the move? This way if there was some switch bounce it would be ignored if it occurs after the initial press, and before it finishes moving the command distance from the first press.


« Last Edit: August 25, 2019, 11:39:30 PM by jevs »
If you want to stop the new code affecting the screen jog controls I can rewrite some of it using registers which would sort this out.

I think the reason you're getting the errors during start up is that Mach4 see's the input high and runs the jogAxis function. You can fix this by checking that the Mach is enabled in the Jog Plus and Jog Neg code in the signal library. There is a global variable that is set up at the top of the screen load screen 'machEnabled'. I believe you can use this e.g.
Code: [Select]
[mc.ISIG_INPUT50] = function (state) -- Jog- Input
if (machEnabled == 1) then
local axisNum = getAxisToJog()
if(state == 1) then
jogAxis(axisNum, mc.MC_JOG_NEG)
else
jogAxis(axisNum, mc.MC_JOG_STOP)
end
end
end,

Regarding the speed for incremental jog moves, Mach uses the current jog rate % when performing an incremental move. The feed rate control only affects g-code. You could set a different rate for each increment using the setJogRate() function
I've rewritten it using registers which tidies some things up a bit more, and also helps with diagnostics as you can see through the register diagnostics what the jog values are currently set to. It also doesn't affect anything on the Mach screen.

I have added checks to the Jog+ and Jog- signals to check that Mach is enabled (this should prevent errors on startup) and check Mach is at idle (this should help prevent sending a jog command while it is jogging, and also prevent errors if a button is pressed when running g-code or something).  It also looks at input 43 to check that the control panel isn't set to 'Off'

I have added code to input 43 so that if Off is selected while it is jogging, the jogging will stop. You can remove this if you want..

For each of the increment inputs I have added setCpJogRate(100) to set jog rate to 100. You could change it so you have individual speeds for each increment.

There are a couple of functions added/removed and signal library has changed so best to delete what I sent before. You will also need to add the registers via Configure - Plugins - Regfile  (Mach may need to be restarted after)

Double check all the input numbers, I think have them correct

Images of the registers to add are attached

Signal Library
Code: [Select]
[mc.ISIG_INPUT19] = function (state) -- Increment Selection 1
    if(state == 1) then
setCpJogRate(100) --Adjust speed for increment
setCpJogInc(1)
setCpJogType(mc.MC_JOG_TYPE_INC)
end
end,
[mc.ISIG_INPUT20] = function (state) -- Increment Selection 2
    if(state == 1) then
setCpJogRate(100) --Adjust speed for increment
setCpJogInc(0.1)
setCpJogType(mc.MC_JOG_TYPE_INC)
end
end,
[mc.ISIG_INPUT21] = function (state) -- Increment Selection 3
    if(state == 1) then
setCpJogRate(100) --Adjust speed for increment
setCpJogInc(0.01)
setCpJogType(mc.MC_JOG_TYPE_INC)
end
end,
[mc.ISIG_INPUT22] = function (state) -- Increment Selection 4
    if(state == 1) then
setCpJogRate(100) --Adjust speed for increment
setCpJogInc(0.001)
setCpJogType(mc.MC_JOG_TYPE_INC)
end
end,
[mc.ISIG_INPUT23] = function (state) -- Increment Selection 5
    if(state == 1) then
setCpJogRate(100) --Adjust speed for increment
setCpJogInc(0.0001)
setCpJogType(mc.MC_JOG_TYPE_INC)
end
end,
[mc.ISIG_INPUT24] = function (state) -- Jog Rate Selection 1
    if(state == 1) then
setCpJogRate(2)
setCpJogType(mc.MC_JOG_TYPE_VEL)
end
end,
[mc.ISIG_INPUT25] = function (state) -- Jog Rate Selection 2
    if(state == 1) then
setCpJogRate(5)
setCpJogType(mc.MC_JOG_TYPE_VEL)
end
end,
[mc.ISIG_INPUT26] = function (state) -- Jog Rate Selection 3
    if(state == 1) then
setCpJogRate(10)
setCpJogType(mc.MC_JOG_TYPE_VEL)
end
end,
[mc.ISIG_INPUT27] = function (state) -- Jog Rate Selection 4
    if(state == 1) then
setCpJogRate(25)
setCpJogType(mc.MC_JOG_TYPE_VEL)
end
end,
[mc.ISIG_INPUT28] = function (state) -- Jog Rate Selection 5
    if(state == 1) then
setCpJogRate(50)
setCpJogType(mc.MC_JOG_TYPE_VEL)
end
end,
[mc.ISIG_INPUT29] = function (state) -- Jog Rate Selection 6
    if(state == 1) then
setCpJogRate(75)
setCpJogType(mc.MC_JOG_TYPE_VEL)
end
end,
[mc.ISIG_INPUT30] = function (state) -- Jog Rate Selection 7
    if(state == 1) then
setCpJogRate(100)
setCpJogType(mc.MC_JOG_TYPE_VEL)
end
end,

[mc.ISIG_INPUT43] = function (state) -- Off --This will stop all current jogging if off is selected
local axisNum
    if (state == 1) and (machEnabled == 1) then --Only runs if mach is enabled.
for axisNum=0,5,1 do
if mc.mcJogIsJogging(inst, axisNum) == 1 then --Check to see if the axis is jogging
mc.mcJogVelocityStop(inst, axisNum) --If it is then stop jogging
mc.mcCntlSetLastError(inst, "Jog stopped via Control Panel")
end
end
end
end,
[mc.ISIG_INPUT44] = function (state) -- Select X axis
    if(state == 1) then
setCpJogAxis(0)
end
end,
[mc.ISIG_INPUT45] = function (state) -- Select Y axis
    if(state == 1) then
setCpJogAxis(1)
end
end,
[mc.ISIG_INPUT46] = function (state) -- Select Z axis
    if(state == 1) then
setCpJogAxis(2)
end
end,
[mc.ISIG_INPUT47] = function (state) -- Select 4 axis
    if(state == 1) then
setCpJogAxis(3)
end
end,
[mc.ISIG_INPUT48] = function (state) -- Select 5 axis
    if(state == 1) then
setCpJogAxis(4)
end
end,
[mc.ISIG_INPUT49] = function (state) -- Select 6 axis
    if(state == 1) then
setCpJogAxis(5)
end
end,
[mc.ISIG_INPUT51] = function (state) -- Jog+ Input
local hSig = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT43)
local cpJogEna = mc.mcSignalGetState(hSig) ~= 1 --If signal is not equal to 1, then cpJogEna == True
if (machEnabled == 1)  and cpJogEna then --If mach is enabled and cpJogEna == true
if(state == 1) and (machState == mc.MC_STATE_IDLE) then
cpJogAxis(mc.MC_JOG_POS)
else
cpJogAxis(mc.MC_JOG_STOP)
end
end
end,

[mc.ISIG_INPUT52] = function (state) -- Jog- Input
local hSig = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT43)
local cpJogEna = mc.mcSignalGetState(hSig) ~= 1 --If signal is not equal to 1, then cpJogEna == True
if (machEnabled == 1) and cpJogEna then
if (state == 1) and (machState == mc.MC_STATE_IDLE) then
cpJogAxis(mc.MC_JOG_NEG)
else
cpJogAxis(mc.MC_JOG_STOP)
end
end
end,

Screen load script functions
Code: [Select]
function setCpJogInc(inc) --Sets value of cpJogInc register
local inst = mc.mcGetInstance()
local hReg = mc.mcRegGetHandle(inst, "iRegs0/cpJogInc")
mc.mcRegSetValue(hReg, inc)
end

function setCpJogRate(rate) --Sets value of cpJogRate register
local inst = mc.mcGetInstance()
local hReg = mc.mcRegGetHandle(inst, "iRegs0/cpJogRate")
mc.mcRegSetValue(hReg, rate)
end

function setCpJogType(mode) --Sets value of cpJogType register
local inst = mc.mcGetInstance()
local hReg = mc.mcRegGetHandle(inst, "iRegs0/cpJogType")
mc.mcRegSetValue(hReg, mode)
end

function setCpJogAxis(axis) --Sets value of cpJogAxis register
local inst = mc.mcGetInstance()
local hReg = mc.mcRegGetHandle(inst, "iRegs0/cpJogAxis")
mc.mcRegSetValue(hReg, axis)
end

function cpJogAxis(dir) --This function starts the jogging
local inst, hReg
inst = mc.mcGetInstance()
--Retrieve values from registers
hReg = mc.mcRegGetHandle(inst, "iRegs0/cpJogAxis")
local jogAxis = mc.mcRegGetValue(hReg)
hReg = mc.mcRegGetHandle(inst, "iRegs0/cpJogRate")
local jogRate = mc.mcRegGetValue(hReg)
hReg = mc.mcRegGetHandle(inst, "iRegs0/cpJogInc")
local jogInc = mc.mcRegGetValue(hReg)
hReg = mc.mcRegGetHandle(inst, "iRegs0/cpJogType")
local jogType = mc.mcRegGetValue(hReg)
--Set Jog Rate
mc.mcJogSetRate(inst, jogAxis, jogRate)
--Jog Axis
if (jogType == mc.MC_JOG_TYPE_INC) and dir ~= mc.MC_JOG_STOP then --If incremental jog
rc = mc.mcJogIncStart(inst, jogAxis, (jogInc*dir)) --Start the inc jog
if (rc ~= mc.MERROR_NOERROR) then
mc.mcCntlSetLastError(inst, string.format("Error %.0f: Unable to start incremental jog", rc))
end
elseif (jogType == mc.MC_JOG_TYPE_VEL) and dir ~= mc.MC_JOG_STOP then --If continuous and not stopping
rc = mc.mcJogVelocityStart(inst, jogAxis, dir)
if (rc ~= mc.MERROR_NOERROR) then
mc.mcCntlSetLastError(inst, string.format("Error %.0f: Unable to start continuous jog", rc))
end
elseif (jogType == mc.MC_JOG_TYPE_VEL) and dir == mc.MC_JOG_STOP then
mc.mcJogVelocityStop(inst, jogAxis)
end
end
« Last Edit: August 26, 2019, 07:18:30 AM by SwiftyJ »

Offline jevs

*
  •  315 315
    • View Profile
This is beyond anything I would have ever dreamed up! Thank you. I will give this a try tonight and report back.