After assembly installation we can use TwinCat in our project. The easiest solution to add ADS assembly is to use NuGet package manager and search for. If our environment is configured to use Visual Studio – double clicking on script icon will open a new instance of said IDE. In that folder we need a new class (in Unity lingo this will be new C# Script) called “TwinCAT_Handler.cs”. To achieve that, let’s create a folder in our assets directory called “Classes”. The first step is to get the TwinCAT ADS assembly into our project. My Unity is configured to work with Visual Studio, but it is possible to repeat those steps using Mono or any other compatible IDE. In this step we will create an empty 3D Project without any assets or packages. The time has come, to take a look at the other side of the environment – Unity 3D. If everything is setup correctly the result will be as expected – pulsing variable with 1 second cycle. iPulseLength := 500 įbWave(PulseLength := iPulseLength ) // instance of FB_SquareWaveĪt this point we can compile the project, activate the configuration, download and run the PLC program. Output field of the instance will be assigned to one of Communication variables we have created earlier. In the code itself we will call our instance, populating it’s input field. In addition iPulseLength variable is created, for now we will explicitly assign a value of 500 to it. Now, in our MAIN program VAR section we will define an instance of newly created Function Block. Impulse(IN := NOT Impulse.Q, PT := INT_TO_TIME(PulseLength)) Īgain, we will take an advantage of TwinCAT project structure and create separate folder for our FB. The FB will take as input pulse length in ms and returns boolean value as output. To make things a little more interesting let’s create a separate Function Block. As with all introduction projects let’s implement a PLC “Hello World” equivalent – simple square wave generator. We need some simple code to get us going. VAR_GLOBALĪt this moment our PLC is doing absolutely nothing. We’ll need two variables for now – one BOOL and one DINT. In “GVLs” folder we will create a new folder called “Communication” in which we’ll create Global Variable List.įor more complex projects a different approach might work better – we’ll talk about this in the future. To make sure that we use this capability in full we have to have robust data structures that we can refer to in the future. Direct addressing is possible but in this example we will omit it. The implementation of ADS (Automation Device Specification) in Beckhoff’s libraries allows us to query variables using their names. It will come handy when we start communicating with our PLC. If we double click on the PLC project name we can check the ADS port which was assigned to this project. After adding PLC project the structure should look like this
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |