Hello Guest it is April 25, 2024, 08:35:53 PM

Author Topic: Mach 4 question  (Read 4038 times)

0 Members and 1 Guest are viewing this topic.

Mach 4 question
« on: August 23, 2021, 01:19:37 PM »
Hey,

So I have a question with regards to Mach 4. I want to use a pulse encoder generator (jog wheel) to control the jog movements of my axis. I would like it so if a button is pressed it activates the jog wheel for a specific axis(x) and if a different button is pressed it activates the jog wheel for a different axis(y). How would you or is it even possible to connect the pulse generator to Mach 4. Also, is it possible to edit the jog increments from buttons on a panel? Any help would be much appreciated.

Peter
Re: Mach 4 question
« Reply #1 on: August 23, 2021, 04:57:35 PM »
Nice to meet you.
What about MPG?
If so, in my case, I found out by looking at the following article.
URL
https://www.warp9td.com/index.php/faq/faq-pendants-and-mpgs#MultiWirePendantInMachFour
Re: Mach 4 question
« Reply #2 on: August 23, 2021, 05:28:34 PM »
Hi,
That article was very informative and helpful and answers a lot of my question.
Peter
Re: Mach 4 question
« Reply #3 on: August 23, 2021, 07:11:27 PM »
Hi,

Quote
So I have a question with regards to Mach 4. I want to use a pulse encoder generator (jog wheel) to control the jog movements of my axis. I would like it so if a button is pressed it activates the jog wheel for a specific axis(x) and if a different button is pressed it activates the jog wheel for a different axis(y). How would you or is it even possible to connect the pulse generator to Mach 4. Also, is it possible to edit the jog increments from buttons on a panel? Any help would be much appreciated.

All of these things are possible.

If you use an MPG that would have to be wired to your controller/BoB and then to Mach. You could have buttons OR switches to set the active axis and/or the jog
increment. There are some good examples but will still require that you do some Lua coding.

Another alternative is to use a pendant like a VistsCNC P1A, I've been using mine for seven years with Mach4. It has a two rotary switches for the active axis,
speed rate override, incremental/velocity mode, jog increment and more. They cost $160. No wiring, no programming, stands alone from your
controller/BoB so no loss of inputs......

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach 4 question
« Reply #4 on: August 24, 2021, 02:18:18 AM »
Hi,
lets imagine for a moment that you wish to go the hardwired MPG route, and I have given some thought to doing so myself.
Every once in a while my USB connected pendant loses communication and the machine needs to be power cycled to bring it back,
a PITA....doesn't happen often but when it does that's when I think a hardwired pendant has advantages.

An MPG requires four wires, A+,A-,B+ and B-, unless you create a logic board that would reduce those four wires down to two,
namely Step/Direction, and that neglects the common return, so three wires in truth.

Lets say you had two three position rotary switches, each switch would require three wires (one common and the other two binary coded
for the three positions). Assuming the common return could be shared by the two rotary switches then you would require five wires for
the two switches.

Totaling the wires for this arrangement:
4 wires-MPG
4 wires-binary coded switch position (two switches)
1 wire-common return

This would require 8 spare inputs on your BoB/controller combination. Do you have 8 spare inputs?

If you want or need to economise on the inputs you could do it this way:
2 wires-Step/Dir derived from logic circuit of the MPG
2 wires-one for each of two buttons
1 wire-common return

This arrangement requires a small logic circuit be built into your pendant and that you write some Lua code to cycle through the axes
in the case of the ActiveAxis button and the jog increment in the case of the JogIncremnt button. This would reduce the number of spare inputs
required to four. Do you have four to spare?

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach 4 question
« Reply #5 on: August 24, 2021, 03:43:57 AM »
Hello.

I'm using Mach3.
In my case, MPG is the following item.
I think it's easy to understand, so please take a look.
https://ja.aliexpress.com/item/1005003156339630.html?spm=a2g0s.8937460.0.0.39eb2e0eawwZPF
There are 2 wires for power supply and 4 wires for A phase and B phase.
The power supply for GND, BOB, and USB is common.

After that, you need a line for the signal.
Re: Mach 4 question
« Reply #6 on: August 24, 2021, 03:53:27 AM »
Hi,
if you're using Mach3 then good luck.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach 4 question
« Reply #7 on: August 24, 2021, 10:52:02 AM »
Hi,
lets imagine for a moment that you wish to go the hardwired MPG route, and I have given some thought to doing so myself.
Every once in a while my USB connected pendant loses communication and the machine needs to be power cycled to bring it back,
a PITA....doesn't happen often but when it does that's when I think a hardwired pendant has advantages.

