Hello Guest it is April 25, 2024, 11:51:02 AM

Author Topic: Jogging/Pendant Interface-What is the best way? Ramblings  (Read 39812 times)

0 Members and 1 Guest are viewing this topic.

Offline TimGS

*
  •  108 108
    • View Profile
Re: Jogging/Pendant Interface-What is the best way? Ramblings
« Reply #50 on: May 28, 2015, 09:35:42 PM »
I did some more rigorous testing tonight and
found that the <Cycle Jog Inc> controls the Jog Increment for the A+, A-...Jog buttons and must somehow keep store and not use mc.mcGetJogInc variable even though the display does track it.

When the Mach4 "Jogging" display <Cycle Jog Inc> button is used to control the Jog increment, the "Jogging" Mach display buttons and the "Jogging Inputs" controlled by the physical switches increment based upon the display.

If I use the physical Jog Increment Switch to control the increment, the Mach 4 display shows the correct setting and the "Jogging Inputs" controlled by the physical switches increment accordingly but the "Jogging" Mach display buttons increment according to the previous setting controlled by the Mach4 <Cycle Jog Inc> button.   :-\ Bummer  Anyone have any ideas ???



The following is code to date:

Code: [Select]
--Start of Signals

--Set Defaults
--Set Default MPG Axis
    local inst = mc.mcGetInstance();
--Should put these values elsewhere in register or machine.ini
    mc.mcMpgSetAxis(inst, 0, mc.B_AXIS);-- Default Axis; B_Axis not used my configuration
    mc.mcCntlSetLastError(inst, 'MPG Set to Unused Axis');
    mc.mcMpgSetAccel(inst, 0, 100); --25 for servos to 100 for steppers
    mc.mcMpgSetRate(inst, 0, 100);
    mc.mcMpgSetCountsPerDetent(inst, 0, 4);           
--Set Default Jog Increment
    local JogIncrement = 1.0000; -- Default JogIncrement
    mc.mcJogSetInc(inst, mc.X_AXIS, JogIncrement);
    mc.mcJogSetInc(inst, mc.Y_AXIS, JogIncrement);
    mc.mcJogSetInc(inst, mc.Z_AXIS, JogIncrement);
    mc.mcJogSetInc(inst, mc.A_AXIS, JogIncrement);
    mc.mcCntlSetLastError(0, 'JogIncrement = '.. tostring(JogIncrement) .. ' for all Axis');

