Hello Guest it is April 16, 2024, 01:49:07 PM

Author Topic: Help required for relay output code  (Read 907 times)

0 Members and 1 Guest are viewing this topic.

Help required for relay output code
« on: March 15, 2023, 07:45:18 AM »
I require some help adding code to an existing project.

I have built a motion fence for my table saw using Mach3, which works well. But I needed to add an air cylinder to 'clamp' the end of the fence (furthest from the linear rail mounting), as the fence flexed a small amount. This feature is now installed and is manually controlled with a button on the screen-set and successfully clamps the fence rigid. This button uses the Mist Toggle (114) to 'clamp' the fence but I now need to add some code the existing code that moves the fence to the desired position.

Here's what I require.....

After moving the fence to a required position, M7 needs to be turned ON (clamped).  When another position is required, after entering the target with the numeric buttons, firstly, M9 needs to turn OFF (unclamped). A delay of around 1 to 2 seconds is required (I can adjust this to get the right timing), to allow the air cylinder to retract, then the movement (target) can start. When the target position is reached, M7 needs to activate again to clamp the fence. I might need another delay after the target is reached, to ensure that the clamp doesn't engage before the movement has reached its position. I assume 'WhileIsMoving' will work?

An important note is that the clamp must be turned off before the movement takes place, otherwise the fence will move while 'clamped' and will skew (damage) the mechanics. The clamp remains on until another position is entered.

The existing code that moves the fence is shown below, which takes the required 'target' from a numeric keypad....

      Sub Main()
          SetOEMDRO(1400,0)   
          NumericKeyboard(1400)
             Code "G0 X" &GetOEMDro(1400)
      End Sub

I was hoping to amend the code myself but I'm a bit unsure of where exactly to place the code and I don't want to damage any of the mechanics if the clamp doesn't turn off while the fence moves!  Below is the sort of thing I'm looking for....

  Sub Main()
          SetOEMDRO(1400,0)   
          NumericKeyboard(1400)

DISENGAGE CLAMP (M9)
WAIT 1 SECOND (TO ALLOW CYLINDER TO RETRACT)

                   
                       Code "G0 X" &GetOEMDro(1400)

ENGAGE CLAMP (M7)
WAIT 2 SECONDS (TO ALLOW CYLINDER TO CLAMP)


      End Sub

I hope you can assist me with this.
Re: Help required for relay output code
« Reply #1 on: March 16, 2023, 04:15:38 AM »
With a bit of perseverance I've now managed to achieve this.  Not sure if it's the correct or best method but it works a treat.

Created two macros M667 and M666...

M666 - ActivateSignal(Output1)
M667 - DeActivateSignal(Output1)


      Sub Main()
          SetOEMDRO(1400,0)   
          NumericKeyboard(1400)
             Code("M667")
             Sleep(1000)
             Code "G0 X" &GetOEMDro(1400)
             Code("M666")
             Sleep(1000)
      End Sub
« Last Edit: March 16, 2023, 04:17:48 AM by krsykes23 »

Offline Tweakie.CNC

*
  • *
  •  9,197 9,197
  • Super Kitty
    • View Profile
Re: Help required for relay output code
« Reply #2 on: March 16, 2023, 07:04:12 AM »
If it works well that is all that is important. My congrats on getting it done, nice screen also.

Tweakie.
« Last Edit: March 16, 2023, 07:44:44 AM by Tweakie.CNC »
PEACE