Machineering.png

Connect ctrlX AUTOMATION to machineering iPhysics simulation

maxvogeley
Established Member

 

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).

Figure 1: Set the HIL code generator to Bosch Rexroth ctrlX and check the connection settingsFigure 1: Set the HIL code generator to Bosch Rexroth ctrlX and check the connection settings

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).

Figure 2: Local connnection settings for the iPhysics serverFigure 2: Local connnection settings for the iPhysics server

Start the HIL-Assistant to interactively setup the HIL connection (see Figure 3).

Figure 3:  Start the HIL Assistant to interactively setup the HIL interfaceFigure 3: Start the HIL Assistant to interactively setup the HIL interface

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).

Figure 4: Accept the preset Bosch Rexroth ctrlX HIL code generatorFigure 4: Accept the preset Bosch Rexroth ctrlX HIL code generator

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.

Figure 5: Setup the HIL connection using the presetsFigure 5: Setup the HIL connection using the presets

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).

Figure 6: Preview of the control tags to be used for the PLC connectionFigure 6: Preview of the control tags to be used for the PLC connection

Choose next to proceed, in the following summary dialog, check the summary and choose finish to create the interface node.

Figure 7: Code generator log with successFigure 7: Code generator log with success

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).

Figure 8: Create a new projectFigure 8: Create a new project

Select the device you are using. In this case a ctrlX COREvirtual soft PLC is used. Establish a connection to the PLC (Figure 9).

Figure 9: Connection to the PLCFigure 9: Connection to the PLC

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).

 Figure 10: Import the exported file from iPhysicsFigure 10: Import the exported file from iPhysics

Choose the file “MNG_SimIO.export” among the other created files from iPhysics.

Figure 11: Export file from iPhysicsFigure 11: Export file from iPhysics

The folder structure should then look like specified in Figure 12.

Figure 12: Folder structure of the exported fileFigure 12: Folder structure of the exported file

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.

Figure 13 Fix the priority of the MNG_SIMIO-taskFigure 13 Fix the priority of the MNG_SIMIO-task

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.

Figure 14: Adding global variablesFigure 14: Adding global variables

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:

maxvogeley_14-1632479540065.png

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).

Figure 15: Create a POUFigure 15: Create a POU

Choose a name for each of the functions (e.g. MapInputs and MapOutputs), specify the type and enter a return value (see Figure 16).

Figure 16: Creation of the functions to map the input signalsFigure 16: Creation of the functions to map the input signals

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:

maxvogeley_1-1632479841648.png

Figure 17: Mapping of the inputsFigure 17: Mapping of the inputs

The controlled output variable is then mapped to the output signal.

MapOutputs:

maxvogeley_3-1632479934559.png

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().

maxvogeley_4-1632479965001.png

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.

maxvogeley_5-1632480033659.png

Figure 18: Script to control the cylinderFigure 18: Script to control the cylinder

Now generate the code, login and start the simulation in ctrlx PLC Engineering.

Figure 19: Generate code and loginFigure 19: Generate code and login

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”. 

Figure 20: ComTCP-ViewFigure 20: ComTCP-View

The settings should be specified as in figure Figure 21.

Figure 21: Export settings for HIL configurationFigure 21: Export settings for HIL configuration

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.

Figure 22: Listening failed on TCP serverFigure 22: Listening failed on TCP server

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.

 

machineering_logo_ctrlx-world.jpg

 

 

 

Must Read

Trending

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist