Communication Configuration and Example Program Usage

This topic provides instructions on setting up the Standard Interface communication based on the Siemens PLC Snap7 protocol between a Siemens SIMATIC S7 PLC using the TIA Portal software and Mech-Vision and Mech-Viz.

Hardware and Software Requirements

Hardware

  • The following S7 series PLCs from Siemens are supported:

    • S7-300: Integrated PN network port or CP343-1

    • S7-400: Integrated PN network port or CP443-1

    • S7-1200: No special requirement for modules

    • S7-1500: No special requirement for modules

  • Power adapter: 220V AC to 24V DC

  • IPC or host of Mech-Mind Vision System

  • Ethernet cable

Software

  • Siemens PLC programming software TIA Portal V15.1

  • Mech-Vision & Mech-Viz versions: 2.0.0 or above

  • Interface file for S7 communication between Siemens Tia Portal and Mech-Vision and Mech-Viz:

    • Data block file MM Interface.db for data communication

    • File MM Interface Program.scl for implementing the features of various interface functions

  • The files are stored on the Mech-Mind IPC or host. They are located in Communication Component/Robot_Interface/Siemens Snap7/TIA Portal in the installation directory where Mech-Vision and Mech-Viz are installed. Please copy the files to the computer where the TIA Portal software is installed.

  • Do not use the MM Interface DB as the IN/OUT interface parameters. The reason is that the PLC reads and writes the IN/OUT interface parameters in each scan cycle. If the DB remains in the enabled status, data already sent by the vision system can be overwritten. To avoid such a problem, data structures ToCamera and FromCamera should be respectively used as the OUT and IN interface parameters.

Create and Configure the PLC Project

Create a PLC Project

  1. Open TIA Portal, click Create new project, enter Project name, select a Path, and click Create. A new window will pop up. Click Open project view.

    build plc 1
  2. In the Project tree section, double-click Add new device to open the window. Under Controllers, select the module that is consistent with the physical PLC. The default device name can be used. Click OK.

    build plc 2
  3. On the device configuration page, click Device view, then double-click the network port label of PLC_1. On the Properties/General page, click Ethernet address and set the IP address to 192.168.1.22. The default subnet mask can be used (should be in the same network segment as the vision system’s IPC).

    build plc 3
  4. Select the device PLC_1 in the project tree, right-click and select Properties, and enter the interface General  Protection & Security in turn in the pop-up window. Under Access level, check Full access (no protection). Under Connection mechanisms, check Permit access with PUT/GET communication from remote partner. Click OK to save the project.

    build plc 4
    build plc 5

Import the S7 Communication Interface File

  1. Under the project tree, click External source files and Add new external file. In the pop-up window, select files MM Interface.db, MM Interface Program.scl, and click Open to import the files to the new project.

    import s7 files 1
  2. Select the newly imported external source files (select MM Interface.db first, then select MM Interface Program.scl), right-click, and select Generate blocks from source. Click OK in the pop-up window (this operation will overwrite the functions and data blocks with the same names in the project, and automatically select an unoccupied number).

    import s7 files 2
    import s7 files 2 1
    If the operations are not performed in the order of the selected files above, an error message will appear in the log window.
  3. The functions and data blocks generated by the external source file are as follows, where the DB number of MM Interface must be consistent with the DB number set in Robot Communication Configuration in Mech-Vision. The DB Camera_User stores user data.

    import s7 files 3
  4. In the project, to facilitate the maintenance of functions and data blocks, you can right-click the Program blocks, select Add new group, name it “Mech-Mind”. Then, select all the newly generated functions and data blocks and move them to the group folder.

    import s7 files 4
    import s7 files 5

Download the S7 Communication Interface File

  1. Click Save project, then in the project tree, right-click the new project PLC_1. Select Download to device  Hardware and software (only changes) in turn, and the download window will pop up.

    download s7 files 1
  2. In the pop-up download window, select the network card driver connected to PLC for PG/PC interface, select Direct at slot ‘1 X1’ for Connection to interface/subnet, select Show all compatible devices for Select target device, and then click Start search. Select the detected CPU device, click Download, click Finish after the download is complete.

    download s7 files 2

Configure IPC and Initiate Communication

Set up “Robot Communication Configuration”

  1. Ensure that the IP address of the IPC is on the same subnet as the PLC, for instance, 192.168.1.10. Open Command Prompt on the IPC and ping the PLC IP address to check if they are connected successfully.

  2. Click Robot Communication Configuration on the toolbar of Mech-Vision.

  3. In the Robot Communication Configuration window, complete the following configurations.

    1. Click the Select robot drop-down menu, and select Listed robot. Click Select robot model, and select the robot model that you use. Then, click Next.

    2. In the Communication mode area, select Standard Interface for Interface service type, and select Siemens PLC Client for Protocol. Set Slot number to 1, and set DB number (i.e. the ID of “MM Interface” in the PLC project) to 2.

    3. Set the PLC IP address to 192.168.1.22 (i.e. the PLC IP address set previously in SIMATIC Manager)

    4. (Optional) Select Auto enable interface service when opening the solution.

    5. Click Apply.

      siemens plc tia

