Machsupport Forum

Mach Discussion => General Mach Discussion => Topic started by: RWElphinstone on July 23, 2016, 04:31:44 PM

Title: Auto Tool Zero Macro Help - I'm 1/3 of the way there!
Post by: RWElphinstone on July 23, 2016, 04:31:44 PM
Hey all,

I've implemented a macro for my auto-tool zero script, based upon information I found on this wonderful site, however, I would like to improve on the code somewhat if possible. (And, of course, not being a programmer, I do not know how to do so!) My current code will lower the z-axis slowly, until it registers the touch plate I built, and then will take the thickness of the plate into effect, zero the z-axis and return to 1" above the stock. This is the code I am presently using for my z-axis zeroing:

Code: [Select]
Code "(Now attempting to Zero the Z-Axis.)"

PlateThickness = 0.11811 'Z-plate thickness DRO

If GetOemLed (825)=0 Then 'Check to see if the probe is already grounded or faulty
DoOEMButton (1010) 'zero the Z axis so the probe move will start from here
Code "G4 P5" 'this delay gives me time to get from computer to hold probe in place
Code "G31Z-40 F500" 'probing move, can set the feed rate here as well as how far to move
While IsMoving() 'wait while it happens
Wend
ZProbePos = GetVar(2002) 'get the exact point the probe was hit
Code "G0 Z" &ZProbePos 'go back to that point, always a very small amount of overrun
While IsMoving ()
Wend
Call SetDro (2, PlateThickness) 'set the Z axis DRO to whatever is set as plate thickness
Code "G4 P0.25" 'Pause for Dro to update.
Code "G0 Z1" 'put the Z retract height you want here
Code "(Z axis is now zeroed)" 'puts this message in the status bar
Else
Code "(Z-Plate is grounded, check connection and try again)"'this goes in the status bar if applicable
Exit Sub
End If   


