Hello Guest it is September 27, 2021, 09:27:57 AM

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

0 Members and 1 Guest are viewing this topic.

Offline jevs

*
  •  315 315
    • View Profile
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
« Last Edit: August 24, 2019, 04:44:50 PM by jevs »
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
My wife left with my best friend...
     and I miss him!

Offline jevs

*
  •  315 315
    • View Profile
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.

Offline jevs

*
  •  315 315
    • View Profile
Exact code to force a wait for an incremental jog to finish?
« Reply #3 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.....
Do you not just need a conditional statement to prevent mc.mcJogVelocityStop from running when jog mode is in incremental?

Offline jevs

*
  •  315 315
    • View Profile
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.
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

Offline jevs

*
  •  315 315
    • View Profile
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.
« Last Edit: August 25, 2019, 01:36:08 PM by jevs »

Offline jevs

*
  •  315 315
    • View Profile
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)
« Last Edit: August 25, 2019, 04:13:42 PM by jevs »
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