Hello Guest it is December 06, 2019, 12:45:38 PM

Author Topic: Need a beep function for Mach3 - For Touch Plate/Center Finder  (Read 8195 times)

0 Members and 1 Guest are viewing this topic.

Offline Vogavt

*
  •  258 258
    • View Profile
Need a beep function for Mach3 - For Touch Plate/Center Finder
« on: December 24, 2009, 03:27:43 PM »
I've been working on the Auto-zeroing Probe with great success.  Well, that is, as long as I remember to connect the wire to the touch plate/Center Finder.

I've failed to connect the wire twice and on both occasions I've ripped the pipe off the touch plate.  Both instances have been due to distractions (kids) right at the integral moment.

What I need is a snippet of code to put in the *.m1s that forces the computer to Beep. Not the external speakers, but the computer's speaker.


What I'm trying to do here is have the code stop you from performing a centering function until you have touched the spindle at least once. (This is to let Mach know that you may not have connected the wire to the plate just yet).  Once I touch the spindle with the wire/alligator clip, I want the code to resume in ~5 seconds. This will give me enough time to connect the wire to the touch plate and know that it's ready for use.


I can work on the delay factor later. For now here are the attempts I've made in the probe code to just get some sound:

If GetOemLed (825) <> 1 Then       'Forces you to make certain the TPGW is connected
   Code "(Touch Probe Ground Wire is not connected)"
   Beep
End If
------Only works on External Speakers - Need the PC's internal Speaker to work ----


If GetOemLed (825) <> 1 Then       'Forces you to make certain the TPGW is connected
   Code "(Touch Probe Ground Wire is not connected)"
   Beep (500, 1000)
End If
------Only works on External Speakers - Need the PC's internal Speaker to work ----



I turned on the "Allow Speak" function in General Configuration and tried this:

If GetOemLed (825) <> 1 Then       'Forces you to make certain the TPGW is connected
   Code "(Touch Probe Ground Wire is not connected)"
   Speak ("Connect the touch probe ground wire")
End If
------Doesn't work / Don't hear anything ----



I know that the code "If GetOemLed (825) <> 1 " is to look to see if the LED is not lit, and "<> 0" is to check and see if you're already grounded.  That's why I put this in front of the "If GetOemLed (825) <> 0 " portion of the code.


Any help would be appreciated and Merry Christmas to all,

Vogavt
« Last Edit: December 24, 2009, 04:01:24 PM by Vogavt »
Re: Need a beep function for Mach3 - For Touch Plate/Center Finder
« Reply #1 on: December 25, 2009, 07:58:04 PM »
Here is what is working for me, Had to stay away from the beep as it is a VB function.
Add this to the top of the button page:

Private Declare Function BeepAPI Lib "kernel32" Alias "Beep" (ByVal dwFrequency _
    As Long, ByVal dwMilliseconds As Long) As Long


'then this beeps at 500hz for 500ms on the motherboard speaker
BeepAPI 500, 500

good luck
Re: Need a beep function for Mach3 - For Touch Plate/Center Finder
« Reply #2 on: December 29, 2009, 06:54:47 AM »
I added a LED to my touch plate - it is blue.  I touch the plate to my bit, the LED turns blue, I know I have a circuit and so I can run my zero touch plate macro.  It works great.

Offline Vogavt

*
  •  258 258
    • View Profile
Re: Need a beep function for Mach3 - For Touch Plate/Center Finder
« Reply #3 on: January 01, 2010, 04:43:25 PM »
I added a LED to my touch plate - it is blue.  I touch the plate to my bit, the LED turns blue, I know I have a circuit and so I can run my zero touch plate macro.  It works great.

That's pretty cool, but it doesn't address me remembering to actually do that. Still a neat addition, that would keep me from having to crane my neck around to see the Mach3 screen LED.

I suppose it would also be another tool in the tool box because I'm always looking right the the tool with my finger on the ESC key just in case it doesn't stop! This would also help me to make sure I'm not actually grounded while doing the clipping on of the alligator clip. I like it and will give it a whirl.

I will install it inline though not on the touch plate (for me that will work best).

Vogavt
« Last Edit: January 01, 2010, 04:46:22 PM by Vogavt »

Offline Vogavt

*
  •  258 258
    • View Profile
Re: Need a beep function for Mach3 - For Touch Plate/Center Finder
« Reply #4 on: January 01, 2010, 04:47:53 PM »
Here is what is working for me, Had to stay away from the beep as it is a VB function.
Add this to the top of the button page:

Private Declare Function BeepAPI Lib "kernel32" Alias "Beep" (ByVal dwFrequency _
    As Long, ByVal dwMilliseconds As Long) As Long


'then this beeps at 500hz for 500ms on the motherboard speaker
BeepAPI 500, 500

good luck


I'm assuming you mean at the start of the HiddenScript.m1s. Correct?
Re: Need a beep function for Mach3 - For Touch Plate/Center Finder
« Reply #5 on: January 01, 2010, 05:15:14 PM »
Here is the code I use. It requires an initial touch after you click the zero button. When you make that inital touch, the router moves up and down a very short distance to let you know it made the touch. After a short pause, it will start probing downward. If you don't make contat within 15 seconds after clicking hte zero button, the routine wil simply tinme out. This utilizes a screen that has the zero button and a DRO used to specify the thickness of your plate. Note that there are many places used to force Mach to sync up with the code. Some of this code may seem unnessary, but after I added it I have never had a unexpected plunge. USE THIS AT YOUR OWN RISK.


