Drilling Systems Modeling & Automation, Part 9: PLC ladder diagram import
From the series: Drilling Systems Modeling & Automation
Existing PLC control software is often in ladder logic notation. However, it could be challenging to optimize this software with simulation and perform verification studies with this legacy PLC code. The ladder import feature of Simulink PLC Coder allows you to import Ladder Diagram created with Rockwell Automation® IDEs such as RSLogix™ 5000 and Studio 5000 into the Simulink environment as a model.
After importing or creating the Ladder Diagram models, you can do the following from Simulink.
- You can edit the imported Ladder Diagram model from within Simulink by using the plcladderlib library.
- You can simulate the Ladder Diagram after importing the Ladder diagram into Simulink.
- You can generate C code from the imported Ladder Diagram and integrate the code into your existing C language-based simulation environments.
- You can generate Ladder Diagram code from the imported Ladder Diagram and integrate the code into your Rockwell Automation IDE.
Hi. My name is Jonathan LeSage, and I'm an application engineer with MathWorks.
In this video series we've been covering how we can use design tools and simulations to optimize the performance control system, and also test it upfront. And in particular, we've been focused on using TLCs for our implementation.
For those of you just joining us, we've actually been targeting a drawworks drilling system as kind of our primary example for these design tasks. A drawworks system is a hoisting mechanism that raises and lowers this top drive repeatedly over time. And really, we want to construct some logic that can automate this process, and also can do it in a safe manner using some operational limits.
Now, in our previous cases we've been discussing how we can use state flow and other tools in Simulink to design and test this logic, and optimize it as well. And one thing that you can also do is instead of leveraging and building new logic, you can actually import existing logic from tools like Studio 5000 directly into Simulink.
So if you have legacy ladders implemented in Studio 5000, and you want to implement them in, you can actually import the L5X files. And rather than having a state flow chart diagram, I'll actually have a ladder diagram.
So let's hop over to the tools and see what this would look like. So right now, I'm in Studio 5000. This is not a MathWorks tool, but rather a Rockwell Automation tool for building logic for PLC controllers. I have here some basic logic implemented here for doing an auto drilling mode. So raising and lowering the hoist.
And I want to leverage this in Simulink. And so what we can actually do is we can import this over into Simulink. And this will actually give us a block here that is imported from Studio 5000 that implements this ladder diagram that I can use. And to me, it just appears as a subsystem.
Under the hood, you can actually look at the ladder diagram implementation. This is in Simulink as well. And you can see how that would operate. I'm going to go ahead and push Play to run this simulation.
Now, as the simulation starts, you'll see that just like the other simulations we've been running before of this drawworks system, the hoist we can see you raise and lower here in the animation. And we can observe the dials and gauges giving us the dynamic responses, or take a look at the scopes to visualize the signals as well.
The main difference compared to what we were doing before is this rather than being an implementation in Simulink-based blocks, or with state flow, we're actually using these PLC components that are part of the library and our Simulink PLC coder tool.
Now that we've seen how we can use an imported PLC ladder, let's take a step back and actually see how we can do the import process. Now, with the Simulink PLC coder tool, in addition to being able to generate structured text, we've recently added the ability to import legacy ladders from the Studio 5000 tool by Rockwell Automation.
There is a command that comes with that tool box called PLC import. Ladder. And essentially what this does is it scans an L5X file and then reconstructs the ladder diagram using Simulink implementation of the ladder blocks.
And in the Simulink library, we have a browser, a library of these components. So you'll see kind of the common instructions that you would see in a ladder diagram, the rungs, and gates, and lights, and comparators, logic as well, greater than, less than, so on, and so forth. You could, of course, try to put this together by hand, but I'd much rather use the automation aspect of this.
And so if we have a ladder that we want to bring in, for example, this add-on instruction here. That's the autodriller logic. What I can do is I can right-click on this. I can export this add-on instruction. And then save that. I'll replace that file.
What that's going to do is it's going to take this ladder diagram, convert it over into a text-based representation, basically an XML format that we can read in to Simulink. From there, what we can do is go to the command line. Let me go into this folder here. And you'll see that I have my L5X file here.
What I can do is I can run the Import Ladder command. And so what I do is I point to the L5X FILE and then I tell it that I want the top add-on instruction in this case, which is the autodriller logic. I'll hit Return, and this will start the import process.
And it'll automatically build up the necessary structures. You see that it's creating these files here off on the side automatically. It's going to populate the workspace with the required data types as well, and ultimately, will generate a Simulink model.
Once the process is finished, you'll see that we have an AutoDriller_Logic.slx file. This is the Simulink model of the ladder that we just imported. And you'll see here we have the ladder diagram. It's got the same inputs defined as we had before, and the same outputs. Those inputs and outputs, of course, are pulled from our parameters.
And so in this case, I have a couple of inputs and outputs in here. Inputs, you see inputs. And then we have an output, which is the speed reference. So we're going to pull those directly from this, from the Allen-Bradley tool.
And if you're curious to go under the hood, you can double-click. You can take a look at the variables that are defined here. These are what are imported from the parameters in the L5X file. And then the logic routine itself is the underlying code. And so you can take a look at this ladder diagram. This is the replication of the ladder diagram we had in Studio 5000.
And we've covered quite a bit of topics. Most of the topics we've covered. This was a little bit of a bonus video to talk about ladder import. Over time, I will potentially add more videos on additional ways that you can test and automate your safety critical software design for heavy equipment.
I hope you enjoyed this video series. And stay tuned. And we'll make all of these examples available to you on our file exchange. Thank you.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.