Communication Configuration and Example Program Usage

This topic provides information on setting up communication between a Siemens SIMATIC S7 PLC and Mech-Mind Software Suite via Modbus TCP.

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: Mech-Center 1.6.1 or above, Mech-Vision 1.6.0 or above, and Mech-Viz 1.6.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: XXXX/Mech-Center-xxx/Robot_Interface/Modbus TCP/Siemens TIA Portal (the installation directory of Mech-Center). 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

  1. Open the Control Panel, and go to Network and Internet ‣ Network and Sharing Center ‣ Change adapter settings.

  2. Right-click the Ethernet interface connected to the PLC, and select Properties.

  3. In the pop-up window, double-click Internet Protocol Version 4 (TCP/IPv4).

    ../../../../_images/interface_properties1.png
  4. 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.

    ../../../../_images/set_computer_ip1.png

Configure Mech-Interface in Mech-Center

  1. Open Mech-Center, and click Deployment Settings.

  2. Go to Mech-Interface, check Use Mech-Interface and then select Standard Interface for Interface Service Type.

    ../../../../_images/center_configuration_11.png
  3. In Interface Options, select MODBUS TCP SLAVE, and then change the following settings:

    • Host Address Port: according to your needs (set to 2000 here)

    • Byte order: ABCD

    • Slave ID: according to your needs (set to 255 here)

    Then, click Save to save the changes.

    ../../../../_images/center_configuration_21.png
  4. Click Start Interface in the toolbar. A MODBUS TCP SLAVE icon will appear in the Service Status panel, and the following message will be displayed in Mech-Center Log panel:

    Start MODBUS TCP Slave interface.

Create and Configure PLC Program

Create PLC Program

Hint

If needed, click Save project to save the changes to the project.

  1. Open TIA Portal and click Create new project.

  2. Put in Project name and Path, and then click Create. Click Open the project view in the pop-up page.

    ../../../../_images/create_plc_project_1.png
  3. 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.

    ../../../../_images/create_plc_project_2.png
  4. 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 ethernet_icon in PLC_1.

    ../../../../_images/create_plc_project_3.png
  5. Down in the Properties ‣ General tab, click Ethernet address to set the IP address of the PLC. Use the default value for Subnet mask.

    ../../../../_images/create_plc_project_4.png

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.

  1. In the Project tree panel, double-click External source files, and then double-click Add new external file.

    ../../../../_images/import_example_program_1.png
  2. 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.

  3. 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 speficied order, an error message will be displayed in the log.

    ../../../../_images/import_example_program_2.png
  4. If the following window pops up, select OK.

    ../../../../_images/import_example_program_3.png
  5. The program blocks generated from these external source files are shown below.

    ../../../../_images/import_example_program_4.png

    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.

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

    ../../../../_images/import_example_program_5.png

    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:

  7. In the Project tree panel, navigate to PLC_1 ‣ Program blocks ‣ System blocks ‣ Program resources, check if the MB_CLIENT FB and MB_CLIENT_DB DB are automatically generated.

    ../../../../_images/import_example_program_7.png
  8. To ease the management and maintenance later on, create a new group under Program blocks to organize the blocks:

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

      ../../../../_images/import_example_program_11.png
    2. Select all the FCs and DBs generated from the external source files and drag these blocks into the 3D_Camera group.

      ../../../../_images/import_example_program_12.png

Build Program and Download to PLC

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

    ../../../../_images/build_program_1.png
  2. Double-click the MM ModbusTCP DB to open it, and then click expand_icon. 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-Center (see Configure Mech-Interface in Mech-Center above)

    ../../../../_images/build_program_2.png
  3. In System blocks, double-click the MB_CLIENT_DB DB to open it, and then click expand_icon. Under Static ‣ TDIAG_Status, check if the hexadecimal number in MB_Unit_ID matches the Slave ID set in Mech-Center (see Configure Mech-Interface in Mech-Center above).

    ../../../../_images/build_program_3.png
  4. In the Program tree panel, right-click PLC_1, and select Download to device ‣ Software (all).

    ../../../../_images/build_program_4.png
  5. In the pop-up window, make the following selections:

    • For PG/PC Interfce: 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.

    ../../../../_images/build_program_5.png
  6. Select the corresponding device in the search result, and then click Load.

    ../../../../_images/build_program_6.png
  7. In the pop up window, click Finish once the download is completed.

    ../../../../_images/build_program_7.png

Check Communication

  • In TIA portal: In the Program tree panel, double-click the MM Modbus TCP Interface DB, and then click monitor_icon. If the monitor value of HEARTBEAT keeps changing, then the the connection to Mech-Center is successfully established.

    ../../../../_images/check_communication_1.png
  • In Mech-Center: if the Log panel displays a Mech-Center: Client connected message, the PLC is successfully connected to Mech-Center.

Note

