Hello Guest it is March 29, 2024, 02:59:50 AM

Author Topic: need a little bit of help  (Read 13318 times)

0 Members and 1 Guest are viewing this topic.

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: need a little bit of help
« Reply #10 on: June 01, 2015, 11:33:47 PM »
thanks to everyone`s help it is working now you have to in cress the wx.wxMilliSleep(10); if you wont to see it moving the DRO`S in editor, in a button you see no movement on screen but I have tested it on a machine and it works

by truck its fast as in blink I will post here for you boys to look at it and if anyone has anything to added please do. I will be adding in credit to who helped and post it to tool box at end of the week
« Last Edit: June 01, 2015, 11:39:54 PM by daniellyall »

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: need a little bit of help
« Reply #11 on: June 01, 2015, 11:46:06 PM »
here it is it`s not quite right yet you don't see any DRO movement on screen I have tested it on a machine and it does work so use at own risk

Code: [Select]
--Laser Zero
------------------------turn output on/off------------------------------------
local inst = mc.mcGetInstance();--Get the instance of the controller
local out5= mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT5);--Get the out5 handle
local outstate = mc.mcSignalGetState(out5);--Output TOGGLE
   if (outstate == 1) then
       mc.mcSignalSetState(out5, false);
     else
       mc.mcSignalSetState(out5, true);
    end
wx.wxMilliSleep(10);
--------------------------Move to work zero------------------------------------

local inst = 0;
local rc = 0;
local Xmove = "X20"; --set to x offset from spindle
local Ymove = "Y30"; --set to y offset from spindle
mc.mcCntlGcodeExecute(inst, "G91 G0" .. Xmove .. " \n" .. Ymove.."\n G90 \n");--run some g-code
    wx.wxMilliSleep(10);  --this is here other wise it`s to fast to see anything on DRO`S in editor
    mcState = mc.mcCntlGetState(inst);
    while (mcState ~= mc.MC_STATE_IDLE) do --This part is so it will Zero axis`s after movement
    mcState = mc.mcCntlGetState(inst);
    wx.wxMilliSleep(10);
end
mc.mcAxisSetPos(inst, 0, 0.000) --zero x axis
mc.mcAxisSetPos(inst, 1, 0.000) --zero y axis 
Re: need a little bit of help
« Reply #12 on: June 02, 2015, 12:08:20 AM »
Nice! I'm impressed...I couldn't get a while or a repeat loop (even with a break) to work for me, just kept freezing the GUI as button scripts are 'ran as events'. I just figured I'd start using wx.wxMessageBox to break up the chunks. I finally got all kinds of movement in on a button script now by breaking it up with the message box (all kinds of mc.mcCntlMdiExecute and mc.mcJogVelocityStart functions going on without racing) for multiple phases in the auto tool button without G31. I was using the message box to prompt the user and when a movement phase was complete, the user just hit ok. This would signal Lua to execute the next chunk in the script. If you don't mind, I'd like to try the while loop with wx.wxMilliSleep combo. Nothing like automation! ...man, I love this stuff! Below is a what I mean, this is just a snippet. I agree with BR549, smart dude. The machine works for us (Period!)

--josh

Code: [Select]
gCode = "G0 G90 G54 G17 G40 G49 G80\n"
gCode = gCode .."G53 Z0.0\n"
gCode = gCode .."G53 X14.0 Y0.0\n"
gCode = gCode .."G53 X12.0 Y1.0\n"
mc.mcCntlMdiExecute(inst, gCode)
mc.mcSignalSetState (hSigOZero, 1)
wx.wxMessageBox ("Next:  Probe table.")

mc.mcJogSetRate (inst, 2, 40)
mc.mcJogVelocityStart (inst, 2, -1)
mc.mcSignalSetState (hSigOZero, 1)
if inputZero ==1 then mc.mcJogVelocityStop (inst, 2)end
wx.wxMessageBox ("Next:  Goto Tool Setter Position.")
« Last Edit: June 02, 2015, 12:12:52 AM by Screwie Louie »
Re: need a little bit of help
« Reply #13 on: June 02, 2015, 12:43:09 AM »
I was thinkin....you think it's wise to dive into the mc.mcMotion functions? Whats up with the "Cycle planner" anywho? I gather it is communication with the motion controller and the core whereas, the motion controller reports (by motor counts) to the core the position of the mill and then the core updates the data on Mach GUI. I wonder if we can control this or is this strictly OEM afforded functions...hmm, idk. And another thing, the screw mapping functions...is that a way to do our axis calibration? I think so, we just have to code it. It seems easy. I just want to know if it is for axis calibration or not. Ok, I'm talking too much. Later Daniel!

--josh

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: need a little bit of help
« Reply #14 on: June 02, 2015, 12:51:09 AM »
it cool you rants are fine

the stupid thing I tried the while loop yesterday same as I have it, it would not work then buttons on screen with code in them stopped working had to replace them now its all fine just one of those random bug`s. it`s fun when things work

Offline smurph

*
  • *
  •  1,544 1,544
  • "That there... that's an RV."
    • View Profile
