Hello Guest it is March 28, 2024, 11:48:05 AM

Author Topic: VB Script  (Read 4821 times)

0 Members and 1 Guest are viewing this topic.

Re: VB Script
« Reply #20 on: October 10, 2018, 03:45:52 AM »
Once again mate, many thanks for the time you are taking to help me out here :)

Gave this a try this morning and we are certainly getting somewhere. I am probing between two edges that I know to be roughly 40mm apart.

I place the probe (deliberately) off centre in the space and click on "Probe"  The probe starts to move X- and stops when it touches the edge and I now get this message



I click "OK" again and the probe starts to move X+,  after touching the opposite edge, it stops and I get this message



I click "OK" once more and it then backs off a tiny amount and I get this message



Clicking "OK" once more will then return the probe to the centre of the part and the X dro will update to 0.000, so it is in fact now working. I just don't understand the third message that I get with the tiny number !

Offline TPS

*
  •  2,501 2,501
    • View Profile
Re: VB Script
« Reply #21 on: October 10, 2018, 04:48:05 AM »
the third number is the calculated Center of the two Pobepositions:


Center = ProbeXNeg + ((ProbeXPos - ProbeXNeg) / 2)







anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.
Re: VB Script
« Reply #22 on: October 10, 2018, 06:39:45 AM »
the third number is the calculated Center of the two Pobepositions:


Center = ProbeXNeg + ((ProbeXPos - ProbeXNeg) / 2)








Ahh, I see.   Looks like it is giving the centre of the tiny amount that it backs off, after probing X+

Offline TPS

*
  •  2,501 2,501
    • View Profile
Re: VB Script
« Reply #23 on: October 10, 2018, 07:00:12 AM »
here is a Version with a small delay after the probes, maybe it is more acurate

Code: [Select]
'simple X-center script
Sub Main()
SetOEMDro(800,0)

    'do the X- probe
    Message ("probe X- ")
    Code "G31 X-100 F150"
    While IsMoving()
        x = GetOEMDRO(800) 'X actpos
        If x <= -100 Then
            DoOEMButton(1003) 'Stop too far no probe hit
            MsgBox ("Probe X- canceled , no probe hit!" )
            Exit Sub
        End If
    Wend           

Sleep(200)
'get the exact probepos
ProbeXNeg = GetVar(2000)


MsgBox "X Probe - : " + CStr(ProbeXNeg)


'clear the probe
Code "G91 X2 F150"
    While IsMoving()
Sleep(10)
    Wend           
Code "G90"


    'do the X+ probe
    Message ("probe X+ ")
    Code "G31 X200 F150"
    While IsMoving()
        x = GetOEMDRO(800) 'X actpos
        If x >= 200 Then
            DoOEMButton(1003) 'Stop too far no probe hit
            MsgBox ("Probe X+ canceled , no probe hit!" )
            Exit Sub
        End If
    Wend           

Sleep(200)
'get the exact probepos
ProbeXPos = GetVar(2000)


MsgBox "X Probe + : " + CStr(ProbeXPos)



'clear the probe
Code "G91 X-2 F150"
    While IsMoving()
Sleep(10)
    Wend           
Code "G90"

'goto the center
middle = ProbeXNeg + ((ProbeXPos - ProbeXNeg)/2)
Code "G90 G01 X" + CStr(middle)
    While IsMoving()
Sleep(10)
    Wend           
SetOEMDro(800,0)

End Sub

anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.
Re: VB Script
« Reply #24 on: October 10, 2018, 12:04:14 PM »
here is a Version with a small delay after the probes, maybe it is more acurate

Code: [Select]
'simple X-center script
Sub Main()
SetOEMDro(800,0)

    'do the X- probe
    Message ("probe X- ")
    Code "G31 X-100 F150"
    While IsMoving()
        x = GetOEMDRO(800) 'X actpos
        If x <= -100 Then
            DoOEMButton(1003) 'Stop too far no probe hit
            MsgBox ("Probe X- canceled , no probe hit!" )
            Exit Sub
        End If
    Wend           

