Luyện nói tiếng Anh bằng Shadowing qua video: PLC Programming #5: User-Defined Data Types (UDTs) Explained

Đang tạo bài học...
1
Hello and welcome back to the channel.
2
In today's video, we'll be continuing our PLC tutorial series.
3
And today we'll be looking at user -defined data types, UDTs, which are a super important concept in PLC programming.
4
Okay, so today's tutorial is going to be a little bit different
5
because I've been doing a lot of code along tutorials in this series, but today's video is going to need to feature a fair bit of structured text,
6
which I haven't gone super deep into on the channel. And
7
so I think what would be more valuable than sharing the
8
writing of this code line by line is talk about the concept and show it in a practical use environment.
9
And then I'll explain to you the code I generated for this.
10
start very high level with the concept,
11
a user defined data type is essentially a grouping of tags that you want associated with a shared type of device.
12
So a very common example is in a big chemical plant, you'd make a user defined data type for every valve, every pump and motor.
13
And sometimes you go even more generic and you say every two state device is going to have auto manual commands,
14
it'll have alarms, overrides, and a whole bunch more features.
15
Every single device of this type is going to have these things.
16
So you bunch a bunch of features together for shared objects in a data type.
17
The example that I'm going to show with you guys today is going to be alarms.
18
This is very common, regardless of the size of your system, to want a bunch of shared alarms in your factory.
19
So if you're building a little standalone system, there still could be 15, 20 things that go wrong with it.
20
And if you're controlling an entire factory from this PLC, there could be hundreds or thousands of things that could go wrong with it.
21
So in TIA Portal, there's a folder called PLC data types over on the left in the system tree.
22
In Rockwell, I think there's a section called UDTs, user -defined data types.
23
And most other PLC platforms, it'll be pretty clear.
24
It'll be something that says data types.
25
And when you make a new one, you go to add new data type.
26
I've already generated the base code for alarm.
27
And here's where I think it's really clear what's going on.
28
You're saying, what does every alarm have?
29
that's going to trigger it initially
30
and then it's going to need to give me the option to acknowledge
31
that alarm and say yep i've seen it because
32
when you trigger an alarm the most normal response case is
33
that a light would turn on to say hey i'm in
34
alarm state you would shut down the logic until someone had come over
35
and said i see the alarm it's okay to resume
36
So then there will be this bit tracking if that alarm is active, if it has not yet been acknowledged.
37
And then when someone does try to acknowledge it, we need to retain that bit because there's a chance someone hits acknowledge, but the trigger condition is still active.
38
In that case, we need to see that it's been acknowledged, but not yet cleared.
39
sort of SCADA software so you can track alarms over time
40
and then we'll just give a couple identifying things so id
41
and message could just be like enumerated one through 20
42
and message could be like here's the thing that just happened
43
so you put that information again on an HMI
44
and we'll say every alarm in our system we want to share these
45
and you can see we have booleans we have long date say no matter how many alarms we make,
46
we want to keep track of all of these alarms.
47
And then to show where this gets really useful, we make a data block, we make a global database apologies.
48
And we say, hey, we're going to store all the information about all these alarms inside of this database.
49
So I go and make an array of 20 alarms.
50
And right off the bat, I get 20 individual Initially,
51
I have one of these tied to a physical push button.
52
I have another one tied to a PLC bit.
53
I could come right in here and I could say this is actually my third alarm.
54
It doesn't matter.
55
And then we'll say and this ID is two.
56
And you can see this is the default timestamp it loads in at.
57
So this has never been triggered.
58
OK, but I get all of this information for 20 objects, 21, really, just by making an array from zero to 20 of alarm.
59
I can make infinite numbers of that data type and I get all of those tags populated every time.
60
And then I made one individual outside of the array to say current alarm
61
because a really common thing in big systems in particular is alarm fatigue
62
and so many alarms go off when something shuts down
63
that you lose sight of what has happened most recently or what the most critical one is.
64
So I made a separate one and for the sake of this demonstration today this will be really valuable whatever triggered last.
65
So you can see the last alarm that I triggered was the button trigger, the one that's tied to the button.
66
So I'm going to drag that off to the side, we'll pull that back up later.
67
But now we've created a bunch of these objects, right, they live in this DB alarms, but we're not doing anything with them yet.
68
And this is where the structured text is going to come in.
69
So buckle up.
70
An important thing to understand is for loops are not super easy to
71
something kind of brute force with like counter variables and move blocks.
72
But almost the whole reason structured text became a thing.
73
And in Siemens, it's called SCL structured command language.
74
It is Siemens version of structured text, all the syntax people can calm down.
75
The reason structured text kind of emerged as a viable PLC programming language is
76
because loops and other sort of more advanced programming concepts are really tricky to do in ladder.
77
Rockwell does have a four block, but honestly, if you can pick up a little bit of structured text, you're going to be a better PLC programmer anyways.
78
And I'll talk you through what's happening here.
79
And let's talk through how you would want alarms in your factory to work.
80
Any alarm goes off in my system and I want it to activate the alarm light, the, hey, you have an alarm and it hasn't been acknowledged light.
81
So that's my light zero right here.
82
last alarm that occurred is into my current alarm field.
83
Okay, this is partly for me for this tutorial.
84
So I can keep it up over here on the right and show you how this code works.
85
But this is also a very real world scenario where you'd want to keep track of whatever the last alarm
86
that went off was and show that on the HMI
87
or you might want to do it where the first right the oldest unacknowledged alarm was
88
that might be more useful if you're doing like root cause analysis.
89
pretty easily in structured text.
90
And what we're going to do here is we're going to talk through the code
91
that I have set up in my alarm processing routine.
92
And then if you're doing this in kind of a follow along fashion, feel free to pause and copy it.
93
Um, and then But anyways, the first thing we're going to do is we're just going to check the local time.
94
This is useful when we're doing time comparisons later.
95
And then we're going to reset the light to zero.
96
So the way functions work, and this is in a function, not a function block, the way functions work is they don't have memory.
97
So we're going to start every scan of the alarm logic as if there is no alarm active.
98
And so we're going to turn the light off unless we find
99
that one of the alarms is active as we iterate through on our for loop.
100
that's when we'll turn the light back on as we'll see in a bit.
101
Okay.
102
And then latest time and latest index are just going to be, they're going to be checkers for us to see if we've iterated through the whole loop.
103
And if we found alarms that have gone off more recently than the kind of initial time, right?
104
The default time when you first set up a new tag.
105
Okay.
106
So hopefully that or Python programming, Arduino.
107
Hopefully this looks pretty familiar to you at the beginning.
108
Now, the meat of what the alarm handler is doing for us is it's iterating from zero to 20, right?
109
Because we made an array of zero to 20 alarms.
110
So important to note, If you made a new array with 50 new alarms and you call them something different, you do need to make a new version of this
111
or at least update this counter with your new array size and you need to point it at the right input tags.
112
Okay.
113
But anyways, for zero to 20, which is going to iterate through all of our alarms in our database of alarms.
114
First, we're going to check if the trigger is active.
115
So if it's actively having the alarm condition trigger it, and it hasn't already been active so if the triggers on
116
but we've already seen
117
that it's active on past cycles doesn't make sense to do all this initial stuff again
118
but what we'll do then is we'll say okay active is true we'll reset acknowledged
119
because even if for some reason it had been previously acknowledged the alarm is still occurring
120
so we'll make that false and then we'll set the time stamp
121
that this alarm has last gone off at as temp time so this will give us a snapshot of the triggered.
122
Then we'll also say if acknowledge is true, or this is something I forgot to mention, acknowledge all.
123
So what I have physically is two push buttons, one I'm going to use to trigger one of the alarms.
124
The other one I want to use as an acknowledge all button.
125
Okay, if you've been in an industrial environment, it's very normal for a cabinet to have like an alarm acknowledge push button on the outside.
126
So I have an acknowledge all push button here.
127
So if I acknowledge just or I press acknowledge all,
128
then I want acknowledged acknowledged past tense to go equal to true and then I can reset acknowledge equal to false.
129
Again, acknowledged is that intermediate value that's checking to see if acknowledged has been true, then I should reset the thing.
130
If trigger is not currently active and acknowledged is true, then we want to set active back equal to false.
131
And we don't really need an and if active check here
132
because there's no harm in setting a value that's already false equal to false again.
133
So And then again, if we get any alarm that is currently active, let's have our active alarm light just be on.
134
And then this little bit here is just for us to be able to track the most recently triggered
135
and active alarm and move it into our global alarm.
136
So that's this line down here, whatever our latest time and latest alarm indexes, let's go ahead and copy that whole thing into the current alarm.
137
And then the last thing we'll do is we'll assume ACK all is equal to false, right?
138
So if we detect that it's true, we'll go ahead and reset it at the end.
139
This we could actually delete most likely now that I'm reading it to you, but we're going to leave it as is because I know this is working.
140
So I put all that logic in a function I called alarm handler.
141
And then in main, I call two things, I call the alarm handler, and then I call another function called alarm setup.
142
And this one I made purely for the sake of demonstrating how this works.
143
Okay.
144
So like I I'm the first one tied to zero on my PLC.
145
I'm going to use it to simulate the trigger for alarm zero.
146
And then I made a memory tag called trigger one, I'll use that to simulate triggering alarm one.
147
And then my other push button tied to input one, I'll use that as the acknowledge all signal.
148
Okay, again, I hope this is making sense in terms of why to use it, I set up alarm zero and alarm one to be a button trigger and a PLC bit trigger.
149
I trigger them here on the left, you'll see them populate this current alarm on the right, and you'll get a good sense of the benefit of a UDT.
150
So if I push the start push button, you can see on the left side there that activates alarm zero in the field, my output, my light is on now.
151
And if I go ahead and press stop, all that'll trigger acknowledge all the light is off.
152
And what you can see in current alarm here in the bottom right, is we got an updated timestamp and it says, hey, the button trigger was the last alarm to go off.
153
Now, if I modify to one, what's cool is the light just turned on in the field.
154
So the same output triggered, that's my, hey, an alarm is active and hasn't been acknowledged yet.
155
And here you can see PLC bit trigger is the last alarm that got triggered.
156
And the ID is one, and I got an updated timestamp.
157
So again, I'll press acknowledge, but it's not going to actually trigger condition is still true.
158
If I modify to zero, the trigger condition goes away.
159
Now I can clear the thing.
160
So I'm able to generate a lot of alarms with shared logic very quickly
161
and they all have a trigger and acknowledge and active acknowledge timestamp.
162
They have all these shared conditions
163
and I know they're going to work the same way thanks to the UDT that I generate.
164
But I can still reference the individual tags under each of those alarms and use them to program unique functionality.
165
So if only one or two of these alarms need to open up a vent valve or stop a certain pump, I could still do that with these UDTs.
166
Hopefully that's a useful practical tutorial for you.
167
Apologies, this is a little bit of a chaotic tutorial, but this is honestly a pretty tricky one to teach
168
because I didn't want to get super in the weeds on structured text with you
169
and the lines and the use cases between UDTs and function blocks and instance data blocks do get a little bit blurry.
170
that you want every device of a certain type to have access to, to one master data type tag,
171
like an alarm that needs a trigger, acknowledge, active, and timestamp.
172
It's also totally common practice to create UDTs, data types for devices like alarms, pumps, motors, valves, analog sensors,
173
and combine that with function blocks.
174
So it's not either or user defined data types or function
175
be combined and that's how you can make some really powerful clean well -structured code okay
176
so i still hope this practical tutorial was useful for you as always
177
if you have questions
178
or there are things i forgot to cover in this feel
179
free to ask them in the comments below i'll get back
180
to you as soon as i can let me know what
181
you want to see next on the channel in the comments
182
and please don't forget to leave a like on the video subscribe to the channel
183
if you're finding this content useful thanks for watching good luck with your projects and see you next time Bye.

