FAQ Pendants and MPGs


 


 

What is a MPG?

MPG stands for Manual Pulse Generator.  It is a knob you can spin by hand and generate a quadrature pulse stream with.  The SmoothStepper can read in this pulse stream and pass it into Mach.

 


 

What is a Pendant

A Pendant will usually have a MPG and selector switches to choose between axes and rates.  However, xBox controllers and other gaming devices can be used if an appropriate plugin is available for them.

 

 

 


 

What are some of the available Pendants?

 

This section woefully under represents the number of Pendants out there.  Please let us know of ones we should add. 

 

 

  • XBox controller.  If you have an XBox controller, you can use it with a Mach3 plugin or a Mach4 plugin.

 

  • VistaCNC
    • By Joe.Average (Craig) on June 22nd, 2019:
      I use a VistaCNC pendant, and it to is connected to the PC via USB.
      In order for Mach to recognize the pendant you must of course use the VistaCNC
      Mach4 plugin. It does not require an MPG to be configured in the ESS, the pendant
      MPG never even comes close to the ESS.

      May I suggest disconnecting the MPG from the ESS and removing all input assignments
      that its installation might have required. This will remove any doubt and confusion
      as to what is going on. You want to deal with the VistaCNC pendant alone.

      I have been using the P1A pendant for nearly three years with Mach4. The original Mach4
      plugin released by VistaCNC was a touch buggy, many users of VistaCNC pendants
      that have an LCD screen were inclined to 'brick'. As my pendant does not have an
      LCD screen I did not have that problem. VistaCNC have released an updated Mach4
      plugin within the last couple of months. I would make sure you have it.

      One issue that I had was that when I turned my machine PC on I had to have the USB
      pendant connected or it would not subsequently be recognized by Mach. If I turned
      the PC on and THEN connected the pendant it would never be recognized by Mach until
      I power cycled.

      The last issue is that while there is a VistaCNC plugin, there is no diagnostic or
      plugin setting dialogue, at least with the original and early model plugin.
      As a consequence when a setting is made to Mach which affects the VistaCNC pendant
      like the MPG settings in Mach4 Control plugin page there is no means to flush
      those changes to the .ini file.

      May I suggest that if and when you make a change in Mach via the Control setting
      dialogue that might affect the pendant shut Mach down and restart. The shutdown
      will ensure that any changes you have made during the session get flushed to
      the .ini file.

 

 

 

 

 

The USB plugin for the WHB04B has caused this issues for several people running Mach3, most notably "Error reported by SS. Halting. Flags Register:80000049”

 

The key steps for getting this product to run better are:

 

1)      Make sure you are using their latest driver: http://www.cdxhctech.com/html/eProduct/view_363.html

  1. Click on English at the top of their page and then press the back button
  2. Click on the download button just underneath their picture of the WHB04B   it looks to be V3.84

2)      Make sure you don’t have any unneeded USB devices on your PC, other than your keyboard and mouse.  Make sure you don’t have any flash memory sticks in your PC since this was the root problem in half the cases.

3)      Adjust your PC’s Virtual Memory and restart: https://warp9td.com/index.php/faq/faq-windows#AdjustingVirtualMemory

4)      Run Mach3 at a higher priority level: https://warp9td.com/index.php/faq/faq-windows#HigherPriorityLevel

5)      Follow the recommendations in this article about how to optimize Mach3 and your PC: https://warp9td.com/index.php/faq/faq-mach3#RanOutOfData

 

In another case:

Thanks for help and ideas from Andy, I was able to delete all the HID controllers and let the machine reinitialize the Wireless controller as the first HID unit and it now works flawlessly.

It was a weird combination of using the Microsoft Surface Pro laptop which has MANY HID items already installed, such as the detachable Keyboard.

I uninstalled All, plugged in the wireless controller and it worked great.

 


 

How to wire a multi wire pendant.

This shows how to hook up and use a Pendant with a MPG (Manual Pulse Generator) and a SmoothStepper.

