サンプルプログラム7:MM_S7_Viz_SwitchTCP
プログラム概要
| 機能 | ロボットはMech-Vizプロジェクトをトリガーして実行し、計画された経路を取得します。その後、把持点のロボットハンド番号に基づいて対応するロボットハンドを切り替え、把持および配置を実行します。 | 
| ファイル場所 | Mech-VisionとMech-Vizソフトウェアのインストールディレクトリにある  | 
| 必要なプロジェクト | Mech-VisionとMech-Vizプロジェクト | 
| 使用前提 | 
 | 
| 
 | 
プログラム説明
以下はMM_S7_Viz_SwitchTCPサンプルプログラムのコードと関連する説明です。
| このサンプルは、MM_S2_Viz_Basicサンプルに比べて、ロボットハンド番号に基づいてロボットハンドを切り替える機能(太字部分のコード)のみが追加されています。そのため、MM_S2_Viz_Basicサンプルと同じ部分のコードについては、以下で再度説明することはありません(詳細は MM_S2_Viz_Basicサンプルの説明 をご参照ください)。 | 
NOP
'--------------------------------
'FUNCTION: trigger Mech-Viz
'project and get planned path,
'switch TCP according to the
'toolId
'Mech-Mind, 2023-12-25
'--------------------------------
'clear I50 to I69
CLEAR I050 20
'initialize p variables
SUB P081 P081
SUB P082 P082
SUB P083 P083
'move to robot home position
MOVJ C00000 VJ=50.00
'initialize communication
'parameters (initialization is
'required only once)
CALL JOB:MM_INIT_SOCKET ARGF"192.168.10.40;50000;1"
'move to image-capturing position
MOVJ C00001 VJ=50.00 PL=0
'open socket connection
CALL JOB:MM_OPEN_SOCKET
'trigger Mech-Viz project
CALL JOB:MM_START_VIZ ARGF"2;30"
'get planned path, 1st argument
'(2) means getting pose in Pose
CALL JOB:MM_GET_VIZDATA ARGF"2;51;52;53"
'check whether planned path has
'been got from Mech-Viz
'successfully
IFTHENEXP I053<>2100
	'add error handling logic here
	'according to different error
	'codes
	'e.g.: I053=2038 means no
	'point cloud in ROI
	 PAUSE
ENDIF
'close socket connection
CALL JOB:MM_CLOSE_SOCKET
'switch TCP according to the
'toolId
'save waypoints of the planned
'path to local variables one
'by one
CALL JOB:MM_GET_POSE ARGF"1;81;61;62"
CALL JOB:MM_GET_POSE ARGF"2;82;63;64"
CALL JOB:MM_GET_POSE ARGF"3;83;65;66"
'reset tool signals according
'to received toolid
SWITCH I064 CASE 1
	'reset tool signal
	'SETE P081 TL#(0)
	'SETE P082 TL#(0)
	'SETE P083 TL#(0)
	 PAUSE
CASE 2
	'reset tool signal
	'SETE P081 TL#(1)
	'SETE P082 TL#(1)
	'SETE P083 TL#(1)
	 PAUSE
DEFAULT
	'reset tool signal
	 PAUSE
ENDSWITCH
'follow the planned path to pick
'move to approach waypoint of
'picking
MOVL P081 V=166.6 PL=0
'move to picking waypoint
MOVL P082 V=50.0 PL=0
'add object grasping logic here,
'such as DOUT OT#(1) ON
SWITCH I064 CASE 1
	'open tool signal
	 PAUSE
CASE 2
	'open tool signal
	 PAUSE
DEFAULT
	'open tool signal
	 PAUSE
ENDSWITCH
'move to departure waypoint of
'picking
MOVL P083 V=166.6 PL=0
'move to intermediate waypoint of
'placing
MOVJ C00002 VJ=50.00
'move to approach waypoint of
'placing
MOVL C00003 V=166.6 PL=0
'move to placing waypoint
MOVL C00004 V=50.0 PL=0
'add object releasing logic here,
'such as DOUT OT#(1) OFF
'reset tool signals according
'to received toolid
SWITCH I064 CASE 1
	'reset tool signal
	 PAUSE
CASE 2
	'reset tool signal
	 PAUSE
DEFAULT
	'reset tool signal
	 PAUSE
ENDSWITCH
'move to departure waypoint of
'placing
MOVL C00005 V=166.6 PL=0
'move back to robot home position
MOVJ C00006 VJ=50.00
END上記のサンプルプログラムの処理流れは、下図の通りです。
 
下表は追加されたコードとその説明です。
| 処理流れ | コートと説明 | ||
|---|---|---|---|
| 計画された経路を取得 | 
 このコマンドは、ロボットがMech-Vizプロジェクトから返された計画経路を取得することを意味します。 
 | ||
| 計画された経路を保存 | 
 「CALL JOB:MM_GET_POSE ARGF"1;81;61;62」コマンドは、最初の経路点のツール位置姿勢、ラベル、およびロボットハンド番号をそれぞれ指定された変数に保存することを意味します。 
 | ||
| ロボットハンド番号に基づいてロボットハンドを切り替える | 
 上記のコードは、I064の値に基づいて、ロボットが対応する姿勢(把持点)に移動する際に使用するロボットハンドを決定できることを意味します。つまり、ロボットハンド番号に基づいてロボットハンドを切り替えることができます。 ロボットが把持点に移動する際、ロボットハンド番号に基づき、対応するロボットハンドのDO信号をオンにすることができます。例えば、以下はサンプルコードの一例です。 ロボットが配置点に移動する際、ロボットハンド番号に基づき、対応するロボットハンド番号のDO信号をオフにし、リセットすることができます。例えば、以下はサンプルコードの一例です。  |