Machsupport Forum

Mach Discussion => General Mach Discussion => Topic started by: PROTOPLANT on November 16, 2009, 11:42:04 AM

Title: Lathe turret, VB, PLC, MODBUS, Position
Post by: PROTOPLANT on November 16, 2009, 11:42:04 AM
Hi all,

Thanks to everyone's help I am making good progress on the Takisawa turret.  I've got all the I-O wired and have a CLICK PLC wired up and communicating with MACH.  Also the power side is up and running, the motor relays are happy....  I have a few questions that maybe some folks could help with, any comments would be appreciated :-)

1-  I am having trouble with the idea of home switches and separate coordinate systems.  This may expose some ignorance on my part, but on my other machines I have no home switches and never change between coordinate systems, just zero the machine on the part and go.  Now I want the tool change to take place at the same spot all the time without having to zero off anything but the home switches, I think....  Anybody have a good explanation of this?

2- Another conceptual issue I am having is with communication between Mach and the PLC via VB scripts.  What it looks like others have done is write a ladder in the PLC and have Mach write a bit to the PLC to initiate that ladder program.  In other words Mach communicates with the PLC with single bits like I-O instead of sending some sort of commands?  I've read through a lot of posts on here and that seems like the idea but I wanted to see what folks think before assuming that is how it works. 

3-I think I want to avoid Brains for this one, is that a good idea?

4- When setting up the MODBUS, the dialogue box will not go away.  If you hit OK it just goes to the bottom left of the screen and stays there?  Is this abnormal?

OK, hope that's not too much stuff....  I will post some more images in show and tell one of these days, it is looking good.
Thanks so much,
Dustin
Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: Hood on November 16, 2009, 02:14:06 PM
1-  I am having trouble with the idea of home switches and separate coordinate systems.  This may expose some ignorance on my part, but on my other machines I have no home switches and never change between coordinate systems, just zero the machine on the part and go.  Now I want the tool change to take place at the same spot all the time without having to zero off anything but the home switches, I think....  Anybody have a good explanation of this?

I never use the work offsets in turn,  I just stick to G54,  but some do.
Tool offsets however are a must if you have a turret :)
How accurate yours will be will depend on the accuracy of your homing. I do the homing external to Mach, my drives are cabable of homing to a mechanical switch then once it is seen the drive will look for the encoders index pulse and gate it with A and B channels, this makes it extremely accurate. If your drives do not have that feature then I would suggest that either very high quality mechanical switches or optical switches would be the way to go. If using opticals you will have to house them in a waterproof casing and just have a trigger rod coming out of the box via an 0 Ring seal or similar.



2- Another conceptual issue I am having is with communication between Mach and the PLC via VB scripts.  What it looks like others have done is write a ladder in the PLC and have Mach write a bit to the PLC to initiate that ladder program.  In other words Mach communicates with the PLC with single bits like I-O instead of sending some sort of commands?  I've read through a lot of posts on here and that seems like the idea but I wanted to see what folks think before assuming that is how it works. 

Yes thats it, the PLC does the tool change but Mach tells it when to start and which tool to go to, once there the PLC then tells Mach its done and the macro finishes and allows Mach to carry on.


3-I think I want to avoid Brains for this one, is that a good idea?

Not keen on Brains myself for anything like this, fine for FRO or SRO etc but thats just me, others use Brains for toolchanging.



4- When setting up the MODBUS, the dialogue box will not go away.  If you hit OK it just goes to the bottom left of the screen and stays there?  Is this abnormal?

Thats normal, it will be gone the next time you start Mach, well unless you open it again ;D

Hood
Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: Peter Homann on November 16, 2009, 04:15:10 PM
Hi Dustin,

All your VB script stuff should be in your M6Start macro. You will need to use a brain to transfer info between the M6 start macro and the modbus config data areas.

Basically your M6 start macro should indicate to the plc what tool it wants, then the plc does its stuff and returns after it is done with a success or error status.

If this is not clear, let me know?

Cheers,

Peter.
Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: Hood on November 16, 2009, 04:26:05 PM
Peter, how do the click PLC's connect to modbus, serial? TCP?
I use a D0-06 and the old style serial interface and there is no need for a Brain.