Tại sao nên luyện nói với video này?

Luyện nghe nói qua video là một phương pháp hiệu quả giúp người học cải thiện khả năng giao tiếp tiếng Anh. Video này cung cấp một bối cảnh thực tế về lập trình PLC và các kiểu dữ liệu do người dùng định nghĩa (UDTs). Bằng cách tham gia vào quá trình thực hành, bạn sẽ không chỉ học được những thuật ngữ chuyên ngành mà còn rèn luyện khả năng phát âm tiếng Anh chuẩn. Hơn nữa, việc hiểu rõ cách áp dụng các cấu trúc ngôn ngữ trong một bối cảnh cụ thể sẽ giúp bạn tự tin hơn khi giao tiếp trong lĩnh vực kỹ thuật.

Ngữ pháp & Cách diễn đạt trong bối cảnh

  • “user-defined data types”: Cụm từ này được sử dụng để chỉ các kiểu dữ liệu do người dùng định nghĩa, rất quan trọng trong lập trình PLC. Việc nắm vững nghĩa và cách sử dụng cụm từ này trong thực tế sẽ giúp bạn dễ dàng hơn trong giao tiếp kỹ thuật.
  • “a grouping of tags”: Cách diễn đạt này giúp bạn hiểu rằng một kiểu dữ liệu có thể bao gồm nhiều nhãn khác nhau. Đây là một khái niệm cơ bản trong lập trình mà bạn cần nắm chắc.
  • “common example”: Cụm từ này thường được dùng để bắt đầu một ví dụ có thể hiểu rõ hơn về một khái niệm. Việc sử dụng mẫu câu này cũng giúp bạn dễ dàng tiếp cận các tình huống thực tế trong giao tiếp.
  • “needs to give me the option”: Cấu trúc này thể hiện yêu cầu hoặc mong muốn, là cách diễn đạt rất hữu ích trong các tình huống giao tiếp hàng ngày.