What I would like to do is similar, with the x-axis and y-axis limit switches. I would like to manually bring the x-axis and y-axis within 6" of the zero values (no code required here - I'll move the machine myself) and then have it slowly approach the x-axis, and then once it touches it, it should move 1/4" in the positive, and set the x-axis zero for the machine to this value. Then, I would like it to have it do the same for the y-axis. (Have it slowly approach the y-axis, and then once it touches it, it should move 1/4" in the positive, and set the y-axis zero for the machine to this value.)

I have had a number of issues in the past whereby my machine has gotten caught up on stock, and then losing it's location values because of it. (The machine would get jammed up, and the software would still think it was moving.) As such, I've then had to reposition the router and manually reset the x-axis and y-axis. I figure if I can implement this code properly, it will improve everything significantly. First, I won't have to perform the manual process any longer, and second, I should be able to perform cuts on the same sheet once the system is re-aligned properly. (On occasion, I've had to recut into the same parts, but after the manual process, it can be out by 1/8" or more, which as you can imagine, is not good enough for anything. So, toss that part away.)

My other questions are these:


I would like to say that I appreciate all of the help I've received over the years here. While I haven't posted too much, I've read and learned a lot here. I would really, really appreciate any help you guys are prepared to give.

Thanks!

Rick
Title: Re: Auto Tool Zero Macro Help - I'm 1/3 of the way there!
Post by: Davek0974 on July 23, 2016, 04:48:25 PM
Sounds like you need to set your limits as homes too, this can be done.

Once a limit is tripped, no code runs.

If the limits go back to the breakout board and not a safety circuit, its not too much to change.

More detail on limit wiring would help i think.
Title: Re: Auto Tool Zero Macro Help - I'm 1/3 of the way there!
Post by: ger21 on July 23, 2016, 05:49:57 PM
Go to Config > Ports and Pins, and configure the X Home input to match the X- Limit.
Do the same for the Y axis Home (Match the Y- Limit.
Go to Config > Homing Limits, and enter -0.25 in the "Home Off." columns for the X and Y axis, and check "Home Neg." for both.
Use the Ref X and Ref Y buttons to home the axis, and they'll set your machine coordinates to -0.25 at the switch locations.

You limits will still work the same way they do now.

You'll want to make sure that you don't have any X or Y axis offsets set.
Title: Re: Auto Tool Zero Macro Help - I'm 1/3 of the way there!
Post by: RWElphinstone on July 23, 2016, 06:26:15 PM
Sounds like you need to set your limits as homes too, this can be done. Once a limit is tripped, no code runs. If the limits go back to the breakout board and not a safety circuit, its not too much to change. More detail on limit wiring would help i think.

Sounds good to me. Right now, the limit switches are wired directly to the breakout board. What detail would you like/need? What could help? I'll be happy to take pics of the connections, or screenshots of the settings, if that helps.

Go to Config > Ports and Pins, and configure the X Home input to match the X- Limit.
Do the same for the Y axis Home (Match the Y- Limit.
Go to Config > Homing Limits, and enter -0.25 in the "Home Off." columns for the X and Y axis, and check "Home Neg." for both.
Use the Ref X and Ref Y buttons to home the axis, and they'll set your machine coordinates to -0.25 at the switch locations.

You limits will still work the same way they do now.

You'll want to make sure that you don't have any X or Y axis offsets set.

I can do all of this, thank you. Once set, is there a process to home the machine? Do I simply turn off the limits, and run the machine until it connects with the x-axis (and then, the y-axis after) and it will automagically reset the zero numbers in Mach3?
Title: Re: Auto Tool Zero Macro Help - I'm 1/3 of the way there!
Post by: RWElphinstone on July 23, 2016, 06:48:13 PM
So, I just checked the information on my machine, and noted your instruction to "configure the X-Home input to match the X- Limit". I wanted to confirm that you meant the "X-- Limit", or if I'm in the wrong place altogether. And then, I noticed that I have my configuration set to the "X++ Limit", and figured I would check with you to see if this is also incorrect.

Here is a screenshot of my configuration:

(http://i.imgur.com/2UHV3j2.png)

Now, at the moment I have two limit switches wired to each axis. (I have one switch on either side of my x-axis gantry, and do stop the machine if they ever get run into.) I'm not sure if this is the wrong way to do things, but when I wired them in, I did not have enough connections to wire them in separately.

I appreciate the quick replies. Thank you very much!
Title: Re: Auto Tool Zero Macro Help - I'm 1/3 of the way there!
Post by: Davek0974 on July 24, 2016, 03:28:23 AM
So, there is only one switch and its configured as ++ so would possibly be the point furthest away from you?

Sounds like you might need a couple more switches at the other ends of the axes for the -- and homing option.

Unless of course your machine references to the ++ end and uses soft-limits for the other end

or

the switch is mounted on the travelling part and hits a fixed stop at each end??

The latter idea is my thought as it works just as well and saves components - where s the switch mounted?? 
Title: Re: Auto Tool Zero Macro Help - I'm 1/3 of the way there!
Post by: ger21 on July 24, 2016, 10:07:06 AM
It doesn't really matter which limit you have setup, as Mach3 will see them all the same. I was just assuming that you had one set to the negative switch.
Quote
Once set, is there a process to home the machine?

As I said before:

Quote
Use the Ref X and Ref Y buttons to home the axis, and they'll set your machine coordinates to -0.25 at the switch locations.
Title: Re: Auto Tool Zero Macro Help - I'm 1/3 of the way there!
Post by: RWElphinstone on July 24, 2016, 12:31:49 PM
So, there is only one switch and its configured as ++ so would possibly be the point furthest away from you? Sounds like you might need a couple more switches at the other ends of the axes for the -- and homing option. Unless of course your machine references to the ++ end and uses soft-limits for the other end. Or, the switch is mounted on the travelling part and hits a fixed stop at each end?? The latter idea is my thought as it works just as well and saves components - where s the switch mounted??

I have two switches wired in parallel at each end of each axis, to one set of inputs. So, if I go past 0" it hits one switch and stops dead. If I go past 49" on the same axis, it hits the other switch and stops dead. Both switches are wired to the same input, and as such, show the same LED lit on the debugging menu when I hit them. (I'm not sure if this is going to cause me a problem with the solution Ger21 is recommending, but I'm hoping it's not.)

It doesn't really matter which limit you have setup, as Mach3 will see them all the same. I was just assuming that you had one set to the negative switch. Use the Ref X and Ref Y buttons to home the axis, and they'll set your machine coordinates to -0.25 at the switch locations.

Thank you for this, and the image for instructions! I do have one question. As I mentioned above to Davek0974, I have two switches for each axis wired to one input. If I use the buttons you mention to home the axis, what happens if the machine hits one of the limit switches on the far side? (i.e. 49"+ on the y-axis, or 98"+ on the x-axis?)
Title: Re: Auto Tool Zero Macro Help - I'm 1/3 of the way there!
Post by: ger21 on July 24, 2016, 12:44:29 PM
If I use the buttons you mention to home the axis, what happens if the machine hits one of the limit switches on the far side? (i.e. 49"+ on the y-axis, or 98"+ on the x-axis?)

Do you mean during homing?

If you check "Home Negative" in Config > Homing/Limits, as I mentioned earlier, it won't, because it will be moving in the other direction.

When you're not homing, all of your switches will act like limit switches, as they have before.
Title: Re: Auto Tool Zero Macro Help - I'm 1/3 of the way there!
Post by: RWElphinstone on August 07, 2016, 02:00:10 PM
It's alive! ALIIIIIVE!!! :) Thank you, everyone, for all of your help! Now, I have one last question. (Of course, right? Because this never ends. LOL.)

I have made some changes to the "Ref All Home" button, to make the X and Y axis come off the limit switches by 0.5" each and re-zero (I'll post the code shortly) but have a question in regards to the Homing Process. Right now, I have my Soft Limits set to 0.25" for both X and Y axis. This means, when I'm using the homing command (via the button), I have to turn off my Soft Limits first, and then, perform the process, and then turn it back on again.

Is there a command I can place in the Ref All Home script that will disable Soft Limits at the beginning of the homing process, and then another command to turn it back on once I have completed?

Thanks again!

Title: Re: Auto Tool Zero Macro Help - I'm 1/3 of the way there!
Post by: ger21 on August 07, 2016, 02:38:05 PM
DoOEMButton(119) toggles softlimits on and off.

You'll want to check the status of OEMLED(815) to see if they are on or off before calling the button.
Title: Re: Auto Tool Zero Macro Help - I'm 1/3 of the way there!
Post by: RWElphinstone on August 07, 2016, 04:12:58 PM
DoOEMButton(119) toggles softlimits on and off. You'll want to check the status of OEMLED(815) to see if they are on or off before calling the button.

Ok, that sounds awesome. Thank you!

I'm not versed in the code, personally, but if it's not too much trouble, is there an easy way to create an "IF" statement to check this? (I'm reading this over, and am not fully understanding how this is to be set.) I get that there should be a line that works like "IF OEMLED(815) is ON THEN DoOEMButton(119) 'If the Soft Limits button is lit, turn it off", but I can't exactly understand how. (I know my pseudo-code is a poor example.)

I appreciate the help!
Title: Re: Auto Tool Zero Macro Help - I'm 1/3 of the way there!
Post by: Davek0974 on August 07, 2016, 04:20:23 PM
You're actually spot on...

If OEMLED(815) then 'if led is on....
  DoOemButton(119)  'turn it off.
End if


:)
Title: Re: Auto Tool Zero Macro Help - I'm 1/3 of the way there!
Post by: RWElphinstone on August 07, 2016, 04:33:38 PM
You're actually spot on...

Wow. You're kidding! Well, thank you very much! I'll implement this.