Hello Guest it is May 13, 2021, 01:29:32 AM

Author Topic: Help with Mach 4 controlling a PLC for tool changes.  (Read 11524 times)

0 Members and 1 Guest are viewing this topic.

Re: Help with Mach 4 controlling a PLC for tool changes.
« Reply #30 on: January 24, 2018, 02:36:05 AM »
I appreciate the help, but as I said I'm no programmer. I understand what you mean and can program my PLC for the most part, but I'm not understanding the code.

How does Mach know what signal to send to my PLC with the identity of the tool that needs changing? Is that the register you're talking about?

Offline Chaoticone

*
  • *
  •  5,626 5,626
  • Precision Chaos
    • View Profile
Re: Help with Mach 4 controlling a PLC for tool changes.
« Reply #31 on: January 24, 2018, 09:09:45 AM »
Quote
I understand what you mean and can program my PLC for the most part

Good, get that done first like I said. Once you have the tool changer working right and it can change tools when you tell it 2 things....

1) What tool to get through a register
2) Change to that tool (start tool change) through a register

you're virtually finished and you can do all of this before you ever even install Mach4.

Then you will need the PLC to tell you that the tool change is complete (by changing that register that told it to change tools).

Once you have that done getting the m6 to do 3 things......

1) Tell the PLC those 2 things (what tool to get and start tool change).
2) Then wait for conformation that the PLC has finished changing tools.
3) Then update your tool offsets or error out depending on what the confirmation check comes back with.

will be super easy with Mach4. I have given you most of it (though not completely accurate) already. But you get the PLC changing tools as I described using only the PLC and Qmodbus (or similar) someone here will help you get the scripting in your m6 (if I have to do it myself). And do note I said help. Help means you will learn too. But if someone else does it all for you it will take all the fun out of it. Don't want that. Hobbies are supposed to be fun.  :)

Quote
How does Mach know what signal to send to my PLC with the identity of the tool that needs changing?

local current, rc = mc.mcToolGetCurret(inst)
local selected, rc = mc.mcToolGetSelected(inst)

But, like I said, you need not even worry about that yet. Use Qmodbus to write to a register in the PLC telling the PLC what tool to change to.

Quote
but I'm not understanding the code.

You can fix that. Look up those 2 api calls in the Mach4 core API doc. It's in your C:\Mach4 Hobby\Docs directory.

Trust me, doing this in Mach4 will be much easier than you think if you can get the PLC doing its thing. But I wont be helping much with that. Others here probably will but if not I'm sure you can work through it between Click's docs and AutomationDirects forum, support and other resources.
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Help with Mach 4 controlling a PLC for tool changes.
« Reply #32 on: January 24, 2018, 10:52:03 AM »
Take a look at my macro again.  It uses registers to tell the Click which tool is requested.
Chad Byrd

Offline Chaoticone

*
  • *
  •  5,626 5,626
  • Precision Chaos
    • View Profile
Re: Help with Mach 4 controlling a PLC for tool changes.
« Reply #33 on: January 24, 2018, 05:34:40 PM »
Take a look at my macro again.  It uses registers to tell the Click which tool is requested.

Yup, Chads' m6 looks like it does exactly all you will need to do in script. Get the PLC doing its thing and your done!  :)
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Help with Mach 4 controlling a PLC for tool changes.
« Reply #34 on: January 24, 2018, 07:57:52 PM »
Thanks both of you! I'm starting to get a handle on the Lua. I don't understand how register's work, but I'm sure I can figure it out. PLC's are pretty easy to program.
Re: Help with Mach 4 controlling a PLC for tool changes.
« Reply #35 on: January 24, 2018, 10:35:30 PM »
Ok I'm starting to wrap my head around this. I've re-read this whole thread a bunch of times tonight.

Chad, you said use the compare function in Click DS1 = 1 turn on C1. Got that, that's easy. I'm already using C bits for each tool, C1-C8.

Now, if I tell Mach M6 T0101, I'm guessing it will send a 1 to DS1 and the click will goto tool 1, then a 2 for T0202, etc..?

In your macro you mention Output 22, DS1 and Input 0. Input 0 I take it is the signal going to the click verifying a tool change has completed? and that in turn tells mach that the tool change has completed and to continue with gcode?

Is the DS1 referenced in your macro sending a signal to click or just getting the value and output 22 is actually sending the tool number?

I also don't get what this code is referencing?  --Send signal to the Click to start the tool change.
         mc.mcSignalSetState(ToolChange,1) --Y001
         wx.wxMilliSleep(1000)
         mc.mcSignalSetState(ToolChange,0) --Y001