I bought my pendant off of eBay for $60, and it is identified as 5V-100PPR ELCG-03/L. This stands for:

  • 5V -> 5 Volts, which is perfect for the SmoothStepper (ESS or USS) and most BOBs (Break Out Boards).
  • 100PPR -> 100 Pulses Per Revolution of the big wheel, and this matches up with the numbers on the dial. If feels like there is a good solid detent click and hold with each individual turn/pulse of the dial and an audible click. However, unless I focus, I will typically move more than a single detent. This isn't a huge issue, but it happens.
  • ELCG-03/L Wow... Umm... Google couldn't find the datasheet (or the manufacture) so I can't tell you what that means.
  • Wire colors and chart.  Some pendants, actually come with a wiring color code chart, but even so, I have a hard time distinguishing between the faint wire colors.   Since there was no datasheet for this one, I had to open up the back of the pendant and use a multimeter to measure the resistance from one wire end to the other.  If yours does come with a chart, and you can read it, you can skip this step. Otherwise, use a multimeter and create a chart like this:

 

Pendant01WiringChart.png

 

Since I am using a BOB (Break Out Board) with no electronics, the ESS input resistors will be doing the pull down and pull up work instead.  The Bidirectional Input pins 2-9 have Pull Down resistors, so the pins will go LOW (0V) if nothing is driving them.  The Dedicated Input pins 10, 11, 12, 13 and 15 have Pull UP resistors, so the pins will go  HIGH (+5V) if nothing is driving them.

 

There are eight switch based inputs I need to wire to the SmoothStepper, and I will use the eight (very convenient) Pull Down inputs available on pins 2 through 9.

  • One of the Rate (or Multiplier) Switch positions (X1, X10 or X100) will always be active, and that active one will have the "Axis and Rate Common Signal (COM)" wire driving it.  The other two switch positions will be disconnected or floating (and the ESS pull down resistor will pull those signals low).  That means I want to hook the "Axis and Rate Common Signal (COM)" wire to +5V.
  • One of the Axis Switch positions (OFF, X, Y, Z or 4) will always be active, and that active one will have the "Axis and Rate Common Signal (COM)" wire driving it.  The other four switch positions will be disconnected or floating (and the ESS pull down resistor will pull those signals low).  That means I want to hook the "Axis and Rate Common Signal (COM)" wire to +5V.  (The "OFF" position has no wire, and in that position all of the others are disconnected from the +5V.
  • On the EStop switch there is a Common, which I will hook to 5V for the previously mentioned reason.  I will then use the EStop NC (Normally Closed) wire, since I should then get +5V all the time unless it is pressed (or power is lost) and then it will go to 0V. Since this is logically inverted from the other seven signals, I need to make it active low.

 

Regardless of the MPG's position, the MPG outputs "MPG A" and "MPG B" are actively driven high and low.  This means that we can wire them up to ANY ESS (or BOB) input pin (it doesn't matter if it is a pull up or a pull down).  This makes it an easy choice to use two of the available PULL UP Dedicated Inputs.

If my pendant had two more axis positions (5 and 6), I would need to hook them up to two of the available PULL UP Dedicated Inputs, and then use a 3 kOhm to 470 Ohm resistor tied to ground to make them pull down inputs.  Or I could use a BOB that would give me enough inputs (that it can actively drive to the SmoothStepper).

 

Here are the wires that I tied to 5V:

Pendant02WiringChart.png

 

I didn't need to use the MPG's inverted output signals "Not A" and "Not B", nor the EStop's NO (Normally Open) wire.

 Pendant03WiringChart.png

 

 


 

How to set up a multi wire pendant in Mach4.

To setup your motors, home switches or anything else please read our Getting Started Guide.  Here we are only going to setup the Pendant related pins and signals.

 

1. The following picture shows how to set up the Pendant's Pins, based upon the wiring chart I showed in the previous article.  I used Port 3 since most rigs don't have it in use to begin with.  Port 2 would work the exact same way other than moving up to Port 2 from Port 3.  You may change to other pins as you wish, but then you will need to modify the following steps and you will need to change the lua code accordingly.

 

Go to: "Menu -> Configure -> Plugins… -> ESS v... - Warp9 Tech Design, Inc"

 

Pendant04Pins.png

 