Hood
Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: PROTOPLANT on November 16, 2009, 04:43:50 PM
Hi Peter, Hood,

Thanks Peter, I think it is clear, I need to spend some hours with it and get in further.  What I think you are saying is that I will need to use brains to allocate PLC addresses to Mach inputs, or something similar....

Hood, the CLICK I have is hooked up with a serial cable.  It is the DB 9 pin at the computer and a phone cord at the PLC.

Thank you,
Dustin
Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: PROTOPLANT on November 16, 2009, 04:47:22 PM
Hood, Thanks for the information, I need to look into the G54 and tool offsets a bit....  I guess I don't care if the home switches are accurate, I don;t think I would trust them for actual cutting anyway.  I was more thinking of a tool change reference point that would not change every time the machine was turned on.  I may still be slightly confused on the sequence of things, need to work with it a little more...

Thanks for the input,
Dustin
Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: Hood on November 16, 2009, 04:50:21 PM
Hi Peter, Hood,
Hood, the CLICK I have is hooked up with a serial cable.  It is the DB 9 pin at the computer and a phone cord at the PLC.

Thank you,
Dustin

No need to use a Brain then if you use the old style serial interface, never used the serial plugin so dont know whether a brain is needed for it.


Heres a small part of my M6 macro

If GetSelectedTool=1  Then               'If selected tool = 1
 Do                                       'Start loop
 Call SetModOutput (9,1)                  'Toolchange signal to PLC to start turret indexing
 If GetInput (0) Then Exit Do             'Correct tool in position signal from PLC and exit loop
 Loop                                     'Continue loop if above signal is not present
 End If
 Call SetModOutput (9,0)                  'Cancel tool change signal to PLC
 
 If GetSelectedTool=2 Then                'If selected tool = 2
 Do
 Call SetModOutput (9,1)
 If GetInput (1)  Then Exit Do
 Loop
 End If
 Call SetModOutput (9,0)



Hood
Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: Hood on November 16, 2009, 04:55:49 PM
The reason you want accurate homing is that you can set all your tools up in your turret and when you call them to go to a dia you know they will go exactly to that dia. Some people have said home switches are a waste of time on a lathe and that the tool will never cut at the same dia unless you take a test cut first and set them each time you start. I suspect they have lightweight machines that are not very rigid, your lathe is like mine, built like a brick s**t house and rigidity is not a problem ;)

Hood
Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: PROTOPLANT on November 16, 2009, 04:56:05 PM
Thanks for the snippet Hood, I've found that on other posts and it is helpful.  Is SetModOutput a subroutine?  Or is that a command?  Where would I find info on the syntax of that (what the (9,1) means, etc)?  I am assuming it is toggling bit "9" in the PLC but I am fuzzy on how to address the PLC.

Dustin
Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: Hood on November 16, 2009, 05:02:49 PM
You dont actually need the Call part now (just found that out a few weeks ago from Ray)
The SetModOutPut(9,1) will set mod Output 9 active, SetModOutPut(9,0) will turn it off again.
GetInput(0)  is looking for the mod input 0

I will attach a screenshot, in a few mins, of the part of my ladder that the VB above is for.

Hood
Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: Hood on November 16, 2009, 05:07:40 PM
Heres the part of the ladder that works the rear turret on my lathe, the front toolpost is similar.

Hood
Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: Hood on November 16, 2009, 05:10:17 PM
Sorry, snipped the start of the toolchange ladder off, heres the relevant  screenshot.
Hood
Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: Hood on November 16, 2009, 05:16:29 PM
Actually looking at that I have the mod inputs named wrong, B2000.0  should be named in the ladder as Modin0 not modin1 as I have there. That is only a reference for me looking at so it wont affect the VB but would muddle me up if I was looking at it LOL.

Hood
Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: PROTOPLANT on November 16, 2009, 05:18:29 PM
Hood, Yeah, I am hoping rigidity is not an issue here, I think that would be a bad sign :-)

Hmm, Hopefully the home switches that are on there are good enough, they are the stock Takisawa ones so I am assuming they are fairly accurate, as long as I go at them with the same feedrate.

Dustin
Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: PROTOPLANT on November 16, 2009, 05:21:28 PM
Hood, Thanks for the ladder snippets, I think that will be really helpful.  The big picture is becoming clearer...

