Example Program 7: MM_S7_Viz_SwitchTCP

Program Introduction

Description

The robot starts the Mech-Viz project, obtains the path planning result, and then changes the tool according to the tool ID of the picking waypoint 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/FANUC/sample/MM_S7_Viz_SwitchTCP 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_S7_Viz_SwitchTCP example program.

The only difference between the MM_S7_Viz_SwitchTCP example program and the MM_S2_Viz_Basic example program is that MM_S7_Viz_SwitchTCP can change the tool according to the tool ID(this code of this feature is bolded). As such, only the feature of handling errors based on the different error codes is described in the following part. For information about the parts of MM_S6_Viz_ErrorHandle that are consistent with those of MM_S2_Viz_Basic, see Example Program 2: MM_S2_Viz_Basic.
   1:  !-------------------------------- ;
   2:  !FUNCTION: trigger Mech-Viz ;
   3:  !project and get planned path, ;
   4:  !switch TCP according to ;
   5:  !the tool NO.;
   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:  !(2) means getting pose in TCP ;
  25:  CALL MM_GET_VIZ(2,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 one ;
  32:  !by one ;
  33:  CALL MM_GET_POS(1,60,70,80) ;
  34:  CALL MM_GET_POS(2,61,71,81) ;
  35:  CALL MM_GET_POS(3,62,72,82) ;
  36:  !switch TCP according to the ;
  37:  !received tool NO. ;
  38:  IF R[81]=1,JMP LBL[1] ;
  39:  IF R[81]=2,JMP LBL[2] ;
  40:  JMP LBL[999] ;
  41:   ;
  42:  LBL[1:use tool NO.1] ;
  43:  !set current tool NO. to 1 ;
  44:  UTOOL_NUM=1 ;
  45:  !reset tool signal ;
  46:  !DO[1]=OFF ;
  47:  !set a Flag ;
  48:  F[1]=(ON) ;
  49:  JMP LBL[3] ;
  50:   ;
  51:  LBL[2:use tool NO.2] ;
  52:  !set current tool NO. to 2 ;
  53:  UTOOL_NUM=2 ;
  54:  !reset tool signal ;
  55:  !DO[2]=OFF ;
  56:  !set a Flag ;
  57:  F[2]=(ON) ;
  58:  JMP LBL[3] ;
  59:   ;
  60:  LBL[3:pick path] ;
  61:  !follow the planned path to pick ;
  62:  !move to approach waypoint ;
  63:  !of picking ;
  64:L PR[60] 1000mm/sec FINE    ;
  65:  !move to picking waypoint ;
  66:L PR[61] 300mm/sec FINE    ;
  67:  !add object grasping logic here, ;
  68:  !IF (F[1]),DO[1]=(ON) ;
  69:  !IF (F[2]),DO[2]=(ON) ;
  70:  PAUSE ;
  71:  !move to departure waypoint ;
  72:  !of picking ;
  73:L PR[62] 1000mm/sec FINE    ;
  74:  !move to intermediate waypoint ;
  75:  !of placing ;
  76:J P[3] 50% CNT100    ;
  77:  !move to approach waypoint ;
  78:  !of placing ;
  79:L P[4] 1000mm/sec FINE Tool_Offset,PR[2]    ;
  80:  !move to placing waypoint ;
  81:L P[4] 300mm/sec FINE    ;
  82:  !add object releasing logic here, ;
  83:  !IF (F[1]),DO[1]=(OFF) ;
  84:  !IF (F[2]),DO[2]=(OFF) ;
  85:  PAUSE ;
  86:  !move to departure waypoint ;
  87:  !of placing ;
  88:L P[4] 1000mm/sec FINE Tool_Offset,PR[2]    ;
  89:  !move back to robot home position ;
  90:J P[1] 100% FINE    ;
  91:  !reset the Flags ;
  92:  F[1]=(OFF) ;
  93:  F[2]=(OFF) ;
  94:  END ;
  95:   ;
  96:  LBL[99:vision error] ;
  97:  !add error handling logic here ;
  98:  !according to different ;
  99:  !error codes ;
 100:  !e.g.: status=2038 means no ;
 101:  !point cloud in ROI ;
 102:  PAUSE ;
 103:   ;
 104:  LBL[999:label error] ;
 105:  !add handling logic here if the ;
 106:  !label is invalid ;
 107:  PAUSE ;

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

sample7

The table below describes the bolded code.

Feature Code and description

Obtain the planned path

  21:  !get planned path, 1st argument ;
  22:  !(1) means getting pose in JPs ;
  23:  CALL MM_GET_VIZ(2,51,52,53) ;
  • MM_GET_VIZ: The command to obtain the path planned by Mech-Viz.

  • 2: The pose type of the obtained waypoint is set to TCP.

  • 51: The numeric register R[51], which stores the number of waypoints returned by the vision system.

  • 52: The numeric register R[52], which stores the position of the Vision Move waypoint (picking waypoint) in the path.

  • 53: The numeric register R[53], which stores the command execution status code.

The entire statement indicates that the robot obtains the planned path from the Mech-Viz project.

The returned planned path is saved to the robot memory and cannot be directly obtained. To access the planned path, you must store the planned path in a subsequent step.

Store the planned path

  28:  !save waypoints of the planned ;
  29:  !path to local variables one ;
  30:  !by one ;
  31:  CALL MM_GET_POS(1,60,70,80) ;
  32:  CALL MM_GET_POS(2,61,71,81) ;
  33:  CALL MM_GET_POS(3,62,72,82) ;
  • MM_GET_POS: The command to store the planned path.

  • 1: Store the first waypoint.

  • 60: The position register PR[60], which stores the TCP of the first waypoint.

  • 70: The numeric register R[70], which stores the label of the first waypoint.

  • 80: The numeric register R[80], which stores the tool ID of the first waypoint.

The entire command “CALL MM_GET_JPS(1,60,70,80)” stores the TCP, label, and tool ID of the first waypoint in the specified registers.

  • Please store the planned path based on the actual Mech-Viz project. In this example, the path planned by Mech-Viz consists of three waypoints: the first waypoint is the approach waypoint of picking (PR[60]), the second waypoint is the picking waypoint (PR[61]), and the third waypoint is the departure waypoint of picking (PR[62]). R[81] specifies the ID of the tool used by the robot when the robot moves to the picking waypoint (PR[61]).

  • This example program will change the tool ID based on the R[81] value. As such, the Mech-Viz project used must include a Change Tool Step and the parameters of the Change Tool Step must be properly set.

    • The Change Tool Step must be connected to the Has results output port of the Check Vision Result Step.

    • The Operation Mode parameter of the Change Tool Step must be set to Auto-switch to appropriate tool.

Change the tool based on the tool ID

  36:  !switch TCP according to the ;
  37:  !received tool NO. ;
  38:  IF R[81]=1,JMP LBL[1] ;
  39:  IF R[81]=2,JMP LBL[2] ;
  40:  JMP LBL[999] ;
  41:   ;
  42:  LBL[1:use tool NO.1] ;
  43:  !set current tool NO. to 1 ;
  44:  UTOOL_NUM=1 ;
  45:  !reset tool signal ;
  46:  !DO[1]=OFF ;
  47:  !set a Flag ;
  48:  F[1]=(ON) ;
  49:  JMP LBL[3] ;
  50:   ;
  51:  LBL[2:use tool NO.2] ;
  52:  !set current tool NO. to 2 ;
  53:  UTOOL_NUM=2 ;
  54:  !reset tool signal ;
  55:  !DO[2]=OFF ;
  56:  !set a Flag ;
  57:  F[2]=(ON) ;
  58:  JMP LBL[3] ;
  ...
  60:  LBL[3:pick path] ;
  ...
  67:  !add object grasping logic here, ;
  68:  !IF (F[1]),DO[1]=(ON) ;
  69:  !IF (F[2]),DO[2]=(ON) ;
  ...
  82:  !add object releasing logic here, ;
  83:  !IF (F[1]),DO[1]=(OFF) ;
  84:  !IF (F[2]),DO[2]=(OFF) ;
  ...
  91:  !reset the Flags ;
  92:  F[1]=(OFF) ;
  93:  F[2]=(OFF) ;
  94:  END ;

You can determine the tool to be used when the robot moves to the picking waypoint based on the value set in the R[81] register. The description of the above code is shown below.

  • If the tool ID at the picking waypoint is 1 (JMP LBL[1]), the robot utilizes the tool corresponding to No.1 tool reference frame (UTOOL_NUM=1) for the picking operation.

  • If the tool ID at the picking waypoint is 2 (JMP LBL[2]), the robot utilizes the tool corresponding to No.2 tool reference frame (UTOOL_NUM=2) for the picking operation.

  • If the tool ID at the picking waypoint is another value (JMP LBL[999]), the robot will stop. You can add other code according to the actual situation.

If the robot controls tool 1 with the DO[1] signal and tool 2 with the DO[2] signal, the program must also establish their relationships using flags F[1] and F[2] respectively.

  • If F[1] is set to ON, the robot controls the DO[1] signal to perform picking and placing.

  • If F[2] is set to ON, the robot controls the DO[2] signal to perform picking and placing.

In the following example, No.1 tool ID is used to describe the pick-and-place operation.

  1. Switch the tool reference frame to 1 (UTOOL_NUM=1).

  2. Reset the DO signal that controls No.1 tool ID (DO[1]=OFF).

  3. Set F[1] to ON (F[1]=(ON)), which indicates that the robot will control the DO[1] signal to perform picking and placing.

  4. When the robot moves to the picking waypoint and F[1] is set to ON, set DO[1] to ON to complete the picking operation.

  5. When the robot moves to the placing waypoint and F[1] is set to ON, set DO[1] to OFF to complete the placing operation.

  6. When the robot returns to the home position, reset F[1] to OFF to mark the DO signal ID the robot will use for the next pick-and-place operation.

The process for using No.2 tool ID is similar to the above, and will not be repeated here.

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.