Hello Guest it is March 29, 2024, 06:35:17 AM

Author Topic: Make moves still in progress from pendant MPG stop if enable switch released?  (Read 666 times)

0 Members and 1 Guest are viewing this topic.

Offline jevs

*
  •  315 315
    • View Profile
I have all the pendant functions working now except I have no idea how to get velocity mode.

However, I have another question besides that one that I have not figured out and it is time to quit on this for tonight.

If I do get velocity mode working or add a step that moves more than the now max .001, like say .01, it could que up a bit of moving if you spin the wheel fast. This means it could still be moving even after you stopped spinning the wheel.

What I want to know is how I can make it stop moving if the enable button is let go, but it still has not finished moving the commanded distance? It seems like it would be safer if something bad happened and you let go of the switch but it was still trying to make the queued up moves.

However, I have not thought of anything that releasing the button would not cause other moves not to work also because the state of the switch will be off normally when the pendant is not being used. So, telling it to stop anything moving when the button is released also might keep anything from ever moving. If that makes sense.

So, any ideas? Here is my code on the pendant so far. Some stuff is commented out because I ended up not needing it for now. I will clean it up when I am done. I don't know what shuttle mode is and I cannot find what it is so far. I was hoping it was another name for velocity mode, but it does not seem to do anything. I read one post about it in mach3 forums and it said something about moving through g code faster or slower...would be nice to know what it is.

I don't know what mc.mcMpgSetEnable is either, so I was trying to see if that disabled and enabled the MPG. It does not seem to, but I cannot find anything about that. You will see those commented out also and put back to setting the axis to -1.

Code: [Select]
-- Add Pokeys Inputs for Pendant Switches

--[mc.ISIG_INPUT3] = function (state) -- Y, Z, 6 on Top Pendant Switch
-- if(state == 1) then
-- PendantAxis()
-- end
--end,
--[mc.ISIG_INPUT4] = function (state) -- X, Z, 5 on Top Pendant Switch
-- if(state == 1) then
-- PendantAxis()
-- end
--end,
--[mc.ISIG_INPUT7] = function (state) -- 4, 5, 6 on Top Pendant Switch
-- if(state == 1) then
-- PendantAxis()
-- end
--end,
[mc.ISIG_INPUT9] = function (state) -- .001 on Bottom Pendant Switch
if(state == 1) then
rc = mc.mcMpgSetRate (inst, 0, 100) -- Set Pendant MPG velocity rate to 100%
rc = mc.mcMpgSetInc(inst, 0, .001) -- Set Pendant MPG incremenent to .001
else
rc = mc.mcMpgSetRate (inst, 0, 100) -- Set Pendant MPG velocity rate to 100%
rc = mc.mcMpgSetInc(inst, 0, .0001) -- Set Pendant MPG incremenent to .0001 since this position has no input
end
end,
[mc.ISIG_INPUT10] = function (state) -- V on Bottom Pendant Switch
if(state == 1) then
rc = mc.mcMpgSetRate(inst, 0, 100) -- Set Pendant MPG velocity rate to 100%
rc = mc.mcMpgSetShuttleMode (inst, 1)
--rc = mc.mcMpgSetInc(inst, 0, .001)
else
rc = mc.mcMpgSetShuttleMode (inst, 0)
rc = mc.mcMpgSetRate(inst, 0, 100) -- Set Pendant MPG velocity rate to 100%
rc = mc.mcMpgSetInc(inst, 0, .0001) -- Set Pendant MPG incremenent to .0001 since this position has no input
end
end,
[mc.ISIG_INPUT12] = function (state) -- Pendant Enable Key
if(state == 1) then
--rc = mc.mcMpgSetEnable (inst, 0, 1) -- Enable MPG
PendantAxis()
else
--rc = mc.mcMpgSetEnable (inst, 0, 0) -- Disable MPG
rc = mc.mcMpgSetAxis(inst, 0, -1) -- Sets Pendant MPG to no valid axis so it cannot move anything when not pressed
end
end,

Code: [Select]
-----Pendant functions------
--Set Pendant axis
function PendantAxis()
local inst = mc.mcGetInstance()
local in3, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT3) -- Y, Z, 6 on Top Pendant Switch
    local axYZ6, rc = mc.mcSignalGetState(in3)
    local in4, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT4) -- X, Z, 5 on Top Pendant Switch
    local axXZ5, rc = mc.mcSignalGetState(in4)
    local in7, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT7) -- 4, 5, 6 on Top Pendant Switch
    local ax456, rc = mc.mcSignalGetState(in7)

if ax456 == 0 and axYZ6 == 0 and axXZ5 == 0 then  -- Axis Off
        --rc = mc.mcMpgSetEnable (inst, 0, 0) -- Disable MPG
rc = mc.mcMpgSetAxis(inst, 0, -1) -- Negative one to select a non valid axis
        rc = mc.mcCntlSetLastError(inst, "Pendant Axis Off")
    elseif ax456 == 0 and axYZ6 == 0 and axXZ5 == 1 then  -- Axis X
        rc = mc.mcMpgSetAxis(inst, 0, 0)
        rc = mc.mcCntlSetLastError(inst, "Pendant Axis X Selected")
elseif ax456 == 0 and axYZ6 == 1 and axXZ5 == 0 then  -- Axis Y
        rc = mc.mcMpgSetAxis(inst, 0, 1)
        rc = mc.mcCntlSetLastError(inst, "Pendant Axis Y Selected")
elseif ax456 == 0 and axYZ6 == 1 and axXZ5 == 1 then  -- Axis Z
        rc = mc.mcMpgSetAxis(inst, 0, 2)
        rc = mc.mcCntlSetLastError(inst, "Pendant Axis Z Selected")
elseif ax456 == 1 and axYZ6 == 0 and axXZ5 == 0 then  -- Axis 4
        rc = mc.mcMpgSetAxis(inst, 0, -1) -- Minus one because their is not currently an axis 4
        rc = mc.mcCntlSetLastError(inst, "Invalid Pendant Axis Selected")
elseif ax456 == 1 and axYZ6 == 0 and axXZ5 == 1 then  -- Axis 5
        rc = mc.mcMpgSetAxis(inst, 0, -1) -- Minus one because their is not currently an axis 5
        rc = mc.mcCntlSetLastError(inst, "Invalid Pendant Axis Selected")
elseif ax456 == 1 and axYZ6 == 1 and axXZ5 == 0 then  -- Axis 6
        rc = mc.mcMpgSetAxis(inst, 0, -1) -- Minus one because their is not currently an axis 6
        rc = mc.mcCntlSetLastError(inst, "Invalid Pendant Axis Selected")
end
end
« Last Edit: August 28, 2019, 11:58:39 PM by jevs »