Hello Guest it is July 12, 2024, 08:39:24 AM

Author Topic: Macros  (Read 4795 times)

0 Members and 1 Guest are viewing this topic.

« on: April 26, 2008, 09:47:50 PM »
I just converted my CNC router from WinCNC to CandCNC and Mach3. While most of the Mach3 settings are superior to WinCNC, and there is much better control, I have found one serious deficiency. WinCNC has a button labeled "Touch Top". When selected, the Z axis goes down until it touches a touchpad (I got the Mach3 software to do that), then it stops, deducts the thickness of the touchpad (0.498"), sets Z to zero, then raises the Z axis to .750".

So far, I have gotten Mach3 to lower the Z axis until the tool touches the touchpad, but at that point is stops. I have to manually raise the head, remove the touchpad, manually enter 'Z-.498', reset Z to 0, then raise the head. I know a macro can be made and assigned to one of the screen buttons (Load Material , for isntance, is useless to me ...), but I don't want to reinvent the wheel if there is already something out there that will do a similar job. Does anyone have anything like that, or do I need to start studying VB again (I used it years ago, but hoped I would never have to again ...)


Offline jimpinder

  •  1,232 1,232
  • Wakefield, West Yorks, UK
Re: Macros
« Reply #1 on: April 27, 2008, 03:20:54 AM »
Yes - you are quite right - I don't know of any already written, unless someone has one they can post. I would perhaps search the forum, there are several sections, and see if any has what you want.

Look at the video tutorials on Scripting

You will need to learn a little of the Mach3 specific Visual Basic instructions, but yes, you can write a macro to "borrow" the touching bit, and then write to the relevant DRO's (or clear them) and move your tool to convenient position.

If you write one - how about posting it.
Not me driving the engine - I'm better looking.
Re: Macros
« Reply #2 on: April 27, 2008, 08:27:35 PM »
I have the following macro in the "set tool offset' button on the Offsetts screen

CurrentFeed = GetOemDRO(818) 'Get the current feedrate.
PlateThickness = 0.062 'plate thickness
ProbeFeed = 1.0 'probing feedrate

If GetOemLed (825)=0 Then
'Code "G4 P5" Time to get to the z-plate
Code "G31Z-1 F" &ProbeFeed
While IsMoving()
Code "G4 P0.25"
ZProbePos = GetVar(2002)
Code "G0 Z" &ZProbePos
While IsMoving ()
Call SetDro (2, PlateThickness)
Code "G4 P0.5" 'Pause for Dro to update.
Code "G0 Z 0.1" 'Change the Z retract height here
Code "(Z axis is now zeroed)"
Code "F" &CurrentFeed
Code "(Plate is grounded, check connection and try again)"
Exit Sub
End If 

Note it has the plate thickness coded into it, and a move of .1 after the touch. You could edit those values to anything you want.

To use this select the offsets screen, then select from the Operator menu the item Edit button script. All the VB buttons will blink, select the 'Set tool offset' button. When the VB window opens delete all the code there and replace it with this code.

Note that this one is going to try to move Z to -1. If you were already below -1 it wouldnt move for a probe cycle. I ought to be more clever and do a relative mode of -1. Maybe someday Ill fix that.
Re: Macros
« Reply #3 on: April 27, 2008, 09:19:51 PM »
This is the cool thing about Mach3 is you can add anything you can think of to it!  I'm no programmer but managed to get Mach3 to do some very trick things for me that no other cnc software would with the same ease.
Re: Macros
« Reply #4 on: April 27, 2008, 09:38:03 PM »
Thanks Ron. I'll take a look at that code. I should be able to edit it for my purposes. I've been playing with the VB editor all day, and while I used to do some VB programming, making it interface and pass commands to Mach3 seems to be a major headache.


Offline jimpinder

  •  1,232 1,232
  • Wakefield, West Yorks, UK
Re: Macros
« Reply #5 on: April 28, 2008, 04:39:57 AM »
For anybody who is interested the post attached is the Mach3 specific part of Vis Basic - how to access and post to Mach3 from Vis Basic. It is available on this site (but I can't remember where)

Found another file re Mach specific sub routines  - it is on this forum as a wikki - cnc tutorials\Mach specific Subroutines-Functions grouped by purpose - MachCustomizeWiki.mht
« Last Edit: April 28, 2008, 08:53:16 AM by jimpinder »
Not me driving the engine - I'm better looking.