Sleep(200)
'get the exact probepos
ProbeXNeg = GetVar(2000)


MsgBox "X Probe - : " + CStr(ProbeXNeg)


'clear the probe
Code "G91 X2 F150"
    While IsMoving()
Sleep(10)
    Wend           
Code "G90"


    'do the X+ probe
    Message ("probe X+ ")
    Code "G31 X200 F150"
    While IsMoving()
        x = GetOEMDRO(800) 'X actpos
        If x >= 200 Then
            DoOEMButton(1003) 'Stop too far no probe hit
            MsgBox ("Probe X+ canceled , no probe hit!" )
            Exit Sub
        End If
    Wend           

Sleep(200)
'get the exact probepos
ProbeXPos = GetVar(2000)


MsgBox "X Probe + : " + CStr(ProbeXPos)



'clear the probe
Code "G91 X-2 F150"
    While IsMoving()
Sleep(10)
    Wend           
Code "G90"

'goto the center
middle = ProbeXNeg + ((ProbeXPos - ProbeXNeg)/2)
Code "G90 G01 X" + CStr(middle)
    While IsMoving()
Sleep(10)
    Wend           
SetOEMDro(800,0)

End Sub



Success !!! That seems to have got it my friend. It is now working perfectly (apart from having to click on the "OK" buttons) I am assuming that the debugging can be removed.

Also, while I am at it, could a Y centre script be done by replacing all instances of  X-  X+   with  Y- Y+ ?

Thank you so much for all your help, much appreciated.

Offline TPS

*
  •  2,501 2,501
    • View Profile
Re: VB Script
« Reply #25 on: October 11, 2018, 02:29:46 AM »
here we have the X-Center without the debug Windows
Code: [Select]
'simple X-center script
Sub Main()
SetOEMDro(800,0)

    'do the X- probe
    Message ("probe X- ")
    Code "G31 X-100 F150"
    While IsMoving()
        x = GetOEMDRO(800) 'X actpos
        If x <= -100 Then
            DoOEMButton(1003) 'Stop too far no probe hit
            MsgBox ("Probe X- canceled , no probe hit!" )
            Exit Sub
        End If
    Wend           

Sleep(200)
'get the exact probepos
ProbeXNeg = GetVar(2000)

'clear the probe
Code "G91 X2 F150"
    While IsMoving()
Sleep(10)
    Wend           
Code "G90"


    'do the X+ probe
    Message ("probe X+ ")
    Code "G31 X200 F150"
    While IsMoving()
        x = GetOEMDRO(800) 'X actpos
        If x >= 200 Then
            DoOEMButton(1003) 'Stop too far no probe hit
            MsgBox ("Probe X+ canceled , no probe hit!" )
            Exit Sub
        End If
    Wend           

Sleep(200)
'get the exact probepos
ProbeXPos = GetVar(2000)

'clear the probe
Code "G91 X-2 F150"
    While IsMoving()
Sleep(10)
    Wend           
Code "G90"

'goto the center
middle = ProbeXNeg + ((ProbeXPos - ProbeXNeg)/2)
Code "G90 G01 X" + CStr(middle)
    While IsMoving()
Sleep(10)
    Wend           
SetOEMDro(800,0)

End Sub


and the y-Center

Code: [Select]
'simple Y-center script
Sub Main()
SetOEMDro(801,0)

    'do the Y- probe
    Message ("probe Y- ")
    Code "G31 Y-100 F150"
    While IsMoving()
        y = GetOEMDRO(801) 'Y actpos
        If y <= -100 Then
            DoOEMButton(1003) 'Stop too far no probe hit
            MsgBox ("Probe Y- canceled , no probe hit!" )
            Exit Sub
        End If
    Wend           

Sleep(200)
'get the exact probepos
ProbeYNeg = GetVar(2001)

