Example Program 12: MM_S12_Viz_ForLoop

Program Introduction

Description

The robot triggers the Mech-Viz project to run, obtains the planned path, and then stores the planned path by looping for 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/FANUC/sample/MM_S12_Viz_ForLoop path.

Project

Mech-Vision and Mech-Viz projects

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_S12_Viz_ForLoop example program.

The MM_S12_Viz_ForLoop example program is similar to the MM_S2_Viz_Basic example program, except that MM_S2_Viz_Basic stores waypoints one by one and MM_S12_Viz_ForLoop stores waypoints by looping (the code of this feature is bolded). As such, the features of MM_S12_Viz_ForLoop that are similar to those of MM_S2_Viz_Basic are not described in this part. For more information about these features, see Example Program 2: MM_S2_Viz_Basic.
   1:  !-------------------------------- ;
   2:  !FUNCTION: trigger Mech-Viz ;
   3:  !project and get planned path, ;
   4:  !get poses using for-loop ;
   5:  !structure ;
   6:  !Mech-Mind, 2023-12-25 ;
   7:  !-------------------------------- ;
   8:   ;
   9:  !set current uframe NO. to 0 ;
  10:  UFRAME_NUM=0 ;
  11:  !set current tool NO. to 1 ;
  12:  UTOOL_NUM=1 ;
  13:  !move to robot home position ;
  14:J P[1] 100% FINE    ;
  15:  !initialize communication ;
  16:  !parameters(initialization is ;
  17:  !required only once) ;
  18:  CALL MM_INIT_SKT('8','127.0.0.1',50000,5) ;
  19:  !move to image-capturing position ;
  20:L P[2] 1000mm/sec FINE    ;
  21:  !trigger Mech-Viz project ;
  22:  CALL MM_START_VIZ(2,10) ;
  23:  !get planned path, 1st argument ;
  24:  !(1) means getting pose in JPs ;
  25:  CALL MM_GET_VIZ(1,51,52,53) ;
  26:  !check whether planned path has ;
  27:  !been got from Mech-Viz ;
  28:  !successfully ;
  29:  IF R[53]<>2100,JMP LBL[99] ;
  30:  !save waypoints of the planned ;
  31:  !path to local variables using ;
  32:  !for-loop structure ;
  33:  FOR R[100]=1 TO R[51] ;
  34:  R[101]=59+R[100]    ;
  35:  R[102]=69+R[100]    ;
  36:  R[103]=79+R[100]    ;
  37:  CALL MM_GET_JPS(R[100],R[101],R[102],R[103]) ;
  38:  ENDFOR ;
  39:  !follow the planned path to pick, ;
  40:  !in this example waypoint 2 ;
  41:  !(PR[61]) is picking waypoint ;
  42:  !move to approach waypoint ;
  43:  !of picking ;
  44:J PR[60] 50% FINE    ;
  45:  !move to picking waypoint ;
  46:J PR[61] 10% FINE    ;
  47:  !add object grasping logic here, ;
  48:  !such as "DO[1]=ON" ;
  49:  PAUSE ;
  50:  !move to departure waypoint ;
  51:  !of picking ;
  52:J PR[62] 50% FINE    ;
  53:  !move to intermediate waypoint ;
  54:  !of placing ;
  55:J P[3] 50% CNT100    ;
  56:  !move to approach waypoint ;
  57:  !of placing ;
  58:L P[4] 1000mm/sec FINE Tool_Offset,PR[2]    ;
  59:  !move to placing waypoint ;
  60:L P[4] 300mm/sec FINE    ;
  61:  !add object releasing logic here, ;
  62:  !such as "DO[1]=OFF" ;
  63:  PAUSE ;
  64:  !move to departure waypoint ;
  65:  !of placing ;
  66:L P[4] 1000mm/sec FINE Tool_Offset,PR[2]    ;
  67:  !move back to robot home position ;
  68:J P[1] 100% FINE    ;
  69:  END ;
  70:   ;
  71:  LBL[99:vision error] ;
  72:  !add error handling logic here ;
  73:  !according to different ;
  74:  !error codes ;
  75:  !e.g.: status=2038 means no ;
  76:  !point cloud in ROI ;
  77:  PAUSE ;

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

sample12

The table below describes the feature of storing the planed path in waypoints by looping. You can click the hyperlink to the command name to view its detailed description.

Feature Code and description

Store the planned path by looping

  32:  !for-loop structure ;
  33:  FOR R[100]=1 TO R[51] ;
  34:  R[101]=59+R[100]    ;
  35:  R[102]=69+R[100]    ;
  36:  R[103]=79+R[100]    ;
  37:  CALL MM_GET_JPS(R[100],R[101],R[102],R[103]) ;
  38:  ENDFOR ;
  • Line 33: FOR indicates the start of a loop segment. R[100] is used to control the number of iterations (beginning at 1, R[100] increments by 1 after each iteration until it surpasses the value set in R[51], at which point the loop ends). R[51] is the numeric register indicated by the second parameter in the MM_GET_VIZ command. The numeric register stores the number of waypoints that are returned by the vision system. As such, R[100] can indicate the position ID of the current waypoint in the planned path.

  • Lines 34 to 36: R[101], R[102], and R[103] represent the registers used for the joint positions, label, and tool ID that correspond to the current waypoint, respectively.

  • Line 37: The MM_Get_Jps command stores the joint positions, label, and tool ID of a specific waypoint in the specific registers. The entire command stores the joint positions, label, and tool ID of the waypoint with an ID of the R[100] value in the R[101], R[102], and R[103] registers respectively.

Assuming that the path planned in this example program contains three waypoints, the above for loop is equivalent to the following three commands in the MM_S2_Viz_Basic example program:

  CALL MM_GET_JPS(1,60,70,80) ;
  CALL MM_GET_JPS(2,61,71,81) ;
  CALL MM_GET_JPS(3,62,72,82) ;

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.