'     Z-AXIS TOUCHPLATE ZERO
'     Author: Kent Janes
'     October 11, 2009
'     Version 1.4

'     This routine is used to zero the Z-axis using a touch probe.
'     The probe must be ungrounded when this routine starts.
'     The user is given 15 seconds to touch the probe to the bit.
'     Once the bit is touched, the z axis will be moved up then down by a small
'     amount to let the user know that the touch was successful. The routine
'     will then pause for 1/2 second to allow the user to move the probe to the
'     top of the workpiece. The system will then move the probe downward until
'     it contacts the touchplate. Once touched,the z-axis DRO is set to the
'     plate thickness (specified by the user and entered on the Mach screen).
'     The z-axis will then be moved upward by the distance specified as
'     Final_Back_Off constant.
 
Dim Final_Backoff
Dim Inital_Backoff
Dim Probing_feed_rate
Dim Plate_Offset
Dim Touched_Flag
Dim Initial_Incremental_Flag
Dim Initial_Machine_Coordinates_Flag
Dim Initial_G_State
Dim Initial_Feed_Rate
Dim Initial_Back_Off
Dim Final_Back_Off
Dim New_Z
Dim i

'     Initialize constants.
   
   Final_Back_Off = 0.20
   Initial_Back_Off = 0.02
   Probing_Feed_Rate = 4
   
'     Display a message and exit if the user has not specified a plate offset.

   Plate_Offset = GetUserDRO(1151)
   If Plate_Offset <= 0 Then
      Code "(A positive value must be entered for the Plate Offset.)"
      Exit Sub
   End If
   
'     Test to see if the touchplate is already grounded or faulty.
'     Display a message and exit if it is grounded.

   If GetOEMLed (825) <> 0 Then       
      Code "(Touchplate is grounded...check connection and try again.)"
      Exit Sub
   End If
   
'   Set the Z-Setter Plate to Material Offset DRO to -999 so that the
'   Z-Setter Tool Change routine will be able to detect that the users
'   is trying to run it when they should not. Some users won't have this
'   DRO so skip this if an error occurs.

   On Error Resume Next
   Call SetUserDRO(1102,-999)
   On Error GoTo 0
   
 '    Loop for a maximum of 15 seconds to let the user touch the probe to the bit.
 '    Exit if the user does not touch the probe to the bit within 15 seconds.
 
   Code "(Briefly touch the probe to the bit to start probing for zero.)"
   Touched_Flag = False
   For i = 1 To 600
      If GetOEMLed (825) <> 0 Then
         Touched_Flag = True
         Exit For
      End If
      Sleep 25
   Next i
   
   If Touched_Flag = False Then
      Code "(The touchplate routine timed out.)"
      Exit Sub
   End If
 
'     Save the incremental mode, the machine coordinates mode,
'     the G0/G1 state, and the feed rate. Then set the system to
'     absolute mode (G90) and to work coordinates mode.

   Initial_Incremental_Flag = GetOEMLed(49)
   Initial_Machine_Coordinates_Flag = GetOEMLEd(16)
   Initial_G_State = GetOEMDRO(819)
   Initial_Feed_Rate = GetOEMDRO(818)
   
   DoOEMButton (180)
   Code "G90"
   While IsMoving()      
      Sleep 100
   Wend
   
'     Move the z-axis upward by the Inital_Back_Off_Amount and then back down.
'     This lets the user know tha they made the inital contact that starts the
'     final probing.
 
   New_Z = GetOEMDRO(802) + Initial_Back_Off
   Code "G0"
   While IsMoving()      
      Sleep 100
   Wend
   Code "G0 Z" & New_Z
   While IsMoving()      
      Sleep 100
   Wend

   New_Z = New_Z - Initial_Back_Off
   Code "G0 Z" & New_Z
   While IsMoving()      
      Sleep 100
   Wend

'     Change the feed rate to the Probing_Feed_Rate and start probing downward
'     after a 1/2 second pause. Also place in G1 mode.
 
   New_Z = GetOEMDRO(802) - 6
   Code "F" & Probing_Feed_Rate
   Code "G1"
   While IsMoving()      
      Sleep 100
   Wend
   Sleep 500      
   Code "G31Z" & New_Z
   While IsMoving()      
      Sleep 100
   Wend
   
'     Move back to the hit point in case there was overshoot.
'     Set the z-DRO to the Plate_Offset. Display a message
'     stating the z-axis is zeroed. Return to the original
'     feed rate.

   New_Z = GetVar(2002)
   Code "G1 Z" & New_Z
   While IsMoving ()
      Sleep 100
   Wend

   Call SetOEMDRO (802,Plate_Offset)
   sleep 250
   Code "G0"
   While IsMoving()      
      Sleep 100
   Wend
   New_Z = Plate_Offset + Final_Back_Off
   Code "G0 Z" & New_Z       
   Code "(Z axis is now zeroed.)"
   While IsMoving ()
      Sleep 100
   Wend

'     Restore the feed rate, the incremental/absolute mode setting, the
'     work coordinates/machine coordinates setting, and the G0/G1 setting
'     to what they were in the beginning.

   Code "F" & Initial_Feed_Rate

   If Initial_Incremental_Flag = True Then
      Code "G91"
   End If
   
   If Initial_Machine_Coordinates_Flag = True Then
      DoOEMButton(179)
   End If

   If Initial_G_State = 0 Then
      Code "G0"
   Else
      Code "G1"
   End If