Book a Demo

Author Topic: How to design a PLC program (TwinCAT 3) with EA  (Read 52404 times)

Oliver Tonn

  • EA Novice
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
How to design a PLC program (TwinCAT 3) with EA
« on: January 31, 2021, 02:25:18 am »
For the first time since I'm working for different customers on PLC related projects since the beginning of 2008, I want to plan a software project in advance. During the last project I was working on, I had to modify an existing Software and had to plan the modification in advance with EA, which till that day I’ve never used. Even after reading most parts of the compendium I’m still a newbie.
For the current project I should create a software with which real hardware (e.g., valves, door switch, and so on) should be simulated against the machine PLC, good cases and failure cases.
I thought I’ll create a function block for each device. I’m not sure at the moment, if I will use methods or not. But my question is how to start and how to do it right? I’ve created a sample project in TC3 and created a UML model from it with TC3, but the result doesn’t appeal to me.
I’ve created an EA project with two Packages under the root package.  One for the function blocks and another for the program.
For the FBs I have added a class diagram and another one for used EMUMs. The first FB I’ve created is one for a valve. At the moment it consists of four inputs and two outputs which I realized by adding them as attributes with the stereotype Input and Output.
The FB contains also a Method (FB_Init) which needs three inputs at the moment one of these inputs is used to specify the type of the valve and is based on an enum.  And that’s where my first question starts. In the one class diagram I design the ENUM and in the class diagram I place an instance of it, but with which link I connect the instance with the FB and in which direction must the arrow go? I think with a usage link drawn from the FB to ENUM instance. And there will be a second instance of it in the declaration part of the FB, because the memory of a method is temporary and while executing the method FB_Init I have to copy the data to another instance of the ENUM, but how do I design this in EA.
Next question is, if I place an instance of the FB in the class diagram for the project it doesn’t show the attributes and operations any more, could this be activated, that it still does it.
Next thing is, that, as mentioned before, the FB is using two instances of an ENUM must/should I also add a link of the instance of the ENUM? If I do so, it doesn’t add the link automatically, should/must I add this manually? Another question is, if I drag and drop the instance used by the FB into the program diagram it doesn’t create a new instance, but each instance of the valve FB will of course have its own two instances of the ENUM. How must this solved correctly?
Thanks in advance.
Send from something with internet access.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to design a PLC program (TwinCAT 3) with EA
« Reply #1 on: January 31, 2021, 04:52:29 am »
Hi Oliver,

I would want to help, if I only understood what you are asking.
Your question comes across as a big wall of text, and I gave up trying to understand it before even finishing.

It might be a good idea to split up your post into smaller, easier digestible parts.
Maybe with some images? (publish the image on a public image hosting site, and link it here)

Geert

Oliver Tonn

  • EA Novice
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Re: How to design a PLC program (TwinCAT 3) with EA
« Reply #2 on: January 31, 2021, 07:43:02 am »
Hello Geert,
thanks for your answer. The problem is quite complex, thats why I had used so many text, but I'll try to divide it.
I'm designing a PLC project (TwinCAT 3) with which I will simulate the reaction of real hardware, like valves, temp sensors and so on.
I started with a valve and created a FB which variables could be seen here. The FB has also a method with one variable defined by me (The last one, the other two were defined by the system). A screenshot could be found here. A screenshot of the ENUM could be found here.
In EA I have created this structure. The ENUM looks like this and the FB (Method is missing) with an instance of the ENUM looks like this.
My first question is now, if I did everything correctly in EA, or for example, the arrow of the link must show in the opposite direction?
« Last Edit: January 31, 2021, 11:17:37 am by Oliver Tonn »
Send from something with internet access.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: How to design a PLC program (TwinCAT 3) with EA
« Reply #3 on: January 31, 2021, 09:38:55 am »
And the answer is: maybe. I had the same issue as Geert (but was too lazy to actually bring it to words). I would suggest you either hire a consultant to get you on your feet or to take some time for studies. Such a broad modelling question as you brought up is not well suited here. On StackOverflow it will certainly be closed as being too broad. Pretty sure I'm not the only one who doesn't know what you mean by PLC (and the other acronyms). Wiki has lots of (funny) choices: https://en.wikipedia.org/wiki/PLC (I would guess it's the one very far down; something like my Arduino).