SignalTable = {
    [mc.ISIG_INPUT0] = function (on_off)--ESS Port 1 pin 15
        local inst = mc.mcGetInstance();
        if( on_off==1 ) then
            -- On
            mc.mcCntlEnable(inst, true);
            mc.mcCntlSetLastError(inst, 'Machine Enabled via switch');

        else
            -- Off
            mc.mcCntlEnable(inst, false);
            mc.mcCntlSetLastError(inst, 'Machine Disabled via switch');
        end
    end,
    [mc.ISIG_INPUT1] = function (on_off)--ESS Port 2 pin 15
        --This works; you can get it out of sync with the display
        --if you push the screen <jog mode> [tri-state] button but goes back in sync
        --when you push the physical [bi-state] button 
        local inst = mc.mcGetInstance();
        local jogRate
        local hsig1 = mc.mcSignalGetHandle(inst, mc.OSIG_JOG_INC)
        local hsig2 = mc.mcSignalGetHandle(inst, mc.OSIG_JOG_CONT)
        mc.mcJogGetRate(inst, mc.X_AXIS, jogRate);
        if( on_off==1 ) then
            -- Jog Increment
            mc.mcJogSetType(inst, mc.X_AXIS, mc.MC_JOG_TYPE_INC);
            mc.mcJogSetType(inst, mc.Y_AXIS, mc.MC_JOG_TYPE_INC);
            mc.mcJogSetType(inst, mc.Z_AXIS, mc.MC_JOG_TYPE_INC);
            mc.mcJogSetType(inst, mc.A_AXIS, mc.MC_JOG_TYPE_INC);
            --Update Jog Display Tab LEDs
            mc.mcSignalSetState(hsig1, 1)--Real LED mapped to Jog Inc in MACH 4 Config
            mc.mcSignalSetState(hsig2, 0)
        else
            -- Jog Continuous
            mc.mcJogSetType(inst, mc.X_AXIS, mc.MC_JOG_TYPE_VEL,jogRate);
            mc.mcJogSetType(inst, mc.Y_AXIS, mc.MC_JOG_TYPE_VEL,jogRate);
            mc.mcJogSetType(inst, mc.Z_AXIS, mc.MC_JOG_TYPE_VEL,jogRate);
            mc.mcJogSetType(inst, mc.A_AXIS, mc.MC_JOG_TYPE_VEL,jogRate);
            --Update Jog Display Tab LEDs
            mc.mcSignalSetState(hsig1, 0) --Real LED mapped to Jog Inc in MACH 4 Config
            mc.mcSignalSetState(hsig2, 1)
        end
    end,
--[[
The following inputs are mapped through the Ethernet Smooth Stepper to a rotary switch
that closes one pair of 4 pairs of contacts at a time. The first position has no contacts.
The movement is limited to 5 positions in the following order starting at the CCW most position
"NONE"CW->"INPUT3"CW->"INPUT4"CW->"INPUT5"CW->"INPUT6"CCW->"INPUT5"CCW->"INPUT4"CCW->"INPUT3"CCW->"NONE"
representing MPG Axis Control where NONE=B_AXIS, Input3=X_AXIS, Input4=Y_AXIS, Input5=Z_AXIS
and Input6=A_AXIS
Note 1: I chose B_AXIS as a NONE or MPG OFF because I don't have one and the call requires a non NIL input.
Note 2:  The order of processing is important.  Signals are processed in order from the top down.
]]--


    [mc.ISIG_INPUT3] = function (on_off)--ESS Port 3 pin 2
        local inst = mc.mcGetInstance();
        local MPGAxisEnabled = mc.mcMpgGetAxis(inst, 0); --Get ID of Last Axis MPG Mapped to
        if( on_off==1 ) then
            -- X AXIS Enabled
            mc.mcMpgSetAxis(inst, 0, mc.X_AXIS);
            mc.mcCntlSetLastError(inst, 'Axis = '..tostring(MPGAxisEnabled)..' No Longer Mapped to MPG');            MPGAxisEnabled = mc.mcMpgGetAxis (inst , 0);
            MPGAxisEnabled = mc.mcMpgGetAxis (inst , 0);
            mc.mcCntlSetLastError(inst, 'MPG Mapped to X Axis = ' .. tostring(MPGAxisEnabled));
        else
            --MPG Disabled
            --Next if Only true during switch transition from "Input3"->"NONE"
            --and briefly during transition from "Input3"->"Input4"; Doesn't really matter
            mc.mcCntlSetLastError(inst, 'MPG ENABLE X_Axis; Input3 = 0');
            if(MPGAxisEnabled == mc.X_AXIS) then
                -- Setting to unused B Axis
                mc.mcMpgSetAxis(inst, 0, mc.B_AXIS);
                mc.mcCntlSetLastError(inst, 'Axis = '..tostring(MPGAxisEnabled)..' No Longer Mapped to MPG');            local Counts = mc.mcMpgGetCountsPerDetent (inst , 0);
                MPGAxisEnabled = mc.mcMpgGetAxis (inst , 0);
                mc.mcCntlSetLastError(inst, 'MPG Mapped to B Axis = ' .. tostring(MPGAxisEnabled));
                mc.mcCntlSetLastError(inst, '...MPG Turned OFF');
            end
        end
    end,
    [mc.ISIG_INPUT4] = function (on_off)--ESS Port 3 pin 3
        local inst = mc.mcGetInstance();
        local MPGAxisEnabled = mc.mcMpgGetAxis(inst, 0); --Get ID of Last Axis MPG Mapped to
        if( on_off==1 ) then
            -- Y AXIS Enabled
            mc.mcMpgSetAxis(inst, 0, mc.Y_AXIS);
            mc.mcCntlSetLastError(inst, 'Axis = '..tostring(MPGAxisEnabled)..' No Longer Mapped to MPG');            local Counts = mc.mcMpgGetCountsPerDetent (inst , 0);
            MPGAxisEnabled = mc.mcMpgGetAxis (inst , 0);
            mc.mcCntlSetLastError(inst, 'MPG Set to Y Axis = ' .. tostring(MPGAxisEnabled));
        else
            -- No Need to do anything
            mc.mcCntlSetLastError(inst, 'MPG ENABLE Y_Axis; Input4 = 0');
        end
    end,
    [mc.ISIG_INPUT5] = function (on_off)--ESS Port 3 pin 4
        local inst = mc.mcGetInstance();
        local MPGAxisEnabled = mc.mcMpgGetAxis(inst, 0); --Get ID of Last Axis Mapped to MPG
        if( on_off==1 ) then
            -- Z AXIS Enabled           
            mc.mcMpgSetAxis(inst, 0, mc.Z_AXIS);
            mc.mcCntlSetLastError(inst, 'Axis = '..tostring(MPGAxisEnabled)..' No Longer Mapped to MPG');
            MPGAxisEnabled = mc.mcMpgGetAxis (inst, 0);
            mc.mcCntlSetLastError(inst, 'MPG Mapped to Z Axis = ' .. tostring(MPGAxisEnabled));
        else
            -- No Need to do anything
            mc.mcCntlSetLastError(inst, 'Z_Axis; Input5 = 0');
        end
    end,
    [mc.ISIG_INPUT6] = function (on_off)--ESS Port 3 pin 5
        local inst = mc.mcGetInstance();
        local MPGAxisEnabled = mc.mcMpgGetAxis(inst, 0); --Get ID of Last Axis Mapped to MPG
       if( on_off==1 ) then
            -- A AXIS Enabled           
            mc.mcMpgSetAxis(inst, 0, mc.A_AXIS);
            mc.mcCntlSetLastError(inst, 'Axis = '..tostring(MPGAxisEnabled)..' No Longer Mapped to MPG');
            MPGAxisEnabled = mc.mcMpgGetAxis (inst , 0);
            mc.mcCntlSetLastError(inst, 'MPG Set to A Axis = ' .. tostring(MPGAxisEnabled));
        else
            -- No Need to do anything
            mc.mcCntlSetLastError(inst, 'A_Axis; Input6 = 0');
        end
    end,

--[[
The following inputs are mapped through the Ethernet Smooth Stepper to a rotary switch that closes
one pair of 4 pairs of contacts at a time. The first position has no contacts. The movement is
limited to 5 positions in the following order starting at the CCW most position
"NONE"CW->"INPUT7"CW->"INPUT8"CW->"INPUT9"CW->"INPUT10"CCW->"INPUT9"CCW->"INPUT8"CCW->"INPUT7"CCW->"NONE"
representing Increments NONE=1.0, Input7=0.1, Input8=0.01, Input9=.001 and Input10=.0001
Note:  The order of processing is important.  Signals are processed in order from the top down.]]--

    [mc.ISIG_INPUT7] = function (on_off)--ESS Port 3 pin 6
        local inst = mc.mcGetInstance();
        if( on_off==1 ) then
            mc.mcCntlSetLastError(0, 'JogIncrement was = '.. tostring(JogIncrement));
            JogIncrement = 0.1;
            mc.mcJogSetInc(inst, mc.X_AXIS, JogIncrement);
            --Why use the X AXIS? Because it matches the screen
            --Mach4 Display Jog Tab INC number seems to track X_Axis Increment Setting
            --Note Each axis jog increment can be set independently
            mc.mcJogSetInc(inst, mc.Y_AXIS, JogIncrement);
            mc.mcJogSetInc(inst, mc.Z_AXIS, JogIncrement);
            mc.mcJogSetInc(inst, mc.A_AXIS, JogIncrement);
            JogIncrement = mc.mcJogGetInc(inst, mc.X_AXIS);
mc.mcCntlSetLastError(0, 'JogIncrement is now = '.. tostring(JogIncrement));
        else
            mc.mcCntlSetLastError(inst, 'IncDot1; Input10 = 0');
            -- JogIncrement Set to 1.0000
            --Next if Only true during switch transition from "Input7"->"NONE"
            --and briefly between transition from "Input7"CW->"Input8"
            if(JogIncrement == 0.1)then
                mc.mcCntlSetLastError(0, 'JogIncrement was = '.. tostring(JogIncrement));
                JogIncrement = 1.0000;
                mc.mcJogSetInc(inst, mc.X_AXIS, JogIncrement);
                mc.mcJogSetInc(inst, mc.Y_AXIS, JogIncrement);
                mc.mcJogSetInc(inst, mc.Z_AXIS, JogIncrement);
                mc.mcJogSetInc(inst, mc.A_AXIS, JogIncrement);
                mc.mcCntlSetLastError(0, 'JogIncrement is now = '.. tostring(JogIncrement));
            end
        end
    end,
    [mc.ISIG_INPUT8] = function (on_off)--ESS Port 3 pin 7
        local inst = mc.mcGetInstance();
        if( on_off==1 ) then
            mc.mcCntlSetLastError(0, 'JogIncrement was = '.. tostring(JogIncrement));
            JogIncrement = 0.01;
            mc.mcJogSetInc(inst, mc.X_AXIS, JogIncrement);
            --M4 Display Jog Tab INC number seems to track X_Axis Increment Setting
            --Note Each axis jog increment can be set independently
            mc.mcJogSetInc(inst, mc.Y_AXIS, JogIncrement);
            mc.mcJogSetInc(inst, mc.Z_AXIS, JogIncrement);
            mc.mcJogSetInc(inst, mc.A_AXIS, JogIncrement);
            mc.mcCntlSetLastError(0, 'JogIncrement is now = '.. tostring(JogIncrement));
        else
            -- No Need to do anything
            mc.mcCntlSetLastError(inst, 'IncDot01; Input8 = 0');
        end
    end,
    [mc.ISIG_INPUT9] = function (on_off)--ESS Port 3 pin 8
        local inst = mc.mcGetInstance();
        if( on_off==1 ) then
            mc.mcCntlSetLastError(0, 'JogIncrement was = '.. tostring(JogIncrement));
            JogIncrement = 0.001;
            mc.mcJogSetInc(inst, mc.X_AXIS, JogIncrement);
            --M4 Display Jog Tab INC number seems to track X_Axis Increment Setting
            --Note Each axis jog increment can be set independently
            mc.mcJogSetInc(inst, mc.Y_AXIS, JogIncrement);
            mc.mcJogSetInc(inst, mc.Z_AXIS, JogIncrement);
            mc.mcJogSetInc(inst, mc.A_AXIS, JogIncrement);
            mc.mcCntlSetLastError(0, 'JogIncrement is now = '.. tostring(JogIncrement));
        else
            -- No Need to do anything
            mc.mcCntlSetLastError(inst, 'IncDot001; Input9 = 0');
        end
    end,
    [mc.ISIG_INPUT10] = function (on_off)--ESS Port 3 pin 9
        local inst = mc.mcGetInstance();
        if( on_off==1 ) then
            mc.mcCntlSetLastError(0, 'JogIncrement was = '.. tostring(JogIncrement));
            JogIncrement = 0.0001;
            mc.mcJogSetInc(inst, mc.X_AXIS, JogIncrement);
            --Display INC number seems to track X_Axis setting though INC setting can be set for each Axis
            mc.mcJogSetInc(inst, mc.Y_AXIS, JogIncrement);
            mc.mcJogSetInc(inst, mc.Z_AXIS, JogIncrement);
            mc.mcJogSetInc(inst, mc.A_AXIS, JogIncrement);
            mc.mcCntlSetLastError(0, 'JogIncrement = '.. tostring(JogIncrement));
        else
            -- No Need to do anything
            mc.mcCntlSetLastError(inst, 'IncDot0001; Input10 = 0');
        end
    end
}
--I left off the Signal Table, too long for the posting
« Last Edit: May 28, 2015, 09:39:10 PM by TimGS »

