样例程序7:MM_S7_Viz_SwitchTCP
程序解读
以下为MM_S7_Viz_SwitchTCP样例程序的代码及相关解释说明。
| 与MM_S2_Viz_Basic样例相比,本样例主要新增了根据末端工具编号切换工具的功能(加粗部分的代码)。因此,下文不再重复解释与MM_S2_Viz_Basic样例相同部分的代码(详情请参考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 ;上述样例程序代码对应的流程如下图所示。
 
下表为新增代码的逻辑解读。
| 流程 | 代码及说明 | ||
|---|---|---|---|
| 获取规划路径 | 
 因此,整条指令表示机器人获取Mech-Viz工程返回的规划路径。 
 | ||
| 转存规划路径 | 
 因此,“CALL MM_GET_POS(1,60,70,80)”整条指令表示将第一个路径点的工具位姿、标签和末端工具编号分别转存至指定寄存器。 
 | ||
| 根据末端工具编号切换末端工具 | 用户可根据R[81]寄存器值,决定机器人移动到抓取点时所使用的末端工具。上述代码的逻辑说明如下所示。 
 假设机器人通过DO[1]信号控制末端工具1,通过DO[2]信号控制末端工具2,则程序还需通过F[1]与F[2]两个标志分别建立两者关系。 
 接下来以末端工具编号1为例,讲解具体抓放流程。 
 机器人使用末端工具编号2的流程与上述流程类似,此处不再赘述。 |