Machsupport Forum

Mach Discussion => General Mach Discussion => Topic started by: AutoNorv on July 29, 2021, 01:12:38 PM

Title: Problem reading G31 sytem varibles
Post by: AutoNorv on July 29, 2021, 01:12:38 PM
Hi
this is my first post
Please can anyone help me with getting values from system variables?
I am building a machine to grind stump grinder teeth and am trying to learn G code as I go.
Although nothing like a Mill I am using Machmil profile
So far I have managed to get over lots of problems as they came up
But I am stuck
I am using an optical switch as a probe to find depth of Z axis (to determine wear on cutter to be ground)
I am running Mach3 (Version R3.043.062) with a USB breakout board
The digitizer light comes on when the switch is triggered
When I try to read #2002 for the z position I get zero
I have included some sample code
When the machine runs the cutter moves till the light on the switch comes on then returns
And then moves the z axis to 2

g21
#50=3
a4.5 f200
g1 x193 y2 f600
g1 z1
g4 p1
g31 z20 f200
#50=[#2002+2]
g4 p1
z1.25
z#50
m30
(null line to load code)

I have looked at the forum chats and no one else seems to have trouble reading system variables
Am I being dumb or doing something stupid?
Please help

Title: Re: Problem reading G31 sytem varibles
Post by: Stuart on July 29, 2021, 01:22:40 PM
bet you have a Far Eastern USB board installed not setting the 2002 pound var is typical ie they do not work for probing in the 99.99% of them

IMHO get a smooth stepper USB if you must but Ethernet is better
Title: Re: Problem reading G31 sytem varibles
Post by: AutoNorv on July 29, 2021, 01:30:01 PM
Hi thanks for the reply
Yes it is a far eastern  board but I would have thought that if the digitizer light comes on then mach3 would be doing the variable setting internally
Title: Re: Problem reading G31 sytem varibles
Post by: Tweakie.CNC on July 29, 2021, 02:08:19 PM
If the value is not stored in VAR(2002) then there is a good chance that it is stored in OEMDRO(802).

Tweakie.
Title: Re: Problem reading G31 sytem varibles
Post by: AutoNorv on July 29, 2021, 02:58:28 PM
Thanks Tweakie
I have now tried looking at #802 and still got zero.
I seem to get zero from any system variable
any more suggestions?
Title: Re: Problem reading G31 sytem varibles
Post by: Tweakie.CNC on July 30, 2021, 12:49:32 AM
OEMDRO(802) is not a system variable in the same sense as #802. It is usually read within a VB routine as GETOEMDRO(802).

Tweakie.
Title: Re: Problem reading G31 sytem varibles
Post by: AutoNorv on July 30, 2021, 10:33:27 AM
I am not doing to bad with gcode but vb script is a bit beyond me at the moment.
I will try to get some help with it
Title: Re: Problem reading G31 sytem varibles
Post by: Graham Waterworth on July 30, 2021, 12:43:44 PM
#50=[#2002+2]

What is the +2 about?

Have you tried it this way :-

#50=[[#2002]+2]



Title: Re: Problem reading G31 sytem varibles
Post by: AutoNorv on July 30, 2021, 01:03:01 PM
I have now tried #50=[[2002]+2] still moving to 2 (so 0+2)
The plus 2 was because at one point I had it working and the value I got back was 2 higher than the z position I assumed some kind of probe compensation that I could not find.
the time it worked was after a new install but I have tried that again since and no joy.
Title: Re: Problem reading G31 sytem varibles
Post by: AutoNorv on August 01, 2021, 08:51:11 AM
if Tweakie is still seeing this
I now have enough vbscript to display variables in a message box.
But I do not understand the results.
the #2002 #5023 and oemdro(802) all read zero
if I assign a value to #5023 either before or after the g31 code then I get the value that I have assigned.
I don't know what else to try
Title: Re: Problem reading G31 sytem varibles
Post by: ZASto on August 01, 2021, 09:35:25 AM
Hre you have some macros for chinese controller(s), I do not know which one, but I have it in my collection)

https://mega.nz/file/INFz0aqT#wo65uqPkmdppACMRy4mS5vYViE9uBQPdrxEyk6G9-9s
Title: Re: Problem reading G31 sytem varibles
Post by: Tweakie.CNC on August 01, 2021, 10:17:14 AM
If it helps, this is a typical tool height setting script. The line in red would usually read GetVar(2002) but has been changed to GetOEMDRO(802) to allow for the Chinese controllers that do not recognize #2002.