Offline TimGS

*
  •  108 108
    • View Profile
Re: Jogging/Pendant Interface-What is the best way? Ramblings
« Reply #51 on: May 28, 2015, 10:02:18 PM »
I reloaded tonight a cleared my <Enable/Disable> switch not updating the state of the Mach 4 Display <Enable/Disable> button.  The Mach 4 Display <Enable/Disable> button tracks the switch and both the switch and the Mach 4 Display <Enable/Disable> button control the Enabled indicator (LED).  Since the switch is a latching type, if I use the Mach 4 Display <Enable/Disable> button to control the Machine Enabled state, one push of the button changes nothing and resynchronizes both.
Re: Jogging/Pendant Interface-What is the best way? Ramblings
« Reply #52 on: May 29, 2015, 05:03:05 AM »
Now that took some time! Congrats Tim. You are almost there! Best guess to deconflict actions....

Event signals are mapped to a table reference of functions by input name in the PLC that execute would GUI type scr. calls to change the property values of that button/display to reflect your input. Considering your GUI environment matches your physical hardware binary/latching/electrical characteristics and vice versa.

GUI actions are mapped to executable functions within the PLC. Not hardware actions to GUI or GUI to hardware. The PLC is your interface.
That may take care of some syncing issues but the real issue as Simpson36 states is resolution of resource conflict. You may be using inputs from both
the MPG and the GUI to the exact same memory space resulting in syncing issues again, latency, or worse freeze-up. But shoot, I'm just a newbie trying to code auto tool zero without using G31. You guys are on like expert level.