An MPG requires four wires, A+,A-,B+ and B-, unless you create a logic board that would reduce those four wires down to two,
namely Step/Direction, and that neglects the common return, so three wires in truth.

Lets say you had two three position rotary switches, each switch would require three wires (one common and the other two binary coded
for the three positions). Assuming the common return could be shared by the two rotary switches then you would require five wires for
the two switches.

Totaling the wires for this arrangement:
4 wires-MPG
4 wires-binary coded switch position (two switches)
1 wire-common return

This would require 8 spare inputs on your BoB/controller combination. Do you have 8 spare inputs?

If you want or need to economise on the inputs you could do it this way:
2 wires-Step/Dir derived from logic circuit of the MPG
2 wires-one for each of two buttons
1 wire-common return

This arrangement requires a small logic circuit be built into your pendant and that you write some Lua code to cycle through the axes
in the case of the ActiveAxis button and the jog increment in the case of the JogIncremnt button. This would reduce the number of spare inputs
required to four. Do you have four to spare?

Craig

Hi Craig,

Thanks for the useful information. I have a spare CNCdrive UC400ETH lying around with the breakout board that goes with it. I have it setup and running in Mach4. I used the script which will be below this post. I am able to use a series of switches to enable either the x y or z axis and also either x1 x10 x100 these all work. The only thing i cannot get to work is the MPG. I have assigned Pin A and Pin B in the plugin and mapped UC400EETH/Encoder 1 to MPG#1. I can see the LED indicators on the board change when I move the jog wheel. But it just doesnt jog the axis is there something wrong in the gcode?
« Last Edit: August 24, 2021, 10:54:37 AM by peter g »
Re: Mach 4 question
« Reply #8 on: August 24, 2021, 10:52:35 AM »
---------------------------------------------------------------
-- Monitor the switches on the Pendant.
-- We break the three different mechanical switches into three separate function calls, since each function has a separate job.
-- We don't need to assign the MPG wheel since Mach handles that for us.
---------------------------------------------------------------
SigLib = {


    [mc.ISIG_INPUT10] = function (state)   --If you are not using INPUT10 for the Axis Selection X, change the INPUT#!!!!
        PendantAxisChange()                     --This is called if there is a change with the Pendant's Axis Selection Switch Posion X
    end,


    [mc.ISIG_INPUT11] = function (state)   --If you are not using INPUT11 for the Axis Selection Y, change the INPUT#!!!!
        PendantAxisChange()                     --This is called if there is a change with the Pendant's Axis Selection Switch Posion Y
    end,


    [mc.ISIG_INPUT12] = function (state)   --If you are not using INPUT12 for the Axis Selection Z, change the INPUT#!!!!
        PendantAxisChange()                     --This is called if there is a change with the Pendant's Axis Selection Switch Posion Z
    end,

-------------
    [mc.ISIG_INPUT13] = function (state)       --If you are not using INPUT6 for theX1 Selection, change the INPUT#!!!!
        PendantSpeedChange()                      --This is called if there is a change with the Pendant's Rate Selection Switch X1
    end,


    [mc.ISIG_INPUT14] = function (state)       --If you are not using INPUT7 for the X10 Selection, change the INPUT#!!!!     
        PendantSpeedChange()                     --This is called if there is a change with  the Pendant's Rate Selection Switch X10
    end,


    [mc.ISIG_INPUT15] = function (state)       --If you are not using INPUT8 for the X100 Selection, change the INPUT#!!!!     
        PendantSpeedChange()                     --This is called if there is a change with the Pendant's Rate Selection Switch X100
    end,

-------------
    [mc.ISIG_INPUT16] = function (state)     --If you are not using INPUT9 for the Pendant EStop Switch, change the INPUT#!!!!     
        PendantEStopChange()                     --This is called if there is a change with the Pendant's EStop Switch
    end,


-------------

--These next three are not part of the Pendant code, but show you a few more options for inputs

[mc.ISIG_INPUT17] = function (state)       --Performs a Cycle Start

InputCycleStart()

end,

 

[mc.ISIG_INPUT18] = function (state)       --Performs a Cycle Stop

InputCycleStop()

end,

 

[mc.ISIG_INPUT19] = function (state)       --Performs a reset

InputReset()

end
}

 

---------------------------------------------------------------

-- The Input Signal for a Cycle Start Occurred. This is not needed for the rest of the pendant example

