Hello Guest it is April 24, 2024, 04:33:28 AM

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - beezerlm

Pages: « 1 2 3 4 5 6 »
31
Mach4 General Discussion / Re: Macro - Pause until input triggered
« on: September 27, 2016, 02:36:03 PM »
Well a gave it a go as and I get a lua error in the macro "Error while running chunk"  it doesn't seem to want to run my function (GrindCycle) in the Screenload script from within the Macro(M100)?

Here is what I have now:

Add to the ScreenLoad script:

Code: [Select]

--My GrindCycle function starts here:
   
function GrindCycle()

    local inst = mc.mcGetInstance()
    local input_20 = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT20) -- Get handle for input 20
    local input_20_State = mc.mcSignalGetState(input_20) -- Get input 20 state
   
    if input_20 == 0 then
        wx.wxMessageBox("Could not locate signal!")

    else

        if input_20_State == 1 then --If input_20_State equals 1, then grind cycle active signal is High.
            wx.wxMessageBox("Signal is already active!")

        else    --If input_20_State does not equal 1, then the grind cycle signal is inactive.
            mc.mcSignalSetState(input_20, 1) -- set grind cycle signal active
            mc.mcSignalWait(inst, z_home_sig, WAIT_MODE_HIGH, 20) -- wait for z to get home
            coroutine.yield () --yield coroutine so we can do the following after motion stops
            wx.wxMessageBox("Grind Cycle Complete")
        end
    end
end

--My GrindCycle function ends here:


In the M100 macro:

Code: [Select]

function M100()
    wait = coroutine.create (GrindCycle) --Run the GrindCycle function as a coroutine named wait.
end

if (mc.mcInEditor() == 1) then
    M100()
end


Added to the PLC script:

Code: [Select]

-------------------------------------------------------
--  Coroutine resume
-------------------------------------------------------
if (wait ~= nil) and (machState == 0) then --wait exist and state == idle
local state = coroutine.status(wait) --Get the status of the coroutine named wait
    if state == "suspended" then --Coroutine named wait is suspended
        coroutine.resume(wait) --Resume coroutine named wait
    end
end



32
Mach4 General Discussion / Re: Macro - Pause until input triggered
« on: September 27, 2016, 11:59:15 AM »
Hmmm....I changed the signal to "mc.ISIG_MOTOR3_HOME"  which is mapped to the Z axis home switch and it still just moves on to the next line in the main G-code program?



Code: [Select]

function M100()
    
    local inst = mc.mcGetInstance()
    local input_20 = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT20) -- Get handle for input 20
    local input_20_State = mc.mcSignalGetState(input_20) -- Get input 20 state
    local z_home_sig = mc.ISIG_MOTOR3_HOME -- Get signal for Z axis home switch
  


    if input_20 == 0 then
        wx.wxMessageBox("Could not locate signal!")

    else

        if input_20_State == 1 then        
            wx.wxMessageBox("Signal is already active!")

        else    --If input_20_State does not equal 1, then the signal is inactive.
          
            mc.mcSignalSetState(input_20, 1)
            mc.mcSignalWait(inst, z_home_sig, WAIT_MODE_HIGH, 20)    
        end
    end
end

if (mc.mcInEditor() == 1) then
    M100()
end


33
Mach4 General Discussion / Re: Macro - Pause until input triggered
« on: September 27, 2016, 11:09:54 AM »
Thanks.  I gave it a try by adding it to the end of the macro.  For some reason it does not wait for the "Z home" signal before moving on to the next line of the Gcode program ( a G0 X/Y axis positioning move ).   I also tried WAIT_MODE_LOW and it did the same thing.  I was hoping the machine would stop all movement until the Z axis reached the home position. Any Ideas what I am doing wrong?

Code: [Select]
function M100()
   
    local inst = mc.mcGetInstance()
    local input_20 = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT20) -- Get handle for input 20
    local input_20_State = mc.mcSignalGetState(input_20) -- Get input 20 state
    local z_home_sig = mc.mcSignalGetHandle(inst, mc.OSIG_ZHOME) -- Get handle for Z axis home switch
   

    if input_20 == 0 then
        wx.wxMessageBox("Could not locate signal!")

    else

        if input_20_State == 1 then                   --If input_20_State equals 1, then the signal is active.
            wx.wxMessageBox("Signal is already active!")

        else                                                   --If input_20_State does not equal 1, then the signal is inactive.

            mc.mcSignalSetState(input_20, 1)
            mc.mcSignalWait(inst, z_home_sig, WAIT_MODE_HIGH, 20)   

        end
    end
end

if (mc.mcInEditor() == 1) then
    M100()
end


34
Mach4 General Discussion / Macro - Pause until input triggered
« on: September 26, 2016, 08:14:44 PM »
Is there a simple way to pause motion until an input is triggered within a macro? 

I would like to ensure my Z axis returns home before the macro ends because after the macro would be an X-Y move. This is a cylinder where I have output 1 activate the "up" direction and output 0 activate the "down" direction. 