Dustin
Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: Hood on November 16, 2009, 05:24:28 PM
No probs, if you  need help just shout, not the best at it but have managed to muddle through a few.
If you go the plugin route then Poppabear or Peter are probably the ones to ask as I know nothing about the plugin.

Hood
Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: Peter Homann on November 16, 2009, 06:02:30 PM
Peter, how do the click PLC's connect to modbus, serial? TCP?
I use a D0-06 and the old style serial interface and there is no need for a Brain.

Hood

Hi Hood,

If you use the old legacy Modbus interface, you are correct as there are VB functions to access the Modbus buffers. This is what I used for my ModIO controlled toolchanger

With the newer Modbus with PlugIn support module, the only way to access the modbus buffers is either via a plugin or by Brains. There is no support to access them via a VB Script macro. :( This is a big limitation as I see it. I've asked Brian to add them in, and I think that they will be there for Mach4. It is a real shame that they can't be added in to Mach3 as it is just 4 simple functions that are required.

Accessing them through Brains is a pain. The brain has to copy the data to a User DRO, then the Macro read the DRO.  Same for data going the other way.

I came up with a tool-change macro that  I was hoping could be the basis of a standard toolchange interface to Modbus devices, ModIO, PLCs, etc.

I've seen a number of toolchange macros that don't really have any safety features built in.

Cheers,

Peter.
Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: Hood on November 16, 2009, 06:11:15 PM
Thanks for the clarification Peter, I have never used the plugin, looks too complicated for me ;D

I know my toolchange is fine anyway, tried to index to tool 7 the other day, its on the front toolpost rather than the turret, when I came back expecting the part to be finished all I saw was the turret indexing. One of the limit switches has gotten drowned (supposed to be IP65 LOL) and Mach was patiently waiting for the signal that the tool was in position. Took 5 mins to replace the switch and off it went, luckily I have a few spares :)

Hood
Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: PROTOPLANT on November 17, 2009, 12:31:15 PM
OK, I'm getting there, but am having trouble getting the PLC to talk to Mach, I think mainly because I'm confused about terminology.  I have input FROM the PLC to Mach working but activating input auto-polling and setting it to "coils" (whatever that means :-))  In the PLC the inputs are called X and the address starts at hex 0000, so that is where I started the addressing in mach, seems to work fine, I told mach to look for Y home on port 0, pin 0 and if I activate the first input on the PLC the DRO lights up in Mach, everything is OK-Dokey.

The other way is where I am confused.  The PLC outputs are labeled Y, but I don't think that is what I want.  There is also a "thing" in the PLC called "C" which seem to be internal registers and I figured they would be what I need to write to, as they are the only other thing that seems to make sense.  Their Modbus addresses start at 4000 HEX.  If I enter 4000 hex into Mach it says that is an invalid address depending on where it is set.  I've tried what seems like every combo of Holding, Coils, Input, and Discrete in the test page and while some seem to write values into the PLC somewhere, they don;t seem to change the "C" state....

Does that make any sense :-)?  Thanks so much for all the help so-far, I appreciate it!
Dustin
Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: Hood on November 17, 2009, 01:57:00 PM
Which serial interface in Mach are you using? Normal or Plugin?

Hood
Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: PROTOPLANT on November 17, 2009, 06:07:51 PM
Hood,  Normal, I am pretty sure.  I don;t think I am using a plug-in, but I am not sure what that is.

Dustin
Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: Peter Homann on November 17, 2009, 06:16:00 PM
Hi Dustin,

You probably need to start reading some of the Modbus specs, it will help with the understanding.

X are discrete inputs. They connect to the outside world.
Y are discrete outputs. They connect to the outside world.
C are internal coils. Thinkof them as temporary memory.

With the addressing, Modbus has 2 schemes. 'Hex' addressing and '984' addressing.

So in 984 format the first C1 bit coil is located at address 16385. In hex format, the address of C1 is 0x4000 which is 16384.

Try to write to coil 16384 from Mach3.

I know it sounds really weird, but in 984 addressing each data type is offset by a certain amount depending on its data type. It was initially to do with how PLCs used to be built.

Mach uses hex addressing but in decimal form. So hex 4000 is decimal 16384