Check Communication

  1. 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. The PLC is successfully connected if the Console tab of Mech-Vision Log panel displays Connect to PLC server successfully. If not, please check the configuration and check whether the physical connection is normal.

    center settings 3
  2. Return to the main interface of TIA Portal, select the device PLC_1, and click Go online.

    center settings 4
  3. Under PCL_1  Program blocks of the project tree, double-click the data block MM Interface, then click Monitor all icon_2 . If the connection is established successfully, the monitor value of Heartbeat will keep changing.

    center settings 5

Test with Vision Projects

This section describes how to use the Siemens PLC Client interface program for the startup and data acquisition of Mech-Vision and Mech-Viz projects. For the specific functions and introduction of Siemens PLC Snap 7 communication parameters, please see Siemens PLC.

Prerequisites

  1. Create Mech-Vision solution: Right-click the solution and select Autoload Solution. Projects in the solution are also autoloaded. Meanwhile, the project number will show up before each project name.

  2. Create Mech-Viz project: Right-click the project name in Resources in Mech-Viz and select Autoload Project.

    The Mech-Viz project used for testing should contain a “Branch by Msg” Step that has been renamed to 1 as shown below.

    prepared 4

Run Mech-Vision Project and Obtain Vision Points

Configure Programs

  1. In the main interface of TIA Portal, under the project tree  Program blocks , double click Main [OB1] under Program blocks, and drag the function MM_Start_Vis to Network 1 of the main program.

    get visual point from vision 1
  2. The EN port of “MM_Start_Vis” connects the function that compares the Step ID, and a rising-edge trigged function is defined for the input port Start_Vision. When the value of the port Vision_Proj_Num is set to 1, Mech-Vision project No.1 will be started.

  3. Set the value of Req_Pose_Num to 0, indicating that the Mech-Vision project will send all the vision points.

  4. Set the port value of Robot_Pose_Type to 0, indicating no image-capturing pose needs to be obtained from the robot (such as in the Eye-to-Hand mode).

    get visual point from vision 4
  5. Under the project tree, click the data block Camera_User, and drag the parameters under the Details view to the corresponding ports of “MM_Start_Vis”. Click data block MM Interface, and drag the parameters under the Details view to the corresponding ports of “MM_Start_Vis”.

    get visual point from vision 5
  6. Drag MM_Get_VisData to Network 2 of the main program. The EN port connects the function that compares the Step ID, and a rising-edge trigged function is defined for the input port Get_VisData.

    get visual point from vision 6
  7. Set the port value of Vision_Proj_Num to 1, and the vision recognition result of project No.1 in Mech-Vision will be obtained.

  8. Under the project tree, click data block Camera_User, and drag the parameters under the Details view to the corresponding ports of “MM_Get_VisData”. Click data block MM Interface, and drag the parameters under the Details view to the corresponding ports of “MM_Get_VisData”.

    get visual point from vision 9
  9. Under the project tree, click to select PLC_1, select Download to device  Software (only changes). Click Load in the pop-up download window to download the latest program to the PLC.

    get visual point from vision 10
    get visual point from vision 11

Trigger Mech-Vision Project to Run

  1. In the main program window of Main [OB1], click Enable/Disable Monitoring icon_2 to enable monitoring.

    get visual point from vision 12
  2. Right-click “Camera_User”.Step_Num, which is connected to the EN port of “MM_Start_Vis”, and change the value to 6. Right-click the input variable “Camera_User”.Start_Vis and change it to 1 to trigger the Mech-Vision project; then, reset the variable. At this time, the variable StatusCode of the MM Interface DB should have a returned value of 1102, indicating that the project is started successfully. Otherwise, the corresponding error code will be returned. Please refer to Status Codes and Troubleshooting for troubleshooting.

    get visual point from vision 13
    get visual point from vision 14

Get Vision Target(s) Calculated by Mech-Vision

Right-click “Camera_User”.Step_Num, which is connected to the EN port of “MM_Start_Vis”, and change the value to 8. Right-click the input variable “Camera_User”.Get_VisData and change it to 1 to obtain vision points; then, reset the variable. At this time, the variable StatusCode of the MM Interface DB should have a returned value of 1100, indicating that the project is started successfully. Otherwise, the corresponding error code will be returned. Please refer to Status Codes and Troubleshooting for troubleshooting.

get visual point from vision 15

The returned data from the MM Interface is as follows. The value of “Number of Pose Sent” is 1, meaning that one pose has been obtained. The pose data is stored in TargetPose.

get visual point from vision 16

Mech-Vision Automatic Control Logic Example

The automatic control logic example of Mech-Vision. For more information, see MM_S1_Vis_Basic.