Những cạm bẫy phát âm phổ biến

Khi luyện nói qua video, bạn có thể gặp một số từ hoặc cụm từ khó phát âm, như “acknowledge”. Nhiều người học có thể gặp khó khăn trong việc phát âm âm “k” và “dge”. Tương tự, từ “device” cũng có thể gây khó khăn do sự kết hợp giữa âm /d/ và /v/. Để khắc phục điều này, bạn có thể áp dụng kỹ thuật shadow speak, để lặp lại và lắng nghe cách phát âm chuẩn của những từ này ngay trong video.

Cuối cùng, không quên rằng việc học phát âm tiếng Anh chuẩn không chỉ giúp giao tiếp hiệu quả mà còn nâng cao tự tin cho bạn trong mọi tình huống. Hãy kiên trì thực hành và khám phá thêm nhiều video hữu ích để có thêm kiến thức và kỹ năng trong việc học tiếng Anh!

Ngữ pháp trong video

Những cấu trúc người nói dùng nhiều nhất, kèm đúng cụm từ trong video:

Cấu trúcTrong video
Câu điều kiện if + mệnh đề, will/would + động từ — điều kiện và kết quảif we detect that it's true, we'll go
Thì hiện tại hoàn thành have/has + quá khứ phân từ — việc đã xảy ra nhưng còn liên quan đến hiện tạihaven't gone · I've already generated · i've seen
Câu bị động be + quá khứ phân từ — nhấn vào việc xảy ra, không phải người làmbeen acknowledged · been triggered · be combined

Phương Pháp Shadowing Là Gì?

Shadowing là kỹ thuật học ngôn ngữ có cơ sở khoa học, ban đầu được phát triển cho chương trình đào tạo phiên dịch viên chuyên nghiệp và được phổ biến rộng rãi bởi nhà đa ngôn ngữ học Dr. Alexander Arguelles. Nguyên lý cốt lõi đơn giản nhưng cực kỳ hiệu quả: bạn nghe tiếng Anh của người bản xứ và lặp lại to ngay lập tức — như một "cái bóng" (shadow) đuổi theo người nói với độ trễ chỉ 1–2 giây. Khác với luyện ngữ pháp hay học từ vựng bị động, Shadowing buộc não bộ và cơ miệng phải đồng thời xử lý và tái tạo ngôn ngữ thực tế. Các nghiên cứu khoa học xác nhận phương pháp này cải thiện đáng kể phát âm, ngữ điệu, nhịp điệu, nối âm, kỹ năng nghe và độ lưu loát khi nói — đặc biệt hiệu quả cho người luyện IELTS Speaking và muốn giao tiếp tiếng Anh tự nhiên như người bản ngữ.

Phương pháp shadowing: đọc hướng dẫn từng bước đầy đủ →