CurrentFeed = GetOemDRO(818) 'Get the current feedrate to return to later
CurrentAbsInc = GetOemLED(48) 'Get the current G90/G91 state
CurrentGmode = GetOemDRO(819) 'Get the current G0/G1 state

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 P3" ' this delay gives me time to get from computer to hold probe in place
Code "G90 G31Z-1. F4" 'probing move, can set the feed rate here as well as how far to move
While IsMoving() 'wait while it happens
Wend
ZProbePos = GetOEMDro(802)  '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, 0.766) ' change 0.766 to your plate thickness and then adjust for final accuracy
Sleep 200 'Pause for Dro to update.
Code "G1 Z1. F5" 'put the Z retract height you want here, must be greater than the touch plate thickness
While IsMoving ()
Wend
Code "(Z axis is now zeroed)" 'puts this message in the status bar
Code "F" &CurrentFeed 'Returns to prior feed rate
Else
Code "(Z-Plate is grounded, check connection and try again)" 'this goes in the status bar if applicable
End If
If CurrentAbsInc = 0 Then 'if G91 was in effect before then return to it
Code "G91"
End If
If CurrentGMode = 0 Then 'if G0 was in effect before then return to it
Code "G0"
End If         
Title: Re: Problem reading G31 sytem varibles
Post by: AutoNorv on August 01, 2021, 05:33:56 PM
I am coming to the conclusion that I need to buy another motion controller.
But I want to get it right this time.
I am running 4 axis but may need a 5th in the future.
the probe must work.
and I need at least 4 outputs plus  motor controls.
I would like to buy it in the UK.
and hopefully not hundreds of pounds.
Any recommendations?
Title: Re: Problem reading G31 sytem varibles
Post by: Tweakie.CNC on August 02, 2021, 02:53:44 AM
If you buy a new motion controller (there are many to choose from) I recommend that you purchase one that is manufactured in the EU or USA and avoid anything made in China.

Tweakie.
Title: Re: Problem reading G31 sytem varibles
Post by: Stuart on August 02, 2021, 10:37:36 AM
here you go
http://www.amadeal.co.uk/
http://emvioeng.com/

got mine ESS from the latter

but note you will still need a BOB or two maybe three as the ESS has three PP 26 pin headers to connect to the BOB

and to qualify my info I did have a Far Eastern motion controller but I built a 3d probe it got smashed researched the problem put it in the square black thing that sits outside the house got the ESS rewired the mill ( 4 axis ) to get rid of the hidden resistors that they had put in the wiring now it works as it should inc. G31 G31.1 G31.2 and G31.3
so 4 axis and 9 proximity limit switches completes the mill

Stuart  central UK

both are ok to deal with but disclaimer I am only a customer and have no ties with either

Title: Re: Problem reading G31 sytem varibles
Post by: AutoNorv on August 04, 2021, 02:54:16 PM
Can anyone tell me how to transfer a value from a vb script variable to a #variable
Title: Re: Problem reading G31 sytem varibles
Post by: TPS on August 05, 2021, 02:43:09 AM
from VB script documentation:

SetVar

Sub SetVar(VarNum As Integer, Val As Double)

This function sets the Mach variable specified by VarNum to the value given by Val.
Mach variables are accessible both to CB scripts, using the SetVar() and GetVar()
functions, as well as G-code programs, using the #nnnn syntax.
Arguments:
VarNum is Integer the number of the Mach variable to be set.
Val is the Double value to which the variable will be set
Return Value:
None

Example:

‘ Set a variable 1234 to our target position of 2.3456
SetVar(1234, 2.3456)

‘ Now move X to our target position
Code “G0 X #1234”

See also:
GetVar()

https://www.machsupport.com/wp-content/uploads/2013/02/Mach3_V3.x_Macro_Prog_Ref.pdf
Title: Re: Problem reading G31 sytem varibles
Post by: AutoNorv on August 05, 2021, 12:23:51 PM
can val be a vb script variable?
Title: Re: Problem reading G31 sytem varibles
Post by: TPS on August 05, 2021, 12:48:22 PM
yes sure.
Code: [Select]
myvariable = 1.234
SetVar(1234,myvariable)

even both arguments can be a VB variable

Code: [Select]
myvariable = 1.234
mysetvar = 1234

SetVar(mysetvar,myvariable)

Title: Re: Problem reading G31 sytem varibles
Post by: AutoNorv on August 06, 2021, 01:29:53 PM
Thanks for all the help folks.
I think that I am getting somewhere now