Showing posts with label Allen Bradley. Show all posts
Showing posts with label Allen Bradley. Show all posts

Useful resources for PLC programming: PLC-DEV website


I want to make a review on plc-dev website that contains some posts that i think they are really helpful and complete for PLC programmers.
The website has 3 main sections for the 2 most used marks of PLC, Siemens and Allen Bradley, and a talk about Modbus protocol, one of the most used protocols and a protocol that is supported from all PLCs:

Allen Bradley
Even if I think that the best blog to learn Allen Bradley programming (and ladder in general) is Nearly In Control with his RsLogix 5000 tutorial, PLC DEV contains a mass of documentation about Allen Bradley and their products.
Some useful post for starters are:
and a big collection of manuals that must be read (depending on the hardware you are using) is here:

Siemens
The section of Siemens programming is really helpful.
The pain of Siemens PLC is AWL / STL language of programming, both for programmers than for "readers" of programs.
Also this section contains some useful article that resume how to connect, upload and download programs with Step7 (not the best User Interface in the world as you already know), a quick reference for Siemens Libraries (OB, FC, FB, SFC, SFB), and it contains also some useful information about AWL/STL language and addressing.
The parts that i found more useful are:

Modbus
Modbus protocol is a very common protocol that every device support.
This section explain what is a Modbus (RTU, TCP, Modbus +), the electrical wiring (RS 232, 422, 485, Ethernet) and it solves many doubts about the difference between Protocol and Networks.
Modbus FAQ

PLC Training: Exercise #2 Solution with RSLogix 5000

With those posts i will show how to use  RSLogix 5000 and Emulate 5000 to simulate a simple program.
I will also cover all the steps that are needed to realize a program with ladder logic and a simple sequence, to give a sample on how you could base your automation projects.

The text of the exercise is available here: http://www.megaupload.com/?d=PIWQA7AS

Realize the automation of the following Filling system:

Outputs:
- Motor contactor (contactor O:2/0) moves the conveyor
- Solenoid valve (contactor O:2/1) to fill the boxes
- Run pilot lamp (O:2/2) activated when the machine is running
- Fill pilot lamp (O:2/3) activated when the machine is filling
- Full pilot lamp (O:2/4) activated when the box on conveyor is full

Inputs:
- Start Push button (I:0/0)
- Stop  Push Button (I:0/1)
- Prox Sensor (I:0/2) the box is in position on his right falling edge
- Level Sensor (I:0/3) the box is full when the sensor is ON
- Three-state Selector:
I:0/4 for Continous mode
I:0/5 for Manual Restart (after a box is full, this will bring the box out of level sensor and bring a new box in position)
I:0/6 for Filling bypass

You can find the various steps here:
- Process analysis: http://mestaa.blogspot.com/2011/04/plc-training-exercise-2-with-rslogix.html
- Input mapping: http://mestaa.blogspot.com/2011/04/plc-training-exercise-2-with-rslogix.html
- Writing and manage a sequence: http://mestaa.blogspot.com/2011/05/cycles.html
- Outputs Mapping:
- Simulating the process to debug the program: http://mestaa.blogspot.com/2011/05/bsimulation-in-test-driven-development.html
- Exercise file for RSLogix 5000: http://www.megaupload.com/?d=9GXL96L7

PLC Training: Exercise #2 Cycles with RSLogix 5000

You can find the other parts of the exercise here: http://mestaa.blogspot.com/2011/05/plc-training-exercise-2-solution-with.html
  

4) Cycle logic
To realize automatic cycles and sequences i often use a shift register with BSL block.
In this way it's possible to define the sequence's steps as bits, giving a comment to everyone.
In my opinion this is a clear way to read the current state of the cycle and what's happening inside.
Every cicle is made of 5 parts:
- Init (command outputs when in Stop state)
- Start (latches the 1st step)
- Stop (conditions to block the cycle and go to INIT state)
- Advance Step conditions (contains the BSL block)
- Outputs for every step (contains the commands for outputs)

In the scheme above we see that we have 3 steps + a Stop state.
Step #1: Waiting for Box in position
Step #2: Box is full
Step #3: Box is moved outside the level sensor
We can notice also that to change steps are needed some signals and that the sequence can go only one way:
Stop -> 1 -> 2 -> 3 -> 1 -> 2 ... while stop isn't pressed.
We also notice that when Start is pressed, the sequence can restart only from the 1st step, this because the exercise asks that the process must be restarted.
When working with real processes anyway can happen that the cycle step must be mantained when a user push stop for mantainence, or that the system should recognize the current state from the Inputs, so it can start an init or ending automatic sequence once restarted.

Usually i start writing my cycles from "Step Advance" and "Commands" blocks:

As you notice every step in the diagram has the same number as the step in the cycle, and for every step there is the condition for advancing in the same rung.

Commands:
 
