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 |
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, only the feature of storing waypoints by looping is described in the following section. For information about the parts of MM_S12_Viz_ForLoop that are consistent with those of MM_S2_Viz_Basic, see Example Program 2: 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
The workflow corresponding to the above example program code is shown in the figure below.
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 |
The SET command is similar to an assignment statement in other programming languages. The above code indicates that variables I001, I002, I003, and I004 are assigned the values 1, 71, 61, and 81, respectively.
The above code indicates that the program loops through the code between “*CYCLE” and “JUMP *CYCLE”.
The VAL2STR command converts variables of other data types into string variables. For example, if the variable I001 has an integer value of 1, then "VAL2STR S001 I001" converts the integer 1 into the string "1", making the value of S001 "1". If the integer variables I001, I002, I003, and I004 are set to 1, 71, 61, and 81 respectively, after executing the above commands, the values of S001, S002, S003, and S004 will be "1", "71", "61", and "81", respectively.
The above statement indicates that the character with the encoding of 59, which is the semicolon (";"), is stored in S005.
The CAT$ instruction is similar to a string concatenation statement in other programming languages. For example, if S001 is the string "1" and S005 is the string ";", then "CAT$ S000 S001 S005" concatenates "1" and ";" into "1;" and assigns it to S000, making the value of S000 "1;". After executing the above commands, the value of S000 will be "1;71;61;81".
If S000 is set to "1;71;61;81", the above statement is equivalent to “CALL JOB:MM_GET_JPS ARGF"1;71;61;81"”.
The INC command increases the value of a specified variable by 1. The above statement means that the values of the variables I001, I002, I003, and I004 are each incremented by 1.
I001 represents the number of iterations. I051 is the variable corresponding to the second parameter in the MM_GET_VIZDATA command. This variable represents the number of waypoints returned by the vision system. Suppose the planned path in this example has 3 waypoints (approach waypoint of picking, picking waypoint, and departure waypoint of picking). In this case, I051 is set to 3 and the above loop is equivalent to the following two commands.
|