'**********************************************************************''   M1200.mls   Tool Probe Functions                        15DEC2010''   Handle all tool probe funtions''**********************************************************************Const toolProbeRadus            = 0.200Const toolProbeRadusAdditional  = 0.050Const backoffDistance           = 0.100Const jogBackTravel             = 0.600Const maxTravel                 = 1.000Const userDRO_touchSpeed        = 1150Const userDRO_rapidSpeed        = 1151Const userDRO_circleDiameter    = 1350Const userDRO_xError            = 1351Const userDRO_yError            = 1352Const userDRO_zError            = 1353Const oemLED_toolProbe          = 825Const oemDRO_xPOS               = 800Const oemDRO_yPOS               = 801Const oemDRO_zPOS               = 802Const oemDRO_xMachinePOS        = 83Const oemDRO_yMachinePOS        = 84Const oemDRO_zMachinePOS        = 85Const oemVar_xTouchPos          = 2000Const oemVar_yTouchPos          = 2001Const oemVar_zTouchPos          = 2002'**********************************************************************''   Main ''**********************************************************************Sub Main()    ' Make sure the Tool Probe is not active    If getOemLED( oemLED_toolProbe ) Then        Message "!!! Tool Probe is Currently Active !!!"        Exit Sub    End If    ' Save the start position to calculate the Error    xStartErrorPosition = GetOEMDRO( oemDRO_xMachinePOS )    yStartErrorPosition = GetOEMDRO( oemDRO_yMachinePOS )    zStartErrorPosition = GetOEMDRO( oemDRO_zMachinePOS )    ' Process the selected tool probe button    buttonId = Param1()    Select Case buttonId        ' XYZ Buttons        Case 1  buttonPosXNegY  ' X+Y-        Case 2  buttonNegY      ' Y-        Case 3  buttonNegXNegY  ' X-Y-        Case 4  buttonPosX      ' X+        Case 5  buttonNegZ      ' Z-        Case 6  buttonNegX      ' X-        Case 7  buttonPosXPosY  ' X+Y+        Case 8  buttonPosY      ' Y+        Case 9  buttonNegXPosY  ' X-Y+                ' ID and OD Functions        Case 10 buttonCircleID  ' C-ID        Case 11 buttonCircleOD  ' C-OD    End Select    ' Get the end position to calculate the Error    SetUserDro( userDRO_xError, xStartErrorPosition - GetOEMDRO( oemDRO_xMachinePOS ))    SetUserDro( userDRO_yError, yStartErrorPosition - GetOEMDRO( oemDRO_yMachinePOS ))    SetUserDro( userDRO_zError, zStartErrorPosition - GetOEMDRO( oemDRO_zMachinePOS ))End Sub '**********************************************************************''   C-OD 'buttonCircleOD'''**********************************************************************Sub buttonCircleOD()    ' Get the current X and Y Machine Coords    xStartPosition = GetOEMDRO( oemDRO_xMachinePOS )    yStartPosition = GetOEMDRO( oemDRO_yMachinePOS )    ' Calculate the max search radius    maxSearchDiameter = GetUserDro( userDRO_circleDiameter )    maxSearchRadius = maxSearchDiameter / 2.000    ' Touch Off the Z Height    If touchOffZ() = 1 Then        Exit Sub    End If            '    ' Find the X Center    '        ' Move to the X Start Search Pos        codeW( "G1 G53 X" & xStartPosition + maxSearchRadius & " F" & GetUserDro( userDRO_rapidSpeed ) )                ' Bring the Z Down        If moveDownTheZ() = 1 Then            Exit Sub        End If                ' Search for X-        If touchOffNegX( maxSearchRadius ) = 1 Then            Exit Sub        End If                    ' Save Neg X        xNegPosition = GetOEMDRO( oemDRO_xMachinePOS )            ' Bring Z Up        codeW( "G1 Z.1 F" & GetUserDro( userDRO_rapidSpeed ) )        ' Move to the X Start Search Pos        codeW( "G1 G53 X" & xStartPosition - maxSearchRadius & " F" & GetUserDro( userDRO_rapidSpeed ) )        ' Bring the Z Down        If moveDownTheZ() = 1 Then            Exit Sub        End If                ' Search for X+        If touchOffPosX( maxSearchRadius ) = 1 Then            Exit Sub        End If                    ' Save Pos X        xPosPosition = GetOEMDRO( oemDRO_xMachinePOS )                ' Bring Z Up        codeW( "G1 Z.1 F" & GetUserDro( userDRO_rapidSpeed ) )            ' Move to the NEW Center of X        xCenter = ( xNegPosition + xPosPosition ) / 2        codeW( "G1 G53 X" & xCenter & " F" & GetUserDro( userDRO_rapidSpeed ) )            '    ' Find the Y Center    '        ' Move to the Y Start Search Pos        codeW( "G1 G53 Y" & yStartPosition + maxSearchRadius & " F" & GetUserDro( userDRO_rapidSpeed ) )                ' Bring the Z Down        If moveDownTheZ() = 1 Then            Exit Sub        End If                ' Search for Y-        If touchOffNegY( maxSearchRadius ) = 1 Then            Exit Sub        End If                    ' Save Neg Y        yNegPosition = GetOEMDRO( oemDRO_yMachinePOS )            ' Bring Z Up        codeW( "G1 Z.1 F" & GetUserDro( userDRO_rapidSpeed ) )        ' Move to the Y Start Search Pos        codeW( "G1 G53 Y" & yStartPosition - maxSearchRadius & " F" & GetUserDro( userDRO_rapidSpeed ) )        ' Bring the Z Down        If moveDownTheZ() = 1 Then            Exit Sub        End If                ' Search for Y+        If touchOffPosY( maxSearchRadius ) = 1 Then            Exit Sub        End If                    ' Save Pos Y        yPosPosition = GetOEMDRO( oemDRO_yMachinePOS )                ' Bring Z Up        codeW( "G1 Z.1 F" & GetUserDro( userDRO_rapidSpeed ) )            ' Move to the NEW Center of Y        yCenter = ( yNegPosition + yPosPosition ) / 2        codeW( "G1 G53 Y" & yCenter & " F" & GetUserDro( userDRO_rapidSpeed ) )        '    ' We are now in at the center of the hole, update the DROs    '    SetOEMDRO( oemDRO_xPOS, 0.000 )    SetOEMDRO( oemDRO_yPOS, 0.000 )End Sub '**********************************************************************''   C-ID 'buttonCircleID'''**********************************************************************Sub buttonCircleID()    ' Get the current X and Y Machine Coords    xStartPosition = GetOEMDRO( oemDRO_xMachinePOS )    yStartPosition = GetOEMDRO( oemDRO_yMachinePOS )    ' Calculate the max search radius    maxSearchDiameter = GetUserDro( userDRO_circleDiameter )    maxSearchRadius = maxSearchDiameter / 2.000    '    ' Find the X Center    '        ' Search for X-        If touchOffNegX( maxSearchRadius ) = 1 Then            Exit Sub        End If                    ' Save Neg X        xNegPosition = GetOEMDRO( oemDRO_xMachinePOS )            ' Move back to the Start        codeW( "G1 G53 X" & xStartPosition & " F" & GetUserDro( userDRO_rapidSpeed ) )            ' Search for X+        If touchOffPosX( maxSearchRadius ) = 1 Then            Exit Sub        End If                    ' Save Pos X        xPosPosition = GetOEMDRO( oemDRO_xMachinePOS )            ' Move to the NEW Center of X        xCenter = ( xNegPosition + xPosPosition ) / 2        codeW( "G1 G53 X" & xCenter & " F" & GetUserDro( userDRO_rapidSpeed ) )        '    ' Find the Y Center    '        ' Search for Y-        If touchOffNegY( maxSearchRadius ) = 1 Then            Exit Sub        End If                    ' Save Neg Y        yNegPosition = GetOEMDRO( oemDRO_yMachinePOS )            ' Move back to the Start        codeW( "G1 G53 Y" & yStartPosition & " F" & GetUserDro( userDRO_rapidSpeed ) )            ' Search for Y+        If touchOffPosY( maxSearchRadius ) = 1 Then            Exit Sub        End If                    ' Save Pos Y        yPosPosition = GetOEMDRO( oemDRO_yMachinePOS )            ' Move to the NEW Center of Y        yCenter = ( yNegPosition + yPosPosition ) / 2        codeW( "G1 G53 Y" & yCenter & " F" & GetUserDro( userDRO_rapidSpeed ) )        '    ' We are now in at the center of the hole, update the DROs    '    SetOEMDRO( oemDRO_xPOS, 0.000 )    SetOEMDRO( oemDRO_yPOS, 0.000 )End Sub '**********************************************************************''   X+Y+ 'buttonPosXPosY'''**********************************************************************Sub buttonPosXPosY()    ' Touch Off the Z Height    If touchOffZ() = 1 Then        Exit Sub    End If            ' Positon for X+    xNewPosition = GetOEMDRO( oemDRO_xPOS ) - jogBackTravel    codeW( "G1 X" & xNewPosition & " F" & GetUserDro( userDRO_rapidSpeed ) )    ' Bring Z Down    If moveDownTheZ() = 1 Then        Exit Sub    End If            ' Touch off the X    If touchOffPosX( maxTravel ) = 1 Then        Exit Sub    End If            ' Bring Z Up    codeW( "G1 Z.1 F" & GetUserDro( userDRO_rapidSpeed ) )        ' Positon for Y+    xNewPosition = 0.000 + backoffDistance + toolProbeRadus    yNewPosition = GetOEMDRO( oemDRO_yPOS ) - jogBackTravel    codeW( "G1 X" & xNewPosition & "Y" & yNewPosition & "F" & GetUserDro( userDRO_rapidSpeed ) )            ' Bring Z Down    If moveDownTheZ() = 1 Then        Exit Sub    End If            ' Touch off the Y    If touchOffPosY( maxTravel ) = 1 Then        Exit Sub    End If            ' Park at the new Zero    codeW( "G1 Z.1 F" & GetUserDro( userDRO_rapidSpeed ) )    codeW( "G1 Y0 X0 F" & GetUserDro( userDRO_rapidSpeed ) )    End Sub '**********************************************************************''   X+Y- 'buttonPosXNegY'''**********************************************************************Sub buttonPosXNegY()    ' Touch Off the Z Height    If touchOffZ() = 1 Then        Exit Sub    End If            ' Positon for X+    xNewPosition = GetOEMDRO( oemDRO_xPOS ) - jogBackTravel    codeW( "G1 X" & xNewPosition & " F" & GetUserDro( userDRO_rapidSpeed ) )    ' Bring Z Down    If moveDownTheZ() = 1 Then        Exit Sub    End If            ' Touch off the X    If touchOffPosX( maxTravel ) = 1 Then        Exit Sub    End If            ' Bring Z Up    codeW( "G1 Z.1 F" & GetUserDro( userDRO_rapidSpeed ) )        ' Positon for Y-    xNewPosition = 0.000 + backoffDistance + toolProbeRadus    yNewPosition = GetOEMDRO( oemDRO_yPOS ) + jogBackTravel    codeW( "G1 X" & xNewPosition & "Y" & yNewPosition & "F" & GetUserDro( userDRO_rapidSpeed ) )            ' Bring Z Down    If moveDownTheZ() = 1 Then        Exit Sub    End If            ' Touch off the Y    If touchOffNegY( maxTravel ) = 1 Then        Exit Sub    End If            ' Park at the new Zero    codeW( "G1 Z.1 F" & GetUserDro( userDRO_rapidSpeed ) )    codeW( "G1 Y0 X0 F" & GetUserDro( userDRO_rapidSpeed ) )    End Sub '**********************************************************************''   X-Y- 'buttonNegXNegY'''**********************************************************************Sub buttonNegXNegY()    ' Touch Off the Z Height    If touchOffZ() = 1 Then        Exit Sub    End If            ' Positon for X    xNewPosition = GetOEMDRO( oemDRO_xPOS ) + jogBackTravel    codeW( "G1 X" & xNewPosition & " F" & GetUserDro( userDRO_rapidSpeed ) )    ' Bring Z Down    If moveDownTheZ() = 1 Then        Exit Sub    End If            ' Touch off the X    If touchOffNegX( maxTravel ) = 1 Then        Exit Sub    End If            ' Bring Z Up    codeW( "G1 Z.1 F" & GetUserDro( userDRO_rapidSpeed ) )        ' Positon for Y    xNewPosition = 0.000 - backoffDistance - toolProbeRadus    yNewPosition = GetOEMDRO( oemDRO_yPOS ) + jogBackTravel    codeW( "G1 X" & xNewPosition & "Y" & yNewPosition & "F" & GetUserDro( userDRO_rapidSpeed ) )            ' Bring Z Down    If moveDownTheZ() = 1 Then        Exit Sub    End If            ' Touch off the Y    If touchOffNegY( maxTravel ) = 1 Then        Exit Sub    End If            ' Park at the new Zero    codeW( "G1 Z.1 F" & GetUserDro( userDRO_rapidSpeed ) )    codeW( "G1 Y0 X0 F" & GetUserDro( userDRO_rapidSpeed ) )    End Sub '**********************************************************************''   X-Y+ 'buttonNegXPosY'''**********************************************************************Sub buttonNegXPosY()    ' Touch Off the Z Height    If touchOffZ() = 1 Then        Exit Sub    End If            ' Positon for X    xNewPosition = GetOEMDRO( oemDRO_xPOS ) + jogBackTravel    codeW( "G1 X" & xNewPosition & " F" & GetUserDro( userDRO_rapidSpeed ) )    ' Bring Z Down    If moveDownTheZ() = 1 Then        Exit Sub    End If            ' Touch off the X    If touchOffNegX( maxTravel ) = 1 Then        Exit Sub    End If            ' Bring Z Up    codeW( "G1 Z.1 F" & GetUserDro( userDRO_rapidSpeed ) )        ' Positon for Y    xNewPosition = 0.000 - backoffDistance - toolProbeRadus    yNewPosition = GetOEMDRO( oemDRO_yPOS ) - jogBackTravel    codeW( "G1 X" & xNewPosition & "Y" & yNewPosition & "F" & GetUserDro( userDRO_rapidSpeed ) )            ' Bring Z Down    If moveDownTheZ() = 1 Then        Exit Sub    End If            ' Touch off the Y    If touchOffPosY( maxTravel ) = 1 Then        Exit Sub    End If            ' Park at the new Zero    codeW( "G1 Z.1 F" & GetUserDro( userDRO_rapidSpeed ) )    codeW( "G1 Y0 X0 F" & GetUserDro( userDRO_rapidSpeed ) )    End Sub '**********************************************************************''   Z- 'buttonNegZ'''**********************************************************************Sub buttonNegZ()    ' Touch Off the Z Height    If touchOffZ() = 1 Then        Exit Sub    End If        End Sub '**********************************************************************''   Y+ 'buttonPosY'''**********************************************************************Sub buttonPosY()    ' Touch Off the Z Height    If touchOffZ() = 1 Then        Exit Sub    End If            ' Positon for Y+    yNewPosition = GetOEMDRO( oemDRO_yPOS ) - jogBackTravel    codeW( "G1 Y" & yNewPosition & " F" & GetUserDro( userDRO_rapidSpeed ) )    ' Bring Z Down    If moveDownTheZ() = 1 Then        Exit Sub    End If                ' Touch off the Y    If touchOffPosY( maxTravel ) = 1 Then        Exit Sub    End If            ' Park at the new Zero    codeW( "G1 Z.1 F" & GetUserDro( userDRO_rapidSpeed ) )    codeW( "G1 Y0 F" & GetUserDro( userDRO_rapidSpeed ) )    End Sub '**********************************************************************''   Y- 'buttonNegY'''**********************************************************************Sub buttonNegY()        ' Touch Off the Z Height    If touchOffZ() = 1 Then        Exit Sub    End If                ' Positon for Y-    yNewPosition = GetOEMDRO( oemDRO_yPOS ) + jogBackTravel    codeW( "G1 Y" & yNewPosition & " F" & GetUserDro( userDRO_rapidSpeed ) )        ' Bring Z Down    If moveDownTheZ() = 1 Then        Exit Sub    End If            ' Touch off the Y    If touchOffNegY( maxTravel ) = 1 Then        Exit Sub    End If            ' Move Z Up    codeW( "G1 Z.1 F" & GetUserDro( userDRO_rapidSpeed ) )    codeW( "G1 Y0 F" & GetUserDro( userDRO_rapidSpeed ) )End Sub '**********************************************************************''   X+ 'buttonPosX'''**********************************************************************Sub buttonPosX()    ' Touch Off the Z Height    If touchOffZ() = 1 Then        Exit Sub    End If            ' Positon for X+    xNewPosition = GetOEMDRO( oemDRO_xPOS ) - jogBackTravel    codeW( "G1 X" & xNewPosition & " F" & GetUserDro( userDRO_rapidSpeed ) )    ' Bring Z Down    If moveDownTheZ() = 1 Then        Exit Sub    End If            ' Touch off the X    If touchOffPosX( maxTravel ) = 1 Then        Exit Sub    End If            ' Park at the new Zero    codeW( "G1 Z.1 F" & GetUserDro( userDRO_rapidSpeed ) )    codeW( "G1 X0 F" & GetUserDro( userDRO_rapidSpeed ) )    End Sub '**********************************************************************''   X- 'buttonNegX'''**********************************************************************Sub buttonNegX()    ' Touch Off the Z Height    If touchOffZ() = 1 Then        Exit Sub    End If            ' Positon for X-    xNewPosition = GetOEMDRO( oemDRO_xPOS ) + jogBackTravel    codeW( "G1 X" & xNewPosition & " F" & GetUserDro( userDRO_rapidSpeed ) )    ' Bring Z Down    If moveDownTheZ() = 1 Then        Exit Sub    End If                ' Touch off the X    If touchOffNegX( maxTravel ) = 1 Then        Exit Sub    End If            ' Park at the new Zero    codeW( "G1 Z.1 F" & GetUserDro( userDRO_rapidSpeed ) )    codeW( "G1 X0 F" & GetUserDro( userDRO_rapidSpeed ) )    End Sub '**********************************************************************''   touchOffZ''   Finds the Z-, backs it off 0.100 and updates the Z DRO''   Returns 0 Success, 1 Failure''**********************************************************************Function touchOffZ() As Integer    ' Set the default error code to FAILURE    touchOffZ = 1    ' Calculate MAX travel and Move    zNewPosition = GetOEMDRO( oemDRO_zPOS ) - maxTravel    codeW( "G31 Z" & zNewPosition & " F" & GetUserDro( userDRO_touchSpeed ) )    ' Are we Touched or did we Error    If getOemLED( oemLED_toolProbe ) = 0 Then         Message "!!! Z- Tool Probe did not reach the target !!!"        Exit Sub    End If    ' Get the touch position    zTouchPosition = GetVar( oemVar_zTouchPos )        ' Calculate the backoff park spot and Move    zNewPosition = zTouchPosition + backoffDistance    codeW( "G1 Z" & zNewPosition & " F" & GetUserDro( userDRO_rapidSpeed ) )    ' Update the DRO with the new position    SetOEMDRO( oemDRO_zPOS, 0.000 + backoffDistance )    ' Success: Update the return code    touchOffZ = 0    End Function'**********************************************************************''   touchOffPosX''   Finds the X+, backs it off 0.100 and updates the X DRO''   Returns 0 Success, 1 Failure''**********************************************************************Function touchOffPosX( ByVal searchTravel As Variant ) As Integer    ' Set the default error code to FAILURE    touchOffPosX = 1    ' Calculate MAX travel and Move    xNewPosition = GetOEMDRO( oemDRO_xPOS ) + searchTravel    codeW( "G31 X" & xNewPosition & " F" & GetUserDro( userDRO_touchSpeed ) )    ' Are we Touched or did we Error    If getOemLED( oemLED_toolProbe ) = 0 Then        Message "!!! X+ Tool Probe did not reach the target !!!"        Exit Sub    End If    ' Get the touch position    xTouchPosition = GetVar( oemVar_xTouchPos )        ' Calculate the backoff park spot and Move    xNewPosition = xTouchPosition - backoffDistance    codeW( "G1 X" & xNewPosition & " F" & GetUserDro( userDRO_rapidSpeed ) )    ' Update the DRO with the new position    SetOEMDRO( oemDRO_xPOS, 0.000 - toolProbeRadus - backoffDistance )    ' Success: Update the return code    touchOffPosX = 0    End Function'**********************************************************************''   touchOffNegX''   Finds the X-, backs it off 0.100 and updates the X DRO''   Returns 0 Success, 1 Failure''**********************************************************************Function touchOffNegX( ByVal searchTravel As Variant ) As Integer    ' Set the default error code to FAILURE    touchOffNegX = 1    ' Calculate MAX travel and Move    xNewPosition = GetOEMDRO( oemDRO_xPOS ) - searchTravel    codeW( "G31 X" & xNewPosition & " F" & GetUserDro( userDRO_touchSpeed ) )    ' Are we Touched or did we Error    If getOemLED( oemLED_toolProbe ) = 0 Then        Message "!!! X- Tool Probe did not reach the target !!!"        Exit Sub    End If    ' Get the touch position    xTouchPosition = GetVar( oemVar_xTouchPos )        ' Calculate the backoff park spot and Move    xNewPosition = xTouchPosition + backoffDistance    codeW( "G1 X" & xNewPosition & " F" & GetUserDro( userDRO_rapidSpeed ) )    ' Update the DRO with the new position    SetOEMDRO( oemDRO_xPOS, 0.000 + toolProbeRadus + backoffDistance )    ' Success: Update the return code    touchOffNegX = 0    End Function'**********************************************************************''   touchOffNegY''   Finds the Y-, backs it off 0.100 and updates the Y DRO''   Returns 0 Success, 1 Failure''**********************************************************************Function touchOffNegY( ByVal searchTravel As Variant ) As Integer    ' Set the default error code to FAILURE    touchOffNegY = 1    ' Calculate MAX travel and Move    yNewPosition = GetOEMDRO( oemDRO_yPOS ) - searchTravel    codeW( "G31 Y" & yNewPosition & " F" & GetUserDro( userDRO_touchSpeed ) )    ' Are we Touched or did we Error    If getOemLED( oemLED_toolProbe ) = 0 Then        Message "!!! Y- Tool Probe did not reach the target !!!"        Exit Sub    End If    ' Get the touch position    yTouchPosition = GetVar( oemVar_yTouchPos )        ' Calculate the backoff park spot and Move    yNewPosition = yTouchPosition + backoffDistance    codeW( "G1 Y" & yNewPosition & " F" & GetUserDro( userDRO_rapidSpeed ) )    ' Update the DRO with the new position    SetOEMDRO( oemDRO_yPOS, 0.000 + toolProbeRadus + backoffDistance )    ' Success: Update the return code    touchOffNegY = 0    End Function'**********************************************************************''   touchOffPosY''   Finds the Y+, backs it off 0.100 and updates the Y DRO''   Returns 0 Success, 1 Failure''**********************************************************************Function touchOffPosY( ByVal searchTravel As Variant ) As Integer    ' Set the default error code to FAILURE    touchOffPosY = 1    ' Calculate MAX travel and Move    yNewPosition = GetOEMDRO( oemDRO_yPOS ) + searchTravel    codeW( "G31 Y" & yNewPosition & " F" & GetUserDro( userDRO_touchSpeed ) )    ' Are we Touched or did we Error    If getOemLED( oemLED_toolProbe ) = 0 Then        Message "!!! Y+ Tool Probe did not reach the target !!!"        Exit Sub    End If    ' Get the touch position    yTouchPosition = GetVar( oemVar_yTouchPos )        ' Calculate the backoff park spot and Move    yNewPosition = yTouchPosition - backoffDistance    codeW( "G1 Y" & yNewPosition & " F" & GetUserDro( userDRO_rapidSpeed ) )    ' Update the DRO with the new position    SetOEMDRO( oemDRO_yPOS, 0.000 - toolProbeRadus - backoffDistance )    ' Success: Update the return code    touchOffPosY = 0    End Function'**********************************************************************''   moveDownTheZ''   Moves the Z Axis Down while checking for a Probe Hit.  This prevents'   the probe from crashing''   Returns 0 Success, 1 Failure''**********************************************************************Function moveDownTheZ() As Integer    ' Set the default error code to FAILURE    moveDownTheZ = 1    zNewPosition = 0.000 - toolProbeRadus - toolProbeRadusAdditional    codeW( "G31 Z" & zNewPosition & " F" & GetUserDro( userDRO_rapidSpeed ) )    ' Did the Z Crash?    If getOemLED( oemLED_toolProbe ) Then        Message "!!! Z Crashed into Stock !!!"        Exit Sub    End If    ' Success: Update the return code    moveDownTheZ = 0End Function'**********************************************************************''   codeW helper''   Does a code command with wait''**********************************************************************Sub codeW( ByVal g_codeCommand As String )    ' Send out the G Code Command    Code g_codeCommand        ' Wait for the machine to stop moving    While IsMoving()               Sleep 10    WendEnd Sub 