I would like to point the attention on the use of Set/Reset coils for Motor Command.
Even if i prefere to use normal coils instead of Set/Reset, i like even more to see my steps in order from the 1st to the last one.
I know that it's possible and easy to convert the OTL and OTU into a single OTE coil, but for readability i prefere to use one rung for each step and place them in ascending order.
That's why for every output that should be energized more than once during the cycle, usually i use latch/unlatch coils.
Be careful on doing it with finite state machines, because it's easy to make error if the cycle skips the rung that resets the coil.
Notice that in the step #2 it's implemented the condition to start the motor (manual restart + PB pressed). Usually it's a good habit to put a NO contact on the top and an NC on the bottom to refere to the same condition (like Automatic / Manual selector) but here it was used a three state selector, and so i suppose to have 3 inputs.

In the end i usually write the Start - Stop - Init rungs:
As you can notice, to start the cycle it's enough to latch the 1st step, the reset request is satisfied by the cicle stop and the init must reset the commands.
Cycle is enabled by pressing of start PB and stopped by Stop PB, so i called the enable signal "Automatic Mode", so everyone can understand what's going on in the program.

5) Output Mapping
For Outputs, except pilot lamps, i separate rungs in "Automatic mode" and "not Automatic mode", using the second essentially for jogging.
In this exercise it's required the possibility to move the conveyor with a "bypass selector" that is exactly a jogging control for conveyor.(i will add the picture soon... be patient)

6) Exercise file
you can find the exercise solved for RSLogix 5000 here: http://www.megaupload.com/?d=9GXL96L7

Next part here: Simulation

PLC Training: Exercise #2 Simulation with RSLogix 5000

You can find the other parts of the exercise here: http://mestaa.blogspot.com/2011/05/plc-training-exercise-2-solution-with.html

RSEmulate Tutorial:
You can find a good tutorial for RSEmulate 5000 here: http://www.plcdev.com/a_quick_tutorial_on_rslogix_emulator_5000.
Pay attention especially in the last part where it says that for inputs you should refere to local_input[1] and for output refere to local_output[0].

7)Simulation
In test driven development usually it's a good habit to write simulation before the logic, and then test the logic while writing it.
To simulate a real plant just connect the output to inputs, designing an ideal behaviour of your plant.
For example we know that when the motor is ON the conveyor moves and the position of the box changes.
When the box is in a certain position we know also that the Prox Sensor must be ON.
So to simulate that the position increase use a DINT variable to increment when the motor is ON and to reset after a defined value (8 in my case).
Then turn ON the proximity when position is between 3 and 5.
The same can be done with the level sensor, but we have to remember that when the box is full, the level sensor remains ON until the box hasn't moved away from it.
The following is one way to simulate this process.

PLC Training: Exercise #2 Input Mapping

You can find the other parts of the exercise here: http://mestaa.blogspot.com/2011/05/plc-training-exercise-2-solution-with.html
 
1) Sequence analisys and algorithym

Step #1: Waiting for Box in position
Step #2: Box is full
Step #3: Box is moved outside the level sensor
To change steps follow the arrow and the signal that has to be received.
From all steps you must be able to stop the machine if Stop push button is pressed
If the machine is stopped, pressing Start push button will restart the cycle from Step #1

2) Writing the program:
Defining tasks:

those 3 tasks should be in every program
-Simulation
-Map Inputs
-Map Outputs
- There should be an Alarm task also, but in this exercise alarms are not requested.
I gave the name MainProgram to the task that runs the cycle because this is a really simple program, with one short cycle and a start/stop without particular requests.

3)Input Mapping:

I usually map inputs in DINT variables, so i can force them without problems while debugging on the real plant.
Also it makes it easy to change a broken Input without having to change all the program.
Other programmers uses to map Input in UDT data types, with all the problems connected on the  debugging phase the real system when it is ready.

As for the output i usually write an alias tag, because i always use outputs once in all program and with a coil segment.

Next part is here: Cycles and Outputs

PLC Training: Some interesting exercises

I found some interesting exercises about plc programming that cover almost all the topics that a programmer should know.
The document is mainly thought for Allen Bradley plcs users, but it can be useful also for others.
The exercises are:
1) Using simple relays logic to control a motor
2) Using relays logic to control simple sequences
3) Using Timers, Retentive Timers and Counters
4) Using relays logic + everything saw before to control a batch mixing system
5) Using shift registers to determine the position of a bottle in a filling plant
6) Using various modules to control an elevator system.

The pdf  was found on http://thelearningpit.com/lp/logixpro.html, they also sells some kind of graphical simulation to run the plants if you're interested.
 I reccomend to try logixpro simulator (15 days trial) because it can really improve your ladder code with just your time.
You can download the exercise file directly from learning pit website or from here:
http://www.megaupload.com/?d=PIWQA7AS

Using PLC Simulators: Testing plants without plants

One thing that i usually do when i program is to write test routines for the program.
Test routines are useful because:
1 - you can check how the code is running and if he has some bugs, debugging it without doing some physical damage to the plant.
2 - you can check if the model of the machine in your mind is similar to the real machine, seeing how the code is going and what is still needed to complete the machine.
3 - other people that read the program checks how "it should work" through the test utility, for example what input you should expect if the motor starts running, or how you control an analogic output coming from a PID, or simulate movements whit motors and encoders, and so on.


