Example Program 17: MM_S17_Vis_ParseLabel

You are currently viewing the documentation for the latest version (2.1.0). To access a different version, click the "Switch version" button located in the upper-right corner of the page.

■ If you are not sure which version of the product you are currently using, please feel free to contact Mech-Mind Technical Support.

Program Introduction

Description

The robot triggers the Mech-Vision project to run to obtain the vision result, parses the labels, and then adopts a handling method based on the label to perform picking and placing.

File path

You can navigate to the installation directory of Mech-Vision and Mech-Viz and find the file by using the Communication Component/Robot_Interface/KUKA/sample/MM_S17_Vis_ParseLabel path.

Project

Mech-Vision project (data needs to exist in the labels port of the Output Step)

Prerequisites

This example program is provided for reference only. Before using the program, please modify the program according to the actual scenario.

Program Description

This part describes the MM_S17_Vis_ParseLabel example program.

The only difference between the MM_S17_Vis_ParseLabel example program and the MM_S1_Vis_Basic example program is that MM_S17_Vis_ParseLabel can parse labels (the code of this feature is bolded). As such, only the modification is described in the following part. For information about the parts of MM_S17_Vis_ParseLabel that are consistent with those of MM_S1_Vis_Basic, see Example Program 1: MM_S1_Vis_Basic.
DEF  MM_S17_Vis_ParseLabel ( )
;---------------------------------------------------
; FUNCTION: trigger Mech-Vision project and get
; vision result, then parse the label info
; Mech-Mind, 2023-12-25
;---------------------------------------------------
   ;set current tool no. to 1
   BAS(#TOOL,1)
   ;set current base no. to 0
   BAS(#BASE,0)
   ;move to robot home position
PTP HOME Vel=100 % DEFAULT
   ;initialize communication parameters (initialization is required only once)
   MM_Init_Socket("XML_Kuka_MMIND",873,871,60)
   ;move to image-capturing position
LIN camera_capture Vel=1 m/s CPDAT1 Tool[1] Base[0]
   ;trigger NO.1 Mech-Vision project
   MM_Start_Vis(1,0,2,init_jps)
   ;get vision result from NO.1 Mech-Vision project
   MM_Get_VisData(1,pos_num,status)
   ;check whether vision result has been got from Mech-Vision successfully
   IF status<> 1100 THEN
      ;add error handling logic here according to different error codes
      ;e.g.: status=1003 means no point cloud in ROI
      ;e.g.: status=1002 means no vision result
      halt
   ENDIF
   ;save first vision point data to local variables
   MM_Get_Pose(1,Xpick_point,label,toolid)
   ;parse label info received from Mech-Vision, eg. "label=56" will decompose into 5 and 6
   label_1=label / 10;           !label_1=5
   label_2=label - label_1*10;   !label_2=6
   ;add handling logic according to decomposed label value
   IF label_1==5 THEN
      ;add handling logic a
      halt
   ELSE
      ;add handling logic b
      halt
   ENDIF
   ;calculate pick approach point based on pick point
   tool_offset={X 0,Y 0,Z -100,A 0,B 0,C 0}
   Xpick_app=Xpick_point:tool_offset
   ;move to intermediate waypoint of picking
PTP pick_waypoint CONT Vel=50 % PDAT1 Tool[1] Base[0]
   ;move to approach waypoint of picking
LIN pick_app Vel=1 m/s CPDAT2 Tool[1] Base[0]
   ;move to picking waypoint
LIN pick_point Vel=0.3 m/s CPDAT3 Tool[1] Base[0]
   ;add object grasping logic here, such as "$OUT[1]=TRUE"
   halt
   ;move to departure waypoint of picking
LIN pick_app Vel=1 m/s CPDAT2 Tool[1] Base[0]
   ;move to intermediate waypoint of placing
PTP drop_waypoint CONT Vel=100 % PDAT2 Tool[1] Base[0]
   ;move to approach waypoint of placing
LIN drop_app Vel=1 m/s CPDAT4 Tool[1] Base[0]
   ;move to placing waypoint
LIN drop Vel=0.3 m/s CPDAT5 Tool[1] Base[0]
   ;add object releasing logic here, such as "$OUT[1]=FALSE"
   halt
   ;move to departure waypoint of placing
LIN drop_app Vel=1 m/s CPDAT4 Tool[1] Base[0]
   ;move back to robot home position
PTP HOME Vel=100 % DEFAULT
END

The workflow corresponding to the above example program code is shown in the figure below.

sample17

The table below describes the feature of parsing labels. You can click the hyperlink to the command name to view its detailed description.

Feature Code and description

Parse labels as label_1 and label_2

;parse label info received from Mech-Vision, eg. "label=56" will decompose into 5 and 6
label_1=label / 10;           !label_1=5
label_2=label - label_1*10;   !label_2=6

The MM_Get_Pose command stores the TCP, label and tool ID of the vision point in the Xpick_point, label, and toolid variables respectively. In this example, the label variable is set to 56, "label / 10" stands for the quotient of the label value divided by 10 (i.e., 5), and "label - label_1*10" stands for the remainder of the label value divided by 10 (i.e., 6). In this way, the label is parsed into label_1 and label_2 (i.e., 56 into 5 and 6).

Adopt a handling method based on the label parsing result

;add handling logic according to decomposed label value
IF label_1==5 THEN
   ;add handling logic a
   halt
ELSE
   ;add handling logic b
   halt
ENDIF

The above code indicates that if label_1 is 5, logic a will be executed; otherwise, logic b will be executed. The handling method varies based on the parsed label result. You can adopt a handling method based on your business requirement.

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.