Run Mech-Viz Project and Obtain Planned Path

Configure Programs

  1. Drag MM_Empty_Target to Network 3 of the main program. The EN port connects the function that compares the Step ID, and a normally open function is defined for the input port Start_Empty.

    get planning path from viz 1
  2. Click the data blocks Camera_User and MM Interface respectively, and drag the parameters in the detailed view to the corresponding input-side ports of "MM_Empty_Target".

    get planning path from viz 2
  3. Drag the functions MM_Start_Viz, MM_Set_Branch, MM_Get_VizData to Network 4, 5, and 6 respectively.

    get planning path from viz 4
    get planning path from viz 5
    get planning path from viz 6
  4. Set the port value of Robot_Pose_Type to 0, indicating no image-capturing pose needs to be read from the robot (such as in the Eye to Hand mode). Click the data block Camera_User, and drag the parameters in the detailed view to the corresponding input-side ports of “MM_Start_Viz”.

    get planning path from viz 7
  5. Set the values of Branch_Name and Branch_Exit_Port to 1, meaning that Mech-Viz will take exit port 1 for the “Branch by Msg” Step whose Step ID is 1. Click the data block Camera_User, and drag the parameters in the detailed view to the corresponding input-side ports of “MM_Set_Branch”.

    get planning path from viz 9
  6. Change the value of “Request_Pose_Type” to 1, and Mech-Viz will return data in the form of joint positions. Click the data block Camera_User, and drag the parameters in the detailed view to the corresponding input-side ports of “MM_Get_VizData”.

    Request_Pose_Type here and Robot_Pose_Type in the MM_Start_Vis and MM_Start_Viz functions correspond to the same Pose Type parameter in the MM Interface data block. If the set values are different, they cannot take effect at the same time.
    get planning path from viz 11
  7. Under the project tree, right-click PLC_1, select Download to device  Software (only changes). Click Load in the pop-up download window to download the latest program to the PLC.

    get planning path from viz 13
    get planning path from viz 14

Trigger Mech-Viz Project to Run

  1. In the main program window of Main [OB1], click Enable/Disable Monitoring icon_2 to enable monitoring.

    get planning path from viz 15
  2. Right-click “Camera_User”.Step_Num, which is connected to the EN port of "MM_Empty_Target", and change the value to 14. Right-click the input variable “Camera_User”.Start_Empty and change it to 1 to clear the vision result obtained previously; then, reset the variable.

    get planning path from viz 16

    At this time, the value of the data block Target Pose of the MM Interface DB has been cleared.

    get planning path from viz 17
  3. Right-click “Camera_User”.Step_Num, which is connected to the EN port of “MM_Start_Viz”, and change the value to 18. Right-click the input variable “Camera_User”.Start_Vis and change it to 1 to trigger the Mech-Viz project; then, reset the variable. At this time, the variable StatusCode should have a returned value of 2103, indicating that the project is started successfully. Otherwise, the corresponding error code will be returned. Please refer to Status Codes and Troubleshooting for troubleshooting.

    get planning path from viz 18
    get planning path from viz 19

Set Mech-Viz Branch Exit Port

Right-click “Camera_User”.Step_Num, which is connected to the EN port of “MM_Set_Branch”, and change the value to 24. Right-click the input variable “Camera_User”.Set_Branch and change it to 1 to instruct the Mech-Viz project to take exit 1 at the Branch by Msg Step with an ID of 1; then, reset the variable. At this time, the parameter StatusCode should have a returned value of 2105, indicating that the exit port is successfully set for the Branch by Msg Step. Otherwise, the corresponding error code will be returned. Please refer to Status Codes and Troubleshooting for troubleshooting.

get planning path from viz 20
get planning path from viz 21

Get Mech-Viz Planned Path

Right-click “Camera_User”.Step_Num, which is connected to the EN port of “MM_Get_VizData”, and change the value to 26. Right-click the input variable “Camera_User”.Get_VizData and change it to 1 to obtain planned path from Mech-Viz; then, reset the variable. At this time, the parameter StatusCode should have a returned value of 2100, indicating that the planned path is successfully obtained from Mech-Viz. Otherwise, the corresponding error code will be returned. Please refer to Status Codes and Troubleshooting for troubleshooting.

get planning path from viz 22

The returned data from the MM Interface is as follows. The value of Number of Pose Sent is 6, meaning that 6 sets of joint positions have been obtained; and the data is stored in TargetPose. The value of Index of Vision Picking Point is 3, meaning that the position of the Vision Move waypoint in the entire path is 3.

get planning path from viz 23

Mech-Viz Automatic Control Logic Example

The automatic control logic example of Mech-Viz. For more information, see MM_S5_Viz_SetBranch.

We Value Your Privacy

We use cookies to provide you with the best possible experience on our website. By continuing to use the site, you acknowledge that you agree to the use of cookies. If you decline, a single cookie will be used to ensure you're not tracked or remembered when you visit this website.