Communication Configuration and Example Program Usage (PLC with Built-in Ethernet Port)
This topic provides instructions on setting up the Standard Interface communication based on the MC protocol between a Mitsubishi MELSEC-Q Series PLC (with Built-in Ethernet Port) and the Mech-Mind Vision System.
Hardware and Software Requirements
Hardware
-
Mitsubishi PLC: with built-in Ethernet Port
The CPU used in this example is MELSEC-Q Series Q03UDVCPU. The QPower supply is Mitsubishi Q61P. The base unit is Mitsubishi Q33B.
-
IPC (Industrial Personal Computer)
-
USB Type A male to USB Mini-B male cable
-
Network switch and Ethernet cables
The connection of the hardware system is shown as below.
Software
Software | Description | Installed Location |
---|---|---|
GX Works2 |
Mitsubishi PLC programming software |
Computer that is used for PLC programming |
Mech-Vision & Mech-Viz versions: 1.7.2 or above |
Mech-Mind Vision System software |
IPC |
In addition to the above software, please copy the example program file MC Protocol_Q_Simple_Label.GXW (used to implement the functions of various interface commands) to a PC with GX Works2 installed. The example program files are stored in the folder where Mech-Vision and Mech-Viz are installed: Communication Component/Robot_Interface/Mitsubishi MC
The firewall on the IPC must be turned off. |
Create and Configure the PLC Project
Create a PLC Project
-
Open GX Works2, and click the New icon in the toolbar. In the New Project window, select QCPU (Q mode) as the Series, Q03UDV as the Type, Simple Project as the Project Type. Select Use Label, and select Ladder as the Language. After setting, click OK to save changes.
-
Go to
, and double-click Connection1. -
A Transfer Setup Connection1 window will pop up. Please follow the steps below.
-
Select Serial USB, select QCPU (Q mode) as the PLC Mode, and then click PLC Direct Coupled Setting.
-
Select USB in the pop-up window and click Yes.
-
Go back to the Transfer Setup Connection1 window, click Connection Test. If GX Works2 is connected with the PLC successfully, a message saying Successfully connected with the Q03UDVCPU will pop up.
-
Click OK in the Transfer Setup Connection1 window and return to the main interface of GX Works2.
-
Configure Communication Parameters of MC Protocol
-
Go to
, and double-click PLC Parameter. -
In the pop-up Q Parameter Setting window, click the Built-in Ethernet Port Setting tab.
-
In the IP Address Setting area, set the IP Address of the PLC, for example, as 192.168.1.22 (which should be in the same subnet as that of the IPC). The Subnet Mask Pattern is 255.255.255.0, and the Default Router IP Address is 192.168.1.0.
-
In the Communication Data Code area, select Binary Code.
-
Select Enable online change (FTP, MC Protocol).
-
Click Open Setting, and a Built-in Ethernet Port Open Setting window will pop up.
-
-
In the following window, set the parameters of the first line as shown in the figure below and click End. Go back to the Q Parameter Setting window, click End and return to the main interface of GX Works2.
Import Example Programs
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. |
-
Go back to the main interface of GX Works2. In the menu bar, go to
. -
In the pop-up Import Library to Project window, select Select Library (Project) from the Library List, click Browse to locate the local file
MC Protocol_Q_Simple_Label.gxw
(which should be copied from the IPC in advance), and click Open. -
In the Import Library to Project window, click Refresh FB List. Then select all items in FB List, and then click OK.
-
A message saying “Are you sure to overwrite?” will pop up. Select Yes in the window and go back to the main interface of GX Works2.
-
In the menu bar of GX Works2, go to
. -
In the pop-up Device/Label Automatic-Assign Setting window, modify the Assignment Range of Word Device D, and then click OK.
-
Select Yes in the pop-up window as shown below and return to the main interface of GX Works2.
Download Communication Configuration and Example Programs to PLC
-
In GX Works2, expand the Program Setting in the Navigation, drag the MAIN under No Execution Type to Scan Program. Then double-click Program.
-
Click Rebuild All icon in the toolbar.
-
In the pop-up window asking “Are you sure you want to Rebuild All?”, click Yes.
-
Click the Write to PLC icon in the toolbar.
-
An Online Data Operation window will pop up. Select Write, click Parameter+Program, and click Execute.
-
Click Yes in the pop-up window as shown below.
-
Select Yes to all for “Are you sure you want to overwrite the existing file?”.
-
In the Write to PLC window, when “Write to PLC: Completed” appears in the panel, click Close.
-
A message will pop up as show below. If the system security can be ensured, select Yes to return to the Online Data Operation window, and click Close. Lastly, turn off the PLC CPU power and restart it.
Set up “Robot Communication Configuration”
-
Click Robot Communication Configuration on the toolbar of Mech-Vision.
-
In the Robot Communication Configuration window, complete the following configurations.
-
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.
-
In the Communication mode area, select Standard Interface for Interface service type, Mitsubishi MC Client for Protocol, and 3E for Frame. Users can set Register(D) Base Address according to actual needs. The value is set to 10000 in this example. In addition, the MM_Interface structure occupies 728 D Registers in total.
-
In the PLC IP address text box, enter the IP address and port number of the specific PLC in use.
-
(Optional) Select Auto enable interface service when opening the solution.
-
Click Apply.
-
-
On the main interface of Mech-Vision, make sure that the Robot Communication Configuration switch on the toolbar is flipped and turned to blue.
Check Communication
-
Click the Start Monitoring (All Windows) icon on the toolbar.
-
Click Yes in the pop-up window as shown below.
-
In the Watch1 window, add and expand the Device MM_Camera. If the connection is established successfully, the monitor value of HEARTBEAT will keep changing.
-
The PLC is successfully connected if the following message is displayed in the Console tab of Mech-Vision Log panel: Connect to Melsec PLC successfully. If you don’t see this log message, please check if:
-
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 use the example program function block to trigger the Mech-Vision project to obtain vision points and trigger the Mech-Viz project to obtain the planned path.
Prerequisites
-
Mech-Vision project(s): 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.
-
Mech-Viz project: Right-click the project name in Resources of Mech-Viz and select Autoload Project. The Mech-Viz project used for testing contains a “Branch by Msg” Step that has been renamed to 1 as shown below.
Run Mech-Vision Project and Obtain Vision Points
Open Monitor (Write Mode)
-
In GX Works2, under the Navigation/Project, click Monitor (Write Mode) icon in the toolbar.
-
Click OK in the pop-up window as shown below.
Add and Set the MM_Start_Vis FB
-
Expand POU/FB_Pool and drag MM_Start_Vis to line 0 of MAIN. An Input FB Instance Name window will pop up. Keep the default settings and click OK.
-
Click Horizontal Line icon in the toolbar. Click OK in the pop-up window to connect the left bus line with the EN1 input port of the FB.
-
Set Mech-Vision project ID, namely, the number before the project name in the project list in Mech-Vision. set the port value of Vision_Proj_Num to 1, and project No. 1 in Mech-Vision will run.
-
Set the number of poses to be sent by Mech-Vision project. set the port value of Req_Pose_Num to 0, and all poses in the vision result will be returned from Mech-Vision.
-
Set the type of pose to be sent by the robot. Setting the port value of Robot_Pose_Type to 0 indicates that the project is in the Eye-to-Hand mode, and the image-capturing pose is not needed.
-
Double-click the blue frame area on the left of Start_Vision port of MM_Start_Vis FB. Select Open Contact in the pop-up window, and enter the global label Camera_User.Start_Vis. Then click OK to connect the Start_Vision port with the bus line on the left.
Add and Set the MM_Get_VisData FB
-
Drag MM_Get_VisData to line 0 of MAIN. An Input FB Instance Name window will pop up. Keep the default settings and click OK. Click Horizontal Line icon in the toolbar, and click OK in the pop-up window to connect the left bus line with the EN1 input port of the FB.
-
Set Mech-Vision project ID, namely, the number before the project name in the project list in Mech-Vision. 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.
-
Double-click the blue frame area on the left of Get_VisData port of MM_Get_VisData FB. Select Open Contact in the pop-up window, and enter the global label Camera_User.Get_VisData. Then click OK to connect the Get_VisData port with the bus line.
Write/Convert/Compile Programs to PLC
-
Click the Online Program Change icon in the toolbar.
-
Click OK in the pop-up Confirm Build Method for Online Program Change window.
-
Click Yes in the pop-up window as shown below.
-
Lastly, click OK to complete downloading the program to PLC.
Trigger Mech-Vision Project to Run
-
In the interface of MAIN, right-click the input variable Camera_User.Start_Vis of MM_Start_Vis FB, and select
. -
In the pop-up Modify Value window, click ON to trigger Mech-Vision project to run. Then click OFF to reset the value.
-
Right-click the blank space, select Register to Watch, and enter the global label MM_Camera.Status_Code. If the project is started successfully, the status code 1102 will be returned.
If the status code 10XX is returned, please refer to Status Codes and Troubleshooting for troubleshooting.
Obtain Vision Points
-
Select the input variable Camera_User.Get_VisData of MM_Get_VisData FB, and click ON in the pop-up window to obtain vision points. Then click OFF to reset the value.
-
In the Watch1 window, enter the global label MM_Camera.Status_Code. If the vision points are obtained successfully, the status code 1100 will be returned. Then, enter the global label MM_Camera.Target_Pose, and the pose data of vision points will be returned.
If the status code 10XX is returned, please refer to Status Codes and Troubleshooting for troubleshooting.
Run Mech-Viz Project and Obtain Planned Path
Add and Set the MM_Start_Empty FB
-
Drag MM_Start_Empty to line 54 of MAIN. An Input FB Instance Name window will pop up. Keep the default settings and click OK. Click Horizontal Line icon in the toolbar to connect the left bus line with the EN1 input port of the FB.
-
Double-click the blue frame area on the left of Start_Empty port of MM_Start_Empty FB. Select Open Contact in the pop-up window, and enter the global label Camera_User.Start_Empty. Then click OK to connect the Start_Empty port with the bus line.
Add and Set MM_Start_Viz, MM_Set_Branch, and MM_Get_VizData FB
-
Drag MM_Start_Viz, MM_Set_Branch, and MM_Get_VizData to MAIN respectively. An Input FB Instance Name window will pop up. Keep the default settings and click OK. Click Horizontal Line icon in the toolbar to connect the left bus line with the EN1 input port of the FB.
-
Set the type of pose to be sent by the robot: Setting the port value of Robot_Pose_Type to 0 indicates that the project is in Eye-to-Hand mode, and the image-capturing pose is not needed.
Double-click the blue frame area on the left of EN1 port of MM_Start_Viz FB. Select Close Contact in the pop-up window, and enter the global label Camera_User.Get_VizData. Then, click OK to connect the EN1 port with the left bus line.
Double-click the blue frame area on the left of Start_Viz port of MM_Start_Viz FB. Select Open Contact in the pop-up window, and enter the global label Camera_User.Start_Viz. Then, click OK to connect the Start_Viz port with the left bus line.
-
Set the branch parameters in Mech-Viz project. Set the port value of Branch_Name and Branch_Exit_Port to 1 respectively, and the Mech-Viz project will take the exit port 1 for the “Branch by Msg” Step named 1. Select Open Contact in the pop-up window, and enter the global label Camera_User.Set_Branch. Then, click OK to connect the Set_Branch port with the bus line.
-
Set the pose type of the obtained waypoints: Set the port value of Request_Pose_Type to 1, and Mech-Viz will return waypoints in JPs.
The Request_Pose_Type here and Robot_Pose_Type of the MM_Start_Vis and MM_Start_Viz FB all correspond to the Pose_Type variable of the global label MM_Camera. 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. -
Double-click the blue frame area on the left of EN1 port of MM_Get_VizData FB. Select Close Contact in the pop-up window, and enter the global label Camera_User.Start_Viz. Then click OK to connect the EN1 port with the left bus line.
-
Double-click the blue frame area on the left of Get_VizData port of MM_Get_VizData FB. Select Open Contact in the pop-up window, and enter the global label Camera_User.Get_VizData. Then click OK to connect the Get_VizData port with the left bus line.
Write/Convert/Compile Programs to PLC
-
Click the Online Program Change icon in the toolbar.
-
Click OK in the pop-up Confirm Build Method for Online Program Change window.
-
Click Yes in the pop-up window as shown below.
-
Lastly, click OK to complete downloading the program to PLC.
Trigger Mech-Viz Project to Run
-
In the interface of MAIN, right-click the input variable Camera_User.Start_Empty of MM_Start_Empty FB, and select
in the context menu. In the pop-up Modify Value window, click ON to clear the previously obtained vision result. Then click OFF to reset the value.In the Watch1 window, enter the global label MM_Camera.Status_Code. The status code 3103 should be returned, and the variable values of Camera_User.Target Pose, Camera_User.Target Label, and Camera_User.Speed Percentage should be cleared.
-
In the interface of MAIN, right-click the input variable Camera_User.Start_Viz of MM_Start_Viz FB. In the pop-up Modify Value window, click ON to trigger the Mech-Viz project to run. Then click OFF to reset the value.
-
In the Watch1 window, enter the global label MM_Camera.Status_Code. If the project is started successfully, the status code 2103 will be returned.
If the status code 20XX is returned, please refer to Status Codes and Troubleshooting for troubleshooting.
Set Branch Exit Port
-
In the interface of MAIN, right-click the input variable Camera_User.Set_Branch of MM_Set_Branch FB. In the pop-up Modify Value window, click ON to choose the Mech-Viz branch. Then click OFF to reset the value.
-
In the Watch1 window, enter the global label MM_Camera.Status_Code. If the branch is set successfully, the status code 2105 will be returned.
If the status code 20XX is returned, please refer to Status Codes and Troubleshooting for troubleshooting.
Obtain Planned Path
-
In the interface of MAIN, right-click the input variable Camera_User.Get_VizData of MM_Get_VizData FB. In the pop-up Modify Value window, click ON to obtain the planned path from Mech-Viz. Then click OFF to reset the value.
-
In the Watch1 window, enter the global label MM_Camera.Status_Code. If the planned path is obtained successfully, the status code 2100 will be returned. Then enter the global label MM_Camera.Target_Pose, and the JPs of the waypoints in the path will be returned.
If the status code 20XX is returned, please refer to Status Codes and Troubleshooting for troubleshooting.