Machsupport Forum

Mach Discussion => General Mach Discussion => Topic started by: supahonkey on February 08, 2009, 05:02:48 PM

Title: Mach3 and a tube bender
Post by: supahonkey on February 08, 2009, 05:02:48 PM
Hey yall!  I am currently in the process of using Mach3 to control a tube bender I made last year.  Details of my build can be found here:

http://cnczone.com/forums/showthread.php?t=68163 (http://cnczone.com/forums/showthread.php?t=68163)

I am using a 360 PPR rotary encoder to track die position.  I am aware that Mach3 isn't well equipped to interface encoders.  My bender never moves past 100 degrees and takes 15+ seconds to go from 0 to 100 degrees. 

I finally have my rotary encoder hooked up to a breakout board from CNC4PC.  I have configured the pins in Mach3.  How can I display readings from the encoder?  I have hooked up the encoder, but I don't know how to verify if it is working through Mach. 

I am using a Vickers valve to extend or retract a hydraulic cylinder.   Mach3 will energize and de-energize pins 2 or 3.  Pins 2 and 3 then go to a relay board from CNC4PC.  These relays energize either coil A or B on the valve.  I have assigned spindle CW and CCW to control the relay board. 

My ultimate goal is to enter a value between 1 and 100 degrees.  I would like Mach to energize Pin 2, compare the user input value with the rotary encoder reading, the de-energize Pin 2 when the user input value and the rotary value are equal.

The first step is to interface the encoder with Mach3.  Can I set up a DRO to read degrees from a rotary encoder?

More info about my rotary encoder can be found on page 8 of my thread at cnczone.com

http://cnczone.com/forums/showthread.php?t=68163&page=8 (http://cnczone.com/forums/showthread.php?t=68163&page=8)

Title: Re: Mach3 and a tube bender
Post by: poppabear on February 08, 2009, 06:30:35 PM
Absolutly you can!!!

here is a few steps:

Under Config>ports and Pins click the tab for Encoder/mpgs
pick encoder1 and enable it, set the input pins you going to use
for the A and B channel of the encoder.

you can use the CW and CCW comands if you want or directly on/off
the output your choice, for now we will do it with your set up.

Once you get your encoder hooked up, goto the settings page,
and look at the DRO value for Encoder1(X axis). Turn your die
a specific number of degrees... say 10 or 90 or something you
can easily measure. and look at the encoder display.
if the two dont match, figure the difference, then go back
to ports and pins, encoders and set the steps per detent to
what you think it should be, you may have to play with it.

Now, Put something like this in the macro pump.

also put a user DRO for the angle entry on your screen, call it UserDRO2000.

Note for the macropump I am going to say that when you say CW (0-100) OUTPUT2 goes
high, and CCW (100-0) output3 goes high.

I am going to assume that CW is going from 0 towards 100
and CCW is moving back towards 0.

Now what happens here is you can set your CW or CCW for direction,
the code "Activates".

'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

'scott



'Note: you could also do this with Buttons or by calling custom macros from you G code.........
'the maximum resolution of this will be at the speed of the macro pump which is 1/10 th or a little over of a second.
'so you may have some error depending on how far your encouder moves evey 1/10th of a second.
Title: Re: Mach3 and a tube bender
Post by: supahonkey on February 08, 2009, 09:29:58 PM
Wow Scott, thank you so much!  I wasn't expecting someone to reply that fast and with that much information!  My first problem is that the DRO on the settings page doesn't change.  I am positive I have the A+ and B+ outputs of the encoder hooked up to pins 12 and 13 on the BOB.  If I put a multimeter up to either A+ or B+ I get a change in voltage as I rotate the encoder.  I have verified the encoder is working.  Here is a pic of my pin and port config:

