Need help from the macro experts

Mach3 and Mach4 questions, tips and topics can be posted here
Post Reply
User avatar
djreiswig
4.5 Star Elite Contributing Member
4.5 Star Elite Contributing Member
Posts: 1937
Joined: Thu Nov 19, 2015 10:02 pm
Location: SE Nebraska

Need help from the macro experts

Post by djreiswig »

I have constructed a referencing macro to emulate the dual touch off feature in CommandCNC (as well as incorporating a few other features). It works great for the most part. I have 2 complementary macros that are run from the gcode to set the ohmic or touch leds depending on a setting in the tool in sheetcam. I also have an on screen button to cause the z axis to raise slightly higher to avoid collisions when doing a trial run (block delete feature in mach3) without the THC or torch operating. All this is run from the macro.
The macro works great, except if you try and feedhold while the reference is happening. I've had it crash my smoothstepper and freeze mach.
I think it might have something to do with the ismoving loops, but if I leave them out mach seems to skip over the code.
Any ideas on a way to fix this?

Code: Select all

OhmicLED = 1503 ' LED that indicates OFF
TouchLED = 1504 ' LED that indicates ON
RefFeed = 1120 ' Ref Feed from Settings
PlungeSafety = 1121 ' Plunge Safety from Settings
TrialZ = 1122 ' Trial Z from Settings
SwitchOffset = 1045 ' Switch Offset from Settings

If GetUserLED(OhmicLED) Then
  If IsActive(DIGITIZE) Then
    Message "Ohmic sensor jammed."
    MsgBox "Ohmic sensor jammed.  Clear and hit RUN to continue. ", 0 + 48 , "Clear Z Jam"
    Code ("M0")
  Else
    Code("G00 Z" & GetUserDRO(PlungeSafety) & " (Start probe touch-off)")
    While (IsMoving())
      'Sleep, so other threads can run while we’re waiting
      Sleep(100)
    Wend
    Code("G31 Z -3.937 F" & GetUserDRO(RefFeed))
    While (IsMoving())
      'Sleep, so other threads can run while we’re waiting
      Sleep(100)
      If IsActive(ZHOME) Then 'ohmic missed
        Message "Ohmic sensor missed."
        If MsgBox ("Ohmic sensor missed.  Use touch?", 4 + 48, "Ohmic sensor missed.") = 6 Then
          Code("G92 Z0.0")
          While (IsMoving())
            'Sleep, so other threads can run while we’re waiting
            Sleep(100)
          Wend
          Code("G00 Z" & GetUserDRO(SwitchOffset) & " (Switch offset lift)")
          While (IsMoving())
            'Sleep, so other threads can run while we’re waiting
            Sleep(100)
          Wend
        Else
          Message ""
          code ("M0")
          End
        End If
      End If
    Wend
    Code("G92 Z0.0")
    While (IsMoving())
      'Sleep, so other threads can run while we’re waiting
      Sleep(100)
    Wend
    If GetOEMLED(66) Then 'trial Z offset    
      Code("G92 Z -" & GetUserDRO(TrialZ) & " (Trial Z offset)")
      While (IsMoving())
        'Sleep, so other threads can run while we’re waiting
        Sleep(100)
      Wend
      Code ("G00 Z 0.0")
    End If
  End If
Else
  If GetUserLED(TouchLED) Then 'touch
    If IsActive(ZHOME) Then
      Message "Touch switch jammed."
      MsgBox "Touch switch jammed.  Clear and hit RUN to continue. ", 0 + 48, "Clear Z Jam"
      Code ("M0")
    Else
      Code("G28.1 Z" & GetUserDRO(PlungeSafety) & " (Start touch-off)")
      While (IsMoving())
        'Sleep, so other threads can run while we’re waiting
        Sleep(100)
      Wend
      Code("G92 Z0.0")
      While (IsMoving())
        'Sleep, so other threads can run while we’re waiting
        Sleep(100)
      Wend
      Code("G00 Z" & GetUserDRO(SwitchOffset) & " (Switch offset lift)")
      While (IsMoving())
        'Sleep, so other threads can run while we’re waiting
        Sleep(100)
      Wend
      Code("G92 Z0.0")
      While (IsMoving())
        'Sleep, so other threads can run while we’re waiting
        Sleep(100)
      Wend
      If GetOEMLED(66) Then 'trial Z offset    
        Code("G92 Z -" & GetUserDRO(TrialZ) & " (Trial Z offset)")
        While (IsMoving())
          'Sleep, so other threads can run while we’re waiting
          Sleep(100)
        Wend
        Code ("G00 Z 0.0")
      End If
    End If
  End If
End If
2014 Bulltear (StarLab) 4x8
C&CNC EtherCut
Mach3, SheetCam, Draftsight
Hypertherm PM65
Oxy/Acetylene Flame Torch
Pneumatic Plate Marker, Ohmic, 10 inch Rotary Chuck (in progress)
Post Reply

Return to “Mach3 & Mach4 CNC”