Machsupport Forum

Mach Discussion => VB and the development of wizards => Topic started by: Oldraven on June 07, 2011, 07:43:22 AM

Title: M6Start for Toolchanger again.
Post by: Oldraven on June 07, 2011, 07:43:22 AM
Hi ,

I used a M6Start macro that someone had written for a 6 tool Boxford ATC.
That worked, sort of, for my Emco5 ATC converted with a stepper motor and one optical slot for homing.

The problem was that the macro could not see if the ATC was homed in the Manual screen, Home All.
It would turn at random, tool positions were not absolute.

I inserted this piece of VB code in the beginning of the macro;

'----------------------------------------
' First check if ATC is homed.

If IsActive(INPUT1) Then
  Message " Input 1 is Active"
  SensorState = "Active"
Else  
  Message " Input 1 is NOT Active, Home first."
  
  Code "M30"   'End the execution of the G-Code.
End
End If
If SensorState = "Active" Then
Current_Tool = 1      'Set ATC Home as Current Tool.
End If         

'-----------------------------------------

That set the Current_Tool as tool # one.
But, when a second tool change was asked for in the G-code things went wrong.
The macro insists to be homed again.

I need some code or place to store the information that the part homing command is to be skipped.
Say that I insert a variable like Homing_Done just before the   end If;

If SensorState = "Active" Then
Current_Tool = 1      'Set ATC Home as Current Tool.
Homing_Done = 1
End If

I want to store this Homing_Done somewhere. Can that be done outside the macro and have the macro look for it each time the M6Start
is called in the current G-code?

This is the total macro;

' Boxford 160TCL Toolchanger Macro.
'
' Works by turning CW to just past the tool position
' and then CCW into a stop.
' Axis setup as rotary e.g. move 360 = 1 full turn.

' Adapted for the EMCO5cnc Automatic Tool Changer.
' Checks if ATC is Homed first and sets Current_Tool as #1.
' If not Homed it ends the program.

If IsLoading() Then
' Do Nothing, program loading
Else


' Dim Variables

Dim Num_Tools As Integer
Dim CW_Steps_Per_Tool As Integer
Dim CCW_Steps As Integer
Dim HoldingDRO As Integer
Dim Requested_Tool As Integer
Dim Current_Tool As Integer
Dim CW_Feed As Integer
Dim CCW_Feed As Integer

Dim moves As Integer
Dim total_move As Integer

'----------------------------------------
' First check if ATC is homed.

If IsActive(INPUT1) Then
  Message " Input 1 is Active"
  SensorState = "Active"
Else  
  Message " Input 1 is NOT Active, Home first."
  
  Code "M30"   'End the execution of the G-Code.
End
End If
If SensorState = "Active" Then
Current_Tool = 1      'Set ATC Home as Current Tool.
End If         

'-----------------------------------------
' set up some vars

Num_Tools = 6
CW_Move_Per_Tool = 360/Num_Tools
CCW_Move = 10
HoldingDRO = 1050
Requested_Tool = GetSelectedTool()
'  Current_Tool = GetUserDRO(HoldingDRO)
CW_Feed = 700      
CCW_Feed = 700
Current_Feed = GetOEMDRO(818)



' start tool change

Message ("Requested Tool No=" & Requested_Tool)

If Requested_Tool > Num_Tools Then
Message "Requested Tool No. too high, program stopped."
Code "M30"
End
End If

If Requested_Tool < 1 Then
Message "Requested Tool No. too low, program stopped."
Code "M30"
End
End If

If Requested_Tool = Current_Tool Then
' do nothing
Else
' lets do some changing
If Requested_Tool > Current_Tool Then moves = Requested_Tool -Current_Tool
If Requested_Tool < Current_Tool Then moves = Num_Tools - Current_Tool +Requested_Tool

total_move = (moves * CW_Move_Per_Tool)+(CCW_Move/2)

'Code "G01 x-10 F700"
'Code "z-10"
Code "G91 G94" 'incremental & Feed per minute
Code "G0 A" & total_move '& "F" & CW_Feed
Code "G0 A" & "-" & CCW_Move '& "F" & CCW_Feed
While IsMoving()
Wend