(http://supahonkey.com/tube%20bender/Website/Encoder/PinsScreen_small.JPG)

Here is a pic of my Settings page:

(http://supahonkey.com/tube%20bender/Website/Encoder/SettingsScreen.jpg)

Any ideas?

Title: Re: Mach3 and a tube bender
Post by: poppabear on February 08, 2009, 11:11:13 PM
in your screen shot, your "Encoder1" is NOT enabled!!! there is a Red X next to it, you have to click on it and make it be a green Check.

scott
Title: Re: Mach3 and a tube bender
Post by: supahonkey on February 08, 2009, 11:31:24 PM
Sorry, that screen shot is older.  The check box is indeed checked.  I have updated the first screen shot above.  What is the function of the "To DRO" and "Load DRO" buttons?

Any more ideas?  I see a voltage fluctuation when I put the red lead to either the A+ or B+.  I see absolutely nothing from the settings screen.  Should I see anything on the Diagnostics screen?  Must I have some sort of X Axis stepper configuration enable to "activate" the encoder reading?


Title: Re: Mach3 and a tube bender
Post by: poppabear on February 09, 2009, 08:23:31 AM
Ok, try this, if your sure your encoder is reading, then drop these two DROs on your screen set some where, and see if either of them will show a value when you turn your Encoder.

Put a DRO 170 (Encoder 1 position in units DRO)
Put a DRO 205 (Endocer 1 DRO external)

put those two above, and if you want copy over your DRO 29, then turn the encoder, if none of these are moving, then the problem is in the way your hooking up your encoder.

I dont have an encoder to test with here, BUT, I think Hood was using one recently, for a simular Encoder test, ask him if the above fails to bear fruit.
I mostly bring in MPGs and they are just a different type encoder. Principle should be the same.

Also: This is a GREAT site, with ALOT of great people with all kinds of different backgrounds and experiences.........  I may be totally "Shot in the Head", on your encoder problem, so perhaps someone who has done encoder unputs recently can take it from here.


I honestly dont know why your not reading it, if the encoder is working, and you have it electrically hooked up right to the inputs on your board, then it should be reading.......

scott
Title: Re: Mach3 and a tube bender
Post by: supahonkey on February 09, 2009, 04:12:32 PM
Scott,

When you say "Put a DRO 170", do you mean create a screen with a DRO, and assign it an OEM value of 170?  I apologize, I am new to Mach3 as of yesterday afternoon.  I am still learning.  I still have A LOT to learn judging by the main screen of Mach3.  

I created 3 DROs, assigned them OEM values of 170, 205 and 29.  I turned the encoder and neither worked.

On the settings tab, I can click the "Set steps per unit".  It asks me how far I would like to move the X-Axis.  I type in 360.  They only way to get anything to display on the settings tab is to rotate the encoder, then click the "Load DRO" button.  A new value updates.  Mach3 then prompts me with "How far did the x-axis move?".  It then tells me it has set X number of steps/unit.  I can now get something to show up on the screen, but I still have to hit "Load DRO", and the displayed value is highly inaccurate.  Isn't the DRO supposed to display in real time?    
Title: Re: Mach3 and a tube bender
Post by: supahonkey on February 11, 2009, 05:37:37 PM
How can I make Mach3 send a 5V signal to an OUTPUT pin?  I need to verify Mach3 is interfacing with my BOB.  The more I troubleshoot my setup, the more I believe Mach isn't communicating with my board.

I have little Omron photosensor switches.  They have a lens which sends 5V when its field of view has been broken.  With the 5V and 0V connected, I have verified 5V comes out of the output wire.  I connected the third wire to pin 10.  If I go to "Automated Setup of Inputs", Mach can't find the signal.  I put my multimeter up to the post where the output wire is connected, and I get a true 5V.  If I look at the diagnostics page, nothing lights up for pin 10. 

I wrote a program in VB a while back with three buttons: Extend, Retract and Pause.  My program works just fine, therefore I know my BOB is working correctly.

I would like to test to see if I can get the BOB to send 5V to pins 2 and 3 to active my relay board.  If I assign pins 2 and 3 to output 2 and 3, what value do I assign the two buttons in ScreenDesigner?

Thanks,
Brenton
Title: Re: Mach3 and a tube bender
Post by: supahonkey on February 12, 2009, 10:51:48 PM
I got Mach to read my rotary encoder and limit switch.  I installed XP on another drive and installed Mach.  I simply configured the pins and every thing is working just fine.  I believe I know why it was giving me so much trouble.  I used a file called inpout32.dll to interface the VB program I made to the parallel port.  Apparently this was somehow over riding the parallel port driver, or simply just the commands send to the parallel port. 

My encoder is 360 PPR.  I typed in 360 in units/rev in the pins config.  Unfortunately, it doesn't read accurately under the settings screen.  I am going slow.  Any idea whats going on here?
Title: Re: Mach3 and a tube bender
Post by: fer_mayrl on February 13, 2009, 12:50:15 AM
Good to hear you got it working,

As I stated over at cnczone, have you tried on putting 1440 in the units per rev?

Best regards
Fernando
Title: Re: Mach3 and a tube bender
Post by: KTM on February 13, 2009, 08:07:38 AM
I would put 1 in count per unit for the encoder in ports and pins, as Mach does not know when the encoder has done 1 revolution, 1 unit will equal 1 degree with a 360ppr encoder.

Regards

KTM
Title: Re: Mach3 and a tube bender
Post by: poppabear on February 13, 2009, 09:02:23 AM
Good to hear that is was a Wierd other program issue.........

Did the Macro above help you out?
what Encoder DRO did you end up using?

scott
Title: Re: Mach3 and a tube bender
Post by: supahonkey on February 13, 2009, 03:24:57 PM
I haven't tried your macro yet.  I am having count issues with my encoder.  Mach reports 360 degrees when my encoder truly moves 90 degrees.  I have tried different values under the counts/unit.  It seems to have no effect, regardless of what value I choose.  Any ideas on what is going on here?
Title: Re: Mach3 and a tube bender
Post by: fer_mayrl on February 13, 2009, 03:28:05 PM
Since 90º is one quarter turn, then set your units per rev to 1440, i have not used an encoder before, you might need to restart mach for settings to take effect.

Regards
Fernando
Title: Re: Mach3 and a tube bender
Post by: supahonkey on February 13, 2009, 03:32:17 PM
Fernando,

I get the same reading.  360* from the DRO for 90 degrees of actual movement.
Title: Re: Mach3 and a tube bender
Post by: fer_mayrl on February 13, 2009, 03:43:16 PM
ok, try this...

since it is counts/unit

and the unit you are looking for is degrees... then 4 ticks of the encoder should give you one degree you turn...

have you tried a value of 4?? if that doesnt do it, try a 1

what happens if you turn your encoder more than 90º say 180º or 360º, what does the dro display?

there is also an MPG calibration in the function cfgs menu

Fernando
Title: Re: Mach3 and a tube bender
Post by: supahonkey on February 13, 2009, 04:12:59 PM
Fernando,

I tried 1 and 4 earlier and they both did nothing.  Restarting the application doesn't help.  If I turn my encoder 180*, Mach reports 720*.  The same multiple goes for 360* and so on.  

I am using DRO29 in the settings screen.  I tried my own screen with DRO 170 and 205.  Both didn't change when I rotated the encoder shaft.  The MPG Configuration utility has no effect.
Title: Re: Mach3 and a tube bender
Post by: fer_mayrl on February 13, 2009, 05:04:26 PM
im out of ideas!!
sorry friend....
Title: Re: Mach3 and a tube bender
Post by: poppabear on February 14, 2009, 09:40:59 AM
Reduce your counts to 1 count per unit, and set your Jog Mode type to "Single Step" and if that doesnt work, try "Multi-Step".

scott
Title: Re: Mach3 and a tube bender
Post by: supahonkey on February 14, 2009, 06:13:46 PM
I reduced my counts 1 count per unit.  I tried both single and multi step modes and neither had an effect. 

Scott, on the last page you said, "also put a user DRO for the angle entry on your screen, call it UserDRO2000."  How do I call a DRO UserDRO2000?  In screen designer, I can only assign an integer as an OEMCode integer.  I see you have GetOemDRO and GetOEMUser, but I don't seen an option for OEMUser.

Here is my screen:

(http://supahonkey.com/tube%20bender/Website/Encoder/EncoderScreen.jpg)

I am lost on this one.  Does the error have to do with not choosing the correct DRO to display encoder shaft position?
Title: Re: Mach3 and a tube bender
Post by: poppabear on February 14, 2009, 09:02:35 PM
Then as far as your encoder is concerened I can no longer help, I have told you all I know to tell you, perhaps someone else can chime in who has more recent experience.

  For DROs, just drop on on the page, and put in the OEM number the UserDRO number or OEMnumber you want.

scott
Title: Re: Mach3 and a tube bender
Post by: vmax549 on February 15, 2009, 11:08:36 AM
SCOTT i'll give this a whirl(;-)

OK for now go BACK to the original screen for mach. Set up the encoder for 4 pulses per unit, SAVE the settings . MAKE SURE you are setting the correct pins and ports to the correct encoder input in this case i would use encoder1 which relates to X axis DRO on the settings page.

NOW rotate the encoder 90 degs. WHat does the dro on the settings page report as number of units???

(;-) TP
Title: Re: Mach3 and a tube bender
Post by: supahonkey on February 15, 2009, 01:00:40 PM
TP,

I am using Encoder 1 X Axis DRO.  I changed it to 4 and saved the units.  After rotating the encoder 90 degrees, the settings page reports 360 degrees.  This value is found under Abs Coords, MPG1, Count.  Should I do anything with the velocity value?  I have tried changing it, but it doesn't seem to do anything.
Title: Re: Mach3 and a tube bender
Post by: vmax549 on February 15, 2009, 01:17:40 PM
"""This value is found under Abs Coords, MPG1, Count.  Should I do anything with the velocity value?  I have tried changing it, but it doesn't seem to do anything."""


I have no idea what you are trying to tell me. This has nothing to do with any of that.

YOu should be looking at the ENCODER POSITION  X axis dro ONLY. WHat does it display for a value???
(;-) TP
Title: Re: Mach3 and a tube bender
Post by: supahonkey on February 15, 2009, 01:21:18 PM
The encoder position X Axis DRO reads -2.5500.  If I rotate the encoder, the DRO does nothing.  The only thing that updates is the MPG1 Count DRO above the Encoder Position X Axis DRO.
(http://supahonkey.com/tube%20bender/Website/Encoder/MPGScreen.jpg)

Title: Re: Mach3 and a tube bender
Post by: vmax549 on February 15, 2009, 01:41:37 PM
(;-) YOU don't have the encoder setup correctly. IT appears you are trying to setup an MPG.

SET up the encoder AS" encoder1" NOT mpg#1. Use 4 as counts per unit.

Then see IF you get a reading on the X pos dro on the settings page.

(;-) TP
Title: Re: Mach3 and a tube bender
Post by: Hood on February 15, 2009, 01:42:22 PM
Why have you set up the encoder as a MPG? Are you not wanting it as a way of seeing the movement of an axis?
Hood
Title: Re: Mach3 and a tube bender
Post by: supahonkey on February 15, 2009, 01:49:55 PM
AH!  I feel like an idiot.  I can't believe that has been the problem this entire time.  For some reason I (1) never saw Encoder 1 under Pins and Ports.  I always thought that Mach 3 wasn't able to handle Encoders, and the encoders had to be read as MPGs.  Nevermind, thanks for the help.

How do I assign a User DRO number to a DRO in screen designer?  The only option I see is OEM number.

(http://supahonkey.com/tube%20bender/Website/Encoder/ScreenDesigner.jpg)

Title: Re: Mach3 and a tube bender
Post by: Hood on February 15, 2009, 02:02:46 PM
Thats probably the way, been so long since I used screendesigner I cant remember, I use screen4 now.
Hood
Title: Re: Mach3 and a tube bender
Post by: vmax549 on February 15, 2009, 04:29:22 PM
WE have all been there before, sometimes it just takes an extra set of eyes to see the problem.

Screen designer????  HUM , user dros run from 1000-1254 so set the correct number in the oemcode selection.

Click on oemcode and type in the dro # you want.

(;-) TP
Title: Re: Mach3 and a tube bender
Post by: poppabear on February 15, 2009, 04:32:24 PM
huh,

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

scott
Title: Re: Mach3 and a tube bender
Post by: supahonkey 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
Title: Re: Mach3 and a tube bender
Post by: poppabear 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
Title: Re: Mach3 and a tube bender
Post by: supahonkey 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.
Title: Re: Mach3 and a tube bender
Post by: Chip 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
Title: Re: Mach3 and a tube bender
Post by: poppabear 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

Title: Re: Mach3 and a tube bender
Post by: Chip 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
Title: Re: Mach3 and a tube bender
Post by: poppabear 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........
Title: Re: Mach3 and a tube bender
Post by: supahonkey 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:

(http://supahonkey.com/tube%20bender/Website/Encoder/Screens/BenderScreen.jpg)

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

(http://supahonkey.com/tube%20bender/Website/Encoder/Screens/MacroPump.jpg)

Here is my pins screen:

(http://supahonkey.com/tube%20bender/Website/Encoder/Screens/SpindlePins.jpg)

And lastly, here is my general config screen:

(http://supahonkey.com/tube%20bender/Website/Encoder/Screens/GeneralConfig.jpg)

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



Title: Re: Mach3 and a tube bender
Post by: fer_mayrl 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
Title: Re: Mach3 and a tube bender
Post by: supahonkey on February 16, 2009, 04:33:00 PM
Fer Mayrl,

Essentially, you are suggesting I add an OEM button and an OEMled.  The OEMbutton will turn on an OEMled.  Once the aforementioned OEMled is on, then the loop will start?  How do I make a button trigger an LED to turn on?

Using my existing interface, I added OEMbutton(233), which turns on Output 4.  Next to the button I have OEMLed(77), which turns on when Output4 is energized.  When I load my screen in Mach3, the LED does not turn on if I click the button.  I can get OEMLed(830) on but hitting one of my limit switches.  Any idea why I can't get an OEMbutton to turn on a corresponding OEMled?
Title: Re: Mach3 and a tube bender
Post by: supahonkey on February 16, 2009, 04:58:37 PM
Here is my "new" code.  I believe I have added the correct stuff.  I can get the LED(830) to turn on when I close the limit switch.  It's weird why my OEMButton and OEMLed for Output 4 won't work.  I still can't get the program to respond to anything.  Here is the code:

'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) Or GetOEMLED(830) Then 'if the CW or CCW or the Limit switch is open, led is on

   If GetOEMLED(164) And GetOEMLED(830) Then 'if the spindle CW led and the limit switch is on.
      If CurrentAngPos <= DesiredAnglePos Then
      ActivateSignal(OUTPUT2) 'coil A cw
      Else
      DeActivateSignal(OUTPUT2)
      End If   
   End If

   If GetOEMLED(165) And GetOEMLED(830) Then 'if the spindle CCW led and the Limit switch is on.
      If CurrentAngPos >= DesiredAnglePos Then
      ActivateSignal(OUTPUT3) 'coil B ccw
      Else
      DeActivateSignal(OUTPUT3)
      End If   
   End If
   
End If   

Title: Re: Mach3 and a tube bender
Post by: fer_mayrl on February 16, 2009, 05:00:58 PM
Well,
you have to add an OEMbutton, if using screen3 you can add the following macro to it: assuming the oem led is number 1200

If GetOEMLED(1200) then
SetUserLED(1200,0)
else
SetUserLED(1200,1)
end if

This will toggle led 1200 on and off

if you are using screen4 then add the button on the screen, then go to mach and click edit button script in the operator menu, you can add the script there and click save...
Title: Re: Mach3 and a tube bender
Post by: supahonkey on February 17, 2009, 09:04:57 PM
Ah, it seems like everything I do never works at first.  I can only get fer mayrl's simple script to work.  Scott - I cannot get your script to do anything.  It throws no syntax errors, it just does nothing.  I tried adding fer mayrl's suggestion to Scott's original code: (Bold reflects the new stuff)

'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) Or GetOEMLED(1200) Then 'if the CW or CCW led is on

   If GetOEMLED(164) And GetOEMLED(1200) Then 'if the spindle CW led and the limit switch is on.
      If CurrentAngPos <= DesiredAnglePos Then
      ActivateSignal(OUTPUT2) 'coil A cw
      Else
      DeActivateSignal(OUTPUT2)
      End If   
   End If

   If GetOEMLED(165) And GetOEMLED(1200) Then 'if the spindle CCW led and the Limit switch is on.
      If CurrentAngPos >= DesiredAnglePos Then
      ActivateSignal(OUTPUT3) 'coil B ccw
      Else
      DeActivateSignal(OUTPUT3)
      End If   
   End If
   
End If   

I still get no response, even if I press the button to light OEMLED1200.  The OemLED1200 does light up, I just get nothing. 

I am having one hell of a time getting Mach to actually save VB scripts when I edit the buttons.  I can only get it to retain code by saving it as the hiddenscript.  If I give the button a new name, such as CW, I can close the editor, click View > Save Current View, go back to the button editor, click the button, and there is absolutely no code present.  I googled the problem and everyone's suggestion was to click "Save Current View." 

Title: Re: Mach3 and a tube bender
Post by: supahonkey on February 17, 2009, 09:31:12 PM
Please correct me if I am wrong, but I would assume something as simple as the following code would work:

If GetOEMLED(1200) Then 'If OEMLED1200 is active
ActivateSignal(OUTPUT2) 'Activate Output2
Else
DeActivateSignal(Output2) 'Deactivate Output2
End If

I have a button that turns on OEMLED1200.  When I hit this button, the LED turns green.  Based on the above code, I would expect for Ouput2 to go high.  Unfortunately I read nothing with the multimeter.  And yes, Output2 is configured.  If I check ActiveLow for Output 2, my relay becomes energized.
Title: Re: Mach3 and a tube bender
Post by: poppabear on February 17, 2009, 10:35:58 PM
no what controlled my code was the direction you wanted to turn your rotary device.

I.e. if you put a "M3" in your MDI or Gcode it would rotate positive, until the encoder reached the desired position.
if you put a "M4" in your MDI or Gcode it would rotate negative, until the encoder reached the desired position.

when you post a M3 the oemLED164 will turn on
when you post a M4 the oemLED165 will turn on

Scott
Title: Re: Mach3 and a tube bender
Post by: vmax549 on February 17, 2009, 10:41:33 PM
(;-) YOU need to brush up on your VB.

If GetOEMLED(1200) Then   THis is a conditional statement BUT you did not specify your condition for activation

If GetOEMLED(1200) =(1)  Then    would indicate IF the led value =1 then do something
If GetOEMLED(1200) <>(0) Then   would indicate that IF the led doesnot equal 0 then do something

Just a thought, (;-) TP
Title: Re: Mach3 and a tube bender
Post by: fer_mayrl on February 18, 2009, 12:08:12 AM
I think the condition is implicit to be a 1 when no argument is used.

Scott... wouldnt a Brain be simpler to implement than this?
its late now and my head is closed for business right now...

Ill give it a try tomorrow.

Regards
Fernando
Title: Re: Mach3 and a tube bender
Post by: poppabear on February 18, 2009, 09:06:55 AM
just a few things:

  it is GetUserLED(1200), the GetOEMLED range is for the OEM leds in VB.

Fernando, you can do it the way you did as well, it is another option.

if you put a User LED 1200 and a User LED 1201 on your screen for testing, then put this code in your macro pump, (check it twice to make sure it is running after you do).

'macropump.m1s

If GetUserLed(1200) Then
SetUserLed(1201, 1)
Else
SetUserLed(1201,0)
End If

the GetUserLED(1200) will evaluate to a "1" if it is on, and a "0" if it is off.
so you can open up your VB scripter window OR, put an On/Off button to control UseLED1200
in eighter case when you toggle the state of 1200, to ON, you will see 1201 turn on, and vice versa.

MacroPump:  Yes Superhonkey it is a pain in the butt, but always go back and check to see if the Cheack to enable the macropump did indeed stay checked.

Brains: Yes it could be done in Brains as well, although the logic would be more complex than he is ready for. He noted that he is new, so coding is sometimes more
human readable than "ladder logic" is. IMHO.

Scott

Title: Re: Mach3 and a tube bender
Post by: supahonkey on February 18, 2009, 09:17:45 AM
Scott,

I finally got the ActivateSignal and DeActivateSignal commands working as a Macropump.  I have two limit switches.  I made a macropump with two if statements:

'Macropump.m1s

If GetOEMLed(833) Then
ActivateSignal(Output3)
Else
DeactivateSignal(Output3)
End If 
 
If GetOEMLED(830) Then
ActivateSignal(Output2)
Else
DeactivateSignal(Output2)
End If

If I close the switches, their respective Outputs energize.  If I have my own screen loaded, the Macropump doesn't work.  If the default 1024.set screen is loaded, the Macropump works.  Why is that happening?  I bet I could Scott's script to work if I could overcome this issue.
Title: Re: Mach3 and a tube bender
Post by: supahonkey on February 18, 2009, 10:29:09 AM
I changed the above code to "If GetOEMLED(164)..." and "If GetOEMLED(165)..."

When I type in M3 or M4 into the MDI, my relays energize less than one second.  How can I make it stay on?

The above was earlier today.  By checking "Immediate Relay Off Before Delay", I was able to at least get one of the relays to energize.  It is very weird though:

If I type in M3 at the MDI, Relay CW energizes less than one second, then immediately shuts off and energizes Relay CCW (m4).  It won't shut off until I send command M5.

If I type in M4, Relay CCW energizes less than one second, and shuts off.

Now, if I un-check "Immediate relay off before delay", I get the same result... very weird.
Title: Re: Mach3 and a tube bender
Post by: supahonkey on February 18, 2009, 04:50:19 PM
IT WORKS! (somewhat)

Scott's macropump is functional.  When I type M3, output 2 energizes until the desired angle is equal to the current angle.  When I type M4, output 3 energizes if the desired angle <= current angle.  I want output 3 to energize until current angle = 0.  I am going to see how far I can get, though I am still new to VB.

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



Is it possible to program a button to send the G-Code "M3"?  I would like to have another button to send the code "M4".
Title: Re: Mach3 and a tube bender
Post by: fer_mayrl on February 18, 2009, 05:02:20 PM
YEs you can add an M3 and an M4 button...

Just add the button in screen designer...
in mach edit the buton script and put in it:

Code "M3" (or m4)

and save the script... no need to fiddle with file names... otherwise it wont save it to the button.

Regards
Fernando
Title: Re: Mach3 and a tube bender
Post by: poppabear on February 18, 2009, 05:38:56 PM
 8)

So do I get a "U DA MAN?".........  hehehehe

on a serious note: a few things I thought of, make sure you "Spindle" motor output is enabled (even though you may not be using one).

also When you Issue a M3 or M4 command Also Issue a S command to...  i.e.  S100 M3, or S100 M4.
Make sure that the range of "Pulley 1" is from 0-1000 or something so that S word falls in that range.
I dont think your M3 or M4 will Stay ON, if there is NO Spindle speed set..........

scott
Title: Re: Mach3 and a tube bender
Post by: supahonkey on February 18, 2009, 05:43:39 PM
SCOTT -----> U DA MAN!

I can't thank you enough for all of your help.

All of my programming issues have been a result of my user created screen.  I can't get the ActivateSignal(Output) command to work unless I modify 1024.set.  Nothing happens if I run it on my own screen.

I added my own screen to 1024.set, but I can't figure out how to pull it up once 1024.set has been loaded.  I made it on page 11, but how do I pull up page 11 in Mach?
Title: Re: Mach3 and a tube bender
Post by: fer_mayrl on February 18, 2009, 06:02:02 PM
Hi,
on Screen designer you have to add a button, and on OEM code put an 11

that should change to page 11 once you press it.

Regards
Fernando
Title: Re: Mach3 and a tube bender
Post by: supahonkey on February 18, 2009, 06:33:14 PM
Thanks Fernando.  I would like to create a button to Zero the Desired Angle UserDRO.  The current UserDRO is 2000.  I assume code must be written since it is a UserDRO.  Does anyone know the VB code to zero UserDRO2000?

Thanks.
Title: Re: Mach3 and a tube bender
Post by: Hood on February 18, 2009, 06:42:52 PM
Call SetUserDro(2000,0)
Title: Re: Mach3 and a tube bender
Post by: poppabear on February 18, 2009, 06:47:49 PM
ok a few more:

first you typed: ActivateSignal(Output), it is ActivateSignal(OUTPUT#), number being 1-20 and ALL caps for OUTPUT.

To Zero a UDRO put a button called Zero Angle Dro or what ever.

in the button in screen designer, tick the VB button screen three, in 4 you have to hit the Edit Button script,

Script is:

SetUserDRO(2000,0)

'that is it that will set UDRO 2000 to Zero.

scott
Title: Re: Mach3 and a tube bender
Post by: fer_mayrl on February 18, 2009, 06:49:20 PM
Damm! two replies while i was typing mine!

great group of guys we got here!
Title: Re: Mach3 and a tube bender
Post by: poppabear on February 18, 2009, 07:02:14 PM
NOTE:
 
YOU CAN put it as:  ActivateSignal(OutPut3)  I guess that must have changed, Brian might have changed it. It used to be that the Signals where ALL in caps (see wiki still up like that). But Hood pointed out that he has been doing it like the above, so I tried it and sure enough it does work that way........... so, I stand corrected, I was unaware that it had changed............

scott
Title: Re: Mach3 and a tube bender
Post by: supahonkey on February 18, 2009, 07:06:01 PM
Ha!  Thanks for all of your help.

I just started having some really weird issues.  My Retract (M4) (output3) is back to turning on really quickly, then turning off.  The LED on the relay board goes bright for less than one second, then flashes very dimly.  I read 0VDC on the incoming 5V signal.  I don't have a problem at all with M3 (output 2).  Very weird... any ideas?

I had a typo a few posts up when I mentioned the ActivateSignal(OutputX) function.  I did type it the correct way in the macro.
Title: Re: Mach3 and a tube bender
Post by: poppabear on February 18, 2009, 07:34:16 PM
something is over writing it then..........

look through your Ports and pins and make sure nothing else is writting to that Port/Pin, and nothing esle is using OUTPUT3 eigther