Hello Guest it is March 28, 2024, 10:09:13 AM

Author Topic: ATC code help  (Read 5255 times)

0 Members and 1 Guest are viewing this topic.

ATC code help
« on: February 27, 2016, 06:44:46 AM »
I'm sure this subject has been discussed many times before, but I need help with setting up my ATC.

I have a Kress spindle with a Sorotec ATC, and a 5 position linear tool holder.  The M/C coordinates for each of the
5 tool holders positions are as follows...

         T1 - X6.83     Y61.61
         T2 - X6.83     Y96.45
         T3 - X6.83     Y131.23
         T4 - X6.83     Y166.05
         T5 - X6.83     Y200.25

The Z height is -50mm (M/C).

As I am fairly new to this, I have tried a VB script with the following code.  Having sourced some ideas from this
forum.  The script is just to select one tool.

If GetSelectedTool() = GetCurrentTool() Then
End
End If
If GetSelectedTool = 1 Then
Code "G53 G0 X40"      
Code "G53 G0 Y61.61"      
Code "G53 G0 X6.83"        
Code "G53 G1 Z-30 F500"
ActivateSignal(OutPut4)
Sleep 1000
Code "G53 G0 Z-50"
While IsMoving()
Wend
Sleep 1000
DeActivateSignal(OutPut4)
Code "G53 G0 Z-30"
Code "G53 G0 X40"
Code "G0 X0 Y0 Z0"
End If

If I omit the first four lines (and the last End If)...it sort of works!  But with the first four lines in, it doesn't do
anything!  I actually don't understand the first four lines....so if someone could advise, that would help.

Also, if I run just the code from line 5, it sort of works...BUT...the ATC opens the drawbar before moving, which
I'm puzzled!

I can't see what is wrong with the simpler code...

Code "G53 G0 X40"      
Code "G53 G0 Y61.61"      
Code "G53 G0 X6.83"        
Code "G53 G1 Z-30 F500"
ActivateSignal(OutPut4)
Sleep 1000
Code "G53 G0 Z-50"
While IsMoving()
Wend
Sleep 1000
DeActivateSignal(OutPut4)
Code "G53 G0 Z-30"
Code "G53 G0 X40"
Code "G0 X0 Y0 Z0"

What am I doing wrong?

Regards.

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: ATC code help
« Reply #1 on: February 27, 2016, 07:38:55 AM »
do you know what the while isMoving() statement does?
Re: ATC code help
« Reply #2 on: February 27, 2016, 07:41:27 AM »
I think so Stirling.  It tells Mach to wait until something stops....Correct?

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: ATC code help
« Reply #3 on: February 27, 2016, 07:51:33 AM »
In the context of what you're doing here - yes. So don't you want to wait for something to stop before you open the drawbar?
Re: ATC code help
« Reply #4 on: February 27, 2016, 08:12:52 AM »
Not with you!  I thought that part of the code was just about right...although I have made a couple of changes.

At this point the drawbar should be closed (OutPut4)

Code "G53 G0 X40"                Move to clear the tool holders
Code "G53 G0 Y61.61"           Move to Tool #1 position in Y
Code "G53 G0 X6.83"             Move to directly above the tool position
Code "G53 G1 Z-30 F500"       Move to a safe height just above the tool
ActivateSignal(OutPut4)          Open the drawbar
Sleep 1000                            Wait 1 second
Code "G53 G0 Z-50"                Move to the tool 'grab' location
DeActivateSignal(OutPut4)       Close drawbar
Sleep 1000                            Wait 1 second
Code "G53 G0 Z-30"               Move back up to the safe height      
Code "G53 G0 X40"                Move away from the tool holder
Code "G0 X0 Y0 Z0"               Move to Fixture Offset (0,0,0)
While IsMoving()
Wend

Could you make any amendments as required?

Keith
« Last Edit: February 27, 2016, 08:14:34 AM by krsykes23 »

Offline ger21

*
  • *
  •  6,295 6,295
    • View Profile
    • The CNC Woodworker
Re: ATC code help
« Reply #5 on: February 27, 2016, 08:18:35 AM »
You need a While IsMoving()
Wend

between every movement.

And if there's already a tool in the spindle, isn't it going to drop it?
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: ATC code help
« Reply #6 on: February 27, 2016, 08:29:59 AM »
OK - so you need to understand something about macros.

They run in a totally separate thread from Mach proper. i.e. they run CONCURRENTLY.

So when you issue (say)

Code "G53 G0 X40"  'Move to clear the tool holders

The macro is saying to Mach - please insert this into your execution queue.

Mach will do as it's asked but here's the thing. Mach will EXECUTE that line of code in it's own good time.

Meanwhile, the macro will move onto the next line and say to Mach - please insert this into your execution queue.

Again, Mach will do this BUT it's probably (most likely) still actually executing the first line.

What you're doing is asking Mach to queue all four lines and then immediately activating output 4.

HOWEVER, Mach is probaby STILL just actually executing the first gcode line.

So you end up activating your draw bar WELL before you should.

So when you ask Mach to queue requests (in this case for movement), you MUST then WAIT until Mach has finished before you carry on. This is called thread synchronisation. The method Mach provides us to do this is the isMoving() function.

So what you need is:

Code: [Select]
Code "G53 G0 X40"       'Move to clear the tool holders
Code "G53 G0 Y61.61"   
Code "G53 G0 X6.83"     'Move to directly above the tool position
Code "G53 G1 Z-30 F500" 'Move to a safe height just above the tool
while isMoving()        'wait for Mach to do everything in the queue
wend
ActivateSignal(OutPut4) 'THEN - Open the drawbar
Re: ATC code help
« Reply #7 on: February 27, 2016, 09:24:05 AM »
Hi all.  Thanks for the replies.  I seem to be getting somewhere now.  I'll adapt the code sample you sent and see
how I get on.

Might have a couple of extra related questions soon.

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: ATC code help
« Reply #8 on: February 27, 2016, 11:28:50 AM »
Ian that is probably the best explaination of why you want to wait (;-)  That i have seen.

But there are times when Mach3 will not have full control over teh qued group of Gcode motion and it can get out of order as well.  This occurs in Mach4/Lua as well (;-)

They are still missing teh boat as a CNC MACRO language. They do NOT provide proper sync of the code line by line .

You will NEVER see that happen in  Macro B or on any control it runs on.


 (;-) TP
« Last Edit: February 27, 2016, 11:34:38 AM by BR549 »

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: ATC code help
« Reply #9 on: February 27, 2016, 11:33:32 AM »
You old charmer - what do you want?  ;D

Dang - you went and edited whilst I posted...

Dang - you just dd it again...
« Last Edit: February 27, 2016, 11:35:29 AM by stirling »