SetCurrentTool Requested_Tool
SetUserDRO HoldingDRO, Requested_Tool
Code "G90" ' back to absolute movement
Code "F" & Current_Feed
End If
End If

' end of tool change          

Thanks for looking,

Jos
Holland
Title: Re: M6Start for Toolchanger again.
Post by: BR549 on June 07, 2011, 11:30:48 AM
There are many ways to do it. Mach has an led indicator that shows IF the axis has been refHome.  Then you ask IF the led is not active then HOME else do the rest of the code.

IF you need more help just ask.

1 tip is to get rid of the END in this section as it will end the program before it gets started(;-)


If IsActive(INPUT1) Then
  Message " Input 1 is Active"
  SensorState = "Active"
Else 
  Message " Input 1 is NOT Active, Home first."
 
  Code "M30"   'End the execution of the G-Code.
End   <---------------------------------------------------------------------------------------------- Delete this piece of code
End If
If SensorState = "Active" Then
Current_Tool = 1      'Set ATC Home as Current Tool.
End If         

(;-)TP

Title: Re: M6Start for Toolchanger again.
Post by: BR549 on June 07, 2011, 12:25:57 PM
Never mind the delte the END stament I see where you are heading(;-)

(;-) TP
Title: Re: M6Start for Toolchanger again.
Post by: Oldraven on June 07, 2011, 12:59:16 PM
Never mind the delte the END stament I see where you are heading(;-)

(;-) TP

Yes, that was the idea. End the execution of the G-code and jump to the beginning.
That works.

I wanted to set a sort of register after the statement ; Current_tool = 1. I.E. Homing_Done = 1
But that info is lost every time M6Start is called by a subsequent tool change in the running G-code.

I need to put the info somewhere in a register so that I can have the macro look at it and determine its status.
By a second call to the tool change the macro can fetch its status and skip checking for the initial homing.

Regards,
Jos
Holland
Title: Re: M6Start for Toolchanger again.
Post by: BR549 on June 07, 2011, 02:14:10 PM
That would be easy to do Just use a Gcode# variable to store the homed bit value.

SetVar(300,0) would be UNhomed , The default is 0 when mach starts up.
Setvar(300,1) would be HOMED.

That way as long as MACH is running the values are held. and when you close down mach the values are not stored.

Then at the begging of the macro ask

IF GetVar(300) =0 then end the script

else continue.

(;-) TP


(;-) TP

Title: Re: M6Start for Toolchanger again.
Post by: Oldraven on June 07, 2011, 02:19:10 PM
OK,

With this I have some direction.
I'll have a look at it tomorrow.

Shutting down for the evening it is past 8 o'clock in the evening here.

Thanks,

Jos
Title: Re: M6Start for Toolchanger again.
Post by: Promech on June 07, 2011, 11:10:14 PM
Will be following this closely.  Have also an Emco (Sauter) turret that needs to be automated. Do not know where to start.  Maybe replacing the AC motor with a Stepper as is suggested here.
Title: Re: M6Start for Toolchanger again.
Post by: BR549 on June 07, 2011, 11:14:54 PM
IF your mechanism is sound I would develope a software solution to run it as it is. I believe it has already been done, need to do some searching.

(;-) TP
Title: Re: M6Start for Toolchanger again.
Post by: Promech on June 08, 2011, 02:21:15 AM
The system is mechanically sound.  It comes with a little A.C. motor, a proximity switch that senses 8 positions (does not know which is which), and an 8 position encoder.  The A.C. motor is controlled by two contactors (forward and reverse) and it goes forward and then reverse each time it selected a tool.  To figure out how the original Emco program was including all these things may be a little complicated. Plus the A.C. motor voltage is 440 V, and I do not want to mess with that voltage again because I would have to add a 220 to 440 transformer.

