Communication Configuration and Example Program Usage¶
This topic provides instructions on setting up the Standard Interface communication based on the Modbus/TCP protocol between a Siemens SIMATIC S7 PLC and Mech-Mind Software Suite.
Hardware and Software Requirements¶
Hardware¶
PLC: Siemens SIMATIC S7-1200
AC 220 V to DC 24 V power adapter
Mech-Mind Vision System IPC
Ethernet cables
Software¶
Siemens TIA Portal V15.1
Mech-Mind Software Suite: 1.7.0 or above.
PLC Example Programs:
MM Modbus TCP.scl (for setting up Modbus TCP communication)
MM Modbus TCP Interface Program.scl (for realizing the functions of interface commands)
Note
File location: xxx\Mech-Mind Software Suite-x.x.x\Mech-Center\Robot_Interface\Modbus TCP\Siemens TIA Portal in the installation directory of Mech-Mind Software Suite. Copy these files to the computer with Siemens TIA Portal installed.
Attention
The firewall on the IPC must be turned off.
Configure IPC and Initiate Communication¶
Set IP Address of the IPC¶
Open the Control Panel, and go to
.Right-click the Ethernet interface connected to the PLC, and select Properties.
In the pop-up window, double-click Internet Protocol Version 4 (TCP/IPv4).
Select Use the following IP address, and then set the IP address, subnet mask and default gateway (must be in the same subnet as the PLC). Then, click OK to save the changes.
Set up “Robot and Interface Configuration” in Mech-Vision¶
Click Robot and Interface Configuration on the toolbar of Mech-Vision.
Select Listed robot from the Select robot drop-down menu, and then click Select robot model.
Select the robot model that you use, and then click Next.
Select the following options and click Apply.
Interface Type: Standard Interface
Protocol: Modbus TCP SLAVE
Port number of Host IP address: according to your needs (set to 2000 here)
Byte order: ABCD
Slave ID: according to your needs (set to 255 here)
Make sure the Interface Service is started: on the toolbar of Mech-Vision, the Interface Service switch on the far right is flipped and turned to blue.
Create and Configure PLC Program¶
Create PLC Program¶
Hint
If needed, click Save project to save the changes to the project.
Open TIA Portal and click Create new project.
Put in Project name and Path, and then click Create. Click Open the project view in the pop-up page.
In the Project tree panel, double-click Add new device. In the new window, click Controller, and find the CPU module you are using, and name it in Device name. Click OK to confirm adding the device. Here, the device is named PLC_1.
Select Device configuration under PLC_1 in the Project tree panel, and then click Device view tab on the right. In this tab, double-click in PLC_1.
Down in the
tab, click Ethernet address to set the IP address of the PLC. Use the default value for Subnet mask.
Import Example Program¶
Note
Before you add the example program to a project already in use, it is recommended to import it to a new project and test it first. In the following steps, the project created earlier is used to import and test the example program.
In the Project tree panel, double-click External source files, and then double-click Add new external file.
In the pop-up window, locate and select the MM Modbus TCP.scl and MM Modbus TCP Interface Program.scl files. Click Open to import these files.
Select MM Modbus TCP.scl first, and then select MM Modbus TCP Interface Program.scl. Next, right-click these files. In the right-click menu, select Generate blocks from source.
Note
If the files are not selected in the specified order, an error message will be displayed in the log.
If the following window pops up, select OK.
The program blocks generated from these external source files are shown below.
The function of the three data blocks are:
Camera_User: store user data
MM Modbus TCP Interface: store communication data
MM Modbus TCP: store communication configuration parameters.
Double-click the MM Modbus TCP FC, open the ToCamera and all FromCamera No.x networks sequentially to check the DB number in the MB_DATA_PTR variable.
This number should match the number of the MM Modbus TCP Interface DB. For example, in the figure below, the DB number in the MB_DATA_PTR variable should be DB4 instead of DB2.
If the DB number in the MB_DATA_PTR variable does not match the number of the MM Modbus TCP Interface DB, and it is not feasible to change the number of the MM Modbus TCP Interface DB, you can utilize the find and replace function to change the DB in the MB_DATA_PTR variable:
Instructions
In the Project tree panel, navigate to
, check if the MB_CLIENT FB and MB_CLIENT_DB DB are automatically generated.If not, follow these steps to generate the above-mentioned blocks:
In the Project tree panel, double-click the Main OB under Program blocks. Select the diagram under any of the networks, and then select the Instructions tab to the right.
Navigate to
, and double-click the MB_CLIENT block.In the pop-up Call option window, click OK.
In the Project tree panel, navigate to
. The MB_CLIENT FB and MB_CLIENT_DB DB should be generated now.When the following messages are displayed in the Compile tab under the Info tab at the bottom, you can delete the MB_CLIENT block under Network 1 in the Main OB.
To ease the management and maintenance later on, create a new group under Program blocks to organize the blocks:
In the Project tree panel, under PLC_1, right-click Program blocks and select Add new group. Here, the new group is named 3D_Camera.
Select all the FCs and DBs generated from the external source files and drag these blocks into the 3D_Camera group.
Build Program and Download to PLC¶
In the Project tree panel, navigate to Program blocks, double-click the Main OB to open it. Then, Drag the MM Modbus TCP FC to Network 1 in the Main OB.
Double-click the MM ModbusTCP DB to open it, and then click . Under RemoteAddress, check if:
The 4 hexadecimal numbers in ADDR match the segments of the IP address of the IPC.
The number in RemotePort matches the port number set in Mech-Vision.
In System blocks, double-click the MB_CLIENT_DB DB to open it, and then click . Under , check if the hexadecimal number in MB_Unit_ID matches the Slave ID set in Mech-Vision.
In the Program tree panel, right-click PLC_1, and select
.In the pop-up window, make the following selections:
For PG/PC interface: the interface connected to the PLC
For Connection to interface/subnet: Direct at slot ‘1 X1’
For Select target device: Show all compatible devices
Then, click Start search.
Select the corresponding device in the search result, and then click Load.
In the pop-up window, click Finish once the download is completed.
Check Communication¶
In TIA portal: In the Program tree panel, double-click the MM Modbus TCP Interface DB, and then click . If the monitor value of HEARTBEAT keeps changing, then the connection is successfully established.
The PLC is successfully connected if the following message is displayed in the Console tab of Mech-Vision Log panel: client connected.
Note
If you don’t see this log message, please check if:
The hardware is properly connected;
If the Interface Service has been started successfully in Mech-Vision;
If the PLC program has been successfully downloaded to the PLC.
Test with Mech-Vision/Mech-Viz Project¶
This section introduces how to run the Mech-Vision/Mech-Viz project and obtain data from the project using the example program.
Prerequisites¶
Mech-Vision project(s):
Executable
Set to autoload: right-click the solution and select Autoload Solution. Projects in the solution are also autoloaded.
Mech-Viz project:
Executable
Set to autoload: right-click the project name in Resources and select Autoload Project
Contains a “Branch by Msg” Step that has been renamed to 1.
Test with Mech-Vision Project¶
Configure PLC Program¶
In the Project tree panel, navigate to Program blocks, double-click the Main OB to open it. Then, Drag the MM_Start_Vis FC to Network 2 in the Main OB.
Configure the parameters of the MM_Start_Vis FC in Network 2:
Set Mech-Vision project ID: change the value of the Vision_Proj_Num port to the ID of the Mech-Vision project you wish to run. For example, if the value is changed to 1, then project No. 1 in Mech-Vision will be started.
Set the number of vision points to be sent by Mech-Vision: change the value of the Req_Pose_Num port. If the value is set to 0, the Mech-Vision project will send all the vision points.
Set the type of pose to be sent by the robot: change the value of the Robot_Pose_Type port. If the value is set to 0, no image-capturing pose will be sent (for Eye-To-Hand installation)
In the Project tree panel, navigate to Program blocks and click the Camera_User DB. From the Details view panel, drag the Robot_Pose, Start_Vision and Set_Edge parameters to the corresponding input ports of the MM_Start_Vis FC.
Drag the MM_Get_VisData FC to Network 3 in the Main OB.
Configure the parameter of the MM_Get_VisData FC in Network 3:
Set Mech-Vision project ID: change the value of the Vision_Proj_Num port to the ID of the Mech-Vision project you wish to run. For example, if the value is changed to 1, then project No. 1 in Mech-Vision will be started.
In the Project tree panel, navigate to Program blocks and click the Camera_User DB. From the Details view panel, drag the Get_VisData and Set_Edge parameters to the corresponding input ports of the MM_Get_VisData FC.
In the Program tree panel, right-click PLC_1, and select
.In the pop-up window, click Load to download the changes to the PLC.
Run Mech-Vision Project and Obtain Vision Points¶
Start the Mech-Vision project: in Network 1, right-click the “Camera_User”.Start_Vis parameter in “MM_Start_Vis”, and select
. Then, reset the value of this parameter.Check returned status code: double-click MM Modbus TCP Interface DB to open it, and check the monitor value of Status Code. 1102 represents that the Mech-Vision project was started successfully. For other values, please refer to Status Codes and Troubleshooting for the corresponding error.
Obtain vision points from the Mech-Vision project: in Network 2 of the Main OB, right-click the “Camera_User”.Get_VisData parameter in “MM_Get_VisData”, and select
. Then, reset the value of this parameter.Check returned status code: double-click MM Modbus TCP Interface DB to open it, and check the monitor value of Status Code. 1100 represents that the vision points are obtained successfully. For other values, please refer to Status Codes and Troubleshooting for the corresponding error.
Check the received vision points: the monitor value of Number of Pose Sent shows how many vision points were received, and the poses are stored in Target Pose. Divide the monitor values by 10000 to obtain the actual pose data.
The logic of the above-used MM_Start_Vis and MM_Get_VisData FCs for controlling a Mech-Vision project are as follows:
Test with Mech-Viz Project¶
Configure PLC Program¶
In the Project tree panel, navigate to Program blocks, double-click the Main OB to open it. Then, Drag the MM_Empty_Target FC to Network 4 in the Main OB.
In the Project tree panel, navigate to Program blocks and click the Camera_User DB. From the Details view panel, drag the Start_Empty parameter to the corresponding input port of the MM_Empty_Target FC.
Click the MM Modbus TCP Interface DB. From the Details view panel, drag the Target Pose, Target label and Speed Percentage parameters to the corresponding input ports of the MM_Empty_Target FC.
Drag the MM_Start_Viz, MM_Set_Branch, and MM_Get_VizData FCs to Network 5, Network 6, and Network 7, respectively, in the Main OB.
Configure the parameter of the MM_Start_Viz FC in Network 5:
Set the type of pose to be sent by the robot: change the value of the Robot_Pose_Type port. If the value is set to 0, no image-capturing pose will be sent (for Eye-To-Hand installation)
Configure the parameters of the MM_Set_Branch FC in Network 6 (setting the branch to take in the Mech-Viz project):
Set Step name: change the value of the Branch_Name port to 1. This tells Mech-Viz that you are trying to select the exit port for the Step named 1. Select exit port: change the value of the Branch_Exit_Port to the exit port you would like the Mech-Viz project to take in Step 1. For example, if you set the value of Branch_Exit_Port to 1, the Mech-Viz project will proceed along exit port 1 of Step 1.
In the Project tree panel, navigate to Program blocks and click the Camera_User DB. From the Details view panel, drag the Set_Branch and Set_Edge parameters to the corresponding input ports of the MM_Set_Branch FC.
Configure the parameters of the MM_Get_VizData FC in Network 7:
Set data type: change the value of Request_Pose_Type to 1. This asks Mech-Viz to send joint positions (instead of TCP data).
Attention
The Request_Pose_Type parameter here and the Robot_Pose_Type parameters in the MM_Start_Vis and MM_Start_Viz FCs all correspond to the same Pose Type parameter in the MM Modbus TCP Interface DB. Therefore, if these parameters are set to different values, the programming should ensure that the two values do not take effect at the same time.
In the Project tree panel, navigate to Program blocks and click the Camera_User DB. From the Details view panel, drag the Get_VizData and Set_Edge parameters to the corresponding input ports of the MM_Get_VizData FC.
In the Program tree panel, right-click PLC_1, and select
.In the pop-up window, click Load to download the changes to the PLC.
Run Mech-Viz Project and Obtain Planned Path¶
Clear stored target data: in Network 4, right-click the “Camera_User”.Start_Empty parameter in “MM_Empty_Target”, and select
. Then, reset the value of this parameter.In the MM Modbus TCP Interface DB, the monitor values of Target Pose, Target Label and Speed Percentage are reset.
Start the Mech-Viz project: in Network 5 of the Main OB, right-click the “Camera_User”.Start_Viz parameter in “MM_Start_Viz”, and select
. Then, reset the value of this parameter.Check returned status code: double-click MM Modbus TCP Interface DB to open it, and check the monitor value of Status Code. 3103 represents that the Mech-Viz project was started successfully. For other values, please refer to Status Codes and Troubleshooting for the corresponding error.
Select branch in the Mech-Viz project: in Network 6 of the Main OB, right-click the “Camera_User”.Set_Branch parameter in “MM_Set_Branch”, and select
. Then, reset the value of this parameter. This asks the Mech-Viz project to proceed along the branch set previously.Check returned status code: double-click MM Modbus TCP Interface DB to open it, and check the monitor value of Status Code. 2105 represents that the branch was selected successfully. For other values, please refer to Status Codes and Troubleshooting for the corresponding error.
Obtain the planned path from the Mech-Viz project: in Network 7 of the Main OB, right-click the “Camera_User”.Get_VizData parameter in “MM_Get_VizData”, and select
. Then, reset the value of this parameter.Check returned status code: double-click MM Modbus TCP Interface DB to open it, and check the monitor value of Status Code. 2100 represents that the planned path is obtained successfully. For other values, please refer to Status Codes and Troubleshooting for the corresponding error.
Check the received path:
The monitor value of Number of Pose Sent shows how many waypoints were received.
The poses are stored in Target Pose. Divide the monitor values by 10000 to obtain the actual pose data.
The monitor value of Index of Vision Move represents the position of the vision point, i.e., the visual_move Step, in the path. In the following example, the value is 3, which means the vision point is the third waypoint in the entire planned robot path.
The logics of the above used MM_Start_Viz, MM_Set_Branch, and MM_Get_VizData FCs for controlling a Mech-Viz project are as follows: