Hello Guest it is March 29, 2024, 03:08:38 AM

Author Topic: ATC built, need some macro help  (Read 5245 times)

0 Members and 1 Guest are viewing this topic.

ATC built, need some macro help
« on: June 21, 2013, 12:32:12 AM »
I've finished building an ATC for my Denford Easimill 3, there are some pictures and info here:
http://coreyrenner.tumblr.com/

The macro is where I'm struggling.  I was hoping that I could use some of the macro commands in the MDI window to make it go, I discovered that you can't.  So, I made a quick fake macro that is intended to just run the changer through all of its movements, but it doesn't seem to do anything.  I replaced the M6start.m1a file with the stuff below.  I typed M6T1 into the MDI window and hit enter.  I was hoping that it would cycle itself.  Instead, I got the "Change tool and press cycle start" message.  Ok, need to tell Mach it's got an ATC, so in the general config, I changed it from "Stop Spindle and prompt for toolchange" to ATC.  Tried again, same message.  Just in-case I made a program like this:

N10 M6T1

and ran that.  Nada.  What am I missing?  Here's my crappo macro, the in/out pins are programmed correctly.  I'd appreciate any guidance.


ActivateSignal(Output12) 'Deploy Changer Cylinder
  While Not IsActive(OEMTRIG3) 'Changer Deployed Switch
  sleep(100)
  Wend
ActivateSignal(Output13) 'Slide In Cylinder
While Not IsActive(OEMTRIG5) 'Slide In Switch
  sleep(100)
  Wend
ActivateSignal(Output14) 'Drawbar Release and Proprod
While Not IsActive(OEMTRIG6) 'Drawbar Released
  sleep(100)
  Wend
ActivateSignal(Output15) 'Toolout Cylinder
While Not IsActive(OEMTRIG8) 'Tool out from Spindle
  sleep(100)
  Wend
'************************************************
'carousel rotation stuff goes here
sleep(5000)
'************************************************
DeActivateSignal(Output15) 'Tool back into spindle
While Not IsActive(OEMTRIG7) 'Tool back in spindle
  sleep(100)
  Wend
DeActivateSignal(Output14) 'Drawbar Grabs
While Not IsActive(OEMTRIG6) 'Drawbar has grabbed
  sleep(100)
  Wend
DeActivateSignal(Output13) 'Slide Out
While Not IsActive(OEMTRIG4) 'Slide is Out
  sleep(100)
  Wend
DeActivateSignal(Output12) 'ATC Retract
While Not IsActive(OEMTRIG2) 'ATC Retracted
  sleep(100)
  Wend

'///Subroutines///
'Sub ATCready
 'If IsActive(OEMTRIG2) And IsActive(OEMTRIG4) And Not IsActive(OEMTRIG6) And IsActive(OEMTRIG7) And IsActive(OEMTRIG9) Then
'End Sub
'MsgBox ("ATC NOT

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: ATC built, need some macro help
« Reply #1 on: June 21, 2013, 05:19:54 AM »
what happens if you just run

Code: [Select]
activateSignal(OUTPUT12)
sleep 1000
deActivateSignal(OUTPUT12)
from the script editor?

then what happens if you just have that in your M6Start.m1s and do a M6T1 from the MDI?

Ian
« Last Edit: June 21, 2013, 05:40:27 AM by stirling »
Re: ATC built, need some macro help
« Reply #2 on: June 22, 2013, 11:30:44 PM »
Stirling,
I didn't know about the script editor, it helped a great deal, thank you.  I was making a couple of dumb mistakes.  I've got the changer operating properly and changing tools in both directions.  I've tried to add logic to deal with the initial tool not being set and skipping the change if the correct tool is already installed.  Those two parts are not working correctly.  I need to know the correct syntax to do an If/Then that exits from the Macro.  Here is what I've got, the first two chunks under Sub Main() do not work, the script editor doesn't complain, but if they're in there it doesn't work.  Without them everything works great, but those two conditions would blow up.  That "Exit Sub" seems to not be the way to do it, have also tried "End Sub" and "Exit".  What's the correct way to exit from a Macro when a condition is met?

cheers,
c

'*************************************
'M6Start.m1a  v.1 by Corey Renner

'Variables:

CurrentTool=GetCurrentTool()
NewTool=GetSelectedTool()

'*************************************

Sub Main()
 
'This stuff is wrong**************
If CurrentTool=0 Then 'Exit with error ATC not homed
MsgBox ("ERROR: ATC Not Homed")
Beep
Code "M00"
Exit Sub 'This Line is a problem, what should be here to exit the Macro?***************
End If
  
If CurrentTool=NewTool Then 'Exit if correct tool is already loaded
MsgBox ("No Toolchange Required")
Exit Sub  'This Line is a problem, what should be here to exit the Macro?***************
End If  
'Up to here.  Everything below is fine.*************      

ActivateSignal(Output12) 'Deploy Changer Cylinder
  While Not IsActive(OEMTRIG3) 'Changer Deployed Switch
  sleep(100)
  Wend
  
ActivateSignal(Output13) 'Slide In Cylinder
While Not IsActive(OEMTRIG5) 'Slide In Switch
  sleep(100)
  Wend
  
ActivateSignal(Output14) 'Drawbar Release and Proprod
While Not IsActive(OEMTRIG6) 'Drawbar Released
  sleep(100)
  Wend
  
ActivateSignal(Output15) 'Toolout Cylinder
While Not IsActive(OEMTRIG8) 'Tool out from Spindle
  sleep(100)
  Wend
  
'************************************************
'carousel rotation stuff
FwdIndex=CurrentTool
FwdStep=0
While FwdIndex<>NewTool
 FwdStep=FwdStep+1
 FwdIndex=FwdIndex+1
 If FwdIndex>12 Then
 FwdIndex=1
 End If
 
Wend

RevStep=12-FwdStep

If FwdStep<=6 Then
CarouselFWD (FwdStep)
Else
CarouselREV (RevStep)
End If

'************************************************

DeActivateSignal(Output15) 'Tool back into spindle
'ActivateSignal(Output16) 'Airblast on
While Not IsActive(OEMTRIG7) 'Tool back in spindle
  sleep(100)
  Wend
  
'DeActivateSignal(Output16) 'Airblast off
DeActivateSignal(Output14) 'Drawbar Grabs
While Not IsActive(OEMTRIG6) 'Drawbar has grabbed
  sleep(100)
  Wend
  
DeActivateSignal(Output13) 'Slide Out
While Not IsActive(OEMTRIG4) 'Slide is Out
  sleep(100)
  Wend
  
DeActivateSignal(Output12) 'ATC Retract
While Not IsActive(OEMTRIG2) 'ATC Retracted
  sleep(100)
  Wend
  
DoButton(24)'Home Z-axis to release prop-rod and correct error

SetCurrentTool (NewTool)
End Sub
 
'///Functions///

Function CarouselFWD(ByVal FwdStep As Integer) As Integer
ActivateSignal(Output17) 'Start Motor in FWD Direction
For X=1 To FwdStep
  While IsActive(OEMTRIG9)
  sleep(100)
  Wend
  While Not IsActive(OEMTRIG9)
  sleep(100)
  Wend
Next X
DeActivateSignal(Output17)
End Function

Function CarouselREV(ByVal RevStep As Integer) As Integer
ActivateSignal(Output18) 'Start Motor in REV Direction
For X=1 to RevStep
  While IsActive(OEMTRIG9)
  sleep(100)
  Wend
  While Not IsActive(OEMTRIG9)
  sleep(100)
  Wend
Next X
DeActivateSignal(Output18)
End Function
            
« Last Edit: June 22, 2013, 11:33:36 PM by vandal968 »

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: ATC built, need some macro help
« Reply #3 on: June 23, 2013, 05:50:45 AM »
Exiting a sub/func prematurely is bad practice. A sub/func should have ONE entry point and ONE exit point. I know you'll see a lot of code where people do it but it's never necessary and just makes code harder to read and more prone to error. The "if" statement comes with an "else" clause to allow structured code.

Code: [Select]
sub
  if condition then
    do this
  else
    do that
  end if
end sub
Simples

Ian
Re: ATC built, need some macro help
« Reply #4 on: June 23, 2013, 10:55:48 PM »
Got it all figured out, thanks for the help.

Here's a video of the whole thing working:
http://www.youtube.com/watch?v=8xvxwUqdcWg

cheers,
c

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: ATC built, need some macro help
« Reply #5 on: June 23, 2013, 11:09:27 PM »
Excellent job on the tool changer(;-)

Care to share the completed macro to control the tool change ?

(;-) TP
Re: ATC built, need some macro help
« Reply #6 on: June 24, 2013, 07:58:15 PM »
+1 on posting the code. I am also building a 10 position ATC for my RF45 and could use some help with the macro side of things.