Virtual Commissioning using Simulink – Part 2: Virtual Commissioning
Overview
Many industries are facing increasingly complex algorithms deployed in production systems to achieve greater productivity. In addition, the cost of downtime for implementing improvements in control software can be prohibitive. Today, companies are tuning to virtual commissioning to address these two issues. Mining companies can leverage virtual commissioning to ensure new control algorithms will be reliable, achieve desired results, and be implemented seamlessly with minimal downtime.
Virtual commissioning uses dynamic models to design and validate algorithms for improved productivity. After validation, these algorithms can be automatically deployed to a simulated PLC, where the code running on the PLC is tested against the plant model.
This seminar focuses on two aspects of virtual commissioning: design with simulation, and implementation with code generation. You will see the workflow demonstrated using a common challenge across mining companies: a multi-tank level control problem.
Part 2: Virtual Commissioning
After developing and validating a control strategy in simulation, the control algorithm is deployed to an embedded platform common in the mining industry: a Programmable Logic Controller (PLC). The generated code is validated by running the code on a simulated PLC that is connected to the Simulink plant model prior to implementation on the real system. This part of the seminar highlights the ease of generating PLC code from a designed algorithm to provide a short reliable path from design to production implementation.
About the Presenter
Ruth-Anne Marchant
Ruth-Anne Marchant is a Senior Application Engineer specializing in Simulink, and Model-Based Design. Since joining MathWorks in 2015, her focus is on supporting customers adopt Model-Based Design with Simulink. Prior to joining MathWorks, Ruth-Anne worked in the Canadian aerospace industry as a control systems engineer. Ruth-Anne holds a BASc in computer engineering and an MASc in electrical and computer engineering, both from the University of Waterloo, Canada, specializing in control systems.
Branko Dijkstra
Branko Dijkstra is a principal technical consultant specializing in Model-Based Design workflows for process industry optimization. Prior to joining MathWorks, Branko was an engineering manager for the development of automotive climate control and electric vehicle thermal management systems. Before that, he worked in the microlithography industry. Branko received his M.E. based on his work modeling a batch crystallization plant. He received his Ph.D. in control engineering (microlithography) from Delft University of Technology, the Netherlands based on his thesis Iterative Learning Control Applied to a Wafer Stage.
Recorded: 14 Oct 2020
Hello, welcome and thank you for joining us for our second mining webinar episode. A few years ago, while I was talking to a senior executive at a mining company responsible for the production side of their business, this executive mentioned two things that stuck in my head, thinking about the topic that we're discussing today. One of them was that this executive said that if they implement a new innovative algorithm in their production environment, it sort of needs to run in production monitored closely for over a year before they're confident that it's robust against all the typical environmental conditions that that algorithm is going to get exposed to. And the other one was that once you start implementing these algorithms in production and you get more and more of them, how can you make sure that they play nice to each other, that they don't start fighting each other?
I think in the first element of this webinar series, Ruth-Anne showed that for tuning the algorithm, she already ran many, many, many simulations so she already exposed this algorithm to a large amount of simulated time. So you can imagine it's not much of a stretch to use that same simulated environment to run many extreme conditions and long, long periods of runtime to make sure that your algorithm that you've developed in simulation is going to be robust. This webinar series is going to look a little bit more at the second element. And that is, once we've got this algorithm and we integrate it with our real control systems, how can we make sure that when we tie these things together, they don't start fighting each other?
And that is the element we'll talk about today, which is virtual commissioning with Simulink. This webinar is going to focus on specifically the virtual commissioning side of things. I am Branko Dijkstra. I'm a technical consultant at MathWorks. Ruth-Anne Marchant is an application engineer who is going to take over somewhere along the way to demonstrate what this topic looks like in action.
Here you see a quote that I've taken from a report of the World Economic Forum from a few years ago that they created in conjunction with Accenture. And it's a quote from a CEO of a mining company saying, harnessing technology is central to making mining safe and more efficient. You could easily replace mining with whatever your field or your industry is, because I think that statement remains true. It is all about using this new technology to get more out of your business, and not just to make your business safer, but to make it better without sacrificing any of that safety or productivity.
Here's another quote from a McKinsey report from a couple of years ago that talks about using analytics techniques. You can think of any kind of algorithm and those analytics techniques directly being able to improve your earnings by several percentage points. It pretty much tells you, you can reduce costs and increase productivity by being smart at what you do, by increasing the complexity of the technology that you apply in your systems.
And that leads to this slide. Pretty much all industries are experiencing this trend. They are experiencing a trend where the complexity of the algorithms that interface with the systems, pretty much the complexity of the software that integrates with the systems, is increasing. And dealing with this complexity comes with its own challenges, and that's what we're going to be talking about today. How can you handle this increased complexity of software and also the increased complexity of operating your systems in a reliable, safe, and predictable manner?
Now it would be ideal if you could develop and experiment new algorithms on your actual system. But here's already a couple of pictures of systems where it is impractical or impossible or too expensive to try to experiment on your real system. For instance, you might want to know how does my wind turbine behave in a hurricane, but it's just a little bit impractical to actually summon a hurricane for your new wind turbine park every time you commission one. So this is why we are talking about using a model for your system.
In the last webinar, Ruth-Anne showed how she used a virtual plant, a model of the plant, to develop an algorithm and to fine tune that algorithm to the dynamics of this system of this plant model. Today, actually take it to the next step where we're going to take that algorithm, that controller that was developed, and we're going to implement that on an actual control or on a PLC and let that PLC work together with our model, with our virtual plant, and to validate that when that PLC starts talking to an actual plant, how it's going to behave and that those things are going to operate properly. That is what we mean with virtual commissioning.
So what we want to do with virtual commissioning is we want to take a model of the plant, put that into a virtual environment, into a simulation, we want to then develop or apply an algorithm that we want to implement in reality. We want to implement that in this virtual environment, try it out in a way that we are confident that when we then flick the switch to get that control system to operate on the real plant, that things are going to run smoothly and correctly, and giving us the confidence that once it starts integrating with all kinds of other systems, things still run nicely.
So the first step that we're going to look at, we started with this metal box with the plant and a controller in it. We're going to transition that controller towards a controller target. And in the example we talk about today, that will be a programmable logic controller, a PLC. It can be any kind of other target, but that is the step that we're showing today. How do we take this algorithm that we've validated and developed in a flexible environment in the simulation, how do we now put that in an environment at full running production? And what we use for that is automatic code generation.
This picture shows pretty much how complicated it is and Ruth-Anne will show this. We have a controller block and we have a plant block. We right click on the controller block and we select we want PLC code. And then we click the button, generate code for the subsystem. That is what will generate PLC code for us that we can then directly put onto a PLC so that we can then run it in production or validate it in virtual commissioning.
What you also notice, if you look at the middle of the screen, is we've selected PLC code. But if you want to implement HDL code or C code, that is perfectly possible too. Which pretty much means that any target that you could imagine, you could generate code for and implement it.
Here's an example of what that would look like. Once we've right clicked, Simulink goes away for a while and then generates for you this structured text file. This structured text file contains links to the original models, so you have traceability back that you actually see what did this code relate to, and it gives you a report on what it generated and what it looks like. So this path of automatic code generation makes sure that you have no mistakes between what you originally implemented, what you've tested, what you've simulated on maybe years' or decades' worth of conditions and scenarios, when you've then implemented into the PLC code, you have a direct link that shows it is the same code that we're now going to be putting into production.
The next step after that is done is the virtual commissioning. We've taken this PLC code, we put it on a PLC, and we then get that PLC to talk to our simulation of the plant. That means that if there is anything that goes wrong with hooking up that algorithm to an actual plant, to our Simulink, if there's any integration issues, we will find them in this virtual environment during this phase of virtual commissioning. And this is a phase where if you would do this on the real plant, it is possible that it actually brings the plant down if you have some sort of integration problems. So this phase, we want to make sure during this code simulation that when we tie this PLC together with the plant, that things are still running properly.
Now to make clear, during the simulation, we validated that the algorithm makes sense. The step that we're doing here is really about making sure that once we put the algorithm on our production target, this PLC, that it still operates properly in its newly integrated environment. So it's the integration that is important here.
So what we're going to do is we're going to take this plant that's going to stay in Simulink and we're going to transition the controller that was in Simulink towards the PLC. And what we'll end up seeing is an environment like this in Simulink that will run exactly like a regular simulation does. So it will look very similar to the simulations we've done before. But under the hood, we actually are communicating to a PLC. And in this particular example, we're communicating to this PLC through OPC UA, which means that this PLC that we're talking to could be anywhere, could be in our own computer, could be a separate computer somewhere. What communication we have is actually across a network much like the PLC [INAUDIBLE] experience during production.
Now, let's have a look at what that looks like an action. Ruth-Anne, take it away.
Thanks very much, Branko. So at this point in the presentation, we're going to see how this can be done in Simulink. So as Branko mentioned, the first step is to automatically generate code from the control algorithm, which is located in this block here. So if you recall from the first presentation a few weeks ago, we had this-- we tuned the control algorithm that lived in this subsystem to meet some requirements. This was all done in continuous time.
Now what we want is for this code to run on, in this example, a PLC, which would be running at a fixed time step. So the first thing we need to do is convert the continuous time control blocks to a discrete time setup. So this involves setting the appropriate sample time, this example in this demonstration, we've selected a sample time of 0.5 seconds, and then rerunning the simulation to test the overall performance of our algorithm. So I'm just going to run a simulation here so we can see with this sample time, with these discrete time control blocks, what the performance of our system looks like.
So I double click on the scope. What you can see here in the top plot is the level of each of the five tanks. And you can see that the first tank, which is the yellow line, has this step response, looks pretty smooth. And then the other four have a little bit of a disturbance as the first tank level adjusts. So this performance, let's say it is acceptable, and now we move on to configuring the control subsystem to automatically generate PLC code.
So we do this first by selecting the block. And the first step we want to do here is we want to change the subsystem to an atomic subsystem. So when I select the block, I can see that this new tab shows up in the tool strip. And I have already selected is atomic subsystem right here. And then what I want to do is set the sample time for the atomic subsystem, so I right click on the block and click block parameters, and I've selected the sample time here. I've parameterized this to allow for easy testing and manipulation of the sample time.
The next thing I want to do is select the target ID. So in the apps tab, the first thing I want to do here is select the PLC coder app. So when I click on that, it opens up a new tab, which allows me to configure the settings for my PLC code generation.
So this brings up the configuration parameters. You can see down at the very bottom here, I have my a PLC code generation options. And for this example, I have selected the Siemens TIA portal as my target IDE. If I expand this list, you can see that out of the box, we support a wide range of-- I've got a PLC, target IDEs. And if you don't see yours here on the list, please come let us know and we're more than happy to talk about your specific use case with you.
Then I ensure that in this block here, I am pointing to the correct subsystem that I want to generate code for. And then you can select generate PLC code right here. And what this does is it automatically generates PLC code configured for the target that was specified in the settings.
So now you can see here that we have successfully automatically generated PLC code for that block. And the generated files live in this scl file right here. I can access the code generation report as well, which is also automatically generated. Click on the scl file. And one of the things that I really like about this tool is that there is this traceability between the generated code and the model. So I can say select this link right here, which in the comments, seems to suggest it's related to some sort of saturation, double click on it, and it takes me directly to this saturation block that lives within the PID controller.
OK, so now that we've automatically generated code, what can you do with it? Well, the next step is the co-simulation piece, or the virtual commissioning or virtual testing part of the example. So what I'm going to do here is show you how you can integrate it into your Siemens project and then set up a virtual simulation or a virtual commissioning test. Now Branko talked about the-- what is virtual commissioning at a high level. In this example, I'm going to-- instead of deploying the code to a physical PLC device, I'm going to use a virtual PLC.
So here we are in the Siemens TIA portal. And the first step I want to do when I'm bringing in my project is to specify that scl file as an external source file right here. So I click on add new external file, point it to that automatically generated code, and bring it in here. And then I can right click on the block and generate blocks from source. And then from there, I'm able to drag and drop the block into my cyclic interrupt, which I've already done here. This is now integrated into the project in the Siemens environment.
What I want to do now is download this onto a virtual PLC. And for that, I'm using PLC SIM [? Advance. ?] Right here, I've already pre-configured it, and the PLC instance is active. And this PLC, virtual PLC, has been configured with an OPC UA server as well. So what I want to do is have this virtual PLC talk to the OPC UA server. And I also want my Simulink model to talk to the OPC UA server. So let's talk about how to do that.
So this was the model that we used to automatically generate the PLC code. Now I'm going to replace what's in the controller block here with an interface with the OPC UA server. So let's go over to the model that does that.
So here's the same model as I previously showed, with the main difference being in this block, there is a interface with the OPC UA server. If I double click on this block, what we see is MATLAB function, where the MATLAB function sets up the connection to the OPC UA server and handles the data transfer inputs and outputs.
And if we go back to the Simulink model, so what we have here is the MATLAB function block takes as an input all of the errors that come from our plant model, then sends it via OPC UA to the virtual PLC that is running the code that we generated in the previous step. That code computes the required valve commands to open and close the valves. That's sent again by OPC UA back to the Simulink model, which sends those signals as input to the model of the plant.
So now let's run the two in a co-simulated way. To start my virtual PLC, click this run button. Wait until the green light's solid. Now I will start the Simulink model.
So what this is doing now is it's running a Simulink model of the plant, calculating all of the plant dynamics, alongside with a virtual PLC that's connected via OPC UA, and it's running the automatically generated controller code. If I double click on the scope here, I am streaming the live values of the levels for each of the tanks that we're testing.
So I'm just going to stop this, bring the scope back up, zoom out so we can see the whole thing, what the whole thing looks like. Now this ran about 38 to 40 seconds' worth of simulation, didn't run the whole five or 10 minutes base simulation that we showed in the PLC co-generated model, just for the sake of time. But the idea here is that you can automatically generate code that you can deploy to your PLC. And then you can test that PLC code before you put it into hardware. You can test it in a virtual environment by connecting a virtual PLC to Simulink.
Now this isn't the only-- OPC UA isn't the only interface that supports this type of workflow. It's one possibility. And this example, yes, I used the Siemens environment. But Siemens is, as you saw, not the only one that supports this type of workflow as well, and this sort of testing framework. So it's certainly possible to do this with many of the other popular vendors out there.
So to wrap up, what you've seen in this demonstration is how to automatically generate code from a Simulink model that can be deployed to a PLC. Then you saw how that automatically generated code ran on a virtual PLC alongside, or co-simulated with, a plant model, the dynamic model of a physical system. And the two ran together in a co-simulated environment using a OPC UA connection. So at this point, I will turn it over to Branko to wrap up.
Thanks, Ruth-Anne. That was really cool to see all of that in action. Now what we just saw is we saw a plant in Simulink that was communicating, co-simulating with a PLC that was running somewhere else. For practical purposes, in this case, that was a virtual PLC as well, provided by Siemens, but it could have been a physical separate PLC box somewhere because we were communicating through OPC UA. So what we've now shown is in the first webinar, we've shown simulation, using simulation to develop and validate an algorithm. Then we used today code generation to take that algorithm and implement it on a PLC. And then we used a virtual commissioning to validate that if we turn that PLC on and we connect it to a plant, that things are still going to play nice.
Now if you have this environment, there's a couple of other things you could do. So one thing is we've already shown that we're generating the code that we put directly in the PLC. So once you've validated, that you've already got the option to just switch that PLC over to production, which is probably a smart thing to do anyway. So you can deploy these optimal algorithms that you validated directly automatically into production.
You can also use this to explore new plant designs with real control systems. So you can imagine that you build a virtual plant of a new site, new factory that you're building. You can develop algorithms for all the control systems that you want, you can actually put them on actual controllers, and you can validate that all those controllers are going to work correctly before you've even built the plant.
You can also connect to any kind of effort platform. So if you want to have an algorithm that runs in the cloud or on a GPU, it is perfectly possible to use this exact same method to validate that kind of integration. So you could try any kind of platform, you can implement any kind of platform you want this way.
And another example is you could use this virtual plant as a training simulator. So you could use this virtual plant to simulate certain disaster scenarios in your plant, and have an operator just interface with it directly as they would with a normal control panel because they're actually directly interfacing with the real PLC. But then they could actually be trained in reacting to situations that hopefully they will never encounter during normal operation. So these are some ideas of what else you can do by having that virtual plant, virtual representation of your actual system.
In the last webinar, Ruth-Anne told you about this story of Baker Hughes using a model to develop an algorithm for their drilling systems. I just want to emphasize another little field in this application where they did not only use models to develop their algorithm, they actually also used hardware in the loop, or what they call HIL tests, which is really the same thing as virtual commissioning, to make sure they didn't have to do many field tests even for integrating these algorithm into their production environment. So they saved their money during the simulation phase, as Ruth-Anne mentioned last time, but they also saved it by doing these virtual commissioning tests.
Now what we have achieved is we have reduced the risk of costly downtime by testing the integration of these algorithms in a production-like environment with a virtual plant first, before we go to production. And in addition, if we use code generation, if we have our algorithms in Simulink and we automatically do this deployment path, we have shortened our time from concept idea to production. So we have saved time by rapidly being able to iterate the design of our algorithms in a virtual environment.
Bringing this together with the results from the last [INAUDIBLE] webinar, we have accomplished a reduction of risk of costly downtime while developing more complicated algorithms by using simulation first and then virtual commissioning second. We have created the ability to improve the performance of our increasingly complex systems so we can develop complicated things in a virtual environment. And we have the ability to save time by rapidly iterating these processes by using automatic code generation.
Here's a list of resources for you to dive into these topics deeper. At the top is a link to the webinar series that we're currently running. There's more interesting topics coming up. There is a white paper available on our website that contains a lot more detail on virtual commissioning and contains links to other videos and papers. There's a link here to another webinar series available for you. And in case you missed the first part of Ruth-Anne's presentation, that is still available on our website too.
But what we'd really like you to do is contact us, one of us or all of us, when you are interested in this topic, when you're interested in building a model to develop algorithms or to validate algorithms in a virtual environment through virtual commissioning or all of that. Please become in touch with us. We are very much willing and eager to help you out with this. Please talk to us. Thank you very much for your attention, and please get in touch.