---------------------------------------------------------------

function InputCycleStart() --This will do a cycle start because of a button push

     CycleStart()

     mc.mcCntlSetLastError(inst, "Input Cycle Start")

end

 

---------------------------------------------------------------

-- The Input Signal for a Cycle Stop Occurred. This is not needed for the rest of the pendant example

---------------------------------------------------------------

function InputCycleStop() --This will do a cycle stop because of a button push

     CycleStop()

     mc.mcCntlSetLastError(inst, "Input Cycle Stop")

end

 

---------------------------------------------------------------

-- The Input Signal for a Reset Occurred. This is not needed for the rest of the pendant example

---------------------------------------------------------------

function InputReset() --This will do a Reset because of a button push

     mc.mcCntlReset(inst)

     mc.mcSpindleSetDirection(inst, 0)

     mc.mcCntlSetLastError(inst, "Input Reset")

end



--In Mach's Config tab for MPGs, if you don't have the ESS's encoder for the pendant assigned to MPG#7, change the 7 to the number you are using:
local MachMpgNumberForPendant = 1

local PendantStepSize = 0.001 --This is in your Mach4's units, mm or Inches, whichever one you have it set to
local PendantDistanceX1 = PendantStepSize * 1    --Multiply by one
local PendantDistanceX10 = PendantStepSize * 10    --Multiply by ten
local PendantDistanceX100 = PendantStepSize * 100    --Multiply by one hundred

--These shouldn't need to be modified, but they reduce the amount of apparently random numbers in the code:
local UnmapMPG = -1         --Use this one for when Axis selector switch is set to OFF
local AxisNumber_X = 0       -- Linear axis X (one of six coordinated motion axes)
local AxisNumber_Y = 1       -- Linear axis Y (one of six coordinated motion axes)
local AxisNumber_Z = 2       -- Linear axis Z (one of six coordinated motion axes)
--Coordinated motion means all six coordinated axes get to the destination point at the same time.
--Not coordinated with motion means that axis can be doing whatever, whenever.  Like a conveyor belt that is always running.




---------------------------------------------------------------
-- The Pendant's EStop switch changed...
-- This will process the Pendant's EStop Switch
-- THIS ESTOP SHOULD BE CONSIDERED A COURTESY SIGNAL, since it based on softare
-- You should still have a EStop that is pure hardwre that can disconnect power.

--If you start Mach with the button pressed in, it will not work when you need to press it!
---------------------------------------------------------------
function PendantEStopChange()

    local hPendantEStop
    local PendantEStop
   
    hPendantEStop, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT9)     --If you are not using INPUT9 for the Pendant EStop Switch, change the INPUT#!!!!   
    PendantEStop, rc = mc.mcSignalGetState(hPendantEStop)
       
    if (PendantEStop == 1) then
        mc.mcCntlEStop(inst)  --Activate the EStop signal in Mach
        mc.mcCntlSetLastError(inst, "Pendant EStop Activated")   --Show a message in the Screen Set
    else
        mc.mcCntlSetLastError(inst, "Pendant EStop Cleared")  --Show a message in the Screen Set
    end 
end



---------------------------------------------------------------
-- The Pendant's Speed switch changed... Reconfigure appropriate settings in Mach4 
--This will process the Pendant's Rate/Speed Selection Switch
---------------------------------------------------------------
function PendantSpeedChange()
   

    --Variable prep first for handles
    local hX1
    local hX10
    local hX100
   

    --Variable prep for signal values
    local Step1
    local Step10
    local Step100
   
    hX1, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT13)       --If you are not using INPUT6 for theX1 Selection, change the INPUT#!!!!
    Step1, rc = mc.mcSignalGetState(hX1)
   
    hX10, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT14)       --If you are not using INPUT7 for the X10 Selection, change the INPUT#!!!!  -- X10 Port 3 Pin 4
    Step10, rc = mc.mcSignalGetState(hX10)
   
    hX100, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT15)       --If you are not using INPUT8 for the X100 Selection, change the INPUT#!!!!
    Step100, rc = mc.mcSignalGetState(hX100)
   
    local msg
       
    if (Step1 == 1) then
        mc.mcMpgSetInc(inst, MachMpgNumberForPendant, PendantDistanceX1 )
        msg = "Jog Distance X1 = " .. PendantDistanceX1
        mc.mcCntlSetLastError(inst, msg)  --Show a message in the Screen Set

    elseif (Step10 == 1) then
        mc.mcMpgSetInc(inst, MachMpgNumberForPendant, PendantDistanceX10)
        msg = "Jog Distance X10 = " .. PendantDistanceX10
        mc.mcCntlSetLastError(inst, msg)  --Show a message in the Screen Set

    elseif (Step100 == 1) then
        mc.mcMpgSetInc(inst, MachMpgNumberForPendant, PendantDistanceX100)
        msg = "Jog Distance X100 = " .. PendantDistanceX100
        mc.mcCntlSetLastError(inst, msg)  --Show a message in the Screen Set
    end
   
   
