样例程序12:MM_S12_Viz_ForLoop
程序解读
以下为MM_S12_Viz_ForLoop样例程序的代码及相关解释说明。
MM_S2_Viz_Basic是逐个转存规划的路径点,本样例是通过循环转存规划的路径点(加粗部分的代码)。因此,下文不再重复解释与MM_S2_Viz_Basic样例相同部分的代码(详情请参考MM_S2_Viz_Basic样例说明)。 |
NOP
'--------------------------------
'FUNCTION: trigger Mech-Viz
'project and get planned path,get
'poses using for-loop structure
'Mech-Mind, 2023-12-25
'--------------------------------
'clear I50 to I69
CLEAR I050 20
'initialize p variables
SUB P071 P071
SUB P072 P072
SUB P073 P073
'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.170.22;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
'(1) means getting pose in JPs
CALL JOB:MM_GET_VIZDATA ARGF"1;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
'save waypoints of planned path
'to local variables using
'for-loop structure
SET I001 1
SET I002 71
SET I003 61
SET I004 81
*CYCLE
VAL2STR S001 I001
VAL2STR S002 I002
VAL2STR S003 I003
VAL2STR S004 I004
CHR$ S005 59
CAT$ S000 S001 S005
CAT$ S000 S000 S002
CAT$ S000 S000 S005
CAT$ S000 S000 S003
CAT$ S000 S000 S005
CAT$ S000 S000 S004
CALL JOB:MM_GET_JPS ARGFS000
INC I001
INC I002
INC I003
INC I004
IFTHENEXP I001⇐I051
JUMP *CYCLE
ENDIF
'follow the planned path to pick
'move to approach waypoint of
'picking
MOVJ P071 VJ=50.00 PL=0
'move to picking waypoint
MOVJ P072 VJ=10.00 PL=0
'add object grasping logic here,
'such as DOUT OT#(1) ON
PAUSE
'move to departure waypoint of
'picking
MOVJ P073 VJ=50.00 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
PAUSE
'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
上述样例程序代码对应的流程如下图所示。
下表为通过循环转存规划路径的逻辑解读。用户单击指令名称的超链接便可查看该指令的详细说明。
流程 | 代码及说明 |
---|---|
通过循环转存规划路径 |
SET指令类似于其他编程语言中的赋值语句,因此,上述代码表示将变量I001、I002、I003、I004分别赋值为1、71、61、81。
上述代码表示,程序循环执行“*CYCLE”与“JUMP *CYCLE”之间的代码。
VAL2STR指令表示将其他数据类型的变量转换为字符串变量。例如,若I001的变量值为整型1,则“VAL2STR S001 I001”表示将整型1转化为字符串"1",此时S001的变量值为"1"。因此,若整型变量I001、I002、I003、I004分别为1、71、61、81,则程序通过上述语句后,S001、S002、S003、S004分别为"1"、"71"、"61"、"81"。
上述语句表示将字符编码为59的字符“;”(英文分号)保存至S005。
CAT$指令类似于其他编程语言中的字符串拼接语句。例如,若S001为字符串"1",S005为字符串";",则“CAT$ S000 S001 S005”表示将"1"与";"拼接成"1;",然后赋值给S000,此时S000的变量值为"1;"。因此,程序执行完上述语句后,S000的变量值为"1;71;61;81"。
若S000的变量值为"1;71;61;81",则上述语句相当于“CALL JOB:MM_GET_JPS ARGF"1;71;61;81"”。
INC指令表示将指定变量的值加1。因此上述语句表示将I001、I002、I003、I004变量值分别自增1。
I001为循环次数。I051为MM_GET_VIZDATA指令中第二个参数所对应的变量,该变量表示视觉系统返回的路径点个数。 假设本样例规划的路径有3个路径点(抓取接近点、抓取点、抓取离开点,即I051为3),则上述循环等同于如下两条指令。
|