- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
- Prerequisites
- Prepare the model for the connection
- Implement the connection in ctrlX PLC Engineering
- Mapping of the signals
- Update connection settings
- Fix for common errors in the connection
- No connection possible
- Connection only shows "Connected", no data exchange
- Related Links
- The Company
Prerequisites
As prerequisite for this hardware in the loop example one needs at least the following components:
- A PC with iPhysics installed and loaded with a simulation model. In this sample we use the model “Howto_FirstModel_ctrlX.iphx” which can be found in the samples folder of the installation
- ctrlX WORKS
- ctrlX PLC Engineering
Prepare the model for the connection
This section describes the steps necessary to create a ComTCP HIL node for a given simulation model. In this documentation a soft PLC will be used.
First open the model “Howto_FirstModel_ctrlX.iphx” which can be found in the folder logistics in the samples folder. This is the same model that is used in the “Howto_EN_FirstModel”, only some control tags have been created to speed up the following process. The way how to implement control tags is described in “HowTo_EN_SIL_PLCSIM_Advanced”. If you have not yet gone through the “Howto_EN_FirstModel” manual it is advisable to do that beforehand. In the following manual the script which is executed in iPhysics to control the expansion cylinder will then be processed on the PLC.
Set the HIL code generator to Bosch Rexroth ctrlX using the HIL menu. Then open the connection presets (see
Figure 1).
In the connection settings make sure the correct IP address is set. Please specify the IP address and port of the iPhysics PC, that will open a server port which will be connected to by the PLC (see Figure 2 and refer to the network layout).
Start the HIL-Assistant to interactively setup the HIL connection (see Figure 3).
The assistant will guide you through the process of creating a HIL interface. In the first window, please select Boch Rexroth ctrlX as HIL code generator and choose next (Figure 4).
In the next window, specify the node name, server address and port where the iPhysics should open the server connection (see Figure 5, also refer to the network setup) and choose next. For the soft PLC the localhost IP is selected.
In the next window you will be presented the preview of the I/Os to be used for the PLC connection. Please enable the labeler to customize the selection and tag labels and choose “Controltags only” after clicking on the tab “Presets”. In this way only the tagged I/Os will show up. These include the signal of the infrared sensor and the necessary control variables for the expansion and retraction of the cylinder. Make sure to select all displayed signals on the right side of the window (see Figure 6).
Choose next to proceed, in the following summary dialog, check the summary and choose finish to create the interface node.
After finishing the previous steps, the generated files are saved in the selected folder. These include the following:
- CodeGen.xml: xml-description of the ComTCP Connection
- IOTable.html: HTML-page with a table of input and output connections
- MNG_SimIO.export: program file to import in ctrlX PLC Engineering. This file contains the “static” parts of the connection (e.g. UDTs) and the “dynamic” part (the UDT containing IO-values to exchange with iPhysics and the FB which is responsible for handling the connection itself) and only needs to be imported once.
- MNG_SimIO_Upd.export: program file to import in ctrlX PLC Engineering. Use this file if you already imported the MNG_SimIO.export once and you adjusted the list of IOs to exchange with iPhysics.
If you are unsure which of the two export files to import, have a look at your ctrlX-project and if you see a folder named MNG_SimIO in your project (see Figure 11), you import MNG_SimIO_Upd.export. Otherwise, you import MNG_SimIO.export, which generates the folder mentioned above.
Implement the connection in ctrlX PLC Engineering
Now launch ctrlX PLC Engineering and to avoid any problems create a new project (see Figure 8).
Select the device you are using. In this case a ctrlX COREvirtual soft PLC is used. Establish a connection to the PLC (Figure 9).
ext you can import the created file from iPhysics into ctrl PLC Engineering. To do so, select the tab “Application”. This is important to maintain the right folder structure (Figure 10).
Choose the file “MNG_SimIO.export” among the other created files from iPhysics.
The folder structure should then look like specified in Figure 12.
If the previous steps were carried out correctly the data will be imported successfully and should look like on the left side of Figure 18. Some important files are:
- MNG_APPLICATION_INPUTS_32BIT (STRUCT): The input signals of the PLC are listed here.
- MNG_APPLICATION_OUTPUTS_32BIT (STRUCT): The output signals of the PLC are listed here.
- MNG_IO (PRG): The executable program that manages to send and receive the data from iPhysics.
- MNG_SIMIO_UPDATER (FB): Handles the connection to iPhysics.
Now there’s only one thing left to do: After the initial import you need to correct the task-priority of the task which was generated during the import (MNG_SIMIO) and it’s Interval time. To do that double-click on the entry which is underlined in red in the project-tree and set the Priority to 20. The Interval should be set to a value which corresponds to half of iPhysics simulation step. The default simulation step in iPhysics is 10ms so per default the value is set to 5ms. Don’t forget to save the project afterwards. The process is depicted in the picture below.
Mapping of the signals
Now the signals need to be made available globally so that they can be read and controlled by the executable program PLC_PRG. A new object of the type “Global Variable List” will be created. This works like shown in Figure 14.
For each signal one variable will be created. The type is of the same kind as the signals. The names can be chosen arbitrarily, but it makes sense to name them in a way that their function can be identified easily later. In the case of this manual they are named like shown below:
Before they can be used these variables need to be mapped accordingly. This is done by two functions which take care of the input and output variables separately. That is important because they are called at different times. To create the function, two objects of the type “POU” are being created (see Figure 15).
Choose a name for each of the functions (e.g. MapInputs and MapOutputs), specify the type and enter a return value (see Figure 16).
The contents of the two functions are the following (the names might differ if you chose different ones before, but the structure needs to be the same). The received signals are mapped to the global input variables (see Figure 17).
MapInputs:
The controlled output variable is then mapped to the output signal.
MapOutputs:
These functions are then called in the program MNG_IO. The output signal needs to be called before the simIO task is executed which transfers the information from and to the iPhysics PC. After mapping of the global output variable to the local variable, the data is then sent by the simIO function. This function also handles the receipt of the input signals sent from iPhysics. They are first stored locally at simIO.I and then mapped to the global variables by calling MapInputs().
The executable script can now be written into the PLC_PGR file. It only uses global variables. For more details about the script please see the “Howto_EN_FirstModel”. Briefly, the script checks the position of the cylinder and the presence of object by the infrared sensor. If the cylinder is retraced and an object is detected the cylinder expands until it reaches its maximal expansion. It then retracts again and waits for the next object. The I. and the Q. label input and output signals of the PLC. Please copy the code into the file.
Now generate the code, login and start the simulation in ctrlx PLC Engineering.
Afterwards rebuild the model in iPhysics and start the simulations there as well. In case the connections does not establish, restart the connection by clicking on the “Stop” and “Start” button. If everything was done correctly it should display “exchanging data” and the simulations should work as expected.
Update connection settings
If you need to update the HIL connection settings (e.g. IP address or exchanged I/Os), apply all changes in iPhysics first. It is then necessary to transfer the changes to ctrlX PLC Engineering as well. Since the HIL configuration is already established, only the export files need to be updated.
To do this open the ComTCP-View and click on “Generate HIL Config”.
The settings should be specified as in figure Figure 21.
Finish the steps and to created new export files at the chosen file directory. To apply the changes in ctrlX PLC Engineering, open the menu “Project” – “Import” and select the file MNG_SimIO_Upd.export. Make sure, all boxes are checked in the next import window. It is now advised to check if the changes were applied successfully. If that is the case, iPhysics should be able to connect to the PLC again.
Fix for common errors in the connection
No connection possible
Incorrect firewall settings
One reason why no communication between iPhysics and the PLC is not possible might be originating of incorrect firewall settings. To check if things are set up correctly, open the “Resource Monitor” and click the tab “Network”. If you search for your chosen IP and the corresponding port in the “Listening Port” section you should find inustrialPhysics.exe. Make sure the firewall settings are: Allowed, not restricted.
Wrong IP specified in iPhysics
Another reason might be that the specified IP address in iPhysics is not correct. The error code in the console would look like in Figure 22 after you did a rebuilt of the project.
To fix this issue, open the TCP-View, choose “Edit” and enter the correct IP address. Now rebuild the project.
Connection only shows "Connected", no data exchange
Cycle time too low
Try to increase the cycle time in iPhysics. It should be at least double of the time-step of the main task in ctrlX PLC Engineering.
Number of I/Os between iPhysics and ctrlx PLC Engineering differs
Check if the ComTCP-View window in iPhysics displays the same number of variables as specified in ctrlx PLC Engineering in MNG_APPLICATION_INPUTS_32BIT or MNG_APPLICATION_OUTPUTS_32BIT respectively.
Related Links
The Company
We work every day full of passion to ensure that you reach your goals faster!
machineering GmbH & Co. KG, based in Munich, develops innovative software solutions for virtual commissioning and for the digital twin. We are a team from practice: Experts from various disciplines advise companies and engineers on all topics relating to visualization and simulation in the areas of development, sales and virtual commissioning. Virtually simulating complex material flows and mechatronic production plants and thus saving valuable time is one of the greatest efficiency reserves in mechanical and plant engineering. In this way, 3D simulation and virtual prototyping of plants can be used to accelerate and secure their development and design.
In project acquisition, planned systems can be visualized in dialogue with the customer in a sales-effective manner. The greatest potential, however, lies in the virtual commissioning of plants and production lines: It has been proven that the costs for installation, testing and optimization of systems can be reduced by up to 75% via simulation.