Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: jevs on August 24, 2019, 04:42:25 PM

Title: Let Incremental jog finish but still shut off Velocity move if button is let go?
Post by: jevs on August 24, 2019, 04:42:25 PM
This works, but it will stop doing the incremental move when you let off the button even if it has not finished the distance commanded. I know it is doing it because it instantly issues a velocity stop when you let go.
However, what is a good way to let this wait for the incremental move to get done?
I may need to revamp this layout for it to work, but it is almost there.....

Code: [Select]
[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)
if axSelX == 1 and jogSel1 == 1 then
rc = mc.mcJogIncStart(inst,0,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
end
Title: Re: Let Incremental jog finish but still shut off Velocity move if button is let go?
Post by: joeaverage on August 24, 2019, 06:07:24 PM
Hi,
is this using the Pokeys or the ESS as input?

I suspect it matters little, neither handle incremental jogs on board or realtime.

A button press will be communicated to Mach with some delay, perhaps a few to maybe tens of milliseconds.
Mach will make an appropriate string of movement instructions and communicate them to the motion controller,
again with a communication delay. The instructions will be queued in the buffer until execution, again with some
delay depending on the depth of the buffer.

Neither the ESS or the PoKeys (to my knowledge) handle jogging on board. Additionally if I understand your
installation you have the ESS as motion controller and the Poekys auxillary data entry. Thus even if the PoKeys
did jogging in real time it would still have to be communicated to Mach and then to the ESS with its attendant
delays.

The delays preclude instantaneous response....they are not the fault of either the input board nor Mach but are
as a consequence of Windows PCs not being realtime....that is to say that Windows CNC solutions MUST be
a buffered (read delayed) control solution.

The only motion controller that does jogging realtime (to my knowledge) is the CSMIO....and I'm not sure but it may
well be the CSMIO/A alone which is capable of it, ie the analogue output board. The CSMIO Mach4 plugin is still
somewhat buggy and has been very slow to develop. Therefore there is not a lot of information about CSMIO and Mach4.

Craig
Title: Re: Let Incremental jog finish but still shut off Velocity move if button is let go?
Post by: jevs on August 24, 2019, 06:17:04 PM
I am using pokeys for these inputs. The latency is not a problem. It all works fine with no noticable lag or wait. The problem is that when i added the functions for continuous jogging at different rates.
 When you turn it  on in the way I have it, it also has to know to stop when you let go of the button. The jog incremental does not need this.
So what happens now is that I added the lines to stop constant velocoty moves when you let go of the button. However this will also stop an incremental jog that has not completed its distance.
At first I was confused because I thought it was just the x1 and x.1 settings. However the others just seemed to work because they finished before i let go of the button.
Title: Exact code to force a wait for an incremental jog to finish?
Post by: jevs on August 25, 2019, 12:43:29 AM
.....or way to make the mcJogVelocityStop code needed to stop a continuous jog not kill an incremental move that has not finished getting where it is going?

I wasted another day of my time trying to figure this out. I cannot get the dumb thing to wait for an incremental move to finish before going on no matter what I try.

Unfortunately there has to be code in there to stop a continuous move when you release the button if it is in continuous mode or it will just keep going until it hits the limit after you release the button. This same code kills an incremental move if you let go of the button before it gets to the commanded distance.

The documentation is so crappy and has no info for how output signals work. I have no idea if OSIG_JOG_INC or OSIG_JOG_CONT is 1 only when the axis is moving or only when its toggled into this mode or if it even uses ones and zeros. I don't know if I can use these as values, or if these are just locations you have to call out then assign a variable to.

I have tried what I can think of with it and so far no luck. I also have no idea if these are just 1,0 or they are a location that has to be called out, then assign the location value to a variable.

I may not even be on the right path of the right way to do this. There are no examples I can find and the API manual is too poor to figure it out easily.

You cannot run the debugger on the screen script. It just skips over anything in the siglib even if you have the button held down. This means a million times of entering and exiting these screens trying stuff.

I cannot get mcSignalWait to work with anything I conjure up. The same goes for mcSignalHandleWait.

The manual is such a piece of crap. The examples have no syntax that works the way it is written. There is no explanation that some things called out are a variable that you can assign whatever text you want. For example hSig. Where does it tell you that you don't actually have to use hSig.....or do you? Is WAIT_MODE_LOW a real thing to use in the command, or is this just the way they decided to say 0 should go there. Aggravating.

Every little simple thing takes hours and hours of trial and error to get syntax and things right due to the horrible documentation.

Anyway, I am deleting the rest of my rant. I am getting so frustrated because I can see now I will have another entire weekend spent and this thing still will not be done. If you knew how to do this already and knew the correct syntax etc, I think I got about 30 minutes of work done in 30 hours..... Every function takes a week worth of precious free time to get working. Unless you are lucky enough to get an answer here, your sunk.....
Title: Re: Let Incremental jog finish but still shut off Velocity move if button is let go?
Post by: SwiftyJ on August 25, 2019, 06:31:12 AM
Do you not just need a conditional statement to prevent mc.mcJogVelocityStop from running when jog mode is in incremental?
Title: Re: Let Incremental jog finish but still shut off Velocity move if button is let go?
Post by: jevs on August 25, 2019, 12:51:04 PM
I have tried every way i could think of to do that and so far nothing works. If you know how to do it please post some code.
Title: Re: Let Incremental jog finish but still shut off Velocity move if button is let go?
Post by: SwiftyJ on August 25, 2019, 12:58:53 PM
Can you post a picture of the controls you are trying to set up or describe what you want everything to do? There may be a way to condense the code you have written and make it bit more user friendly / easier to edit in the future
Title: Re: Let Incremental jog finish but still shut off Velocity move if button is let go?
Post by: jevs on August 25, 2019, 01:33:23 PM
Absolutely. If I can get past this part today I will feel like I had some great success.
The code needs to get even longer this and has gotten longer as I am adding to it, but It is broke right now due to the issue I am having. I did not add in the Y and Z for continuous yet.
Here are the pokeys inputs being used and a couple pictures of the actual control panel and pendant hooked into it. Everything is working fine electrically, I am just stuck on the coding. Even the switches and buttons do what they are supposed to, it just will not complete an incremental move unless you hold down the button until it finishes.
I had to convert this Machmotion panel from pokeys55 to pokeys57E, but I mapped everything out and it is working the same as it did on Mach3 with the old pokeys55 now. The pokeys plugin does not support the old pokeys.
The pokeys pendant settings do not really have what I need in there, so I was not planning to use that either I suppose. They don't even have a .0001 incremental option in the list for example. I did briefly try the mpg with that and it did move.
Title: Re: Let Incremental jog finish but still shut off Velocity move if button is let go?
Post by: jevs on August 25, 2019, 04:10:55 PM
So far today just bashing my head against the wall and wasting time.....none of this works in case you want to know....I have tried a lot of other things, but now I am starting to record all the tries. I just need it to do something so simple, but it refuses......
Code: [Select]
--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)
if( state == 1) then
CPJogPlus()
end
if( state == 0) then
local inc = mc.mcSignalGetHandle(inst, mc.OSIG_JOG_INC);
local joginc = mc.mcSignalGetState(inc)
if (joginc == 1) then
--Do nothing
else
rc=mc.mcJogVelocityStop(inst,0)
rc=mc.mcJogVelocityStop(inst,1)
rc=mc.mcJogVelocityStop(inst,2)
end
end
end,