Offline simpson36

*
  •  1,369 1,369
    • View Profile
Re: Jogging/Pendant Interface-What is the best way? Ramblings
« Reply #53 on: May 29, 2015, 06:39:51 AM »
"If I use the physical Jog Increment Switch to control the increment, the Mach 4 display shows the correct setting and the "Jogging Inputs" controlled by the physical switches increment accordingly but the "Jogging" Mach display buttons increment according to the previous setting controlled by the Mach4 <Cycle Jog Inc> button.   Undecided Bummer  Anyone have any ideas "

My joystick uses only Jog functions and not MPG functions, so there is probably no parallel between our interfaces. My challenges were in keeping the environment separated between the screen jogging buttons and the joystick. For example the joystick would stop jogging movement if it was centered (not calling for movement) and this would also shut off the button jogging. The joystick changes the jog rate, so it was always left at zero, which is appropriate for the stick, but then the jog buttons would not work. And so on, and so on . . .

MPG is, at least in part, a separate environment, so there is less 'racing'.

Speculation on your issues;  The on-screen Jog increment button and DRO seem to be reporting the current system setting, however, a single jog increment setting would logically be either a separate, undocumented variable, or it sets each axis to the same jog increment. Each axis can have its own setting, so there is going to be a disconnect between the single button and the potential multiple rates. For example, if all axis are not at the same setting, and the on-screen single button/DRO can only display one setting, which axis is it reporting?

