'G83
'08/20/05 Edited the macro for the new engine. Brian
' March,03,05 - There was a bug with the first peck depth not working from R                   
' Feb 25 - 2005 Got the Macro working and will do a Full peck with                                                
  'C=0 and High speed peck the C=1 that will retract to the last peck depth                                                            
' Feb 23 - 2005 Added parameters and file call to Turn section                                                             
                                                             
' DRill G83 X (optional)  Z (mandatory) Q (Mandatory) R                                                  
                                              
' added tTaper to replace C parameter C will be 0 for G83, 1 for G83.1           
' Added R as peck size in G81.1      
' added check of R > StartZ for G83    
      
                                           
Test = False                                          
                                                 
EndX = tEndX() ' this is the X in the G83 call                                                             
EndZ = tEndZ() ' this is the Z in the G83                                                             
 Q = Abs(tInFeed()) ' Q value , must be included.                                                              
 R = tZClear() ' R value, must be specified                                                             
 C = tTaper() ' C value will be zero or one                              
 RMode = RetractMode()                            
                                                          
StartZ = tZStart()                                                             
' code here for drill cycle..                                           
                                            
Right_Left = -1                                           
                                            
                                                             
ZClearance = .01                                                            
If GetLED (2) Then                                                             
ZClearance = ZClearance *25.4                                                            
End If             
                
If C = 1 Then                                                          
   Code "G00 Z" & StartZ & "X" & EndX               
   Last_Depth = StartZ           
   BeginZ = StartZ           
Else           
   Code "G00 Z" & StartZ & "X " & EndX     
   If R > StartZ Then    
      Last_Depth = StartZ    
      BeginZ = StartZ    
   Else             
      Last_Depth = R    
      BeginZ = R    
   End If                  
End If               
                                                        
Last_Pass = 0                                     
NCounter = 1                                                             
If Test = True Then                                                              
OpenTeachFile( "TestIt.tap")               
Code "(Start Depth = " &  Last_Depth & ")"                              
Code "(R= " & R &")"                                     
Code "(X= " & EndX &")"                                     
Code "(Z= " & EndZ &")"                                     
Code "(Q= " & Q &")"                         
Code "(C= " & C &")"                                     
Code "(Right_Left= " & Right_Left &")"                                     
Code "(Last_Depth= " & Last_Depth &")"                              
Code "(Mode is " & C & ")"                                     
End If                                     
Do                           
Code "G00 Z" & Last_Depth                                                             
Depth_pass = BeginZ + NCounter * Q * Right_Left                                                            
If Depth_pass <= EndZ Then                                                              
Depth_pass = EndZ                                                             
Last_Pass = 1                                                             
End If                                                             
Code "G01 Z" & Depth_Pass                                                             
If C = 1 Then                                                            
Code "G00 Z" & Depth_Pass + R                                                            
Else                                                            
Code "G00 Z" & R                                                             
End If                                                            
Last_Depth = Depth_Pass + ZClearance                                                              
NCounter = NCounter + 1                                    
If NCounter = 30 Then Exit Do                                                             
Loop While (Last_Pass < 1)        
If C = 1 Then       
  R = StartZ       
End If                            
If RMode = 0 Then                                                          
  Code "G00 Z" & StartZ                            
Else                        
  Code "G00 Z" & R                        
End If                         
                                
If Test = True Then                                             
CloseTeachFile()                                             
LoadTeachFile()                                     
End If                                                         
                                                           
                                                             
