Machsupport Forum
Mach Discussion => General Mach Discussion => Topic started by: BR549 on June 20, 2010, 12:53:23 AM
-
I loaded up a new macro program in the MACH TOOL BOX that allows the machine to travel the PART extents to see if the part can be cut from your material on the table.
Load you program, then move to a position that you think will do for the X0Y0 (origin). Then run the code. The macro will ASK you if your Z position is safe for travel. If yes then it will reset the XY axis to zero, retreive the xy minmax extents and then travel the far corners of those values.
IF not then it ends and asks you to correct the problem then restart.
If the part BOX will fit on your material then you are good to go.
Good for routers GREAT for plasma.
-
Absolutely brilliant - great addition for any machine.
Tweakie.
For those who follow - the Macro is in this thread http://www.machsupport.com/forum/index.php/topic,15154.0.html
-
Agreed, this will be great as I like to utilize all my "scrap" pieces, so this will be a nice way to see if the profile will "fit" the material.
Thanks for this-
Dave
-
Already having a problem and I asked a question in the actual Macro post, maaybe someone can help?
Thanks,
Dave
-
Hi Dave, I just ran it here about a dozen times with different files and NO problems. What version of Mach are you running?
Out of curiousity press the regen button before you try it again. Later vers of mach are not as reliable with VB as the earlier versions. There are as many wait states in that program as I can stuff in there and still have it do anything.
But that is just my opinion
-
Dave I just loaded up the stable ver of mach V.040 and I can say that there is something bad wrong in there with VB/Gcode.
SO I will pull the macro code to keep from causeing issues.
-
Thanks for looking into this, I'm running R3.041 so I guess there's the reason why.
EDIT: Tried the regen and the same exact thing.
Thank you sir-
Dave
-
one last thing, Load up a program and then use the VB editor and single step down through the code to see if it still works. IF it works ok then save and try it again from the button.
I can make it work here by first single stepping down through the code. after that it works every time with the V.040.
Don't ask me why you need to single step it first to make it work ??????
YOU COULD delete out the AUTO section and do that part manually then run the motion code as a button.
It is a darn handy function as we have used it here with plasma for about a year now without problems.
-
Yep, it works correctly as long as the editor is open! What's up with that? :D
Dave
-
Dave could you try this version, I have it working reliably here on the V.040 version
'Macro To AUTOEXTENTS
Sub main()
FR = 30 'Sets FeedRate
DT = 3 'Sets Dwell Time
Msg="Is Your Z HEIGHT Safe To Travel?"
SetVar(120,FR)
SetVar(121,DT)
Response = MsgBox(Msg, 4 )
If Response = 7 Then
GoTo N3:
Else
GoTo N2:
End If
N2:
DoButton(8) 'ZeroX
Sleep(1000)
DoButton(9) 'ZeroY
Sleep(1000)
DoButton(10)
Sleep(1000)
DoOemButton(160) 'Regen ToolPath
Sleep(1000)
Sleep(1000)
SetVar(100,Getoemdro(4))
Sleep(100)
SetVar(101,Getoemdro(10))
Sleep(100)
Setvar(110,Getoemdro(5))
Sleep(100)
Setvar(111,Getoemdro(11))
Sleep(1000)
DoOemButton(169)
Sleep(1000)
Code"G1 X#100 Y#110 F#120"
While Ismoving()
Sleep(100)
Wend
Code"G4 P#121"
Code"G1 X#100 Y#111 F#120"
While Ismoving()
Sleep(100)
Wend
Code"G4 P#121"
Code"G1 X#101 Y#111 F#120"
While Ismoving()
Sleep(100)
Wend
Code"G4 P#121"
Code"G1 X#101 Y#110 F#120"
While Ismoving()
Sleep(100)
Wend
Code"G4 P#121"
Code"G1 X#100 Y#110 F#120"
While Ismoving()
Sleep(100)
Wend
Code"G4 P#121"
Code"G1 X0.000 Y0.000 F#120"
While Ismoving()
Sleep(100)
Wend
DoOemButton(170)
Sleep(1000)
GoTo N4:
N3:
MsgBox("Move Z To A Safe Position And Restart")
GoTo N4:
N4:
End Sub
End
-
No sir, no good and it does something odd as well.
It cycles through the GCode and then disappears and then does it again. Did you try some sort of reset to get it to run correctly?
Thanks again,
Dave
-
(;-) The problem I see IS that mach has no real controll over the VB threading, it can hop and skip over code randomly at times when the cpu may be busy.
I thought that because the Gcode window was active that Mach had a problem with running a VB/Gcode while the Gcode window was open. That helped but there is still a time/threading problem somewhere.
BUT none of that explains the running from an open VB window unless THAT forces VB to behave??????
Can you load a program then Open the Gcode Var window and use Vars 100,101,110,111 and see when you run the program that the Vars are actually loading. If not we need to add more time for them to update.
What speed computer are you running?
-
This is my main PC which is a dual core 2.8 and I have no optimization on it. What I will do is wait until I get on my machine PC which has all optimizations and report back with the results on that one.
It's fathers day and we're having quite a party here so this will have to wait until tomorrow ;)
I will say that all my "usual" macros run fine on this PC but maybe this macro needs every every bit of resource to run?
Thanks again,
Dave
-
Hi Terry - I think the main problem lies with suspending execution until the toolpath regen has finished. This can be tested with isLoading(). So anyway - hope you don't mind but I've done a bit of a re-jig of your code which seems to work for me at least.
'Macro To AUTOEXTENTS
Response = MsgBox("Is Your Z HEIGHT Safe To Travel?", 4 )
If Response = 7 Then
MsgBox("Move Z To A Safe Position And Restart")
Exit Sub
End If
DoButton(8) 'ZeroX
While isMoving()
Wend
DoButton(9) 'ZeroY
While isMoving()
Wend
DoOemButton(160) 'Regen ToolPath
While isLoading()
sleep 100
Wend
feed = 30 'Sets feed
dwell = 3 'Sets Dwell Time
xmin = Getoemdro(4)
xmax = Getoemdro(10)
ymin = Getoemdro(5)
ymax = Getoemdro(11)
Code"F" & feed
While Ismoving()
Wend
Code"G1 X" & xmin & " Y" & ymin
While Ismoving()
sleep 100
Wend
Code"G4 P" & dwell
While isMoving()
sleep 100
Wend
Code"G1 X" & xmin & " Y" & ymax
While Ismoving()
sleep 100
Wend
Code"G4 P" & dwell
While isMoving()
sleep 100
Wend
Code"G1 X" & xmax & " Y" & ymax
While Ismoving()
sleep 100
Wend
Code"G4 P" & dwell
While Ismoving()
sleep 100
Wend
Code"G1 X" & xmax & " Y" & ymin
While Ismoving()
sleep 100
Wend
Code"G4 P" & dwell
While Ismoving()
sleep 100
Wend
Code"G1 X" & xmin & " Y" & ymin
While Ismoving()
sleep 100
Wend
Code"G4 P" & dwell
While Ismoving()
sleep 100
Wend
Code"G1 X0.000 Y0.000"
While Ismoving()
sleep 100
Wend
Cheers
Ian
-
Hi Terry,
Unfortunately neither of the codes you made worked on the fully optimized machine PC either. Thanks though.
Ian, I tried yours but is that the whole code? It seems unfinished as when I run it, it cycles through the GCode in the window but the sits there with the machine time DRO just counting away and never does anything after that. What version of Mach are you running?
Thanks,
Dave
-
Hi Dave - yes that's the whole code (well as long as you copied it all - I make it 87 lines) - as I said it works just fine here.
Strange - the (elapsed) time - if that's what you mean shouldn't run at all as that should only run if you run your gcode program. Try editing the macro and change all the G1 to G0 and see what happens. Or try changing the feedrate - i.e. is a feed of (terry's default) 30 enough on your system or is it just way to slow? - mines metric so I whacked it up to 3000. My version is R3.042.020 but this code is so simple it should run on any version - frankly if this is version dependant I think we might as well pack up and call it a day.
Ian
-
Well this is just weird then, as it will not run with just the button pressed (could it be my button settings?), BUT it WILL run with the VB Editor open, just like Terrys, so it has to be something in my configuration setup here.
Thanks
Dave
-
HIYA GUYS both version work here just fine??????????? I like the first version that still shows the toolpath best , not that it really matters.
Ian , I have tried the While Isloading () Funny thing here IS I have 3 computers I have tested it on AND it took a different approach to make it work on each computer????? Mostly it was a time dwell issue try to keep VB in sync with itself.
Another problem was Mach does NOT like to run Gcode inside VB WHEN it has a Gcode file loaded. It will at times START the Gcode file running WHEN the vb code ends. THAT WAS EXCITING on the machine testing. That is what the Feedhold/Stop code was all about at the end of the file ,IT kept the machine from autostarting the program file. THAT was also why I tested in G1 instead of G0 as the plasma can haul at better than 300IPM if needed.
I think Mach is WAY TOO spooky to be doing anymore cool things for the masses, you never know when something will go bad.
I have many many cool Mcodes and function routines that we use here BUT I think they will stay in the file cabinet untill mach gets stable.
(;-) AUTOSTART in the worst way LOLOLOLOLOL
-
IAN I just tried your version(;-) "Here" At the end of the VB file it will autostart the Gcode program that is loaded.
(;-)
-
Terry - yes - it just did that to me too - funny because I've run it 20 or so times and it behaved perfectly and then suddenly - there's the gcode running all by itself - scaaaaaary. I'm with you - I don't think Mach's anywhere near trustworthy enough for this. Reminds me of my probing routines - that's why I ended up coding a .DLL so I could use as little VB in there as possible.
Ian
-
well - not being able to leave things alone ;D I've come up with a version that SEEMS stable at my end. Note the comment at the top of the file - It MUST be run from a button.
Ian
'This macro MUST be run from a button
'running it from the MDI for example is not recommended
Begin Dialog Dialog1 60, 60, 104, 70, "Auto Extents"
Text 10, 10, 30, 12, "Feedrate:"
TextBox 44, 10, 50, 12, .feedrate
Text 10, 24, 30, 12, "Dwell:"
TextBox 44, 24, 50, 12, .dwell
Text 10, 38, 30, 12, "Z height:"
TextBox 44, 38, 50, 12, .zHeight
OKButton 10, 54, 40, 12
CancelButton 54,54,40,12
End Dialog
Dim Dlg1 As Dialog1
Dlg1.feedrate=getOEMDRO(818)
Dlg1.dwell=1
Dlg1.zHeight=getOEMDRO(802)
button=Dialog(Dlg1)
If button <> -1 Then
Exit Sub
End If
DoButton(8) 'ZeroX
DoButton(9) 'ZeroY
While isMoving()
Wend
DoOemButton(160) 'Regen ToolPath
While isLoading()
sleep 100
Wend
doOEMButton(1002) 'Rewind
While isMoving()
sleep 100
Wend
xmin = minX()
xmax = maxX()
ymin = minY()
ymax = maxY()
dwell=Dlg1.dwell * 1000
Code "F" & Dlg1.feedRate & " G1 Z" & Dlg1.zHeight
While Ismoving()
sleep 100
Wend
Code "G1 X" & xmin & " Y" & ymin
While Ismoving()
sleep 100
Wend
sleep dwell
Code "G1 Y" & ymax
While Ismoving()
sleep 100
Wend
sleep dwell
Code "G1 X" & xmax
While Ismoving()
sleep 100
Wend
sleep dwell
Code "G1 Y" & ymin
While Ismoving()
sleep 100
Wend
sleep dwell
Code "G1 X" & xmin
While Ismoving()
sleep 100
Wend
MsgBox "Finished",0,"Auto Extents"
-
Well thanks for trying Ian, unfortunately same thing for me.
It runs great running it from the VB Editor, but running from the button, it once again cycles through and then the run time just counts up as if the GCode is running.
The new pop up dialog box threw me a bit too, lol!
I appreciate your persistance ;)
Dave
EDIT: I just don't get it, why does it run perfectly through the Editor when open, but not from a button? Is there another way to code a button to do this?
-
Ok, may have found something. Ian, I've deleted a bit of your code and got it working.
You'll notice I deleted:
DoButton(8) 'ZeroX
DoButton(9) 'ZeroY
While isMoving()
Wend
DoOemButton(160) 'Regen ToolPath
While isLoading()
sleep 100
Wend
doOEMButton(1002) 'Rewind
While isMoving()
sleep 100
Wend
Now is this going to be safe?
'This macro MUST be run from a button
'running it from the MDI for example is not recommended
Begin Dialog Dialog1 60, 60, 104, 70, "Auto Extents"
Text 10, 10, 30, 12, "Feedrate:"
TextBox 44, 10, 50, 12, .feedrate
Text 10, 24, 30, 12, "Dwell:"
TextBox 44, 24, 50, 12, .dwell
Text 10, 38, 30, 12, "Z height:"
TextBox 44, 38, 50, 12, .zHeight
OKButton 10, 54, 40, 12
CancelButton 54,54,40,12
End Dialog
Dim Dlg1 As Dialog1
Dlg1.feedrate=getOEMDRO(818)
Dlg1.dwell=1
Dlg1.zHeight=getOEMDRO(802)
button=Dialog(Dlg1)
If button <> -1 Then
Exit Sub
End If
xmin = minX()
xmax = maxX()
ymin = minY()
ymax = maxY()
dwell=Dlg1.dwell * 1000
Code "F" & Dlg1.feedRate & " G1 Z" & Dlg1.zHeight
While Ismoving()
sleep 100
Wend
Code "G1 X" & xmin & " Y" & ymin
While Ismoving()
sleep 100
Wend
sleep dwell
Code "G1 Y" & ymax
While Ismoving()
sleep 100
Wend
sleep dwell
Code "G1 X" & xmax
While Ismoving()
sleep 100
Wend
sleep dwell
Code "G1 Y" & ymin
While Ismoving()
sleep 100
Wend
sleep dwell
Code "G1 X" & xmin
While Ismoving()
sleep 100
Wend
MsgBox "Finished",0,"Auto Extents"
Another question, what can I add to make it go back to the zero coords that I started with when the extents is finished running?
EDIT: The reason I chose to delete those portions was because I was already doing those before running the script. I thought maybe it was getting stuck because it couldn't perform those functions because they were already done! ;D
Thanks again,
Dave
-
Ok, so I added this to the code to get it back to X and Y Zero coords:
Code"G1 X0.000 Y0.000"
While Ismoving()
sleep 100
Wend
Is that correct? I added it like this towards the end:
Code "G1 X" & xmin
While Ismoving()
sleep 100
Wend
Code"G1 X0.000 Y0.000"
While Ismoving()
sleep 100
Wend
MsgBox "Finished",0,"Auto Extents"
Thanks,
Dave
-
Dave if you want to take out the auto part it will run just fine.
NOW last night I worked out a different solution with Sheetcam. I redid the post to output a Dry run around the PART perimeter to verify the material. It also has the block delete charectors in that part so you can turn the funtion on and off if needed.
AND it has nothing to do with VB(;-) Not as quick and easy BUT it does give a more detailed look at the material fit.
-
Dave - as Terry says, now you've taken out the toolpath generation it should work fine. That kind of takes away the point of it though really. BUT as it's proving a bit of a mare that's probably the way to go. Interesting you can get it to run from the VB code window but not the button. In my case it's the exact opposite. If I run it from the VB code window all hell breaks loose and it then completely hangs, I have to power cycle the PC to get it back. Your zero code is fine - not sure where it went from mine - it was in there at some point! Sorry the dialog threw you - just me playing about.
Terry - again I see parallels with your approach and what I had to do in my probing routines. Initially I did everything in VB but then as I said had to do most of it in a .DLL - BUT I also had to write the main loop in gcode to get it to work. I think we may just have to accept that Mach's relationship with VB is about as flaky as a box of kellogs ;D
Ian
-
Thanks so much fellas, I appreciate the info and for all the help.
This will be nice to have, especially to make sure if any clamps or other obstacles may be in the way.
Have a great day-
Dave
-
HI IAN, Actually the Sheetcam approach worked very well ran it all day today testing the idea . It is nice to be able to do a dry run
-
Ran my sorry little code all day today as well and it worked perfectly for each job I ran.
Thanks so much for inspiring me fellas 8)
Dave
-
Way to go Big Dave (;-)
-
I've been working on the same thing this week. Here is my version. Runs from a button.
'Code to test gcode travel limits
'John Champlain - June 20, 2010
'
' Save current XYZ positions
CurrX = GetDRO(0)
CurrY = GetDRO(1)
CurrZ = GetDRO(2)
CurrFeed = GetOemDRO(818)
SafeZ = GetOEMDRO(54)
'
'
Dim Msg, Num ' Declare variables.
Title$ = "Check Extents"
Prompt$ = "Enter Feedrate"
Default$ = ""
x% = 75
Y% =200
Num$ = InputBox(Prompt$, Title$, Default$,X%,Y%) ' Get user input.
'
' Get gcode travel limits
XMin = GetOEMDRO (4)
XMax = GetOEMDRO(10)
YMin = GetOEMDRO(5)
YMax = GetOEMDRO(11)
' Test travel limits
' Move one axis at a time
'
Code "F" & num ' set feedrate
'
'
Code "G1 Z" & SafeZ 'move Z to safe height
While IsMoving ()
Wend
Code "G1 X" & XMin & "Y" & YMin 'move to minimum XY position
While IsMoving ()
Wend
Code "G1 Y" & YMax 'move to maximum Y position
While IsMoving ()
Wend
Code "G1 X" & XMax 'move to maximum X position
While IsMoving ()
Wend
Code "G1 Y" & YMin 'move to minimum Y position
While IsMoving ()
Wend
Code "G1 X" & XMin 'move to minimum X position
While IsMoving ()
Wend
'
' Reset to original settings
Code "G1 X" & CurrX & "Y" & CurrY 'reset X
While IsMoving ()
Wend
Code "G1 Z" & CurrZ 'reset Z
While IsMoving ()
Wend
Code "F" & CurrFeed
Code "(Done)"
Regards All,
John Champlain
-
Hi John,
Just wanted to let you know your script works correctly for me as well from a button. :)
Dave
-
AH, but you left out the regen toolpath(;-) routine to make sure the extents is accurate. Mach does NOT auto correct the extents in the toolpath. Just make sure you do the SET XYAXIS ZERO and REGEN as a manual function before you run it
-
That's why I'm guessing it works for me too Terry-
Dave
-
Thanks,
I see what you mean about the Regen.
Regards,
John Champlain
-
Code revised from suggestions. I would appreciate someone testing and giving opinion.
Thanks,
John Champlain
'Code to test gcode travel limits
'John Champlain - June 20, 2010
'
' Save current XYZ positions
CurrX = GetDRO(0)
CurrY = GetDRO(1)
CurrZ = GetDRO(2)
CurrFeed = GetOemDRO(818)
SafeZ = GetOEMDRO(54)
'
'
Dim Msg, Num ' Declare variables.
Title$ = "Check Extents"
Prompt$ = "Enter Feedrate for Test"
Default$ = ""
x% = 75
Y% =200
Message "Please Wait While Regenerating"
DoOemButton(160) 'Regen ToolPath
While isLoading()
Wend
Message ""
Num$ = InputBox(Prompt$, Title$, Default$,X%,Y%) ' Get user input.
'
' Get gcode travel limits
XMin = GetOEMDRO (4)
XMax = GetOEMDRO(10)
YMin = GetOEMDRO(5)
YMax = GetOEMDRO(11)
' Test travel limits
' Move one axis at a time
'
Code "F" & num ' set feedrate
'
'
Code "G1 Z" & SafeZ 'move Z to safe height
While IsMoving ()
Wend
Code "G1 X" & XMin & "Y" & YMin 'move to minimum XY position
While IsMoving ()
Wend
Code "G1 Y" & YMax 'move to maximum Y position
While IsMoving ()
Wend
Code "G1 X" & XMax 'move to maximum X position
While IsMoving ()
Wend
Code "G1 Y" & YMin 'move to minimum Y position
While IsMoving ()
Wend
Code "G1 X" & XMin 'move to minimum X position
While IsMoving ()
Wend
'
' Reset to original settings
Code "G1 X" & CurrX & "Y" & CurrY 'reset X
While IsMoving ()
Wend
Code "G1 Z" & CurrZ 'reset Z
While IsMoving ()
Wend
Code "F" & CurrFeed
DoOEMButton(1002) 'Rewind code
Message "TEST COMPLETE"
Sleep 5000
Message ""
-
This one does not work for me as a button, but works with the VB Editor open.
Dave
-
Thanks Dave,
Any clue as to why it won't work from a button for you? It works both ways for me (editor and button) using Version R3.042.035.
Regards,
John Champlain
-
Hi John, not a clue as I hardly know anything about VB.
So far all I know is that if it contains the refresh/regen part of the code, it will not work for me.
On the other codes, I just had to edit that out and it works fine from the button.
Dave
-
Dave a question for you(;-) When you run the code from a button do you put the code "IN" the button OR do you make an "Mcode" from the code and call it from the button?
-
I'm not sure I know how to make an MCode, lol!
I set up a button in a screen designer as a VB "Run Script" button and then open Mach 3 and use the "Edit button Script" command to insert the script.
Dave
-
I have a different version if you are game to try it(;-) It keeps the toolpath display working so you can see it draw a pretty line around the part.
-
Sure, absolutely! I'm actually learning a bit more as I go-
Dave
-
Dave does the test Gcode file you load have an "M30" in the last line? Just curious(;-)
'Macro To AUTOEXTENTS
Sub main()
Msg="Is Your Z HEIGHT Safe To Travel?"
Response = MsgBox(Msg, 4 )
If Response = 7 Then
GoTo N3:
Else
GoTo N2:
End If
N2:
DoButton(8) 'ZeroXyZ
DoButton(9)
DoOemButton(160) 'Regen ToolPath
While Isloading()
Wend
DoButton(2)
SetVar(100,Getoemdro(4))
SetVar(101,Getoemdro(10))
Setvar(110,Getoemdro(5))
Setvar(111,Getoemdro(11))
While Ismoving()
Wend
'DoOemButton(169)
While Ismoving()
Wend
Code"G1 X#100 Y#110 F30"
While Ismoving()
Wend
Code"G4 P3"
Code"G1 X#100 Y#111 F30"
While Ismoving()
Wend
Code"G4 P3"
Code"G1 X#101 Y#111 F30"
While Ismoving()
Wend
Code"G4 P3"
Code"G1 X#101 Y#110 F30"
While Ismoving()
Wend
Code"G4 P3"
Code"G1 X#100 Y#110 F30"
While Ismoving()
Wend
Code"G4 P3"
Code"G1 X0.000 Y0.000 F30"
While Ismoving()
Wend
DoButton(2)
GoTo N4:
N3:
MsgBox("Move Z To A Safe Position And Restart")
GoTo N4:
N4:
End Sub
End
-
Hi Terry,
Yes, I use an M30 in my GCode, don't most users?
The new script did not run either :D
Thanks,
Dave
-
Interesting (;-) Can you describe what it actually does step by step?
Yes Most do use the M30 but not all do.
-
Yes, of course but I'll do one better. I'll show you ;)
Take note how after the GCode window cycles, the run time counter continues counting and does not stop.
Oh, and pay no attention to how the fonts and characters are clipped. I have my fonts set larger than normal on my widescreen so that's why it looks that way on my test machine.
http://www.youtube.com/watch?v=Z2fYFqvH84k
Dave
-
OK what happens IF you let it run for a while. Does it return to a rewound screen or never finishes??
Here it runs the code does the Regen then rewinds back to the top and runs the perimeter moves, showing the moves on the toolpath screen then ends and the gcode is ready to run
If you get a chance could you run the enclosed Test Gcode file to see IF it could be file dependant
-
Yep, it's file dependant as your file indeed works correctly, my friend-
Also, yes, the run time counter doesn't stop, the longest I let it run was 15 minutes.
So I'm guessing it's the M30 at the end of my file? What exactly is that affecting?
Dave
-
Could you post the file you were using to test?
The M30 does not have anything to do with it(;-) I had removed the M30 to test and never put it back.
-
Sure, here's one for you.
Dave
-
Thanks Dave, Your file runs fine here with AutoExtents
-
Well now that's just funny! :D
Dave-
-
Do you have any other cool features we need to investigate a way to do???
-
Hi Terry,
Not off the top of my head, but I'm sure there will be more down the road - ;)
Thanks so much for all your help,
Dave