end

   
   
---------------------------------------------------------------
-- The Pendant's Axis switch changed... Reconfigure appropriate settings in Mach4 and turn the Pendant LED ON/OFF
--This will process the Pendant's Axis Selection Switch
---------------------------------------------------------------
function PendantAxisChange()
 
    --Variable prep first for handles
    local hAxis_X  --Position X on Pendant Switch
    local hAxis_Y  --Position Y on Pendant Switch
    local hAxis_Z  --Position Z on Pendant Switch
   
    --Variable prep for signal values, MAKE SURE YOU MATCH THE ONES IN HERE WITH THE ONES JUST ABOVE
    local SelectAxis_X
    local SelectAxis_Y
    local SelectAxis_Z
   
    hAxis_X, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT10)   --If you are not using INPUT0 for the Axis Selection Switch X, change the INPUT#!!!!
    SelectAxis_X, rc = mc.mcSignalGetState(hAxis_X)
   
    hAxis_Y, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT11)   --If you are not using INPUT1 for the Axis Selection Switch Y, change the INPUT#!!!!
    SelectAxis_Y, rc = mc.mcSignalGetState(hAxis_Y)
   
    hAxis_Z, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT12)   --If you are not using INPUT2 for the Axis Selection Switch Z, change the INPUT#!!!!
    SelectAxis_Z, rc = mc.mcSignalGetState(hAxis_Z)

    --This is the Pendant's LED, and it will be ON when an axis is active on the Pendant's switch
    local hLedForActivePendantAxis
    hLedForActivePendantAxis, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT1)-- Pendant LED Port 3 Pin 1
       
       
   
    --Now actual axis Selection Switch processing code

    if (SelectAxis_X == 1) then
        mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, AxisNumber_X)    --Map the MPG to control the X Axis
        mc.mcCntlSetLastError(inst, "X Axis Selected")  --Show a message in the Screen Set
        mc.mcSignalSetState(hLedForActivePendantAxis, 1)       --Turn the Pendant's LED ON to show an axis is active
       
    elseif (SelectAxis_Y== 1) then
        mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, AxisNumber_Y)    --Map the MPG to control the Y Axis
        mc.mcCntlSetLastError(inst, "Y Axis Selected")  --Show a message in the Screen Set
        mc.mcSignalSetState(hLedForActivePendantAxis, 1)       --Turn the Pendant's LED ON to show an axis is active

    elseif (SelectAxis_Z== 1) then
        mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, AxisNumber_Z)    --Map the MPG to control the Z Axis
        mc.mcCntlSetLastError(inst, "Z Axis Selected")  --Show a message in the Screen Set
        mc.mcSignalSetState(hLedForActivePendantAxis, 1)       --Turn the Pendant's LED ON to show an axis is active

    else
        --None of the Axis Switch inputs are active, so unmap the MPG from all axes (by assigning an invalid axis -1)
        mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, UnmapMPG )     --Unmap the MPG, so it won't control any axes
        mc.mcCntlSetLastError(inst, "NO Pendant Axis Selected")  --Show a message in the Screen Set
        mc.mcSignalSetState(hLedForActivePendantAxis, 0)           --Turn the Pendant's LED OFF to show no axis is active
    end
   

end

 


--We will now call the  three functions we made

--This is so the functions  will be initalized to the current pendant values

--When the Screen is loaded by Mach4


PendantEStopChange()
PendantSpeedChange()
PendantAxisChange()
Re: Mach 4 question
« Reply #9 on: August 24, 2021, 11:21:33 AM »
Hey,

So I have got it working. I am able to use the physical switches to select axis and jog rates. I intend on using a Siemens PLC with a HMI I have lying around and use the screen to have button to select the "x" axis "y" axis and "z" axis as well as "x1" "x10" and "x100". If I have enough spare inputs I will also add "Cycle Start" "Feed Hold" and more. The code above does work I just had a loose connection:)

Thanks for your help

Peter