From the series: Virtual Commissioning with Siemens SIMATIC Target 1500S for Simulink
Due to the increasing share of software in modern production machines and systems, the risk of not being able to keep costs, project duration, and quality during on-site commissioning is increasing. The late availability of the physical machine or plant makes testing the machine software more difficult.
Virtual commissioning enables early testing and verification of the software using a digital model of the machine. In the simulation model, the interaction between mechanics, machine software, and the product to be manufactured can be tested, optimized, and verified in various scenarios before the physical machine is available. This approach reduces costs, ensures high product quality, and speeds up commissioning.
Learn how you can create a digital twin of your machine and simulate it with the control algorithm. Then see how the application is integrated into the TIA Portal project using automatic code generation and the Siemens® SIMATIC® Target 1500S™ for Simulink®. Finally, watch as virtual commissioning is performed using the SIMATIC S7-PLCSIM Advanced simulated controller.
Hello, and welcome to this video on virtual commissioning with Siemens SIMATIC Target 1500S for Simulink. My name is Jens Lerche. And I am an application engineer at The MathWorks in Germany. Today, I will do the first part of this video covering the modeling path in a Simulink environment. And for the second part, we have support from Siemens by Mr. Felipe Ravazzi, who will later take over the topic of code generation, integration, and co-simulation.
Felipe, maybe you can give a brief introduction on your own?
Yes. Hello, altogether. My name is Felipe Ravazzi. I work for Siemens in presale support. And I am responsible for automation and virtual commissioning topics.
Here, you can see our agenda. First, I will show you a quick and easy way to create simulation models out of your CAD drawings. Then, we will see how controller logic can be modeled in Simulink to run a closed-loop desktop simulation. After that, Felipe will take over and speak about the code generation using the SIMATIC Target 1500S for Simulink, followed by the integration into a STEP 7 TIA Portal project.
Finally, we will run the co-simulation between the Digital Twin and Simulink and the control algorithm on the simulated Siemens PLC, the PLCSIM Advanced. So let's get started.
In this model, you can see right clearly a closed-loop system that has a plant part that is represented as a robot arm-- or, more general, as a mechanical assembly-- and the control part that is in the front that controls the motion of the mechanical assembly. The first thing you can do with this model is to simulate it in Simulink in the model-in-loop simulation. In an animation window, you see how the plant part behaves. And in the second window, you also see the animation of the state chart that controls the robot arm.
The algorithm of that control software is divided in four single state machines that interact with each other via events. The outer state machines are for the conveyor belts. And the two inner are for the arm of the robot and for the gripper.
It becomes obvious, right away, that you can run your system without having manufactured one single mechanical part, connected one single wire, or transferred any line of code to a PLC. This allows plenty of tests, design iterations, and optimization on the complete system, or single component, without spending thousand of dollars in prototype, manufacturing, testbenches, traveling, and so on. Of course, such a model doesn't fall from the sky. But we see that, in most cases, the models already exist, just in a different development tool.
And this is the CAD tool. Almost all companies in the industry throw their machines in CAD tools. And, therefore, most of the work to create a model of the plant is already done.
Here, you see the model of the robot in a CAD tool. Each body element is connected to its mate with joints that represent the degree of freedom. With the couple of clicks, you can import that model in Simulink. And with one command, your model got created automatically according to CAD assembly. This model can be simulated already. The only thing that must be done from now is to activate the activation inputs and the sensing outputs. Of course, you can add electrical motors, hydraulic cylinders, and so on. But that should not be the topic of that presentation.
From now on, we will focus on the controller. Let's assume that we test the whole algorithm in our model-in-the-loop simulation over and over again. We found a couple of errors and added forgotten requirements. But instead of writing the code in a PLC programming language from scratch, we use automatic code generation to implement the algorithm on the PLC.
I think this is the right time to hand over to you, Felipe.
Yes. Thank you, Jens. I will switch over to my screen.
So we have created this flow chart for the robot arm, as we can see over here. And we would like to reuse this in our field level without having to manually reprogram anything, such as PLC code in ATL or so, because-- the know-how-- it's here, already available. And we want to make use of this.
So for this purpose, we can use the Target 1500S, which is an add on for Simulink, which is being provided by Siemens.
So as a systems target file, after installation, we can simply select the Target 1500S on here. So this means we can do the code generation with the target. Let's quickly walk over the settings of the Target 1500S.
They are available on here, under Target 1500S Options. First thing we can do is select our TIA Portal project. Then with TIA openness, it is recognized which device is available in our project. It is also visible with which PROFINET interface we are connected and which IP address we are using.
If we want to import the SCL file directly to our TIA Portal project, we can use this option down here. We can select import in a software unit, for an example, or into an organization block.
Looking at the next step, we, here, have the choice to activate the external mode, which is used for an online data access with Simulink. Furthermore, we have some more options. On here, for an example, to enable perimeter access in STEP 7, meaning that, for an example, for a PID controller, I could manipulate P, I, and D parameters in TIA Portal. A further option, down here, is to enable STEP 7 access to internal model signals for more transparency of what is happening in our model or, for an example, to enable access to Stateflow states.
A really nice features is this option down here, which exports the Simulink model as an HTML web page, which can then be displayed on the PLC web server. Looking at further options, here we have the possibility to automatically transfer the generated shared object file, which is our binary file, directly onto the PLC.
OK, enough talk about the settings. Let's see this in action. My goal is to generate this block containing the Stateflow logic. And I can do this with a right click, C/C++ code, Build This Subsystem. A new window will pop up and ask for the storage class of our variables. In this case, I will select ExportedGlobal for all my variables and then press Build.
If we go ahead and select to View Diagnostics in the bottom part, we can check the progress of code generation. The SCL sources are automatically imported into the TIA Portal project. And the binary file is transferred to the PLC. This means we have a fully automated integration workflow.
OK. Now, looking at the TA Portal project, we can see that our SCL source was imported, which is also why it is here, visible under External Source Files. This source generated a few function blocks and UDTs in our PLC.
We can say that we have three fundamental function blocks, Load, Unload, and One Step. These blocks are always needed to run a target model on a Siemens PLC. Load is for loading the shared object file into our RAM memory. Unload is for unloading it. And the One Step block is for the execution of our model.
This is why it has the exact same interface as the block that we compiled in Simulink. This basically means that we have the same inputs and the same outputs that also our block and Simulink had. We can see them over here.
Since we are talking about virtual commissioning-- and we want to achieve a full soft render loop solution-- Simmons provides a tool called PLCSIM Advanced, which enables us to simulate a PLC. In this case, we are simulating in an S7-1518 MFP, which is a PLC that has ODK capability, which means it can run C++ code.
So what I did over here was create a new PLC instance and then load my TIA Portal project to the simulated PLC. And my PLC is already in run mode, which means my Stateflow logic that I generated is already running on the PLC.
So to visualize this, I can also, here, go online onto the PLC. Then I can check the values, online, of my inputs and outputs.
Now looking into our next step for virtual commissioning, if we remember correctly, our Simulink model did not only consist of Stateflow logic. We also had this robot arm that was being simulated. So for a virtual commissioning, in this case, we would like to have a co-simulation between PLCSIM Advanced and MATLAB Simulink. So this means we have to find a way to couple the values between both software tools.
One method of coupling the values between these two tools is using an S-function block. So what we did to achieve this value coupling was added the Simulink model a little bit. And now-- here in the control part-- instead of having the Stateflow model that we had before, we added this S-function, which is for coupling values with PLCSIM Advanced.
This S-function is actually addressing the PLCSIM Advanced API and exchanging the values over shared memory. So now that we have the logic running on the PLC, and the robot model still here in Simulink, we can start a simulation by pressing the Play button in Simulink. And as we can see, the robot is doing the exact same movement that we also had in our model-in-the-loop simulation, meaning that the logic on the PLC is working as expected. This is a good method to verify that the execution on a field level is actually showing the same behavior.
OK. Now, if you remember correctly, I also exported the Simulink model as a web page. If we move onto the PLC web server, on here, I can actually display the model.
So this is the Stateflow logic that I generated before. It is now being displayed on the PLC web server. And if I execute the simulation, I can also see the Stateflow states changing while the model is being simulated on here.
Last but not least, let's have a quick look at the used products in this webinar.
From MathWorks' side, we have MATLAB as a basic tool and Simulink as a simulation platform. For describing the mechanical behavior of the robot arm, Simscape and Simscape Multibody tool boxes were used. The state machine logic was displayed with the Stateflow tool box. And the MATLAB Coder and the Simulink Coder were used for the C/C++ code generation.
From Siemens' side, we have a SIMATIC STEP 7 Professional, so TIA Portal for creating the project for our PLC. We also use SIMATIC ODK 1500S as the cross compiler for the C++ code, PLCSIM Advanced Version 3.0 for simulating our PLC, and the SIMATIC Target 1500s as an overall tool for facilitating the workflow, so from compiling the C++ code, creating the ODK project, and transferring the SCL source into the TIA Portal project and transferring the binary file onto the controller.
This much for today's webinar about virtual commissioning with SIMATIC Target 1500s. Thank you very much for your attention.
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.