to me it seems like there are 3 different things in your macro to get the tool changing started.
Re: Help with Mach 4 controlling a PLC for tool changes.
« Reply #36 on: January 25, 2018, 09:22:39 AM »
Cartierusm,
Now, if I tell Mach M6 T0101, I'm guessing it will send a 1 to DS1 and the click will goto tool 1, then a 2 for T0202, etc..?
Yes.  You will need to set up a write register function in Mach4 Modbus.  Register 1 (from Mach) will be DS1 in the Click.  So, in the M6, you will set Register DS1 to the Requested Tool, Chaoticone has referenced this above.
So T101 --> DS1 = 1   T202 --> DS1 = 2  ETC. 

I also don't get what this code is referencing?  --Send signal to the Click to start the tool change.
         mc.mcSignalSetState(ToolChange,1) --Y001
         wx.wxMilliSleep(1000)
         mc.mcSignalSetState(ToolChange,0) --Y001

I am sending a signal to start my tool change.  In my code, you will see that I made the variable "ToolChange" to be set to Output22, Output22 is Y001 in the Click.  So, with the SignalSetState command, I am turning on Output22 for 1 second and then off.  This starts my tool change.  The signal triggers Y001, which sets a bit in the Click, this bit is the Tool Change Start bit.  If I don't turn off Output22 (ToolChange), the Click will read the signal again and restart the tool change (it shouldn't do anything but it will certainly run the routine again).

The DS1 is a register that is actual sending integers to the Click.  You set it up in the modbus function.  I think it is Write Register.  You can name it whatever you want, I named mine DS1 because it is directly linked to DS1 in the Click.

So, to recap how I start my tool change. 
I Set DS1 register in Mach to the requested tool.
I send a register to the Click (DS1) with the tool number.  DS1 in the Click reads that number so it knows which tool to change to.
I Toggle my "ToolChange" output  which is actually Output22 in Mach4 which is linked to Y001 in the Click.
Then I wait for the Input from the Click to continue G Code.
Chad Byrd
Re: Help with Mach 4 controlling a PLC for tool changes.
« Reply #37 on: January 25, 2018, 09:32:07 AM »
In the Click, here is an idea of what the ladder looks like.  
Also, you will need to set up another Memory type (probably DS2) to compare to your DS1.  This DS2 will be your actual tool position on your turret.
X001 -------- MATH  DS2 = 1
X002 -------- MATH  DS2 = 2
ETC

Click LADDER
Y001 ------------ SET C1

C1 ---------------- SUB ROUTINE  TOOL CHANGE
(At this point C1 is set, this is why I turn off Y001)

SUB ROUTINE TOOL CHANGE LADDER
COMPARE  DS1 NE DS2 -------------- Y##  (This will turn on the output that changes your tools)
once it reaches your desired tool it will turn off the output
Once this input is reached
X00# -------------- RESET C1
                       RETURN
Chad Byrd
Re: Help with Mach 4 controlling a PLC for tool changes.
« Reply #38 on: January 25, 2018, 02:34:44 PM »
Ok I'm clearly missing things. I understand what Chaoticone says about the bits and setting them and resetting them. Got that. Chad, I understand essentially what you're saying. I'm not understanding all the relationships in Click.

I've guessed now that a DS register does not trigger a physical action in Click. That's where I was getting hung up on. I figured that when mach sets a 1, for instance for T0101, to DS1 in click that would automatically start the tool change. But what you're implying is it just tells click this is the next tool to change to, but doesn't actually start the tool change program which rotates the tool changer.

Right now I'm using a physical button for each tool. So for tool 1 I'm using X001 to set C1 > then C1 starts the tool change program > when the requested tool, in this case tool 1, is completed it resets C1 and stops the motion.

My tool changer works perfectly like this.

I don't understand what you wrote in your last post about the ladder program.

I think I need to use DS1 to set the tool, then I'm assuming that the DS1 is set, after the correct tool has been physically changed then the DS1 would reset? In between I'll need to start the actual tool change program?

Yeah, I'm not sure how I would write that. I get that's what you wrote about. I'm just not getting it. Let mull it over maybe it'll come to me.

Re: Help with Mach 4 controlling a PLC for tool changes.
« Reply #39 on: January 27, 2018, 09:36:49 PM »
Ok this was as they said, pretty easy. You just have to understand what's going on. I don't understand everything, but I got it to work.

A BIG thanks to Chad!!

So I'll try to explain what Chad said so other can figure it out.

First thing: Get your tool changer working with a PLC. I think the click does everything you need, is inexpensive, easy to use and figure out and come with Tech Support from Automation Direct. I used an 8 Position Rotary switch with a regular momentary button to make my tool changer go manually.

After you get your PLC to change tools perfectly you can add to the same line as your manual switch the following code:

X001-------------------C1