Something like this:

1. activate output_1 (up)
2. wait for Z home switch to trigger
3. end macro.

What is the best way to code step 2 (wait for input) in a Macro?

35
Mach4 General Discussion / Re: PLC Script troubleshooting
« on: September 13, 2016, 09:21:48 AM »
Screenshot is attached.

36
Mach4 General Discussion / Re: PLC Script troubleshooting
« on: September 12, 2016, 11:34:17 AM »
I just did some more testing,  this time the upper stroke limit was 3.000" and the lower limit was 1.000" so all numbers were positive.  I also set the feed rate to a very slow speed.  I still had a bad encoder number of about -12,000.  For some reason it always seems to be an encoder reading between -10,000 and -20,000 even if all numbers are in the positive range .  That would also explain why it only happens on the downstroke.

37
Mach4 General Discussion / Re: PLC Script troubleshooting
« on: September 12, 2016, 09:56:13 AM »
I added the debug script and set the upper limit to 0.0000" and the lower limit to -1.0000" and here is what I found:

Code: [Select]

pos -0.0112 turn output0 off
enc -28.0 turn output0 off

pos -6.6916 turn output1 on   ← bad number here, axis is definitely not at this position.
enc -16729.0 turn output1 on  ← bad encoder count here, axis is definitely not at this position.

pos -0.2652 turn output1 off
enc -663.0 turn output1 off

pos 0.0784 turn output0 on
enc 196.0 turn output0 on

pos -0.0628 turn output0 off
enc -157.0 turn output0 off


Any Idea why I get random bad encoder numbers?  I can actually see the bad number on my screen for a split second while watching the encoder count readout "dro" window i have.  It seems to self correct (carries on with correct readings after the bad one) and the machine does not appear to lose position after the bad encoder number?

38
Mach4 General Discussion / PLC Script troubleshooting
« on: September 10, 2016, 09:37:26 AM »
I have a Moore Jig grinding machine that has a reciprocating pneumatic Z-axis.  It has a glass scale on the axis that is hooked to my motion controler (PMDX-424).  I have a PLC script set up so the user can specify an upper and lower limit on the stroke and the solenoid will change direction once one of the limits are reached.  My problem is that sometimes the machine will only perform a partial stroke on the way down changing direction well before it reaches the lower limit.  It never does this on the way up.  Perhaps there is an issue with my code?

Here is a link to a quick video showing a half stroke on about the 3rd or 4th stroke:

https://youtu.be/L82Gi7fmf28

Here is the code I am using in the PLC script:

Code: [Select]

--My Z axis DRO to inches script starts here:

local inst = mc.mcGetInstance()
local hreg = mc.mcRegGetHandle(inst, "SmartBOBUSB/EncoderDRO") --get encoder input handle
local zEncoderVal = mc.mcRegGetValueString(hreg)
local zEncoderVal = tonumber(zEncoderVal) --convert input to number for math
local zEncoderVal = (zEncoderVal * 0.0004) --convert input from encoder counts to inches
WriteRegister("Z_DRO_INCH", tostring(zEncoderVal)) --write the result to the Z axis DRO

--My Z axis DRO to inches script ENDS here:

--My Z axis stroke monitor script Starts here:

local zStrokeUp = GetRegister("Z_STROKE_UP")
local zStrokeDown = GetRegister("Z_STROKE_DOWN")
local zStrokeUp = tonumber(zStrokeUp)
local zStrokeDown = tonumber(zStrokeDown)
local output_0 = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT0) -- Get handle for output 0
local output_1 = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT1) -- Get handle for output 1
local output_0_state = mc.mcSignalGetState(output_0) --Get state of  signal
local output_1_state = mc.mcSignalGetState(output_1) --Get state of  signal

if  zEncoderVal >= zStrokeUp then
    mc.mcSignalSetState(output_0, 1)
elseif zEncoderVal > zStrokeDown and zEncoderVal < zStrokeUp and output_0_state == 1 then
    mc.mcSignalSetState(output_0, 0)
elseif zEncoderVal > zStrokeDown and zEncoderVal < zStrokeUp and output_1_state == 1 then
    mc.mcSignalSetState(output_1, 0)
elseif zEncoderVal <= zStrokeDown then
    mc.mcSignalSetState(output_1, 1)
end

--My Z axis stroke monitor script Ends here:





39
Thanks for the links I will check them out.  I have some code experience so I am more concerned with the general workflow of customizing Mach4.  I was thinking there was another manual that I couldn't find.

40
Thank you Steve.  More specifically, I am looking for the manual referenced here in the scripting manual:

Quote
3.2 Screen Scripts
The screen contains scripts than run on load and unload and a plc script. Certain screen elements (such as buttons, panels, DROs, and tabs) can also execute user defined scripts. These scripts call all be set in the screen editor (see the Mach4 customization manual for more information of customizing the screen).

The Scripting manual says to see the Customization Manual.  I don't see a Customization manual in the link you provided? 

Pages: « 1 2 3 4 5 6 »