If you don’t see this log message, please check if:

  • The hardware are properly connected;

  • If Mech-Interface has been started by clicking on Start Interface in the toolbar;

  • 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

    • The Project list in Mech-Center ‣ Deployment Settings ‣ Mech-Vision is synced by clicking on sync_icon, and the order of Mech-Vision projects have been adjusted according to actual needs.

      ../../../../_images/prerequisite_17.png
  • Mech-Viz project:

    • Executable

    • Set to autoload

    • Contains a branch_by_msg Task that has been renamed to 1.

Test with Mech-Vision Project

Configure PLC Program

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

    ../../../../_images/run_mech_vision_1.png
  2. 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 Mech-Vision project No. 1 in the Project list of Mech-Center 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 image-capturing 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)

    ../../../../_images/run_mech_vision_2.png
  3. 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.

    ../../../../_images/run_mech_vision_3.png
  4. Drag the MM_Get_VisData FC to Network 3 in the Main OB.

    ../../../../_images/run_mech_vision_4.png
  5. 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 Mech-Vision project No. 1 in the Project list of Mech-Center will be started.

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

    ../../../../_images/run_mech_vision_5.png
  7. In the Program tree panel, right-click PLC_1, and select Download to device ‣ Software (only changes).

    ../../../../_images/run_mech_vision_6.png
  8. In the pop-up window, click Load to download the changes to the PLC.

Run Mech-Vision Project and Obtain Vision Points

  1. In the Main OB window, click monitor_icon.

    ../../../../_images/run_mech_vision_7.png
  2. Start the Mech-Vision project: in Network 1, right-click the “Camera_User”.Start_Vis parameter in “MM_Start_Vis”, and select Modify ‣ Modify to 1. Then, reset the value of this parameter.

    ../../../../_images/run_mech_vision_8.png
  3. 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 Trouble Shooting for the corresponding error.

    ../../../../_images/run_mech_vision_9.png
  4. 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 Modify ‣ Modify to 1. Then, reset the value of this parameter.

    ../../../../_images/run_mech_vision_10.png
  5. 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 Trouble Shooting for the corresponding error.

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

    ../../../../_images/run_mech_vision_11.png

The logics of the above used MM_Start_Vis and MM_Get_VisData FCs for controlling a Mech-Vision project are as follows:

../../../../_images/run_mech_vision_12.png
../../../../_images/run_mech_vision_13.png

Test with Mech-Viz Project

Configure PLC Program

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

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

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

    ../../../../_images/run_mech_viz_1.png
  4. 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.

  5. Configure the parameter of the MM_Start_Viz FC in Network 5:

    Set the type of image-capturing 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)

    ../../../../_images/run_mech_viz_2.png
  6. Configure the parameters of the MM_Set_Branch FC in Network 6 (setting the branch to take in the Mech-Viz project):

    Set Task 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 Task 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 Task 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 Task 1.

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

    ../../../../_images/run_mech_viz_3.png
  8. 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.

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

    ../../../../_images/run_mech_viz_4.png
  10. In the Program tree panel, right-click PLC_1, and select Download to device ‣ Software (only changes).

    ../../../../_images/run_mech_vision_6.png
  11. In the pop-up window, click Load to download the changes to the PLC.

Run Mech-Viz Project and Obtain Planned Path

  1. In the Main OB window, click monitor_icon.

    ../../../../_images/run_mech_vision_7.png
  2. Clear stored target data: in Network 4, right-click the “Camera_User”.Start_Empty parameter in “MM_Empty_Target”, and select Modify ‣ Modify to 1. Then, reset the value of this parameter.

    ../../../../_images/run_mech_viz_5.png
  3. In the MM Modbus TCP Interface DB, the monitor values of Target Pose, Target Label and Speed Percentage are reset.

    ../../../../_images/run_mech_viz_6.png
  4. 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 Modify ‣ Modify to 1. Then, reset the value of this parameter.

    ../../../../_images/run_mech_viz_7.png
  5. 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 Trouble Shooting for the corresponding error.

    ../../../../_images/run_mech_viz_8.png
  6. 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 Modify ‣ Modify to 1. Then, reset the value of this parameter. This asks the Mech-Viz project to proceed along the branch set previously.

    ../../../../_images/run_mech_viz_9.png
  7. 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 Trouble Shooting for the corresponding error.

    ../../../../_images/run_mech_viz_10.png
  8. 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 Modify ‣ Modify to 1. Then, reset the value of this parameter.

    ../../../../_images/run_mech_viz_11.png
  9. 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 Trouble Shooting for the corresponding error.

  10. Check the received path:

    • The monitor value of Number of Pose Sent shows how many targets 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 Task, in the path. In the following example, the value is 3, which means the vision point is the third target in the entire planned robot path.

    ../../../../_images/run_mech_viz_12.png

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:

../../../../_images/run_mech_viz_13.png
../../../../_images/run_mech_viz_14.png
../../../../_images/run_mech_viz_15.png