'clear the probe
Code "G91 Y2 F150"
    While IsMoving()
Sleep(10)
    Wend           
Code "G90"


    'do the Y+ probe
    Message ("probe Y+ ")
    Code "G31 Y200 F150"
    While IsMoving()
        y = GetOEMDRO(801) 'Y actpos
        If y >= 200 Then
            DoOEMButton(1003) 'Stop too far no probe hit
            MsgBox ("Probe Y+ canceled , no probe hit!" )
            Exit Sub
        End If
    Wend           

Sleep(200)
'get the exact probepos
ProbeYPos = GetVar(2001)

'clear the probe
Code "G91 Y-2 F150"
    While IsMoving()
Sleep(10)
    Wend           
Code "G90"

'goto the center
middle = ProbeYNeg + ((ProbeYPos - ProbeYNeg)/2)
Code "G90 G01 Y" + CStr(middle)
    While IsMoving()
Sleep(10)
    Wend           
SetOEMDro(801,0)

End Sub



hope i did everthing right


 
anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.
Re: VB Script
« Reply #26 on: October 11, 2018, 03:09:16 AM »
here we have the X-Center without the debug Windows
Code: [Select]
'simple X-center script
Sub Main()
SetOEMDro(800,0)

    'do the X- probe
    Message ("probe X- ")
    Code "G31 X-100 F150"
    While IsMoving()
        x = GetOEMDRO(800) 'X actpos
        If x <= -100 Then
            DoOEMButton(1003) 'Stop too far no probe hit
            MsgBox ("Probe X- canceled , no probe hit!" )
            Exit Sub
        End If
    Wend           

Sleep(200)
'get the exact probepos
ProbeXNeg = GetVar(2000)

'clear the probe
Code "G91 X2 F150"
    While IsMoving()
Sleep(10)
    Wend           
Code "G90"


    'do the X+ probe
    Message ("probe X+ ")
    Code "G31 X200 F150"
    While IsMoving()
        x = GetOEMDRO(800) 'X actpos
        If x >= 200 Then
            DoOEMButton(1003) 'Stop too far no probe hit
            MsgBox ("Probe X+ canceled , no probe hit!" )
            Exit Sub
        End If
    Wend           

Sleep(200)
'get the exact probepos
ProbeXPos = GetVar(2000)

'clear the probe
Code "G91 X-2 F150"
    While IsMoving()
Sleep(10)
    Wend           
Code "G90"

'goto the center
middle = ProbeXNeg + ((ProbeXPos - ProbeXNeg)/2)
Code "G90 G01 X" + CStr(middle)
    While IsMoving()
Sleep(10)
    Wend           
SetOEMDro(800,0)

End Sub


and the y-Center

Code: [Select]
'simple Y-center script
Sub Main()
SetOEMDro(801,0)

    'do the Y- probe
    Message ("probe Y- ")
    Code "G31 Y-100 F150"
    While IsMoving()
        y = GetOEMDRO(801) 'Y actpos
        If y <= -100 Then
            DoOEMButton(1003) 'Stop too far no probe hit
            MsgBox ("Probe Y- canceled , no probe hit!" )
            Exit Sub
        End If
    Wend           

Sleep(200)
'get the exact probepos
ProbeYNeg = GetVar(2001)

'clear the probe
Code "G91 Y2 F150"
    While IsMoving()
Sleep(10)
    Wend           
Code "G90"


    'do the Y+ probe
    Message ("probe Y+ ")
    Code "G31 Y200 F150"
    While IsMoving()
        y = GetOEMDRO(801) 'Y actpos
        If y >= 200 Then
            DoOEMButton(1003) 'Stop too far no probe hit
            MsgBox ("Probe Y+ canceled , no probe hit!" )
            Exit Sub
        End If
    Wend           

Sleep(200)
'get the exact probepos
ProbeYPos = GetVar(2001)

'clear the probe
Code "G91 Y-2 F150"
    While IsMoving()