2. You may assign the Pendant "MPG A" and "MPG B" pins to any pair of Encoder inputs.  However:

  • Encoders 0 through 5 are ideally used with Motors 0 through 5, so I will avoid them.
  • Encoder Spindle should really be saved for the Spindle, so I will avoid it.
  • Encoder Aux 0 through 3 are the best choices, and I will chose 0. 

If you don't use Encoder Aux 0, you will need to chose differently than I did in"Mach4 MPGs" tab, in step 5.

 Pendant05EncoderInputs.png

 

3. You may assign the Pendant LED output to any Output number 0-63.  If you use a different one, you will need to change the lua code accordingly.

 Pendant06Outputs.png

 

4. You may assign the Switch Inputs to any Input number 0-63.  If you use different ones, you will need to change the lua code accordingly.

 

 Pendant07SwitchInputs.png

 

5. This is the completion of the MPGs setup in step 2. 

Go to: "Menu -> Configure -> Control…".  In the MPGs tab you can use any MPG that you wish!  However, I wanted it to match up with MPGs # 0-5 being reserved for motors 0-5, MPG #6 saved for the spindle, and that makes MPG #7 line up the best with Encoder Aux 0.  If you use different ones, you will need to change the lua code accordingly.

 

My pendant issues 4 counts per detent, so I set that here.  If you go to: "Menu -> Diagnostic-> Plugins… -> ESS v... - Warp9 Tech Design, Inc", and then watch the encoder value change when you move the wheel, you will easily see what the counts per detent value is.

 

 Pendant08MachMPG.png

 

6. Make sure all four of these plugins are active!

 Pendant09Plugins.png

 

 

7.  Make sure Mach4 is Disabled.  Then go to: "Menu -> Operator-> Edit Screen".

 Pendant10EditScreen.png

 

 

8.  Now we will edit the Screen Load Script by:

  • You may want to make a backup of your Screen Set, since there is no undo button or automatic backups!  "C:\Mach4Hobby\Screens\"
  • (Red Arrow) Click on your Screen Set name.
  • (Blue Arrow) Click on Lightning Bolt Icon.
  • (Green Arrow) Click on the Screen Load Script Cell, and then the three dots "..." will appear.
  • (Black Arrow) Click on the three dots to edit the screen load script.

 Pendant11ScreenLoadScript.png

 

 

 

9.  I found the basis for my lua code here, but I made MANY changes and improvements!

Here is my lua Pendant code for Mach4. Paste it in at the very bottom of the Screen Load Script.  If you made any changes, you will need to update those changes where noted!

 

 


---------------------------------------------------------------
-- 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_INPUT0] = function (state)   --If you are not using INPUT0 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_INPUT1] = function (state)   --If you are not using INPUT1 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_INPUT2] = function (state)   --If you are not using INPUT2 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_INPUT3] = function (state)   --If you are not using INPUT3 for the Axis Selection 4, change the INPUT#!!!!
        PendantAxisChange()                     --This is called if there is a change with the Pendant's Axis Selection Switch Posion 4
    end,
    [mc.ISIG_INPUT4] = function (state)   --If you are not using INPUT4 for the Axis Selection 5, change the INPUT#!!!!  
        PendantAxisChange()                     --This is called if there is a change with the Pendant's Axis Selection Switch Posion 5
    end,
    [mc.ISIG_INPUT5] = function (state)   --If you are not using INPUT5 for the Axis Selection 6, change the INPUT#!!!!
        PendantAxisChange()                     --This is called if there is a change with the Pendant's Axis Selection Switch Posion 6
    end,

-------------
    [mc.ISIG_INPUT6] = 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_INPUT7] = 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_INPUT8] = 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_INPUT9] = 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
}



--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 = 7

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)
local AxisNumber_UA = 3       -- Linear axis U or Rotational axis A
local AxisNumber_VB = 4       -- Linear axis V or Rotational axis B
local AxisNumber_WC = 5       -- Linear axis W or Rotational axis C
local AxisNumber_OB0 = 6       -- Out of Band axis 0 (NOT coordinated with motion)
local AxisNumber_OB1 = 7       -- Out of Band axis 1 (NOT coordinated with motion)
local AxisNumber_OB2 = 8       -- Out of Band axis 2 (NOT coordinated with motion)
local AxisNumber_OB3 = 9       -- Out of Band axis 3 (NOT coordinated with motion)
local AxisNumber_OB4 = 10        -- Out of Band axis 4 (NOT coordinated with motion)
local AxisNumber_OB5= 11       -- Out of Band axis 5 (NOT coordinated with motion)

