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.
In order to complete this recipe, you will need to have an understanding of RSLogix 5000 base data types.
Expand the RSLogix 5000 Controller Organizer tab, find and expand the Data Types folder, and select the User-Defined node.
Right-click on the User-Defined node and select New Data Type….
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
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
Next, we can enter the remaining simple base types to the table as follows:
SP: REAL
FLOW: REAL
FLT: BOOL
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:Click on OK to save our UDT. Now we have recreated all of our flow control valve tags in a single UDT.
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).
In the New Tag window, enter the following values:
Name: FC1001
Description:
Flow Control Valve 1001
Data Type: VALVE
Click on the OK button to save the new tag.
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).
Add a Move element to the new rung by selecting it under the Move/Logical element group.
Set the source of the element to
FC1001_PV
and set the destination of the element toFC1001.PV
as shown in the following screenshot:
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.
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.
UDTs can be nested inside other UDTs as required. The nested UDT can be assigned just like any normal data type in RSLogix 5000.