--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 ( joginc == 1) then
else
rc=mc.mcJogVelocityStop(inst,0)
rc=mc.mcJogVelocityStop(inst,1)
rc=mc.mcJogVelocityStop(inst,2)
end
end,

--DOES NOT WORK> INCREMENTAL JOG WILL NOT FINISH IF JOG+ BUTTON IS RELEASE BEFORE IT GETS THERE
-- 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 == 1) then
rc=mc.mcJogVelocityStop(inst,0)
rc=mc.mcJogVelocityStop(inst,1)
rc=mc.mcJogVelocityStop(inst,2)
end
end,

--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 (joginc == 1) then
elseif (joginc == 0) then
rc=mc.mcJogVelocityStop(inst,0)
rc=mc.mcJogVelocityStop(inst,1)
rc=mc.mcJogVelocityStop(inst,2)
end
end,

I have no way to know if these variables are even working other than it will compile...you cannot run debug and get any answers (or at least I don't know the secret)
Title: Re: Let Incremental jog finish but still shut off Velocity move if button is let go?
Post by: SwiftyJ 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
Code: [Select]
[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
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.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
Title: Re: Let Incremental jog finish but still shut off Velocity move if button is let go?
Post by: jevs on August 25, 2019, 05:55:38 PM
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
Title: Re: Let Incremental jog finish but still shut off Velocity move if button is let go?
Post by: jevs on August 25, 2019, 06:21:47 PM
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!
Title: Re: Let Incremental jog finish but still shut off Velocity move if button is let go?
Post by: jevs on August 25, 2019, 06:52:10 PM
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...!

Title: Re: Let Incremental jog finish but still shut off Velocity move if button is let go?
Post by: jevs on August 25, 2019, 07:10:30 PM
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?
Title: Re: Let Incremental jog finish but still shut off Velocity move if button is let go?
Post by: jevs on August 25, 2019, 07:47:46 PM
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.
Title: Re: Let Incremental jog finish but still shut off Velocity move if button is let go?
Post by: jevs 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.
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
Title: Re: Let Incremental jog finish but still shut off Velocity move if button is let go?
Post by: jevs on August 25, 2019, 11:29:56 PM
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.


Title: Re: Let Incremental jog finish but still shut off Velocity move if button is let go?
Post by: SwiftyJ on August 26, 2019, 05:40:52 AM
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
Title: Re: Let Incremental jog finish but still shut off Velocity move if button is let go?
Post by: SwiftyJ on August 26, 2019, 07:06:53 AM
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
Title: Re: Let Incremental jog finish but still shut off Velocity move if button is let go?
Post by: jevs on August 26, 2019, 08:04:22 AM
This is beyond anything I would have ever dreamed up! Thank you. I will give this a try tonight and report back.
Title: Re: Let Incremental jog finish but still shut off Velocity move if button is let go?
Post by: jevs on August 26, 2019, 08:07:46 PM
This seems to be working perfectly so far! I tested everything out and it seems to be working great!
Thanks a million for doing this. This saved me a ton of time and also showed me some new things to do.

I am going to attempt to move on to the feed rate switch next and then the pendant. What you did here gives a great example. I am sure some others will benefit from this code if they find it in the search.

I think this one is solved if no other questions come up.

Thanks again!
Title: Re: Let Incremental jog finish but still shut off Velocity move if button is let go?
Post by: SwiftyJ on August 27, 2019, 04:05:13 AM
Great!

I've seen your other thread about the feed rate switch.. It should be pretty easy to make it control the jog rate for the incremental moves as we've made it using the registers.
In the signal library for the FRO inputs, i'd just call mc.mcCntlSetFRO() API to set the feed rate, and then set the speed for the incremental moves using the function we made before cpSetJogRate(). If we check that the Jog Type is set to incremental it will prevent the FRO control changing the jog rate when the jog is set to continuous.

If you do this remove the setCpJogRate(100) I added for each of the incremental inputs in the signal library otherwise it will reset to 100 if you change increment value.

So you'd have something like this, I've not tested it but it should work...
Code: [Select]
[mc.ISIG_INPUT18] = function (state) -- Set FRO 100%
    if(state == 1) then
local inst = mc.mcGetInstance()
mc.mcCntlSetFRO(inst, 100) --Set FRO value 100%
local hReg = mc.mcRegGetHandle(inst, "iRegs0/cpJogType")
local jogType = mc.mcRegGetValue(hReg)
if (jogType == mc.MC_JOG_TYPE_INC) then --Check that Jog Type is incremental
setCpJogRate(100) --Set jog rate for incremental to 100%
end
end
end,
Title: Re: Let Incremental jog finish but still shut off Velocity move if button is let go?
Post by: jevs on August 27, 2019, 11:39:50 AM
I talked with Machmotion this morning. It sounds like there may have been some limitations with Mach3 that may have affected how things were setup back then.
From the conversation we had, it seems like it may be more normal and desired that FRO never affects any manual jogging speeds weather incremental or continuous (at any percentage)?
 
Which means the way I have it now should be good (without trying to tie the FRO switch to step jog position move rates)? They said basically FRO should only affect G01 moves (Which I assume no manual jogging would be included in that)?