Example Program 10: MM_S10_Viz_Subtask
Program Introduction
Description |
This example program consists of two programs: a main program and a sub program. The sub program (background program) triggers the Mech-Viz project to run to obtain the planned path. The main program (the foreground program) moves the robot based on the planned path. Then, the main program triggers the sub program to run when the robot leaves the picking area to obtain the next planned path, shortening the cycle time.
|
||
File path |
Sub program: You can navigate to the installation directory of Mech-Vision and Mech-Viz and find the file by using the Main program: 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 |
|
|
Program Description
The following part describes the sub program.
Similar to the MM_S2_Viz_Basic example program, the sub program triggers the Mech-Viz project to run and obtains the planned path code. As such, the features of the sub program that are similar to those of MM_S2_Viz_Basic are not described in this part. For more information about these features, see Example Program 2: MM_S2_Viz_Basic. |
DEF MM_S10_Sub ( )
;---------------------------------------------------
; FUNCTION: run Mech-Viz project and get planned
; path in subtask (run together with
; MM_S10_Viz_Subtask)
; Mech-Mind, 2023-12-25
;---------------------------------------------------
$OUT[2001]=FALSE
;initialize communication parameters (initialization is required only once)
MM_Init_Socket("XML_Kuka_MMIND",873,871,60)
LOOP
IF $OUT[2001]==TRUE THEN
;trigger Mech-Viz project
MM_Start_Viz(2,init_jps_b)
;get planned path, 1st argument (1) means getting pose in JPs
MM_Get_VizData(1,pos_num_b,vis_pos_num_b,status_b)
;check whether planned path has been got from Mech-Viz successfully
IF status_b==2100 THEN
;save waypoints of the planned path to local variables one by one
MM_Get_Jps(1,pick_point_b[1],label_b[1],toolid_b[1])
MM_Get_Jps(2,pick_point_b[2],label_b[2],toolid_b[2])
MM_Get_Jps(3,pick_point_b[3],label_b[3],toolid_b[3])
ENDIF
$OUT[2001]=FALSE
ENDIF
ENDLOOP
END
The above code shows that the sub program sets $OUT[2001] to FALSE, initializes the communication parameters, and then continuously listens to the value of $OUT[2001] through a loop.
-
When $OUT[2001] is set to TRUE, the sub program triggers the Mech-Viz project to run, obtains the planned path, and then sets $OUT[2001] to FALSE.
-
When $OUT[2001] is set to FALSE, the sub program continuously listens to the value of $OUT[2001].
The following part describes the main program.
Similar to the MM_S2_Viz_Basic example program, the main program performs picking and placing based on the planned path code. As such, the features of the sub program that are similar to those of MM_S2_Viz_Basic are not described in this part. For more information about these features, see Example Program 2: MM_S2_Viz_Basic. |
DEF MM_S10_Viz_Subtask ( )
;---------------------------------------------------
; FUNCTION: run Mech-Viz project and get planned
; path in subtask (run together with MM_S10_Sub)
; Mech-Mind, 2023-12-25
;---------------------------------------------------
;set current tool no. to 1
BAS(#TOOL,1)
;set current base no. to 0
BAS(#BASE,0)
;move to robot home position
PTP HOME Vel=100 % DEFAULT
;trigger Mech-Viz project and get planned path
$OUT[2001]=TRUE
LOOP
;move to wait position for picking
LIN pick_wait_point Vel=1 m/s CPDAT6 Tool[1] Base[0]
;wait until subtask program finished
WAIT FOR ($OUT[2001]==FALSE)
;check whether planned path has been got from Mech-Viz successfully
IF status_b<> 2100 THEN
;add error handling logic here according to different error codes
;e.g.: status=2038 means no point cloud in ROI
halt
ENDIF
;save waypoints of the planned path to jps variables one by one
Xpick_point1=pick_point_b[1]
Xpick_point2=pick_point_b[2]
Xpick_point3=pick_point_b[3]
;follow the planned path to pick
;move to approach waypoint of picking
PTP pick_point1 Vel=50 % PDAT1 Tool[1] Base[0]
;move to picking waypoint
PTP pick_point2 Vel=10 % PDAT2 Tool[1] Base[0]
;add object grasping logic here, such as "$OUT[1]=TRUE"
halt
;move to departure waypoint of picking
PTP pick_point3 Vel=50 % PDAT3 Tool[1] Base[0]
;trigger Mech-Viz project and get planned path in advance
TRIGGER WHEN DISTANCE = 1 DELAY = 0 DO $OUT[2001]=TRUE
;move to intermediate waypoint of placing
PTP drop_waypoint CONT Vel=100 % PDAT2 Tool[1] Base[0]
;move to approach waypoint of placing
LIN drop_app Vel=1 m/s CPDAT3 Tool[1] Base[0]
;move to placing waypoint
LIN drop Vel=0.3 m/s CPDAT4 Tool[1] Base[0]
;add object releasing logic here, such as "$OUT[1]=FALSE"
halt
;move to departure waypoint of placing
LIN drop_app Vel=1 m/s CPDAT3 Tool[1] Base[0]
;move back to robot home position
PTP HOME Vel=100 % DEFAULT
ENDLOOP
END
The workflow corresponding to the above example program code is shown in the figure below.

The table below illustrates the core code of the main program.
Workflow | Code and description | ||
---|---|---|---|
Trigger the Mech-Viz project to run and obtain the planned path |
The above code indicates that the main program sets $OUT[2001] to TRUE. In this case, the sub program detects the value of $OUT[2001] to be TRUE. Then, the sub program triggers the Mech-Viz project to run and obtains the planned path. |
||
Plan the next path in advance by looping (picking→triggering the next round of path planning→placing) |
The above code indicates that the main program loops through the code between LOOP and ENDLOOP.
In the above example, the robot moves to a waiting waypoint before picking and waits for the sub program to obtain and store the planned path (i.e., $OUT[2001] changes from TRUE to FALSE).
In the above example, the planned path (pick_point_b[1], pick_point_b[2], and pick_point_b[3]) obtained by the sub program will be stored in Xpick_point1, Xpick_point2, and Xpick_point3.
In the above example, the robot moves along the planned path to the approach waypoint of picking (pick_point1) and then to the picking waypoint (pick_point2), performs picking (for example, $OUT[1]=TRUE), and then moves to the departure waypoint of picking (pick_point3).
The above code indicates that when the robot approaches the target point (drop_waypoint, the intermediate waypoint during placing), the robot calls $OUT[2001] = TRUE. This command means that the sub program triggers the Mech-Viz project to run again and obtain the planned path. Now that the robot resides outside the area for placing, the robot can plan the next picking path in advance without waiting for the placing to complete and then planning the next picking path.
The above example indicates that the robot moves to the intermediate waypoint of placing (drop_waypoint) the approach waypoint of placing (drop_app), and then the placing waypoint (drop), performs placing (such as $OUT[1]=FALSE), and then moves to the departure waypoint of placing (drop_app) and then the home position. |