q.
« Last Edit: January 31, 2021, 09:43:12 am by qwerty »

Oliver Tonn

  • EA Novice
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Re: How to design a PLC program (TwinCAT 3) with EA
« Reply #4 on: January 31, 2021, 11:04:13 am »
Sorry for confusing you and the other. I thought, that the meaning of the abbreviation PLC is quite clear, especially in combination with TwinCAT.
PLC stands for programmable logic controller, a, simplified defined, special computersystem that controls a machine. TwinCAT is the name of the PLC Software from the german company Beckhoff, of which I'm using version 3.
I'm working as a freelancer for different companies, mostly machine manufacturers, to support them on different tasks.
At the moment I'm working on a software which should simulate the hardware of a machine against the real machine control. For example a valve. To be a little bit more prepared I want to plan the function blocks prior to programming them. I hoped, that in this forum people could give me some advice and push me in the right direction as people including me doing so in the SPS-Forum (SPS means PLC in german) and supporting people and help them with there issues.
« Last Edit: January 31, 2021, 11:12:11 am by Oliver Tonn »
Send from something with internet access.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to design a PLC program (TwinCAT 3) with EA
« Reply #5 on: January 31, 2021, 06:53:05 pm »
Hi Oliver,

I think you should talk to the guys at LieberLieber.
IIRC they have some experience modelling embedded systems and stuff like that.

I'm not sure if many of the readers here have any experience with that subject. I certainly don't.

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: How to design a PLC program (TwinCAT 3) with EA
« Reply #6 on: January 31, 2021, 07:58:45 pm »
Oliver, I have done quite a bit of work in that direction (formerly for Bombardier here near Berlin). It's a complex matter, yes. You seem to have little experience with UML at all. And tackling that you would likely need to make yourself familiar with SysML and a lot with state machines (and at least the rest of the UML basics).

q.
« Last Edit: January 31, 2021, 10:51:33 pm by qwerty »

Oliver Tonn

  • EA Novice
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Re: How to design a PLC program (TwinCAT 3) with EA
« Reply #7 on: January 31, 2021, 10:18:09 pm »
I think you should talk to the guys at LieberLieber.
IIRC they have some experience modelling embedded systems and stuff like that.

I'm not sure if many of the readers here have any experience with that subject. I certainly don't.
Hello Geert,
thanks again for your answer. I don't think, that Embedded systems and PLCs are quite comparable. Embedded systems are mostly programmed in C or C++, PLCs have there own language, some graphic orientated and some text orientated. The latter one are in some parts a little bit special. TwinCAT from Beckhoff is based on Codesys as many other PLC development systems too and Codesys is based on the IEC61131-3.
« Last Edit: January 31, 2021, 10:19:57 pm by Oliver Tonn »
Send from something with internet access.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to design a PLC program (TwinCAT 3) with EA
« Reply #8 on: January 31, 2021, 10:37:14 pm »
I don't think, that Embedded systems and PLCs are quite comparable.
Goes to show this really isn't my cup op tea ;D

Geert

Oliver Tonn

  • EA Novice
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Re: How to design a PLC program (TwinCAT 3) with EA
« Reply #9 on: February 01, 2021, 12:13:31 am »
Oliver, I have done quite a bit of work in that direction (formerly for Bombardier here near Berllin). It's a complex matter, yes. You seem to have little experience with UML at all. And tackling that you would likely need to make yourself familiar with SysML and a lot with state machines (and at least the rest of the UML basics).
Hello qwerty,
also thank you for your answer. Your impression is correct, I'm not really experienced in using UML and EA in particular. Around 15 Years ago a student on an internship, the lead software developer (The only one beside me) of the company I was working for and me designed a new PC software for controlling a laser glass engraving machine. The drawing was done by the other developer and I was more a provider of keywords.
The company I was working for during the last project was usinf EA for designing the software and for documentation purposes, but after reading the important parts of the EA compendium, I found out, that they used it the wrong way in some cases.
For the current project I thought it would be a good idea to plan the software a little bit in advance and wanted to use EA for that, because I have it.
I know how to create a state machine with EA, but I'm missing some basic knowledge, such as how to draw the mentioned FB (function block) in EA and also hor to draw a used instance of it correctly.
Send from something with internet access.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: How to design a PLC program (TwinCAT 3) with EA
« Reply #10 on: February 01, 2021, 06:49:42 am »
Well, I did not use the state machines or design anything for Bombardier. I "just" made the modeling framework. It took about 2 or 3 years to have some agreed workflow. Lots of effort went into the business part (having the stakeholders review the use cases in the beginning and work actively in later phases). A whole other group was responsible for testing (also using EA). Part of my work was also to create an MDG which borrowed quite a bit from SysML. I did not use the Sparx provided MDG for a coule of reasons (one was that there was nobody fluent in SysML and only a few had basic UML knowledge).