As far as I know, there is no function to set ALL axis at once, so you might try setting ALL axis one at a time to the same inc, including your unused axis B and C. Theoretically, this would resolve any confusion in the reading of the current inc by the system 'action' Toggle Inc (or whatever it is called).

Whatever the behavior is, it would likely also apply to jog rate, or any other 'one button, multiple settings' condition.

The odd enable/disable behavior is probably being caused by errors in the original PLC code provided by Newfangled Solutions.

Since I am not using the MPG functions, this is about all the help I can offer.

Good luck with your project and thanks for sharing!

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: Jogging/Pendant Interface-What is the best way? Ramblings
« Reply #54 on: May 29, 2015, 07:25:57 AM »
when you are testing in the screen have the log running it shows what happening to what ever it is you are doing its one way to debug you can have something run fine in editor but not do anything on screen if nothing shows up on the log nothing is getting through or if something is coming up on the history and its a bad thing the problem can show up in the logging.

also if you have values set in the regfile and you don't think they are working get popabears, DebugVarValueTest or use this in the screen load script

function GetRegister(regname)
local inst = mc.mcGetInstance()
local hreg = mc.mcRegGetHandle(inst, string.format("iRegs0/%s", regname))
return mc.mcRegGetValueString(hreg)
end

and have a button on screen with this in it you just change "Test1" to your reg name it works fine to test any reg you have added to the regfile