Ad to the holding registers DS, there addresses start at 0000 hex.  or 400001 in 984.

I hope this is not to confusing.

Cheers,

Peter.







Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: Peter Homann on November 17, 2009, 06:16:50 PM
Hood,  Normal, I am pretty sure.  I don;t think I am using a plug-in, but I am not sure what that is.

Dustin

If you are using the Plugin, the modbus setup screen looks like a blue table.

Cheers,

Peter.
Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: Hood on November 17, 2009, 06:46:33 PM
Ok I wont even pretend to understand half of what Peter has just said ;D
Heres how I do things, I use the special options as in the pic below, the start address for Inputs is set to 1025 which is decimal equiv of 2001 in octal (I think ;) ) The Outputs are started at 2048 which is decimal for 4000 octal. Been about 2 or 3 years since I read the PLC manual so I cant even remember how I came up with these and your PLC may be different.

Peter may be able to make sense of what I am trying to say and translate it ;)

Hood
Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: Peter Homann on November 17, 2009, 06:58:24 PM
Hi Hood,

What you are doing is sending the bits as holding  registers packed with 16 bits in each, rather than sending each bitseparately.

What you are doing is more efficient and requires the ladder in the PLC to extract the bits out of the holding register, or have a PLC that overlays the bits onto the holding registers. I don't think the click PLC does this. But, the ModIO does. :)

Cheers,

Peter.
Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: Hood on November 17, 2009, 07:04:40 PM
Thanks Peter for the explanation :)
Dont know anything about the click as its fairly new on the scene and I tend to stick with the things I know as it means I dont have to read :)
I will however have to do some reading as I have just got a cheap D0-06DR with 4 analogue Input modules so I will need to read up on the analogue side of things :(

Hood
Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: Peter Homann on November 17, 2009, 08:40:22 PM
Hood,

It's good to use what you know. :)

The ModIP I'm designing will hopefully be an attractive alternation to commercial PLCs. I'm putting in a basic scripting language, so that if you can write macros in Mach3, then you should have no trouble doing it in the ModIP.

The other thing is that there will be many built in functions that will hopefully make it simpler to use. It should cater for building user interface modules as well as more traditional PLC uses such as tool changers etc.

Cheers,

Peter.
Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: PROTOPLANT on November 18, 2009, 12:43:07 AM
Peter, Hood,

Thanks so much for the help, I've got Mach talking nicely to the PLC now using the start address 16384.  Ive even managed to trigger a mini-ladder test program that toggles real outputs on the PLC from a VB script, progress!! 

Peter, the ModIP sounds really great, this is pretty confusing and I've got a fair bit of experience with electronics, and micro-controllers.  I'd hate to jump into this without any background....

I'm still not totally clear on the bit-packing options, but I may just stick with it the way it is, things seem to be working and if the CLICK will not unpack them properly anyway I'm OK with the inefficiency.

Thanks again, I'm going to experiment more with the script tomorrow.

Dustin


Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: Peter Homann on November 18, 2009, 01:00:53 AM
Dustin,

You would have to write ladder code to unpack them. What it means is that the data is transferred as a register rather than a coil (C). The advantage is that the Modbus messges are shorter , so don't worry about it at the moment, (or ever)

Cheers,

Peter.
Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: Hood on November 18, 2009, 05:59:25 AM
The ModIP sounds interesting Peter, have  a link to any details?
Must admit though, I find ladders fairly easy to do and it the talking with the PC part that makes my head hurt ;D

Hood
Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: Peter Homann on November 18, 2009, 06:30:10 AM
Hi Hood,

I had the prototype live on air a few weeks ago. I don't have any other info other than this thread.

http://www.machsupport.com/forum/index.php/topic,12968.0.html

Cheers,

Peter.
Title: Re: Lathe turret, VB, PLC, MODBUS, Position
Post by: PROTOPLANT on November 21, 2009, 02:17:35 PM
Hi All, just a quick update on the tool changer, it is working really well!  I have  it up and running with everything but the clamp going, I don't yet have all the hydraulics installed and ready to go.  I've attached the macro just for fun, I had a good time writing it, and it is really cool to see it working :-)

Thanks for all your great help!!
Dustin