Hello Guest it is May 21, 2019, 05:18:48 PM

Author Topic: Mach3 and a tube bender  (Read 37950 times)

0 Members and 1 Guest are viewing this topic.

Offline poppabear

*
  • *
  •  2,231 2,231
  • Briceville, TN, USA
    • View Profile
    • S S Systems, LLC
Re: Mach3 and a tube bender
« Reply #30 on: February 15, 2009, 04:32:24 PM »
huh,

   Well NOW you can tell me if that macro works for ya............  hehehehe,

scott
Commercial Mach3 & Mach 4, Design/Build/Retrofit CNC and Industrial machines.
http://www.ss-systems-llc.com/
Re: Mach3 and a tube bender
« Reply #31 on: February 15, 2009, 06:08:31 PM »
Scott,

First, forgive my ignorance.  I have only had one week of experience with Mach.  I tried your program, but I can't get it to work.  I created the Macropump and stored it in the \macros\ folder.  I created DRO 29, LED 164 and LED 165.  I have set pins 2 and 3 to spindle CC and CCW.  I assigned proper OEM codes and loaded the interface into Mach.  I opened the Macropump file and clicked run.  I don't really understand how to make this macropump work.  I have tried cycling the encoder to see if the program will activate one of the relays.  How do I trigger the macro to start?  Do I make a "Start" button on the interface to start the script?  If so, how do I start the script.  I am used to Visual Studio 2005 where you create buttons, labels, etc, assign a name, then click on that feature to type code.  I understand Mach is different, but I don't really understand the overview of how the programming is supposed to work. 

When you say USERDRO(2000), should I create a DRO, and assign it a OEM Code value of 2000?

Thanks,
Brenton

Offline poppabear

*
  • *
  •  2,231 2,231
  • Briceville, TN, USA
    • View Profile
    • S S Systems, LLC
Re: Mach3 and a tube bender
« Reply #32 on: February 15, 2009, 08:42:44 PM »
wasnt making fun of you, just been where you are many, many times....................

Ok on to the show

Make sure to save the maco as "Macropump.m1s" and make SURE it is saved to the Folder under macros that matches your profile!!!

Ok, once you have done that, look at the macro, make sure you have all the INPUTS and OUTPUTS that it is using enabled under ports and pins!!

To enable macor pump, goto Config>General and look over to the right, and look for a check box next to "run macropump", and make sure it is cheacked!! hit OK close mach and Reopen.

NOW go BACK to General and make sure the Check did INDEED stay checked, sometimes it doesnt, if not, recheck the box, and appy/ok, close and reopen and recheck it agian. if you see a check in the box then macro pump is running.............

To do a DRO, Open Screen 3, or Screen 4, drop a DRO on the screen, you will see a radio button that has OEM number, make sure there is a tick in the radio button, and put the User DRO number in that box, hit apply/ok....

scott
Commercial Mach3 & Mach 4, Design/Build/Retrofit CNC and Industrial machines.
http://www.ss-systems-llc.com/
Re: Mach3 and a tube bender
« Reply #33 on: February 15, 2009, 09:24:01 PM »
Scott,

I had the "run macropump" checked yesterday, but that was before I made the stupid mistake of having the encoder enabled as a MPG.  I guess my question is:  How does the small program you wrote execute?  In my past programming experience, you would make a button execute a series of code.  How does this program you wrote actually run?  With the macropump enabled, does it just run all macros located in the proper folder? 

I would like your suggestion on a bit more code.  I would like to create three "manual" buttons: extend, retract and pause.  I went through the OEM Code list found on the forum here, and I couldn't find any code numbers to toggle spindle CW and CCW.  Even if I wanted to change the relay outputs to Output1 and Output2, I couldn't find any OEM buttons for Output 1 and 2.

Offline Chip

*
  • *
  •  2,057 2,057
  • Gainesville Florida USA
    • View Profile
Re: Mach3 and a tube bender
« Reply #34 on: February 15, 2009, 10:37:30 PM »
Hi, Brenton

I think this will do what you want, Put these in your buttons, Got to run out, Il'l be back in awhile.

'CW M3 Button*********************

If IsOutputActive( OUTPUT1 ) Then
   DeActivateSignal( OUTPUT1 )
   DeActivateSignal( OUTPUT2 )

   Code "M5"
Else
   DeActivateSignal( OUTPUT2 )
   ActivateSignal  ( OUTPUT1 )
End If


'CCW M4 Button***********************

If IsOutputActive( OUTPUT2 ) Then
   DeActivateSignal( OUTPUT2 )
   DeActivateSignal( OUTPUT1 )

   Code "M5"
Else
   DeActivateSignal( OUTPUT1 )
   ActivateSignal  ( OUTPUT2 )
End If

Edit: Well out a little later than I expected, There may be a better way to do this, Haven't tested it thoroughly hear for proper operation.

May need a lockout relay to ensure CW & CCW don't interfere with each other, Proceed with "Caution" !!!!.

Chip
« Last Edit: February 16, 2009, 04:51:02 AM by Chip »

Offline poppabear

*
  • *
  •  2,231 2,231
  • Briceville, TN, USA
    • View Profile
    • S S Systems, LLC
Re: Mach3 and a tube bender
« Reply #35 on: February 16, 2009, 08:07:48 AM »
Hey Chip,

Put this in your code for spindle controls: (note: also look at the Spindle directon LEDs 164,165 they will give you truer spindle states, more reliable). 
DoSpinCW()
DoSpindCCW() 
DoSpinStop()
the outputs are controlled by this function, so you dont have to override them and they stay in synch.