Some interesting part is the preface. Some guys had tried to setup EA for just that FP design. And that failed since they were not thinking about the important business part. I did not make friends in that department - in the beginning. But honestly, you need to start from business or the whole thing tends to be a "broken pencil" (pointless; bon mot from Sunshine IIRC).

q.

Oliver Tonn

  • EA Novice
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Re: How to design a PLC program (TwinCAT 3) with EA
« Reply #11 on: February 01, 2021, 07:30:41 pm »
By the way, as I mentioned before I'm very active in a (mostly) German language PLC forum ( SPS-Forum ). There you could thank people answering you by clicking on a thanks button and mark the most useful answer to close the thread. Are there similar possibilities here?
Send from something with internet access.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: How to design a PLC program (TwinCAT 3) with EA
« Reply #12 on: February 01, 2021, 07:48:43 pm »
Not really. That "helpful" can only be used if you have enough reputation. I don't care about it much (see the ratio of +/- and the relation to the total number of posts). StackOverflow is something different.

q.

PeterHeintz

  • EA Practitioner
  • ***
  • Posts: 1001
  • Karma: +59/-18
    • View Profile
Re: How to design a PLC program (TwinCAT 3) with EA
« Reply #13 on: February 02, 2021, 12:57:40 am »
Hi Oliver,
in IEC 61131 “somehow” all those graphical interpretations like Ladder Diagram, Functional Bock Diagram,… could be regarded as having Structural Text behind. A structural text is “somehow” the programming language Pascal.
Pascal, C  and some others languages are not Object Oriented Programming languages, but UML has its root in the OO word.
This does not mean that you can not use UML for “Pascal” or “C”. E.g. anything I used UML/SysML for is late rprogrammed in C.
The question is more what you want to achieve/improve by using UML!
I can not answer you this question because this is in your head, but I could imagine that you want to have some king of big picture.
In this case you could e.g. use class diagrams to represent your top level functional blocks including their interfaces and use e.g. sate machines or activities diagram to define what should happen in those top level blocks in an abstract way.
Best regards,

Peter Heintz

Oliver Tonn

  • EA Novice
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Re: How to design a PLC program (TwinCAT 3) with EA
« Reply #14 on: February 02, 2021, 03:23:50 am »
in IEC 61131 “somehow” all those graphical interpretations like Ladder Diagram, Functional Bock Diagram,… could be regarded as having Structural Text behind. A structural text is “somehow” the programming language Pascal.
Pascal, C  and some others languages are not Object Oriented Programming languages, but UML has its root in the OO word.
This does not mean that you can not use UML for “Pascal” or “C”. E.g. anything I used UML/SysML for is late rprogrammed in C.
The question is more what you want to achieve/improve by using UML!
I can not answer you this question because this is in your head, but I could imagine that you want to have some king of big picture.
In this case you could e.g. use class diagrams to represent your top level functional blocks including their interfaces and use e.g. sate machines or activities diagram to define what should happen in those top level blocks in an abstract way.
Hello Peter,
thanks for your answer. I'm using structural text with TwinCAT 3. That TwinCAT 3 and other IEC61131-3 based languages aren't object orientated isn't completely correct they have some capabilities of OOP, like methods and properties (Setter/Getter) for example.
What I want to do is to plan the project/software before programming it, which is a first for me (SHAME!!!). So I started with one FB and designed it in EA with class diagram (see my other posts in this thread with screenshots) and I wanted to know, if I was using EA correctly in thisd case. Beside the already existing model I want to add some notes for this FB and maybe also a state diagram, which would lead me to a next question. I know how to create state diagrams with EA from a former project, but in this case where should I place it?
Send from something with internet access.