On PLC there are simulators (i often use RSEmulate of Allen Bradley, because we often use their plcs) that can execute programs and "force" input and output, so let's see how to use them.
I do an example with a ladder program:
I have a motor (O:0/0)  that  starts when i press a button (I:0/0).
The motor is connected toan encoder (I:0.1) and when encoder is arrived at 14 the motor must stop his run.
There is an alarm sensor (I:0/1) that must block the motor if the encoder fail.
This is a way to do the program:

And this is how i test the inputs and encoders.
It's actually easy not only to test the entire application in this way, but also to see what should happen when the motor starts, and when it should stop.

If you upload a program with a Test Routine (that of course is disabled), you can also understand in a easier way how the program works and save a lot of time, and there is not necessity of calling the constructor's assistance (that fired is main programmer 10 days ago and that is still searching for a cheap one, as usually).

I add a solution for RsLogix 500, that can be emulated and tested with RsEmulate 500.
For Siemens users, try to do this with the simulator of Step 7, and if you can't force Inputs automatically, just use  a DB and put in parallel test bits / words and merkers.

Hope this post can be useful for someone, the program for RsLogix 500 can be found here:
http://www.mesta-automation.com/Downloads/ProcessSimulation.rar

WPF and OPC: a full sample project with RSLinx and databinding

Now that i wrote about databinding, pages and so on, i publish an example on how to connect real time values readed from a PLC (in this case an Allen Bradley PLC, but it can be anyone), update an object collection with this values, and then display them on different pages.

As usual i have my 2 tanks and i want to read what liquid is inside every tank (defined as 16bit integer).
1st tank word is N7:0, second is N7:1
For each tank there is a button that changes its content(writing the PLC word).

This is the new code to analyze: i have 2 buttons that writes the words on PLC, then i have the callback where i read values in PLC, cast them and update my objects.
This objects are defined in the OPC Client class and they are defined as "public"  because i want to access their properties from every window that needs to display real time values or to control them.


This is the MainWindow, where the program begin and where i create the opcclient object as static.
To access to it's properties i just need to bind UI items by databinding.




To access the properties of objects in another window or page, i do like in this example.

And this is the final result

This is how the setup for PLC OPC Server, that should be called as [UNTITLED_2]


Hope it's helpful.
Full solution here:

http://www.mesta-automation.com/Downloads/opc%20sample%202.rar

Previus post describe more in details what's used in this example, if you're interested.

OPC Client c# .Net Sample (RSLinx OPC server)

Hi, a big problem about connecting PLC to PC is the "from where should i start?".
And that's why i suppose people choose commercial SCADA instead of .Net (they already has drivers and so on).
Well, if it was for winforms, i would agree that winforms sucks, they got a lot of bugs and so on, so i would choose a commercial SCADA too.
But since WPF and Silverlight was released, .Net is really more more powerful and beautiful, the code became easier with the binding system and industrial PCs + OPC servers cost always less (and sometimes it's possible to find free drivers).

This post is an example of communication with RSLinx OPC Server (but i use OPC Foundation libraries so the process is the same for every OPC server).


So let's strart by adding a reference to the OPC Foundation dlls:
- OpcNetApi.Com.dll
- OpcNetApi.dll
- OpcNetApi.Xml.dll

Then create Items that are shared for the all the form (or the project)
Then create a button to connect (or just place the code after InitializeComponent(); if you want to autoconnect when the program starts)
Set the URL (in this sample there is the one of RSLinx) then add a group, add some items with theyr connection string, set the update time and the callback for the items that you want to read, then set a group for writings.


 This is the sample callback where i assign values that i read to a custom object.
Remember that the GUI and the OPC client runs on two different threads, so it's needed to use anonymous method for this (just use like is written in the sample).
With WPF and INotifyPropertyChanged it's not needed this.
You can just bind all your objects to the GUI items property, and this is really amazing and simple.
 This is the way that i found to write a single word, basically i create a new one, i check if in the write group there is already one of them, else i add it.
 Writing was always a problem for me, but when i found this way, i got all i needed

This is a sample of how i write from a button reading a textbox


IMPORTANT UPDATE: This code is written on a Micrologix / SLC platform and it reads only integer values, so when i read a value it's supposed to be a 16-bit word: that's why i cast it to (short). Remember that if you read a REAL value (F8:0 for example) you sould cast it to float and if you read from Controllogix or CompactLogix, you have to convert it to (int) because they are 32-bit words.

This is the complete solution:

http://www.mesta-automation.com/Downloads/OPC%20Client.rar

This is another link for a Twincat OPC Server, that is similar to the RSLinx.
http://infosys.beckhoff.com/content/1033/tcopcserver/html/sample1_netapi.htm?id=18186

UPDATE: i wrote a recent post here where i wrote a full sample with WPF and an OPC client in c#. watch it here: http://mestaa.blogspot.com/2010/12/wpf-and-opc-full-sample-project-with.html

[UPDATE #2]: i made a video that explains how to use the code provided: check it here: http://www.mesta-automation.com/opc-client-with-c-an-how-to-video/