I am thinking about replacing the A.C. motor with a stepper or a servo and then the proximity switch and the encoder will not be necessary.  Just use some type of homing so the servo knows where it is at start up and that would be all. Here it looks as you guys are discussing about a mill ATC, in my case it is an 8 position turret in a lathe, but the problem may be similar.

Thanks,

Jorge
Title: Re: M6Start for Toolchanger again.
Post by: BR549 on June 08, 2011, 07:21:11 PM
OK that is a simple overun system that uses an absoute (grey code) encoder to identify each stop position. I would replace the AC motor with a small DC motor.  I have seen the VB code somewhere for that type of changer.

I think Peter Homann from  MODIO  does a great job with this style system using the Modio to do the fuzzy logic. I would give him shout. HE may have the answer already to go in one simple kit.

Just a thought, (;-) TP
Title: Re: M6Start for Toolchanger again.
Post by: Oldraven on June 16, 2011, 09:47:44 AM

OK,
I have it working.
For the Emco5cnc ATC this macro now works.

First of all one has to Home the ATC in Mach3 Manual screen >> Home All.
Then , in Mach3 Auto, load the G-code to be executed.

The macro looks if the Homing has been done and sets a two variables.
One that homing has been done and one to make sure that Mach3 knows that the ATC homing position
is the Tool #1 position.
The hint to use SetVar helped me a lot.

Jos


' Based on Boxford 160TCL Toolchanger Macro.
' Modified for the EMCO5cnc Automatic Tool Changer.
' ATC has a steppermotor and an optical slot @ INPUT1
' Works by turning CW to just past the tool position
' and then CCW into a stop.
' Axis setup as rotary e.g. move 360 = 1 full turn.


If IsLoading() Then
' Do Nothing, program loading
Else

' Dim Variables

Dim Num_Tools As Integer
Dim CW_Steps_Per_Tool As Integer
Dim CCW_Steps As Integer
Dim HoldingDRO As Integer
Dim Requested_Tool As Integer
Dim Current_Tool As Integer
Dim CW_Feed As Integer
Dim CCW_Feed As Integer
Dim moves As Integer
Dim total_move As Integer

' First check if Homing has been done

If GetVar(300) = 1 Then         ' Has homing been done?
  GoTo Main               ' Yes, is Homed, jump to Main
  Else
End If
 
' If Not, check if ATC is homed.

If IsActive(INPUT1) Then              ' Look for ATC Home pulse
    SensorState = "Active"
Else 
  Message " Input 1 is NOT Active, Home first."
  Code "M30"               ' End G-code execution
 End
End If

If SensorState = "Active" Then
    SetVar(300,1)                    'Is Homed
   Setvar(301,1)            'Set Current Tool as #1
End If

Main

' set up some vars

Num_Tools = 6               
CW_Move_Per_Tool = 62          '360/Num_Tools , not used
CCW_Move = 15

Requested_Tool = GetSelectedTool()
Current_Tool = GetVar(301)
CW_Feed = 700   
CCW_Feed = 700
Current_Feed = GetOEMDRO(818)

' start tool change

Message ("Requested Tool No=" & Requested_Tool)

If Requested_Tool > Num_Tools Then
Message "Requested Tool No. too high, program stopped."
Code "M30"
End
End If

If Requested_Tool < 1 Then
Message "Requested Tool No. too low, program stopped."
Code "M30"
End
End If

If Requested_Tool = Current_Tool Then
' do nothing
Else
' lets do some changing
If Requested_Tool > Current_Tool Then moves = Requested_Tool -Current_Tool
If Requested_Tool < Current_Tool Then moves = (Num_Tools - Current_Tool) +Requested_Tool

total_move = (moves * CW_Move_Per_Tool)+(CCW_Move/2)

Code "G91 G94"                'incremental & Feed per minute
Code "G0 A" & total_move               '& "F" & CW_Feed
Code "G0 A" & "-" & CCW_Move            '& "F" & CCW_Feed

While IsMoving()
Wend

SetCurrentTool Requested_Tool
SetVar(301,Requested_Tool)      'Store Current Tool
Code "G90" ' back to absolute movement
Code "F" & Current_Feed
End If
End If

' end of tool change