Re: need a little bit of help
« Reply #15 on: June 02, 2015, 02:37:16 AM »
The "better" way to do this stuff is to use the PLC script in conjunction with a button script.  Make a global var in the Load script to work with.  Something like "myAction".  The button script simply sets myAction to something that the PLC script knows how to handle. 

load script:
Code: [Select]
-- make some global vars.
myAction = -1;  -- holds our action code.
myActionExecuting = 0;  -- is our action executing?  This is like a semaphore.

Button script:
Code: [Select]
if (myAction == -1) then
    myAction = 1; -- set to x20 and y30 offset from spindle.
end

PLC script:
Code: [Select]
if (myAction == 1) then
    mc.mcCntlGcodeExecute(inst, "G91 G00 X20Y30");  -- set to x20 and y30 offset from spindle.
    myActionExecuting = 1; -- mark that we are executing.
    -- The state of the machine will now NOT be idle.  It will be executing the G code.
    -- The PLC script runs top down, so the test below will not see the machine in the
    --  idle state until the code above has been completed.
end

...

mcState = mc.mcCntlGetState(inst);
if (mcState == mc.MC_STATE_IDLE and myActionExecuting == 1 and myAction == 1) then
    --This part is so it will Zero axis`s after movement.
    mc.mcAxisSetPos(inst, 0, 0.000); --zero x axis
    mc.mcAxisSetPos(inst, 1, 0.000); --zero y axis 
    myActionExecuting = 0;  -- no longer excuting myAction
    myAction = -1; -- reset myAction to let another button do something.
end

If you think about it, this is how one would program any PLC where the PLC would be watching an input or register to control program flow.  Just think of a button as sort of way to update a PLC register.

Steve

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: need a little bit of help
« Reply #16 on: June 02, 2015, 02:55:28 AM »
this stuff is new to me so I will do stuff wrong all the time I just do it to full time in I have never used a PLC so I would not know how they work I know what they are
Re: need a little bit of help
« Reply #17 on: June 02, 2015, 03:04:39 AM »
Thanx Steve! That is the theory I've been needing...another Sticky reply! I think you just unleashed Mach 4's potential right there...to everyone. Wow. It's going to take a minute or two to wrap my thinking cap around that but, yah...freakin awesome education right there.

--josh

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: need a little bit of help
« Reply #18 on: June 02, 2015, 03:13:02 AM »
just so I can get this correct


The "better" way to do this stuff is to use the PLC script in conjunction with a button script.  Make a global var in the Load script to work with.  Something like "myAction".  The button script simply sets myAction to something that the PLC script knows how to handle.  


so this bit I just put in screen load script I don't add a ver to the regfile

load script:
Code: [Select]
-- make some global vars.
myAction = -1;  -- holds our action code.
myActionExecuting = 0;  -- is our action executing?  This is like a semaphore.

got this
Button script:
Code: [Select]
if (myAction == -1) then
    myAction = 1; -- set to x20 and y30 offset from spindle.
end


I just put this in PLC and change the number after axis to set the offset

PLC script:
Code: [Select]
if (myAction == 1) then
    mc.mcCntlGcodeExecute(inst, "G91 G00 X20Y30");  -- set to x20 and y30 offset from spindle.
    myActionExecuting = 1; -- mark that we are executing.
    -- The state of the machine will now NOT be idle.  It will be executing the G code.
    -- The PLC script runs top down, so the test below will not see the machine in the
    --  idle state until the code above has been completed.
end

-----------...

mcState = mc.mcCntlGetState(inst);
if (mcState == mc.MC_STATE_IDLE and myActionExecuting == 1 and myAction == 1) then
    --This part is so it will Zero axis`s after movement.
    mc.mcAxisSetPos(inst, 0, 0.000); --zero x axis
    mc.mcAxisSetPos(inst, 1, 0.000); --zero y axis  
    myActionExecuting = 0;  -- no longer excuting myAction
    myAction = -1; -- reset myAction to let another button do something.
end

If you think about it, this is how one would program any PLC where the PLC would be watching an input or register to control program flow.  Just think of a button as sort of way to update a PLC register.

Steve

I have tested as is it runs the same as in a button no seeing moment in DRO`S but it does work. it work`s and does its job so know I can learn other stuff so I can make any code I do easier. I only had to do a laser Zero and a tool height have not tested tool height probing from the manual but it seems to work just testing it.

So thank you very much this would be a better way to do it as the other person who uses the router`s I don't wont them to change anything so it makes it harder to find

thanks Steve may the CNC God`s shine on you

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: need a little bit of help
« Reply #19 on: June 02, 2015, 03:19:55 AM »
its about time you changed your name again, Screwie Louie, screaming ax sound good

yep Steve don't post much but hell it all ways help when he does some people don't like the M4 people not replying much or the blocks that know most of it, but if they gave all the answers no one would learn.
so if we do a code that's good and we did our own hard work them coming along and making it better or showing as a better way is more of a help than not. hell the teacher is coming out in me again.
« Last Edit: June 02, 2015, 03:22:30 AM by daniellyall »