Sleep(10)
    Wend           
Code "G90"

'goto the center
middle = ProbeYNeg + ((ProbeYPos - ProbeYNeg)/2)
Code "G90 G01 Y" + CStr(middle)
    While IsMoving()
Sleep(10)
    Wend           
SetOEMDro(801,0)

End Sub



hope i did everthing right


 
Thank you again for all your help my friend. It will be later tonight before I can try it but I will let you know how it goes.
Re: VB Script
« Reply #27 on: October 11, 2018, 02:08:30 PM »
here we have the X-Center without the debug Windows
Code: [Select]
'simple X-center script
Sub Main()
SetOEMDro(800,0)

    'do the X- probe
    Message ("probe X- ")
    Code "G31 X-100 F150"
    While IsMoving()
        x = GetOEMDRO(800) 'X actpos
        If x <= -100 Then
            DoOEMButton(1003) 'Stop too far no probe hit
            MsgBox ("Probe X- canceled , no probe hit!" )
            Exit Sub
        End If
    Wend           

Sleep(200)
'get the exact probepos
ProbeXNeg = GetVar(2000)

'clear the probe
Code "G91 X2 F150"
    While IsMoving()
Sleep(10)
    Wend           
Code "G90"


    'do the X+ probe
    Message ("probe X+ ")
    Code "G31 X200 F150"
    While IsMoving()
        x = GetOEMDRO(800) 'X actpos
        If x >= 200 Then
            DoOEMButton(1003) 'Stop too far no probe hit
            MsgBox ("Probe X+ canceled , no probe hit!" )
            Exit Sub
        End If
    Wend           

Sleep(200)
'get the exact probepos
ProbeXPos = GetVar(2000)

'clear the probe
Code "G91 X-2 F150"
    While IsMoving()
Sleep(10)
    Wend           
Code "G90"

'goto the center
middle = ProbeXNeg + ((ProbeXPos - ProbeXNeg)/2)
Code "G90 G01 X" + CStr(middle)
    While IsMoving()
Sleep(10)
    Wend           
SetOEMDro(800,0)

End Sub


and the y-Center

Code: [Select]
'simple Y-center script
Sub Main()
SetOEMDro(801,0)

    'do the Y- probe
    Message ("probe Y- ")
    Code "G31 Y-100 F150"
    While IsMoving()
        y = GetOEMDRO(801) 'Y actpos
        If y <= -100 Then
            DoOEMButton(1003) 'Stop too far no probe hit
            MsgBox ("Probe Y- canceled , no probe hit!" )
            Exit Sub
        End If
    Wend           

Sleep(200)
'get the exact probepos
ProbeYNeg = GetVar(2001)

'clear the probe
Code "G91 Y2 F150"
    While IsMoving()
Sleep(10)
    Wend           
Code "G90"


    'do the Y+ probe
    Message ("probe Y+ ")
    Code "G31 Y200 F150"
    While IsMoving()
        y = GetOEMDRO(801) 'Y actpos
        If y >= 200 Then
            DoOEMButton(1003) 'Stop too far no probe hit
            MsgBox ("Probe Y+ canceled , no probe hit!" )
            Exit Sub
        End If
    Wend           

Sleep(200)
'get the exact probepos
ProbeYPos = GetVar(2001)

'clear the probe
Code "G91 Y-2 F150"
    While IsMoving()
Sleep(10)
    Wend           
Code "G90"

'goto the center
middle = ProbeYNeg + ((ProbeYPos - ProbeYNeg)/2)
Code "G90 G01 Y" + CStr(middle)
    While IsMoving()
Sleep(10)
    Wend           
SetOEMDro(801,0)

End Sub



hope i did everthing right


 
Thank you again for all your help my friend. It will be later tonight before I can try it but I will let you know how it goes.

Just tried the codes you provided and they are working perfectly. Once again, many thanks for helping me out with this, you are indeed a top man.