Brenton,

The macropump is a Looping program, it loops once every 1/10th of a second. Think of it as a "Poler". Once you enable it, and close and reopen Mach3, it is
automatically, always running in the back ground.  Every 1/10th of a second, it comes around and goes through your code top down, it looks at all your stuff,
and then acts on the conditions it sees on that loop. DO NOT put ANY While type code in it.

Having said the above, since it will act on your code on each loop, if you want something to only run ONCE, unless the condition changes you have to put an "Interlock" in your code. Example below.

Lets say you have a UserLED called 2000 that when it is active, it will "Push" the estop button. Now in the macro pump when you turn this LED on, it would toggle the state of the Estop button once every 1/10th of a second.............. (NOT GOOD). So you have to put a "State" system in with an interlock.
You can Use DROs or Vars as data storage or in the case below and interlock, I am using a DRO here.

'Interlock example in macropump

interlock1 = GetUserDRO(1500) 'Interlock DRO
TriggerLED = GetUserLED(2000)

if TriggerLED = 1 and interlock1 = 0 then
DoOEMbutton(1021) 'push the Estop
interlock1 = 1 'this "Locks it out from running again on next scan
end if

if GetOEMLED(800) and interlock1 = 1 then 'when estop LED is active, this resets the interlock for when you come out.
SetUserDRO(1500,0) 'resets the interlock counter
end if

'scott

« Last Edit: February 16, 2009, 08:17:10 AM by poppabear »
Commercial Mach3 & Mach 4, Design/Build/Retrofit CNC and Industrial machines.
http://www.ss-systems-llc.com/

Offline Chip

*
  • *
  •  2,057 2,057
  • Gainesville Florida USA
    • View Profile
Re: Mach3 and a tube bender
« Reply #36 on: February 16, 2009, 10:12:38 AM »
Hi, Scott

New there was probably a better way, I can get part of your suggested code to work, But getting allot of Syntax Errors when trying to toggle the ON/OFF state in the button script.

Just in over my head as usual, Got to get some Sleep, Been at the Airport all night working.

Thanks, Chip
« Last Edit: February 16, 2009, 10:15:44 AM by Chip »

Offline poppabear

*
  • *
  •  2,231 2,231
  • Briceville, TN, USA
    • View Profile
    • S S Systems, LLC
Re: Mach3 and a tube bender
« Reply #37 on: February 16, 2009, 11:37:04 AM »
you have to look at the Spindle CW and/or CCW LEDs then depending on thier state, preform your logic........
Commercial Mach3 & Mach 4, Design/Build/Retrofit CNC and Industrial machines.
http://www.ss-systems-llc.com/
Re: Mach3 and a tube bender
« Reply #38 on: February 16, 2009, 03:41:58 PM »
Scott,

I have tried your program, but I can't get it to do anything.  I have ensured "Run Macropump" is checked.  It is weird how you have to restart and recheck it twice to get it to stay.

Here is the code you wrote:

'Goto angle
'Macropump.m1s

DesiredAnglePos = GetUserDRO(2000) 'angle entry dro on your screen
CurrentAngPos= GetOEMDRO(29) 'encoder1 DRO from your die

if GetOEMLED(164) or GetOEMLED(165) then 'if the CW or CCW led is on

   if GetOEMLED(164) then 'if the spindle CW led is on.
      if CurrentAngPos <= DesiredAnglePos then
      ActivateSignal(OUTPUT2) 'coil A cw
      else
      DeActivateSignal(OUTPUT2)
      end if   
   end if

   if GetOEMLED(165) then 'if the spindle CCW led is on.
      if CurrentAngPos >= DesiredAnglePos then
      ActivateSignal(OUTPUT3) 'coil B ccw
      else
      DeActivateSignal(OUTPUT3)
      end if   
   end if
   
end if

I have listed the following Inputs/Outputs:

OEMDRO 29
UserDRO 2000
OEMLED 164
OEMLED 165

Under the Spindle tab in the Ports and Pins page, I have assigned CW (M3) and CCW (M4) to pins 2 and 3.

Here is my program.  As shown, the current angle exceeds the input angle.  Therefore, LED 165 should be lit and output 3 should be energized.  Unfortunately this isn't happening.  The labels display what OEM Code I typed:



Here is my macropump.  I saved this in the correct profile under the \Macros\ folder.



Here is my pins screen:



And lastly, here is my general config screen:



I apologize for the length of this post.  I just want to provide as much useful information as possible to you.



Re: Mach3 and a tube bender
« Reply #39 on: February 16, 2009, 04:08:29 PM »
Ok, ill give this a try.

Your macro pump has two conditionals, this conditionals need to be at least one true to get into the loop, since the starting stage of your machine is with both LEDs off, then it never gets into the loop that turns the CW and CCW outputs on.

A quick way i can think of is to add another OEM button and OEMled to your screen, have that new button toggle the new led on and off,

Now on the conditionals
"if GetOEMLED(164) or GetOEMLED(165) then 'if the CW or CCW led is on"

add another OR that looks for that new led,

and in the single conditionals you have later in the macro:

 if GetOEMLED(164) then 'if the spindle CW led is on.      and
 if GetOEMLED(165) then 'if the spindle CCW led is on.

add an AND conditional to look for that new led.

this way your machine will not move unless you have that LED active, and will only start moving when it is active.

hope it makes sense