--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_INPUT6)       --If you are not using INPUT6 for theX1 Selection, change the INPUT#!!!!
    Step1, rc = mc.mcSignalGetState(hX1)
   
    hX10, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT7)       --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_INPUT8)       --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 = "Pendant Distance X1 = " .. PendantDistanceX1
        mc.mcCntlSetLastError(inst, msg)  --Show a message in the Screen Set

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

    elseif (Step100 == 1) then
        mc.mcMpgSetInc(inst, MachMpgNumberForPendant, PendantDistanceX100)
        msg = "Pendant 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
-- Chose one of these for position 4 ( and another for 5 and 6 if applicable)
    local hAxis_UA  --Use this with a 4, 5 or 6 axis pendant
    local hAxis_VB  --Use this with a 4, 5 or 6 axis pendant
    local hAxis_WC  --Use this with a 4, 5 or 6 axis pendant  
    local hAxis_OB0  --Use this with a 4, 5 or 6 axis pendant
    local hAxis_OB1  --Use this with a 4, 5 or 6 axis pendant
    local hAxis_OB2  --Use this with a 4, 5 or 6 axis pendant
    local hAxis_OB3  --Use this with a 4, 5 or 6 axis pendant
    local hAxis_OB4  --Use this with a 4, 5 or 6 axis pendant
    local hAxis_OB5  --Use this with a 4, 5 or 6 axis pendant

    --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
-- Chose one of these for position 4 ( and another for 5 and 6 if applicable)  
    local SelectAxis_UA  --Use this with a 4, 5 or 6 axis pendant
    local SelectAxis_VB  --Use this with a 4, 5 or 6 axis pendant
    local SelectAxis_WC  --Use this with a 4, 5 or 6 axis pendant
    local SelectAxis_OB0  --Use this with a 4, 5 or 6 axis pendant
    local SelectAxis_OB1  --Use this with a 4, 5 or 6 axis pendant
    local SelectAxis_OB2  --Use this with a 4, 5 or 6 axis pendant
    local SelectAxis_OB3  --Use this with a 4, 5 or 6 axis pendant
    local SelectAxis_OB4  --Use this with a 4, 5 or 6 axis pendant
    local SelectAxis_OB5  --Use this with a 4, 5 or 6 axis pendant
   
    hAxis_X, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT0)   --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_INPUT1)   --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_INPUT2)   --If you are not using INPUT2 for the Axis Selection Switch Z, change the INPUT#!!!!
    SelectAxis_Z, rc = mc.mcSignalGetState(hAxis_Z)

--   Use this with a 4, 5 or 6 axis pendant  RESERVED - NOT CURRENTLY IN USE   
--   hAxis_UA, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT3)   --If you are not using INPUT3 for the Axis Selection Switch 4, change the INPUT#!!!!
--   SelectAxis_UA, rc = mc.mcSignalGetState(hAxis_UA)
   
--   Use this with a 4, 5 or 6 axis pendant  RESERVED - NOT CURRENTLY IN USE
--   hAxis_VB, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT4)   --If you are not using INPUT4 for the Axis Selection Switch 5, change the INPUT#!!!!
--   SelectAxis_VB, rc = mc.mcSignalGetState(hAxis_VB)
       
--   Use this with a 4, 5 or 6 axis pendant  RESERVED - NOT CURRENTLY IN USE
--   hAxis_WC, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT5)   --If you are not using INPUT5 for the Axis Selection Switch 6, change the INPUT#!!!!
--   SelectAxis_WC, rc = mc.mcSignalGetState(hAxis_WC)
   
--   Use this with a 4, 5 or 6 axis pendant  RESERVED - NOT CURRENTLY IN USE
--   hAxis_OB0, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT5)   --If you are not using INPUT5 for the Selection Switch 6, change the INPUT#!!!!
--   SelectAxis_OB0, rc = mc.mcSignalGetState(hAxis_OB0)

