Book Image

Instant PLC Programming with RSLogix 5000

Book Image

Instant PLC Programming with RSLogix 5000

Overview of this book

RSLogix5000 is a user friendly IEC61131-3-compliant interface for programming the current generation of Rockwell Automation PLCs, which includes Ladder Diagrams (LD), Graphical Function Block Diagrams (FBD), Graphical Structured Text (ST), and Sequential Function Charts (SFC). Instant PLC Programming with RSLogix 5000 captures the core elements of PLC programming with RSLogix 5000 with a minimal investment of time. We will avoid getting into control theory and focus on condensing the information specific to RSLogix 5000. We have selected the key areas of RSLogix and provide a step-by-step approach to teaching them. This book start by follows the steps involved in creating a new RSLogix 5000 project and configuring racks, slots, and channels. Next, we will create routines using the various languages available in RSLogix 5000, troubleshooting and resolving issues we encounter along the way. Finally, we will dive into the advanced features, such as online changes, code generation, task management, and user-defined structures. You will also learn object-oriented PLC programming techniques using advanced features like user-defined types (UDTs) that improve the maintainability, uniformity, and readability of our routines. We also highlight the strengths and limitations of online changes and demonstrate techniques to maximize flexibility. You will learn everything you need to get up and running with RSLogix 5000 as well as best practices used by industry experts.
Table of Contents (7 chapters)

Understanding user-defined data types (Advanced)


User Defined Data Types (UDTs) are an extremely powerful feature in the RSLogix 5000 platform that improves the maintainability, uniformity, and readability of our routines. UDTs are groups of base data types (BOOL, REAL, INT, TIMER, and so on), which we can define and re-use.

Getting ready

In order to complete this recipe, you will need to have an understanding of RSLogix 5000 base data types.

How to do it...

  1. Expand the RSLogix 5000 Controller Organizer tab, find and expand the Data Types folder, and select the User-Defined node.

  2. Right-click on the User-Defined node and select New Data Type….

  3. The Data Type window that appears will allow us to configure our UDT. Enter the following name and description in the fields provided:

    • Name: VALVE

    • Description: Valve UDT to manage Valve Positions and Alarms

  4. The data table under the Description UDT allows us to define the tags that will be included with each instance of the structure we've created. If we had created this UDT earlier, it would have saved us quite a bit of work creating all the tags for our various flow control valves (FC1001, FC1002, FC1003, and so on). Let's add our first tag to the table to replace our flow control valve position feedback variable FC1001_PV. Add the following values to the first row of the table:

    • Name: PV

    • Data Type: REAL

    • Description: Current Valve Position

  5. Next, we can enter the remaining simple base types to the table as follows:

    • SP: REAL

    • FLOW: REAL

    • FLT: BOOL

  6. UDTs also allow us to create more complex base types inside them, such as the TIMER type and even other UDTs. Let's add the complex base type tags to our UDT TON: TIMER as shown in the following screenshot:

  7. Click on OK to save our UDT. Now we have recreated all of our flow control valve tags in a single UDT.

  8. Next, we will create an instance of our VALVE UDT and link it to our Analog In card channel. On Controller Organizer, right-click on Controller Tags under the Controller folder and select New Tag… (or press Ctrl + W).

  9. In the New Tag window, enter the following values:

    • Name: FC1001

    • Description: Flow Control Valve 1001

    • Data Type: VALVE

  10. Click on the OK button to save the new tag.

  11. Next, we will link one of the values of our UDT tag using Ladder Logic. Open the VALVES Ladder Logic Routine and add a new rung by right-clicking and selecting Add Rung (or press Ctrl + R).

  12. Add a Move element to the new rung by selecting it under the Move/Logical element group.

  13. Set the source of the element to FC1001_PV and set the destination of the element to FC1001.PV as shown in the following screenshot:

How it works...

One major advantage of UDTs is that they can be changed at any time (as of Version 17 and higher or RSLogix 5000, they can also be modified online); so, if you realize you forgot to add a tag to your UDT halfway through a project, you can easily make this modification.

There's more...

In this exercise, we barely scratched the surface of the power of UDTs; nested UDTs can be used to further improve code maintainability and consistency.

Nesting UDT

UDTs can be nested inside other UDTs as required. The nested UDT can be assigned just like any normal data type in RSLogix 5000.

FBD and SPC types not allowed

Many base types are available to be used in UDT structures; however, FBD and SPC cannot be added to UDT structures.