Yaskawa
eLearning
You're watching the IEC 61131 Basics
Video Tutorial Series
This lesson is on Structures
Hi, I'm Matt Pelletier
and in this video I'd like to show you
what a Structure is and how to create
and use a Structure in MotionWorks IEC.
A Structure is an organized set of data
with mixed data types
so unlike an Array
which has all the same Data Type
a Structure can have any number of
different Data Types.
In the end, it ends up to be similar to a
File or Directory Structure with sub elements
it's a good way to organize your data
and when you use it
you'll end up using Complex names
with this DOT notation so here in the
example that we will do we have a
Variable called G_Gate1_East
and it has different elements
both Boolean and Integer
and it could have other elements as well
and each of those elements are separated by
this DOT notation.
So as in the previous video where we created an Array
here we'll create a Structure
in our Data Type folder
we go to the Data Types folder
and we can use this same YTTS Custom Types
if you don't have this in here
you could right click
to Insert a Data Types worksheet
and create YTTS Custom Types
and then in the Edit wizard you have the
STRUCT Data Type pull that in
and as we did with the Array
we'll just fill in the comments
so I'd like the Type name to be called
YTTS_ParkingGate
the idea here is we could have one Variable
that has all of the elements
of a Parking Gate Program
that we've been using it so far.
So we don't need to do all of them,
let's do a few of them here
and for example one important
variable that we had been using was
is the Gate Open or not
and that was always a Boolean
the other important information about a
Parking Gate in our program was the
NumberOfCars in the lot
and that number was always an Integer
another one was the MaxCapacity
another Integer
we have a Sensor
which is Boolean
and we wanted to know if the lot was open
that was another Boolean
I think I'll take it even one step further and go
beyond the minimum
you can also have
an Array inside of a Structure,
a Structure inside of an Array
as long as the definition from top to bottom
is appropriate you cannot use an Array
in one Data Type that hasn't been defined
above it.
So since I've defined already this
YTTS_TrainArray
maybe I'll call this Array of Data
can't use the word Array by itself
the Data Type is YTTS_TrainArray;
semi colon at the end of all of these
sometimes I like a quick compiled worksheet
just to find any real simple errors
okay oops I had a little thing there
let's try it again
okay so the sheet is good
and this little compiled worksheet
is really all you need now to start
using this Data Type
so in the Global Variables like we did
when we made our Array
let's Insert another Variable
and this one will call G_Gate1_East
you know maybe we've got a parking lot
now with a large number of parking gates
and all controlled by one PLC
we can set them all up to have the exact same data
and keep it a little more organized this way
I'll use the Data Type YTTS_ParkingGate
and let's do like we did with the Array
I will Download the Changes
and then add to the Debug
and now in Debug Mode
I could take a look at this
I'll right-click on it
and add it to the Watch Window
add the whole thing
and can expand it here
and so we can see here Gate1_East is the GateOpen?
How many NumberOfCars?
So imagine this with five or six different parking gates
It would be very easy then to to see everything
in the same order, same data, same name
It makes it very friendly to work with
you just have to know how to set up this
structure ahead of time
which I hope now you know how to do
and of course you'd have to create
your program to use those
so I'll show that real quick here
a little bit at least
so for G_Sensor
I can use G_Gate1_East
and then usually put in the DOT notation
and I'll choose Sensor
we also had the NumberOfCars
so instead, let's do G_Gate1_East.n (NumberofCars)
then down arrow, Enter, Enter
G_Gate1_East.NumberOfCars
we hit a MaxCapacity
G_Gate1_East.MaxCapacity
type an M down arrow, Enter, Enter
and so I could go on to update all
of this code here and you can see here
to be complete I probably should have a Reset
I should have Full in this Structure
the Timer, this DelayTime
and LotOpen would be this one
I'll do LotOpen here
I want G_Gate1_East.LotOpen
so this is how your code starts to look now
with this DOT notation
and I'll just be sure this works
with one Download Changes
okay, close the Resource, back to Debug
and now I haven't tied this to the I/O yet
so I'll just have to double click
on it like we did in the beginning
I didn't put a capacity in here
there we go put a capacity in there, alright
and now in this version of the software 2.5.0.78
if you want an Initial Value
for any of these elements of the Structure
it is required to do that in a
Structured Text POU or any POU
usually we'll use Structured Text
I'll just give you an example
of how that would go
if I wanted to Initialize
maybe with a NumberOfCars here
I could hit F5
put in my G_Gate1_East
and then you use the DOT notation
and maybe want to initialize that the
NumberOfCars:=
and if you didn't look, if you don't remember
what the Data Type is either you can
it will tell you here
I didn't point that out
let me do that again
NumberOfCars is an INT
so NumberOfCars:=INT#
and then however many you think
it should be by default
we'll do 10;
and then when will this run?
remember we put Init in the Cold Task
and the Warm Task so whether we do
cold or warm
we will have a
Reset of this element of the Structure
using this line of code.
And so this is commonly
how a Structure is initialized
as opposed to putting an Initial Value
in the Global List
you can see that there's no way you could
put in multiple Initial Values
for a Multiple Element Variable.
So thank you, that does it
that's the introduction here on Structures
I hope that you know how to make them
a little bit how to use them
and how to initialize them in MotionWorks IEC