--   Use this with a 4, 5 or 6 axis pendant  RESERVED - NOT CURRENTLY IN USE
--   hAxis_OB1, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT5)   --If you are not using INPUT5 for the Axis Selection Switch 6, change the INPUT#!!!!
--   SelectAxis_OB1, rc = mc.mcSignalGetState(hAxis_OB1)

--   Use this with a 4, 5 or 6 axis pendant  RESERVED - NOT CURRENTLY IN USE
--   hAxis_OB2, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT5)   --If you are not using INPUT5 for the Axis Selection Switch 6, change the INPUT#!!!!
--   SelectAxis_OB2, rc = mc.mcSignalGetState(hAxis_OB2)

--   Use this with a 4, 5 or 6 axis pendant  RESERVED - NOT CURRENTLY IN USE
--   hAxis_OB3, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT5)   --If you are not using INPUT5 for the Axis Selection Switch 6, change the INPUT#!!!!
--   SelectAxis_OB3, rc = mc.mcSignalGetState(hAxis_OB3)

--   Use this with a 4, 5 or 6 axis pendant  RESERVED - NOT CURRENTLY IN USE
--   hAxis_OB4, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT5)   --If you are not using INPUT5 for the Axis Selection Switch 6, change the INPUT#!!!!
--   SelectAxis_OB4, rc = mc.mcSignalGetState(hAxis_OB4)

--I AM USING THIS ONE with Axis Selection Switch 4 to move axis OB5
--   Use this with a 4, 5 or 6 axis pendant  RESERVED - NOT CURRENTLY IN USE
   hAxis_OB5, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT3)   --If you are not using INPUT3 for the Axis Selection Switch 4, change the INPUT#!!!!
   SelectAxis_OB5, rc = mc.mcSignalGetState(hAxis_OB5)



    --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, "Pendant Axis X 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, "Pendant Axis Y 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, "Pendant Axis Z Selected")  --Show a message in the Screen Set
        mc.mcSignalSetState(hLedForActivePendantAxis, 1)       --Turn the Pendant's LED ON to show an axis is active

--Not all of these remaining elseif's will be used in your setup, but it is okay to leave them active.
    elseif (SelectAxis_UA== 1) then
        mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, AxisNumber_UA)    --Map the MPG to control the U/A Axis
        mc.mcCntlSetLastError(inst, "Pendant Axis U/A 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_VB== 1) then
       mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, AxisNumber_VB)     --Map the MPG to control the V/B Axis
       mc.mcCntlSetLastError(inst, "Pendant Axis V/B 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_WC== 1) then
        mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, AxisNumber_WC)    --Map the MPG to control the W/C Axis
        mc.mcCntlSetLastError(inst, "Pendant Axis W/C 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_OB0== 1) then
        mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, AxisNumber_OB0)    --Map the MPG to control the OB0 Axis
        mc.mcCntlSetLastError(inst, "Pendant Axis OB0 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_OB1== 1) then
        mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, AxisNumber_OB1)    --Map the MPG to control the OB1 Axis
        mc.mcCntlSetLastError(inst, "Pendant Axis OB1 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_OB2== 1) then
        mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, AxisNumber_OB2)    --Map the MPG to control the OB2 Axis
        mc.mcCntlSetLastError(inst, "Pendant Axis OB2 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_OB3== 1) then
        mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, AxisNumber_OB3)    --Map the MPG to control the OB3 Axis
        mc.mcCntlSetLastError(inst, "Pendant Axis OB3 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_OB4== 1) then
        mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, AxisNumber_OB4)    --Map the MPG to control the OB4 Axis
        mc.mcCntlSetLastError(inst, "Pendant Axis OB4 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_OB5== 1) then
        mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, AxisNumber_OB5)    --Map the MPG to control the OB5 Axis
        mc.mcCntlSetLastError(inst, "Pendant Axis OB5 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()


 

 

 

10. Once you have that pasted, Compile the lua code to make sure that there are no errors, Save the code, and then close the ZeroBrane editor.

 

11.  Just like in Step 6, go to: "Menu -> Operator-> Edit Screen", but this time UN-check "Edit Screen".  When asked if you want to save, click yes.

 

12. Your MPG should now move your axes!

Go to top