Hello Guest it is April 16, 2024, 06:30:37 PM

Author Topic: Set Variable to Current Axis Position in G-Code  (Read 5330 times)

0 Members and 1 Guest are viewing this topic.

Set Variable to Current Axis Position in G-Code
« on: March 12, 2016, 11:12:06 AM »
I would like be able to assign the current Y position to a variable in G-Code. This variable would be updated at various points throughout the program. Something similar to the %(2) function in ShopBot. Is this available via a G or M Code, or is this something that would require VB and some type of GETDRO function?

Depending on the options available, what is considered "Best Practice" for accomplishing this in Mach3?

-Thank you.

Offline ger21

*
  • *
  •  6,295 6,295
    • View Profile
    • The CNC Woodworker
Re: Set Variable to Current Axis Position in G-Code
« Reply #1 on: March 12, 2016, 02:52:32 PM »
Create an M code with VB Script, and call the M code in your g-code.
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html
Re: Set Variable to Current Axis Position in G-Code
« Reply #2 on: March 13, 2016, 03:33:49 PM »
Thank you. I have created a macro M801 with the following.

Dim Yaxis As Integer
Yaxis = 801
SetVar (60,Yaxis)

In my G-Code I have a variable (#60) that represents the YLoc. At the time of the call to M801, will the #60 var will be updated with the current Y axis location? As I call M801 later in the program the #60 var will reflect the new location?

I appreciate the help with this.

Offline ger21

*
  • *
  •  6,295 6,295
    • View Profile
    • The CNC Woodworker
Re: Set Variable to Current Axis Position in G-Code
« Reply #3 on: March 13, 2016, 05:06:58 PM »
Is your Y axis value actually going to be an integer, or are you trying to round it off to one? SetVar is expecting a double, so you might get a type mismatch if you try it that way.

Try:

Dim YAxis
Yaxis = GetOEMDRO(801)
SetVar(60,Yaxis)


The answer to both of your questions is yes, it should.
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html