regval = GetRegister("Test1")
wx.wxMessageBox(regval)

Offline simpson36

*
  •  1,369 1,369
    • View Profile
Re: Jogging/Pendant Interface-What is the best way? Ramblings
« Reply #55 on: May 29, 2015, 07:42:28 AM »

 - or -

use the built in register diagnostics window in which you can view  . . and change . .  any register  . . . . in real time . . .  ;)

Offline TimGS

*
  •  108 108
    • View Profile
Re: Jogging/Pendant Interface-What is the best way? Ramblings
« Reply #56 on: May 29, 2015, 08:55:47 AM »
I am going to put off using registers for the moment.  The code that I posted does not use them.

The <Enable/Disable> Button on the Mach 4 Screen and the Physical <Enable/Disable> Switch/LED work as expected and work just fine.

Thank You ALL

20,000 Axes...I will look into the PLC...that sounds like a viable lead.

The goal is to keep the my Jogging/MPG/switch settings in sync with the existing display for the most part.  SW can't move a switch :D ...without a firmware interface.  What I did not want was to create a situation where I thought that a control was set for one setting and find out it was set for another...very dangerous.  (e.g. Intending to move .01 inches and the actual setting was 1 inch...ouch)

After I get the controls working it would be cool to make my own tab with visual controls that look like the HW controls.

Daniellyall and Simpson36  ... I will look deeper into the debug capabilities....currently just using entries into the history log.

Re: Jogging/Pendant Interface-What is the best way? Ramblings
« Reply #57 on: May 29, 2015, 03:44:29 PM »
Tim, if you are still having syncing problems look at the mc.Motion functions in Mach4.api for direct control over the motion controller ie. mc.mcMotionSync(inst).

Just a thought. Haven't played with it yet.

-josh

Offline TimGS

*
  •  108 108
    • View Profile
Re: Jogging/Pendant Interface-What is the best way? Ramblings
« Reply #58 on: May 29, 2015, 03:57:54 PM »
Thank You for your help... I never looked at that API...it was worth looking at...

The sync problem is between my <1.0, 0.1, 0.01, 0.001, 0.0001> Jog Cycle Inc switch and the Mach 4 Jog Display <Jog Cycle Inc> button; not the position of a motor.

Offline simpson36

*
  •  1,369 1,369
    • View Profile
Re: Jogging/Pendant Interface-What is the best way? Ramblings
« Reply #59 on: May 29, 2015, 05:58:39 PM »
Tim,

I'm sure I would get arguments over this statement, but Lua is a dream compared to MACH3's implementation of VB script.

To resolve your jog increment issue, a good approach would be to use the Lua editor to change all of the axis increments to say 1 and then then change them one at a time while watching the On Screen Increment dro (assuming it is real time) and you will then know what is being read.

This method will answer an important question for you and also give you a tiny taste of what working with Lua is like. The editor has step by step debugging so you can cut and paste the  'Set' functions 6 times and then just change the axis numbers and step down thru one at a time.

Notes: choose 'debug' from the drop down and step thru using the F11 key. Remember to 'stop debugging' before you try to edit again.

The Lua editor will give you a rather vague error message if you try to do the debugging without first saving the file. There is some trick (you can search  it out if you are curious) that you can add to the bottom of the script that tells Lua that the script you want to run is actually IN the editor and (as if it should not already know that) and then it will run the script. However, simply saving the file first accomplished the same thing and ALSO protects you against the Lua editor locking up and loosing the script . . . because it was never saved.  And the Lua editor locks up . . a lot . . . . in my opinion