Code Modularity Basics Lab
Increase Your Productivity with Modular Programming
Chris Como
Product Manager, Logix Software
Rockwell Automation
Rev 5058-CO900D Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved.
Agenda
Modular Programming Concepts
Engineering Problem Solving
Code Modularity Within Logix
When to use What
Demo & Lab
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 2
Snappy Quote
From 2 Dead Guys, 1 Jedi & 1 Live Guy
“A Failure in Planning is a Plan for Failure ” -
Ben Franklin Chris Como
Obi-Wan Kenobi
Winston Churchill
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 3
Modular Programming Concepts
The Fundamentals
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved.
What is Modularity?
Modularity is the degree to which a system's components may be
separated and recombined.
Each team member has their own module
Each module has Inputs/Outputs
Each module does something different
Outputs from one module are used as input
into another module
My Engineering Team
Breaking apart a larger problem and providing flexibility later
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 5
Modular Programming Benefits
What are the benefits of modular programing?
Breaks a larger problem into smaller problem.
Easier for a multi-engineering environment.
Allows for an easier collaboration amongst different designers.
Provides flexibility later when new equipment or code is introduced.
Quicker to diagnose in the field. (easier to follow in the field)
Easier to re-use code. (library concepts)
Development time is reduced.
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 6
Modular Programming
Conceptual Image
Pieces and Parts
Connection
Input1
Input2
Code
Mod1 Output1
Local Tags
Our Modular
Component
Interface
Goal: Modular container of code with defined inputs and outputs
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 7
Modular Programming
Conceptual Image
Line Controller Code
Connections
Code
Mod1 Mod2 Mod3 Mod4
Interface
Clearly Defined Inputs and Outputs
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 9
Modular Programming
Surface Unwind – Single Ply
Line Controller Code
Load Cell Unwind 1 Calendar Load Cell
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 10
Modular Programming
Surface Unwind – Dual Ply
Line Controller Code
Unwind 2 Load Cell Load Cell Unwind 1 Calendar Load Cell
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 11
Engineering Problem Solving
How To Approach The Problem
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved.
Engineering Problem Solving 101
Key Idea: Always use a systematic approach to solving problems
Define
State the Develop Solve Test
Input &
Problem Algorithm Problem Solution
Outputs
Do Not Start Here
Failure in planning
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 13
Engineering Problem Solving
STEP 1: State the Problem
“I need to know the system inertia in units of kg-m2 when presented
with the normalized inertia in seconds from the drive inertia test”
(Sec) ? (kg-m2)
Convert the Normalized Inertia (secs) to Units of kg-m2
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 14
Engineering Problem Solving
STEP 2: Identify Inputs/Outputs
Inputs Outputs
Power (kW)
J(sec)
Inertia (kg-m2)
Δspeed (rpm)
Determine what is known and what is unknown
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 16
Engineering Problem Solving -
STEP 3: Develop the Algorithm
Inputs Algorithm Outputs
Power (kW)
J(sec) Required Equations:
J (sec) * Power (kW ) 91189
Inertia (kg m 2 ) Inertia (kg-m2)
Speed (rpm) 2
Δspeed (rpm) Conversion
Watts sec 2
1000 (60 )
91189 kW min
4 2
Determine what other info you need and how to approach the
Problem
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 17
Engineering Problem Solving
STEP 4: Solve the Problem
Inputs Algorithm Outputs
Power (kW)
J(sec)
J (sec) * Power (kW ) 91189
Inertia (kg m 2 ) Inertia (kg-m2)
Speed (rpm) 2
Δspeed (rpm)
Conversion
Put the prior steps together and form your solution
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 18
Engineering Problem Solving EXAMPLE
STEP 5: Test Solution
Inputs Algorithm Outputs
Power (kW)
J(sec)
J (sec) * Power (kW ) 91189
Inertia (kg m 2 ) Inertia (kg-m2)
Speed (rpm) 2
Δspeed (rpm)
Conversion
Verify your results.
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 19
Engineering Problem Solving EXAMPLE
Problem is solved BUT not modularized yet.
How can we make this work re-usable going forward?
Things to ponder:
Why have to re-work this same problem in the future?
Move on to DIFFERENT problems (keep advancing)
Add this previously solved problem to your Library for use as another
algorithm
Possibly refine this once in the library to adapt to changes in your machine
Take Away:
Solved Problems are only part of the story
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 20
Studio 5000 - Logix Designer Modular
Components
Applying Code Modularity in Logix Designer
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved.
Logix Designer:
Modular Code Building
Building Blocks that Can be used to modularize Code
Tag Scope, UDTs (User Defined Data Types)
Shared Subroutines
AOIs (Add On Instructions)
Program Parameters (new Feature in V22)
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 22
Logix Designer Modularity:
Tag Scope
Local Versus Controller Scope Tags
Controller Scope Tags
Act as Global scope tags within a controller all local programs have
access to these tags.
Program Scope
Access at the program (or local) level.
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 23
Logix Designer Modularity:
Alias Tags
An alias tag lets you create one tag that represents another tag.
How aliases can be used:
Program now / I/O Later
Assign descriptive tag name
Easier to read
Descriptive name for element
of array
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 24
Logix Designer:
User-Defined Data Types (UDTs)
User-defined data types (structures) let you organize your data to
match your machine or process.
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 25
Logix Designer Modularity:
Shared Subroutines
The “Original” modular component Call the Subroutine
JSR - Jump to Subroutine
Passes and returns tags by value.
Pass In THE Values
Execute Subroutine Logic
Return THE Results
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 26
Logix Designer:
What is an Add-on Instruction (AOI)?
User created instruction that is re-usable in one or multiple projects
Instructions encapsulate code that can be developed by the user using
standard instruction set and other add-on instructions
Like a routine that can be instantiated multiple times
Each instance of the instruction has its own backing data
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 27
Logix Designer:
AOI Instruction Parameter Tag Definition
User configurable instruction
parameters
Input (copied in), Output (copied
out)
Support atomic (BOOL,
SINT, INT, DINT and REAL)
data types
InOut (passed by reference)
Support both atomic (BOOL,
SINT, INT, DINT and REAL)
and compound data types
(UDT and Arrays)
Parameter name and definitions
stored on the controller,
descriptions saved in project file
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 28
Logix Designer:
AOI Local Tag Definition
Tags can be defined locally to the instruction
User specified name, data-type and description
Supports atomic (BOOL, SINT, INT, DINT and REAL)
Also compound data types (UDT and Arrays)
Tag definitions and names loaded into controller while descriptions are saved in project
Tags only accessible by the code within the instruction
Use a Parameter if you want to access tag from an HMI
Pass-
Other add-on through
instructions can be descriptions
nested and will show
up as local tags Default
values
29
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved.
Logix Designer:
AOI Run-Time Monitor / Debug
Instruction faceplate provides animated values
Monitoring an Add-in-Instruction provides value animation based on the
specific call that is selected Data context for run-time
monitoring and debugging.
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 30
HMI:
Global Objects
With Global Objects you can create a core set of functionality to be used on multiple
graphic screens or multiple instances on a single graphic screen.
These objects can be defined with parameters that are passed in at runtime for each unique
instance.
All linked instances of the object are updated when edits to the
base object are saved.
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 31
Lab Section 1
Add-On Instructions
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved.
Program Parameters
Something snappy here…..
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved.
Parameters for Programs
Prog_01
Pre-V22 Prog_01
V22
Parameters
In
Out
Code InOut Code
Routines Routines
Public
Program Tags
Local Tags
Supports modular automation practices an enables a higher level of encapsulation
AOI-style Input, Output, and In/Out parameters for Programs
Supports strings, arrays, and structures as parameters
Online editable and supports sub-element connections
Ability to interconnect Programs with these parameters
Ability to Copy / Paste Programs without disturbing parameter configuration
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 34
Parameters for Programs
Conceptual Block Diagram
Prog_01
Parameters
CS_Tag1 In
CS_Tag2 InOut Code
CS_Tag3 Out Routines
Local Tags
Prog_02
Parameters
In
Out Code
Routines
Local Tags
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved.
Public Parameters
Public parameters represent a public
memory space at program level. They
behave very similarly to Controller scope
Controller tag tags. Public parameters can accept
connections from:
Input parameters
Public Input
Program 1 Program 2 Output Parameters
InOut parameters
Output
InOut
Program 3 One Public parameter can be connected
or bound to multiple Input, Output or
InOut parameters to form a shared
memory space.
Data copy Data flow
Reference Reference
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 36
Direct Access to Program Parameters
Complementary approach for Program Parameter access
Direct Access notation supported in all programming
languages
Allows for a more dynamic data values (real-time, unbuffered)
Maintain all properties of normal tags
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 37
Logical Organizer “Execution View”
Controller Organizer
From this view, the user will schedule all programs
and phases in appropriate tasks per system
design.
The existing look and feel of the Logix “controller
organizer” doesn’t change
The number of scheduled programs/phases per
task will be increased.
Preserves existing workflow for those choosing to
work in this view. It doesn’t force a change.
Your Processors way of viewing your code
(Time-Based)
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved.
Logical Organizer “Logical View”
Logical Organizer Mixer
Multi-level,
organizational hierarchy
of folders, programs, &
phases to represent
system.
Fully editable
Stored in the controller
and recoverable on
upload.
Drag & drop of
structure (program +
sub-programs) to and
from a library or
between projects
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved.
Logical Program Grouping
Prog_1 Introducing a virtual concept of “sub-programs”
- Parameters
Code
Allows nesting of an arbitrary number
(<= 10) of sub-programs under a single
Routines
Local Tags
Prog_11 program
Allows for a better representation of
- Parameters
Code
Local Tags
Routines
physical resources and functions
Prog_111 Sub-programs are a logical representation
Parameters
Code
and not an execution view
Local Tags
Routines
Drag & drop of structure (program + sub-
Prog_112 programs) to and from the library
Parameters
Code
Routines
Local Tags
Prog_12
+ Parameters
Code
Routines
Local Tags
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 40
Program Parameters Editor
Shared Editor for Program Parameters and Local Tags
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 41
Parameters for Programs
Conceptual Block Diagram
Program_A
Parameters
InputA
InputB Code
Routines
Local Tags
MainProgram
Parameters
Output1 Code
Routines
Local Tags
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved.
Parameter Connections
Connection information shown for all Parameters
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved.
Parameters for Programs
Conceptual Block Diagram
MainProgram Program_A
Parameters Parameters
InputA
Output1 Code InputB Code
Routines Routines
Local Tags Local Tags
Program_B
Parameters
InputB1
Code
InputB2
Routines
Local Tags
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved.
Parameter Connections
Full connection list is shown in the extended tag property pane
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 45
Parameter Connections
Output1 Has the following: Output1.0 Has the following:
1 Word Level connection 2 Bit Level connections
{1:5} {2:0}
5 Bit Level connections At Bit 0
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 46
Bit level connections
Connections can also be made at a bit level
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 47
Bit level connections
Connections can also be made at a UDT Sub Element level
This is a huge Concept!!!!!
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 48
Parameters for Programs
Benefits:
Code modules are online editable
Enables higher level of encapsulation.
(equipment modules, machines, etc)
Can have multiple routines
Can have strings and structures as parameters
Are independently executed (no extra code required)
Extends current program structure such that customers can
reuse/modify existing code
No extra code required : Simply Deploy, Configure, and Execute
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 49
Program Parameters
Extend Program tags with publically accessible parameters
Publically accessible types:
Input Parameters
Output Parameters
Public Parameters
InOut Parameters
Local tags remain private to the Program
External Access remain selectable (Read/Wright, Read Only or None)
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved. 50
When To Use What
Program Parameters vs AOIs
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved.
Lab Section 2 and 3
Program Parameters
Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved.
Questions?
Rev 5058-CO900D Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved.
Thank you for participating!
Please remember to tidy up your work area for the next session.
We want your feedback! Please complete the session survey!
DE07-CodeModularity Basics Lab
Rev 5058-CO900D Copyright © 2013 Rockwell Automation, Inc. All Rights Reserved.